Page 1 of 1

Glitch with do effect function

Posted: Fri Mar 16, 2018 2:09 pm
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:

Re: Glitch with do effect function

Posted: Fri Mar 16, 2018 4:57 pm
by Matt
What are you trying to do, and what happens instead of that?

Re: Glitch with do effect function

Posted: Fri Mar 16, 2018 10:38 pm
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.

Re: Glitch with do effect function

Posted: Sat Mar 17, 2018 1:09 pm
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

Re: Glitch with do effect function

Posted: Mon Mar 19, 2018 6:56 am
by Apeirogon
I forgot basic math...

I need some rest from gzdoom...

Re: Glitch with do effect function

Posted: Mon Mar 19, 2018 10:20 am
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.

Re: Glitch with do effect function

Posted: Mon Mar 19, 2018 10:48 am
by Apeirogon
I made so, because I dont know how, and can I, change variables directly from master.

And what means "xyz."?

Re: Glitch with do effect function

Posted: Mon Mar 19, 2018 12:27 pm
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.