Page 1 of 1
how do you make something happen?
Posted: Thu Nov 24, 2005 1:32
by BlazingPhoenix
how do you make a script activate after you kill a bunch of monsters? say I have two Imps that just spawned, I want a door to open or something after they die, how do I do this? thingcount or something?
Posted: Thu Nov 24, 2005 1:40
by NecroMage
There are many ways to do this but here is how I would do it. Have each imp activate a script (lets say 1). And then I would use this code:
Code: Select all
#include "zcommon.acs"
int ImpsLeft = 2;
script 1 (void)
{
//i do not know if this works with acs if it doesn't use the other one below
if (--ImpsLeft == 0)
{
door_open(tag,speed,delay); //or whatever do command you want to use
}
//if the above code does not work then use this:
impsleft--;
if (ImpsLeft == 0)
{
door_open(tag,speed,delay);
}
}
ImpsLeft is a variable that tells us how many are remaining. When an imp dies it should run this script and decrease the imps left by 1. When there are 0 left it opens the door.
Posted: Thu Nov 24, 2005 2:00
by BlazingPhoenix
okay the first one worked, thanks

Posted: Thu Nov 24, 2005 3:30
by NecroMage
np
Posted: Thu Nov 24, 2005 6:34
by solarsnowfall
NecroMage wrote:When an imp dies it should run this script and decrease the imps left by 1. When there are 0 left it opens the door.
Either you left something out of that script, or I'm retarded. It doesn't make any sense to me, to do it that way.
KingofFlames wrote:how do you make a script activate after you kill a bunch of monsters? say I have two Imps that just spawned, I want a door to open or something after they die, how do I do this? thingcount or something?
There are plenty of ways to do this, and here are two I would use.
Code: Select all
script 1 open
{
if(thingcount(T_Imp, tid) == 0)
{
door_open(tag, speed, delay);
}
delay(1);
restart;
}
or
Code: Select all
script 1 open
{
until(thingcount(T_Imp, tid) == 0)
{
delay(1);
restart;
}
door_open(tag, speed, delay)
}
They don't need to be open scripts, they just need to be running before the last monster is killed. Say you want the door to open after killing ten Imps, give those ten Imps the same TID. When the count reaches 0, door opens.
If you wanted to keep track of multiple kinds of monsters, put T_None in thingcount(); for the type. As long as all the monsters have the same tid, when the count reaches 0 (after they've all been killed) the door opens. Why is this better?
1.) Doesn't require the monster to activate a script.
2.) Doesn't require a variable.
Posted: Thu Nov 24, 2005 10:57
by Ixnatifual
I think his idea was to have the script activate on each of the imps, so when they die the script is run. When the first imp dies it subtracts one from the integer and stops there. When the second imp dies it finds the integer = 0 and opens the door.
This way you also avoid having a script running constantly in the background. Your script has the advantage that you won't have to put it on every monster the script involves. Pick your poison

Posted: Thu Nov 24, 2005 11:50
by solarsnowfall
How do they execute the script? Upon death from DECORATE? Having the monster activate the script is eluded to in his example, but not demonstrated.
Posted: Thu Nov 24, 2005 12:05
by Graf Zahl
You can assign an action special to each thing. For monsters it is executed when they die.
Posted: Thu Nov 24, 2005 16:47
by Enjay
And just for completeness, you can also combine thingcounts if you need to give the counted monsters more than one tid for some reason. eg
while (Thingcount (0, 23) || Thingcount (0, 24))
I think that will return positive if a monster with either tid 23 or 24 is still alive on the map.
Posted: Fri Nov 25, 2005 14:27
by MartinHowe
Beware that thing-activated counters can fail, because ACS has no locked read-modify-write function. If several monsters get killed at the same time (e.g., by a BFG or WV) some increments to a counter can be missed.
Posted: Fri Nov 25, 2005 15:38
by Graf Zahl
MartinHowe wrote:Beware that thing-activated counters can fail, because ACS has no locked read-modify-write function.
Such a functionality would be useless anyway. ACS is not multithreading capable and there are no interruptions so what should it accomplish.