Placeables don't have OnSpawn...what to use instead?

I have a function that takes the current date and converts to seconds. Ideally I want to do:

-Give a placeable a “birth date” (in seconds)
-Count time when it’s destroyed (in seconds)

For counting time when it’s destroyed, I can use the OnDeath. No problem.
My problem is giving it a birth date. Placeables don’t have an OnSpawn event. Any idea how to do it smartly with placeables?

If the placeable is being spawned by something, then you can place a timestamp at the time of creation within the script that is spawning the placeable.

If the placeable was placed via the toolset, and is original part of the module, you could either target it directly by tag or cycle through all your module placeables, in the OnModuleLoad event, stamping it at the time of the module start. A timestamping function that considers “the time at which the module was started” to be ‘time 0’ would make this unnecessary, though, since all placeables that exist since modulestart always exist since time 0.

Cycling through the placeables in the area when the player first enters them is an option, too. So I’d say the question to ask is, “What is the cause of ‘birth’? Where is it happening? Why is it happening? When is it happening?”. :thinking:

Good questions and fair arguments, I wouldn’t like to get too much into the inner-workings of the eco-system engine I’m working so players wouldn’t know too much of the behind the scenes or try to exploit it.

But to oversimplify the system, birth is often caused when one is destroyed and the object has existed enough time. I would prefer if every server restart these placeables would be randomly generated/created throughout the module. Now that I think about it I can put it in “OnModuleLoad” and generate all my placeables there, and when new ones are generated after the module loaded the creating script would give them a LocalInt… hmm, yea, I think my problem is solved. Thanks :slight_smile:

1 Like

You can use the OnHeartbeat event:

void main()
{ initialization stuff...

    // Clear HB event so it doesn't fire again

SetEventScript() was added in NWN:EE. If you’re using 1.69, you can use a local variable on the placeable so that it only does the initialization once (or use 1.69 nwnx to clear the event script).

1 Like