Lua: object timers
Expose object timers to lua scripts. For example:
local o = obj.new("cockatrice egg");
o:placeobj(5, 5);
o:start_timer("hatch-egg", 3);
Available methods are:
- obj.has_timer("rot-corpse")
returns true if object has attached timer, false otherwise.
- obj.peek_timer("hatch-egg")
returns an integer value, which is the turn when the timer
attached to the object would trigger. returns 0 if no such timer.
- obj.stop_timer("shrink-glob")
stops attached timer, or if no timer type is given, stops all
timers attached to the object.
- obj.start_timer("zombify-mon", 15)
starts a timer with a trigger time in that many turns in the future.
replaces any previous timer of the same type.
Valid timers are "rot-organic", "rot-corpse", "revive-mon",
"zombify-mon", "burn-obj", "hatch-egg", "fig-transform",
and "shrink-glob". Also "melt-ice" is recognized, but does nothing
to objects.
This commit is contained in:
15
src/nhlua.c
15
src/nhlua.c
@@ -191,6 +191,21 @@ get_table_mapchr_opt(lua_State *L, const char *name, schar defval)
|
||||
return typ;
|
||||
}
|
||||
|
||||
short
|
||||
nhl_get_timertype(lua_State *L, int idx)
|
||||
{
|
||||
static const char *const timerstr[NUM_TIME_FUNCS+1] = {
|
||||
"rot-organic", "rot-corpse", "revive-mon", "zombify-mon",
|
||||
"burn-obj", "hatch-egg", "fig-transform", "melt-ice", "shrink-glob",
|
||||
NULL
|
||||
};
|
||||
short ret = luaL_checkoption(L, idx, NULL, timerstr);
|
||||
|
||||
if (ret < 0 || ret >= NUM_TIME_FUNCS)
|
||||
nhl_error(L, "Unknown timer type");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
nhl_add_table_entry_int(lua_State *L, const char *name, int value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user