how do you make something happen?

Advanced OpenGL source port fork from ZDoom, picking up where ZDoomGL left off.
[Home] [Download] [Git builds (Win)] [Git builds (Mac)] [Wiki] [Repo] [Bugs&Suggestions]

Moderator: Graf Zahl

Locked
User avatar
BlazingPhoenix
Posts: 488
Joined: Sun Aug 28, 2005 5:11
Contact:

how do you make something happen?

Post 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?
NecroMage
Posts: 58
Joined: Sun Sep 11, 2005 20:31
Location: nj
Contact:

Post 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.
User avatar
BlazingPhoenix
Posts: 488
Joined: Sun Aug 28, 2005 5:11
Contact:

Post by BlazingPhoenix »

okay the first one worked, thanks :)
NecroMage
Posts: 58
Joined: Sun Sep 11, 2005 20:31
Location: nj
Contact:

Post by NecroMage »

np
User avatar
solarsnowfall
Persecution Complex
Posts: 363
Joined: Fri Aug 05, 2005 8:51

Post 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.
Ixnatifual
Posts: 36
Joined: Tue Sep 06, 2005 14:25

Post 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 :)
User avatar
solarsnowfall
Persecution Complex
Posts: 363
Joined: Fri Aug 05, 2005 8:51

Post 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.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Post by Graf Zahl »

You can assign an action special to each thing. For monsters it is executed when they die.
User avatar
Enjay
Developer
Developer
Posts: 4748
Joined: Tue Aug 30, 2005 23:19
Location: Scotland
Contact:

Post 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.
User avatar
MartinHowe
Posts: 154
Joined: Tue Aug 30, 2005 22:07
Location: East Suffolk (UK)

Post 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.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Post 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.
Locked

Return to “GZDoom”