You could do that, but the engine already has a timer and gives you access to it.
C:
int current_time = openborvariant("elapsed_time");
It's an incremental counter that starts at 0 at each level and goes up every engine update. It's how pretty much everything works in the engine that is time related. Animations, lifespans, you name it - and you can use it in your scripts the same way. You set a value of
current_time + YOUR_DELAY, then on update, you compare current time to that value. When current time catches up, you take your action.
C:
// Kill supplied entity after X time.
void dc_example_suicide(void acting_entity, int delay_time)
{
/* Guards */
if(typeof(acting_entity) != openborconstant("VT_PTR")
|| typeof(delay_time) != openborconstant("VT_INTEGER"))
{
shutdown(1, "ERROR: dc_example_suicide(" + acting_entity + ", " + delay_time + ") - Missing or invalid parameter.");
}
int current_time = openborvariant("elapsed_time");
void kill_time = getentityvar(acting_entity, "kill_time");
// Timer has not been set yet.
if(typeof(kill_time) != openborconstant("VT_INTEGER"))
{
setentityvar(acting_entity, "kill_time", current_time + delay_time);
}
else
{
// Timer expired. Kill entity.
if(current_time >= kill_time)
{
killentity(acting_entity);
}
}
}
Use (typically in the entity update):
C:
// Kill entity after 3 seconds.
void acting_entity = getlocalvar("self");
dc_example_suicide(acting_entity, 300);
HTH,
DC