Zscript Event Handler help?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Zscript Event Handler help?

Post by XASSASSINX »

Hello! I've been trying to introduce myself to Zscript for universal compability in a mod i'm making. I've read Jekyllgrim Zscript guide on GitHub and read some other things on the wiki and here. I got somewhat an idea of how it works, but, is there any other places or mods to reverse-engineer to help? The thing i want to do is every-time a monster dies, it summons (or not, decided by a customizable variable and the chance of it) a Exp Orb, after a X amount of this Exp you get some craftable items.

I also wanted to make it so that the higher the monster health that died, the more Exp he dropped.

I've got a bit of a clue on how to do this, but i'm still a bit confused on the formatting and some functions (A.K.A Event Handler usage and some other Flow Control things).

Any help or suggestions :D ?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

For the event handler, you can do something like this:
Spoiler:
And in MAPINFO:

Code: Select all

GameInfo
{
    AddEventHandlers = "ItemDropEventHandler"
}
As for the Exp Orbs giving craftable items after X amount of them have been picked up, you could make them CustomInventory items that simply check how much of them the player has and give an item based on that.

Edit: And here's an example of the Exp Orbs:
Spoiler:
Last edited by Jarewill on Thu Nov 26, 2020 4:15 pm, edited 1 time in total.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Oh! This is definetly fancier and simpler then ACS (And DECORATE obviously). Just one more thing, how do you integrate Cvar's with Zscript?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

There was some way to detect CVars, but I can't remember it.
However, I am using the GetCVar function and it works fine for me.

Edit: I made a mistake with the ExpOrb item.
You should add the +INVENTORY.KEEPDEPLETED flag to it to prevent a VM abort.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Hm, interesting use of the Zscript. however, is there any technical problem making it on decorate? An item that (somehow, that's the only problem right now i'm thinking off) checks the amount you have of EXP, and wouldn't remove the total quantity. The reason to this is because i wanted to make the items you get with this EXP randomized on certain tiers. (I would use Token Items to see if you have them, as some of them would be one time craftable only).

Any comments?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

It could be possible to make an item like that in DECORATE, however is there any reason why ZScript can't be used here?
I don't think I quite understand how you want it to work though.
Something like this?
Spoiler:
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Kinda of. The reason as to why is of the Token Items, so the game can remember which items you gave. It's because i want to try to make a basic Tier System, so the in the first tier is that the first 3 items you will get when you level up will be randomized between them. Then Tier 2, 3 random items between them, and so on. I'm not sure who complicated this would be on Zscript (Albeit Zscript is a more fancier version of Decorate per say)
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

So something like this?
Spoiler:
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Yeah, kinda like that. The only thing i will add (or rather, you can if you want to) is whenever a item is given such as the plasma rifle, give a Token Item so the game does a quick check to see if you have that. I think you can make that in two lines or so in Zscript.

Oh, sidenote, i'm not sure if you made this intetionally, but on the Item Drop Handler code, if a monster has a health value which is not the same as the Int, it will split the item drops in smaller pickups. I'm pretty sure if you alter it so it doesn't subtract the Intenger, but rather change it to zero, it should "fix" this.

Just putting this little note in case anyone need this thread in a possible future :D

Code: Select all

 Else If(itemdrops>=1000){e.Thing.A_DropItem("Cell"); itemdrops-=1000;}
VVVVV Goes To VVVVVV

Code: Select all

 Else If(itemdrops>=1000){e.Thing.A_DropItem("Cell"); itemdrops=1000;}
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

Detecting items like this?
Spoiler:
Also please don't do that with the handler.
It will result in an infinite zero-duration loop and will freeze the game.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Code: Select all

It will result in an infinite zero-duration loop and will freeze the game.
Huh. Interesting, From what i've tested it seems to work fine. Care to explain?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

I have just tested it and changing:

Code: Select all

itemdrops-=1000;
Into:

Code: Select all

itemdrops=1000;
Will freeze the game if you kill an enemy that has 1000 health or more.

The reason behind that is that it sets the itemdrops integer to the value of a monster's spawn health.
Then it subtracts the value from that integer and spawns an item.
That way it spawns various items based on the health of the enemy.

However if you change -= into just = in any of the lines, it will cause it to set the value to the number instead of subtracting it.
What happens then is an infinite zero-duration loop that will keep spawning the same item without ever stopping, freezing the game in the process.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Interesting. Anyhow, Like last time, i will credit you if this mod ever gets public. I've made some final adjusments like implemeting a Cvar with my custom EXP orb.

Code: Select all

Class SmallExpOrbSpawner : Actor
{
 Default
 {
  +NOINTERACTION
 }
  States
 {
  Spawn:
   TNT1 AAAA 0 NoDelay A_SpawnItemEx("ExpOrb1", 0, 0, 0, frandom(-0.6, 0.6), frandom(-0.6, 0.8), frandom(-0.9, 0.9), 0, 0, (256 * (GetCVar("cl_XPSpawnAmount"))));
   Stop;
 }
}
Along some other minor stuff, like Gldefs and what not.

Also, mind i ask, why did you override this part of the custom inventory?

Code: Select all

    }
    Override void AttachToOwner(Actor other)
    {
        Super.AttachToOwner(other);
        other.A_GiveInventory("ExpOrb1", 1); //Bigger pickup, give 10
        Destroy();
    }
 }
From what i understand of little Zscript, you override the generic PickUp State and changed it to the same thing...?
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Zscript Event Handler help?

Post by Jarewill »

That override is only on the ExpOrbBig and ExpOrbHuge items, which aren't ExbOrb.
It's there so they can give the ExpOrb item in larger quantities.
XASSASSINX
Posts: 380
Joined: Tue Dec 20, 2016 4:53 pm
Location: MURICAA BROTHER! Just kidding, Brazil.

Re: Zscript Event Handler help?

Post by XASSASSINX »

Jarewill wrote:I have just tested it and changing:

Code: Select all

itemdrops-=1000; 
Into:

Code: Select all

itemdrops=1000; 
Will freeze the game if you kill an enemy that has 1000 health or more.

The reason behind that is that it sets the itemdrops integer to the value of a monster's spawn health.
Then it subtracts the value from that integer and spawns an item.
That way it spawns various items based on the health of the enemy.

However if you change -= into just = in any of the lines, it will cause it to set the value to the number instead of subtracting it.
What happens then is an infinite zero-duration loop that will keep spawning the same item without ever stopping, freezing the game in the process.
Sorry for the response time, but just this wrap one final thing up, what i meant to say here (or rather, do) was to change the integer to 0 whenever a monster died, as to not spawn multiple "exp spawners". Like this:

Code: Select all

Else If (itemdrops>=3000){e.Thing.A_DropItem("SupremeEXPOrbSpawner"); itemdrops=0;}
It changes to zero, not change it to itself lol, i knew that would crash it

Anyway, final thanks for the script!! credits are on the files if i ever publish this.
Post Reply

Return to “Scripting”