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

How do i make newly spawned monsters execute a specific script?

Question

in my map I've created an encounter that spawns a bunch of monsters.

I've also created a script that when a monster is killed, it yields an amount of experience points for the player.

Obviously, i had no problem assigning the monsters all ready present on the map to the script.

But i dont' know how to assign these "spawned in monsters" that were not previously present on the map when it opened to the script i want.

So these newly spawned monsters are not giving the player xp.

 

I'm using "Thing_spawnFacing();" to spawn the monsters via map spots.

 

This is the script that I've assigned all the all ready present monsters on the map to in order to yield xp upon death. "playerXp" is an int variable and starts out at 0 upon the map opening.

Quote

script 3 (void)

{
    playerXp = playerXp +5;
}
 

Thanks in advance :)

Share this post


Link to post

7 answers to this question

Recommended Posts

  • 0

Give a specific tag to the newly spawned monsters via your spawn function, then use SetThingSpecial to assign an action and arguments to monsters with this tag.

Share this post


Link to post
  • 0

@scifista42

 

So ive set the monsters all an id off 999 when they spawn in.

 

This is the script that i am using to tie them to script 3.

Quote

script 8 (void)

{
    SetThingSpecial(999,ACS_ExecuteAlways,3,1);
    }
 

This is script 3 - the script that gives the player xp upon a monster kill

 

Quote

script 3 (void)

{
    playerXp = playerXp +5;
}
 

 

Yet upon killing them in game the script is not executing and not providing XP. 

Have i done something wrong?

Share this post


Link to post
  • 0

You need to call the script 8 after the monsters have spawned.

 

If even that isn't working, post the map.

Share this post


Link to post
  • 0

Show the code or physical setup that spawns the monsters and that calls script 8 afterwards. Also, the "map" argument for ACS_ExecuteAlways should better be 0.

Share this post


Link to post
  • 0

Rule of thumb: delay 1 tic before assigning specials to things that need to be spawned in via ACS. Like this:

Thing_SpawnFacing(stuff);
Delay(1);
SetThingSpecial(stuff);

Share this post


Link to post
  • 0

Delay is not necessary, spawning happens immediately as the spawn function is called, and therefore the spawned objects are guaranteed to exist and be fully prepared to be used when the script proceeds to call the next function.

 

Delay would be necessary if it was somehow ambiguous or unpredictable whether the spawn function would be called before or after the other function, while also certain that they would both be called in the same tic (if the delay wasn't applied). But if they're written in sequence and the spawn function is the first one, it's unambiguously called first.

Edited by scifista42

Share this post


Link to post
  • 0

I've got it to work by doing what @Nevander suggested and adding a delay in the same script that summons the monsters before the SetThingSpecial. This actually seems a bit more convenient to code as i don't have to create an entirely different script to assign the monsters to give Xp. Plus the code is near the lines that summon the monsters in question which is nice for organisation. Thanks everybody for the advice :)

 

Edit: Ive just realised i can get it to work without the delay :) 

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
×