Page 1 of 1

ZSCRIPT newbie help

PostPosted: Mon Sep 25, 2017 11:02 am
by ramon.dexter
Hi, salutes!

You already know me, so I'll make it quick. I've noticed that the ZSCRIPT thing is alive, and since I'm little bit skilled in decorate and ACS, I wanted to learn that thing. But wow, it look superb complicated, all those classes, thinker, iterators...too much stuff too learn. And all the introductions are too bit of not explaing to me :cry: So, would anyone lend me a hand and tech me the zcsript magic? Basically, all I need to be explained is, what to do with the stuff. Like...the documentation is little bit not existent, so learning and trying anything is hard for me.

So, would anyone help me learn zcsipt on some of my code examples?

Here is a code example. It's a night vision power-up, that could be activated and then de-activated. While active, it eats another inventory item (could be ammo, also). Since decorate of inventory items does not allow loops, I used a ACS to do the rest (check is batteries are present; if yes, it starts it's job until stopped manually or until batteries are depleted). It worsk well, but since ZCSRIPT is alive, I would like to convert it to it, so I can learn the zscript, and also so the code will be better and more fluid.

decorate (the batteries are not included, because, well...they are not crucial for this):
Code: Select allExpand view
//Night-Eye Device
//==--------------------------------------------------------------------------==
//Inventory Item
//==--------------------------------------------------------------------------==
actor NightEyeDevice : CustomInventory 23048
{
   //$Category "SoA/items"
   //$Color 1
   //$Title "Night-Eye Device"

   //flags
   //==--------------------------
   -Solid
   +invbar
   +inventory.AlwaysPickup
   //==--------------------------
   //dimensions
   //==--------------------------
   radius 8
   height 24
   scale 0.5
   //==--------------------------
   //inventory conf
   //==--------------------------
   Tag "$T_NGHTEYE"
   inventory.icon "I_NEDV"
   inventory.amount 1
   inventory.maxamount 2
   inventory.interhubamount 2
   inventory.PickupMessage "$NGHTEYEFND"
   //==--------------------------
   States
   {
      Spawn:
         NEDV V -1
         Stop

      Use:
         TNT1 A 0 A_JumpIfInventory("lanternActiveToken", 1, "turnOff")
         TNT1 A 0 A_JumpIfInventory("energyCell", 1, "turnOn")
         TNT1 A 0 A_Print("\c[red]NOT ENOUGH ENERGY CELLS!", 0, "smallfont")
         TNT1 A 0 A_Giveinventory("NightEyeDevice", 1)   
         Stop
      
      turnOn:         
         TNT1 A 0 A_Print("\c[green]Night-Eye Module Activated!", 0, "smallfont")         
         TNT1 A 0 A_Giveinventory("lanternActiveToken", 1)
         TNT1 A 0 A_Giveinventory("LanternActive", 1)
         TNT1 A 0 A_Giveinventory("NightEyeDevice", 1)
         TNT1 A 0 ACS_NamedExecute("nightEyeDrain", 0)
         Stop
         
      turnOff:
         TNT1 A 0 A_Print("\c[green]Night-Eye Module Deactivated!", 0, "smallfont")
         TNT1 A 0 A_Takeinventory("PowerLantern")
         TNT1 A 0 A_Takeinventory("LanternActive")
         TNT1 A 0 A_Takeinventory("lanternActiveToken", 1)
         TNT1 A 0 A_Giveinventory("NightEyeDevice", 1)
         TNT1 A 0 ACS_NamedTerminate("nightEyeDrain", 0)
         Stop
   }

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
actor PowerLantern : PowerTorch //PowerLightAmp
{
   powerup.Duration 0x7FFFFFFD
   //inventory conf
   //==--------------------------
   Inventory.Icon "A_NEDV"
   //==--------------------------
}

actor LanternActive : PowerupGiver
{
   //flags
   //==--------------------------
   +INVENTORY.AUTOACTIVATE
   +INVENTORY.FANCYPICKUPSOUND
   //==--------------------------
   //powerup conf
   //==--------------------------
   powerup.Duration 0x7FFFFFFD
   powerup.Type "Lantern"
   //==--------------------------
   //inventory conf
   //==--------------------------
   Inventory.MaxAmount 1
   Inventory.UseSound "pickups/slowmo"
   //==--------------------------
   States
   {
      Spawn:
         TNT1 A 0
         Stop
   }

}

actor lanternActiveToken : inventory
{
   Inventory.MaxAmount 1
}


//==--------------------------------------------------------------------------==
//


and supporting ACS:
Code: Select allExpand view
script "nightEyeDrain" (void)
{
   while(CheckActorInventory(1337, "EnergyCell") > 1)
   {      
      TakeActorInventory(1337, "EnergyCell", 1);
      Delay(70);
   }
   Print(s:"Energy Cells drained out!");
   TakeActorInventory(1337, "PowerLantern", 1);
   TakeActorInventory(1337, "LanternActive", 1);
   TakeActorInventory(1337, "lanternActiveToken", 1);
   Terminate;
}

Re: ZSCRIPT newbie help

PostPosted: Mon Sep 25, 2017 1:07 pm
by Matt
Since decorate of inventory items does not allow loops, I used a ACS to do the rest (check is batteries are present; if yes, it starts it's job until stopped manually or until batteries are depleted). It worsk well, but since ZCSRIPT is alive, I would like to convert it to it, so I can learn the zscript, and also so the code will be better and more fluid.

If that's the only thing keeping you from switching everything to ZScript then DoEffect can replace it.

3.1.0 has a bug that can lead to a desync with DoEffect, however, in which it is called during player prediction as well as each tick, so if you're changing any variables, etc. in there you might want to stick the relevant code into Tick until next release:
Code: Select allExpand view
override void Tick()
{
    super.Tick();
    if(owner)
    {
        //insert all the code you would normally put into DoEffect()
    }


For a full example of a working toggleable lite-amp done entirely in ZScript here's the one from HD.

Re: ZSCRIPT newbie help

PostPosted: Tue Sep 26, 2017 1:56 am
by ramon.dexter
Thank you vaecrius. I will try to look into it.

But as I looked into the HD code, I have a question: Does this example you provided draws energy over time, or it only checks for energy on activation? Sorry to ask, but the code is not commented and without comments, it's hard to understand.

Re: ZSCRIPT newbie help

PostPosted: Tue Sep 26, 2017 4:38 pm
by Matt
Only over time while the "worn" variable is true. The references to the "spent" variable in the use state only concern recharging from the player's cell inventory.

DoEffect() is automatically constantly called while the inventory item is in possession of an owner.