Jump to content
  • 0

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


Raheem

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

@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

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.

Edited by scifista42

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);
Edited by Nevander

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 :) 

Edited by GreenKat

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...