Jump to content

Recommended Posts

Hello. I've ran into somewhat annoying problem. I have my custom character who specializes in magic and the character is able to make creatures follow itself. For now I'm experimenting with just one creature but later I will expand it into having for example 3 creatures at once. The script runs as follows:

I have a table of 20 creature prefab names.

When I cast the spell on a creature a loop iterates through every creature in the table and checks if if target.prefab == monster_table[row]

When the creature is found in the table then I make the creature as my follower and do few other things and then I insert an array into another array

I have an array called FollowerTime which holds arrays and those arrays within FollowerTime hold 2 things:

  • target:ListenForEvent("death", OnDeath)
  • DoTaskInTime(30, ...function...)

The last DoTaskInTime function is the problem here because after the time runs out everything works great and the function makes that a creature no longer follows me and the buggy part which is setting target:ListenForEvent("death", OnDeath) to nil because after the creature is no longer my follower I don't want to check for it's death anymore. Yet target:ListenForEvent("death", OnDeath) still remains even though I'm setting it to nil and after the array is being deleted the onDeath function has no creature to refer to in FollowerTime[1][2]:Cancel() which is stopping the DoTaskInTime which removes the follower after some time.

Is there some way to stop ListenForEvent like FollowerTime[1][2]:Cancel() ?

here are the images of the important parts of the code:

OnDeath:

OgjUa30.png

Adding a new follower, delayed task and listener:

WECfI1J.png

 

Thank you in advance :)

Edited by Thial

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
×
  • Create New...