Jump to content

Recommended Posts

What are you trying to do with the task? There might be a more efficient way of doing it than constantly calling a function unless you are actually repeating something significant.

 

As for how you can use it, why not attach it to the player's instance? That's an always available prefab, unless you completely change the game.

AddSimPostInit(function(inst)    -- inst:DoPeriodicTask()end)

@boardman94, @chromiumboy,

 

To be clear, DoPeriodicTask is a method of EntityScript, so it can be invoked on any entity, not just prefabs.  Essentially anything that has been generated using CreateEntity()

 

True, thanks for clarifying that.

 

@Blueberrys,

The button spawns two prefabs (NPCs) Then waits for them both to be dead then starts a cool down of one day before it becomes active again.

I also am not sure how to make a button visibly inactive (other than hiding it.)

@boardman94

You can set the onkilledbyother function in the combat component for your prefabs, which will be called when they die.

prefab_inst.components.combat.onkilledbyother = function(inst, attacker)    -- ...end

The cooldown can be done with DoTaskInTime. This way the code will only run when you need it to.

 

Hmm. How bout using a tint to make it appear deactivated, and remove the click function temporarily (or put a check for the cooldown in it).

@Blueberrys,

I am now having issues with setting up an event listener in modmain. I have rewritten the NPC so it does its own cool down then uses "PushEvent("mydeath")." but now I can't create an event listener in modmain.  I have triedboth :

GLOBAL.GetPlayer().entity:ListenForEvent("mydeath", buttonUpdate)--andGLOBAL.GetWorld().entity:ListenForEvent("mydeath", buttonUpdate)

But neither one works, (the error states: "Attempt to call "ListenForEvent" a nil value")

@boardman94 Hmm. Try it without the "entity". I think the events are attached directly to the prefab instance.

GLOBAL.GetPlayer():ListenForEvent("mydeath", buttonUpdate)

Make sure you're listening for the event on the same prefab that it's being pushed to. If you push the event to the instance of the NPC, it won't be sent to the player or world instance.

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