Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
jdagenet

Need some ACS assistance

Recommended Posts

I'm trying to make a script that will constantly loop and check if an actors health goes below 701 and when it does, it'll spawn other monsters. Here is the script I currently have put together:

script 1 (void)

{
if (checkactorproperty (60, aprop_health, 700))
{
spawnspot ("SpawnFire", 67, 0, 0);
delay (10);
thing_spawnnofog (67, t_baron, 64, 68);
}
else
{
acs_execute (16, 0, 0, 0, 0);
}
delay (1);
}
I'm not sure if I did the else loop correct but, could someone please help me with this?

Share this post


Link to post

You should format your code a little better to help improve readability.

script 1 (void)
{
  If (CheckActorProperty(60, APROP_HEALTH, 700))
  {
    SpawnSpot("SpawnFire", 67, 0, 0);
    Delay(10);
    Thing_SpawnNoFog(67, T_BARON, 64, 68);
  }
  Else
  {
    ACS_Execute(16, 0, 0, 0, 0);
  }
  Delay(1);
}
The way you have the code written basically works like this:
  Is the actor's health 700?
    Yes, then spawn fire, delay, and spawn some barons.
    No, then execute script 16.
  Now wait 1 tic and exit the script.
As you can see, it doesn't make too much sense.

Here's what you probably want:
Script 1 (void)
{
  // Get health of the target monster.
  int Health = GetActorProperty(60, APROP_HEALTH);
  
  // See if we're below 700 health.
  If (Health < 700)
  {
    // If it is, spawn fire, wait, then spawn barons...
    SpawnSpot("SpawnFire", 67, 0, 0);
    Delay(10);
    Thing_SpawnNoFog(67, T_BARON, 64, 68);
    // The script will stop looping now...
  }
  Else
  {
    // Otherwise, wait a bit and restart the script
    // so the target monster's health can be checked again...
    Delay(1);    
    Restart;
  }
}
I have no idea what Script 16 does, so I didn't include it in my correction. Note the use of GetActorProperty instead of CheckActorProperty. There are other ways of doing this as well, but this one might be the simplest to understand. Hope this helps.

Share this post


Link to post

Thanks a lot, I'll be sure to try this. I'm not really familiar with the loops so that why mine looks so jacked up.

Share this post


Link to post

Usually you would use a loop structure, like "While" or "For" loops, where each work a bit differently. Your situation calls for a "While" loop, but your script is so simple, you can just restart the script and execute the code again. Your original piece of code did not seem to contain a loop, unless script 1 was called by script 16 somehow.

Here's a similar and shorter way of doing the above script:

Script 1 Open
{
  While (GetActorProperty(60, APROP_HEALTH) > 700) Delay(1);
  SpawnSpot("SpawnFire", 67, 0, 0);
  Delay(10);
  Thing_SpawnNoFog(67, T_BARON, 64, 68);
}
This one practically does the same thing, except it starts checking the monster when the map loads, and not when you tell it to start. It'll delay action until the monster falls to 700 or less HP.

Share this post


Link to post

Alternatively:

script 1 (void)
{
  while (GetActorProperty(60, APROP_HEALTH) > 700)
  {
    ACS_Execute(16, 0, 0, 0, 0);
    Delay(1);
  }
  SpawnSpot("SpawnFire", 67, 0, 0);
  Delay(10);
  Thing_SpawnNoFog(67, T_BARON, 64, 68);
}
This code will run the mysterious script 16 every tic until health gets lower than or equal to 700. Then it'll spawn fire, wait 10 tics, spawn a baron, and exit.

Share this post


Link to post
jdagenet said:

Well, script 16 is actually the script you guys are helping me with, I just made it script 1.

Oh. Well, it wasn't going to work because you just made the script executes itself forever all in the same tic.

You could have gotten something working with a delay(1); ACS_Execute(16); setup, but the loop is more elegant anyway.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×