Glitch with do effect function

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!)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Glitch with do effect function

Post by Apeirogon »

I try replicate fractal doom effect on monsters using inventory item with override od effect.
But it dont want to work as I want.

Here video
https://youtu.be/GZ_xEDuujTo

Can some one look at code and say what I missed?
Spoiler:
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Glitch with do effect function

Post by Matt »

What are you trying to do, and what happens instead of that?
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Glitch with do effect function

Post by Apeirogon »

In fractal doom every enemy after death spawn several monsters of the same type as monster that died. But this newborn monsters have smaller hitbox, damage, amount of maximum health, etc.

I try make similar thing. After monster receive hit it must "split" in two monsters (more preciesly, damaged monster must shrink in size, reduce it sprite size, damage, health, etc; then spawn another monster of the same type, which look on original monster and set self hitdbox size, damage, etc. equal to it).

But insted of that, sometimes monster which spawns set self hitdbox size, damage, etc. greater than actor that spawn him. And I cant understand why.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Glitch with do effect function

Post by Matt »

You are using "current_health" divided by "max_health".

But "max_health" is not the starting max health but the max health of the previous monster.

So you could start with a demon with max_health 150, then current_health 100, split into 2x monsters with constanta = 100/150 = 0.67.

But then later one of those guys gets shot, their max_health is 100, their current_health is 70, split into 2x monsters with constanta = 70/100 = 0.7.

If instead of owner/user.health you set max_health to always use the full-size monster's default health (owner/user.spawnhealth()), then in the above example the monsters' sizes would be:

100/150 = 0.67
70/150 = 0.47
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Glitch with do effect function

Post by Apeirogon »

I forgot basic math...

I need some rest from gzdoom...
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Glitch with do effect function

Post by Matt »

I had to run it a couple times and add some lines logging the results at each step before I could see what was going on.

Problems like that would be a lot easier to notice if you do everything at that A_SpawnItemEx step instead of splitting it off into the AttachToOwner.

Remember that pointers can be set for newly created actors and inventory items using the following:

Code: Select all

int bbb;actor aaa;
[bbb,aaa]=xyz.A_SpawnItemEx("ActorName",flags:SXF_TRANSFERFLAGS|SXF_SETMASTER|SXF_NOCHECKPOSITION); 
and

Code: Select all

xyz.A_GiveInventory("ItemName");
inventory abc=xyz.FindInventory("ItemName"); 
or

Code: Select all

xyz.A_GiveInventory("ItemName");
let def=ItemName(xyz.FindInventory("ItemName")); 
which would let you use "def.ppp" where ppp is a property that only ItemName has.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Glitch with do effect function

Post by Apeirogon »

I made so, because I dont know how, and can I, change variables directly from master.

And what means "xyz."?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Glitch with do effect function

Post by Matt »

"xyz" is just the name of the pointer variable, it can be any unique name you want. Remember that in ZScript you're not limited to master/target/tracer.

The example code I posted is specifically so that you can do these changes from the master.

You set up a new pointer variable, have it point to the actor created by A_SpawnItemEx, then use that pointer to make changes to the actor that was given.

Same thing with the item: You set up a new pointer variable, have it (using FindInventory) point to the item created by A_GiveInventory, then use that pointer to make changes to the item that was given.

More about pointers here.

Return to “Scripting”