![]() |
naev 0.12.5
|
Lua hook module. More...
#include "nlua_hook.h"#include "array.h"#include "event.h"#include "hook.h"#include "mission.h"#include "nlua_evt.h"#include "nlua_misn.h"#include "nlua_pilot.h"#include "nlua_time.h"#include "nluadef.h"
Go to the source code of this file.
Functions | |
| static int | hookL_rm (lua_State *L) |
| Lua bindings to manipulate hooks. | |
| static int | hookL_load (lua_State *L) |
| Hooks the function to the player loading the game (starts landed). | |
| static int | hookL_land (lua_State *L) |
| Hooks the function to the player landing. | |
| static int | hookL_info (lua_State *L) |
| Hooks the function to the info menu. | |
| static int | hookL_takeoff (lua_State *L) |
| Hooks the function to the player taking off. | |
| static int | hookL_jumpout (lua_State *L) |
| Hooks the function to the player jumping (before changing systems). | |
| static int | hookL_jumpin (lua_State *L) |
| Hooks the function to the player jumping (after changing systems). | |
| static int | hookL_enter (lua_State *L) |
| Hooks the function to the player entering a system (triggers when taking off too). | |
| static int | hookL_hail (lua_State *L) |
| Hooks the function to the player hailing any ship (not a spob). | |
| static int | hookL_hail_spob (lua_State *L) |
| Hooks the function to the player hailing any spob. | |
| static int | hookL_board (lua_State *L) |
| Hooks the function to the player boarding any ship. | |
| static int | hookL_timer (lua_State *L) |
| Hooks a timer. | |
| static int | hookL_timerClear (lua_State *L) |
| Clear all timers added by hook.timer. This only affects timers created by the mission or event calling this function. | |
| static int | hookL_date (lua_State *L) |
| Hooks a date change with custom resolution. | |
| static int | hookL_commbuy (lua_State *L) |
| Hooks the function to the player buying any sort of commodity. | |
| static int | hookL_commsell (lua_State *L) |
| Hooks the function to the player selling any sort of commodity. | |
| static int | hookL_commjettison (lua_State *L) |
| Hooks the function to the player jettisoning any sort of commodity. | |
| static int | hookL_gather (lua_State *L) |
| Hooks the function to the player gatehring any sort of commodity in space. | |
| static int | hookL_outfitbuy (lua_State *L) |
| Hooks the function to the player buying any sort of outfit. | |
| static int | hookL_outfitsell (lua_State *L) |
| Hooks the function to the player selling any sort of outfit. | |
| static int | hookL_shipbuy (lua_State *L) |
| Hooks the function to the player buying any sort of ship. | |
| static int | hookL_shipsell (lua_State *L) |
| Hooks the function to the player selling any sort of ship. | |
| static int | hookL_shipswap (lua_State *L) |
| Hooks the function to the player swapping their ship. | |
| static int | hookL_equip (lua_State *L) |
| Hooks the function to the player equipping or deequipping any outfit. | |
| static int | hookL_input (lua_State *L) |
| Hooks the function to the player pressing any input. | |
| static int | hookL_mouse (lua_State *L) |
| Hooks the function to the player clicking the mouse. | |
| static int | hookL_safe (lua_State *L) |
| Hook run once at the end of the next frame regardless of anything that can happen. | |
| static int | hookL_update (lua_State *L) |
| Hook run at the end of each frame when the update routine is run (game is not paused, etc.). | |
| static int | hookL_renderbg (lua_State *L) |
| Hook that runs during rendering the background (just above the static background stuff). Meant to be only for rendering things. | |
| static int | hookL_renderfg (lua_State *L) |
| Hook that runs during rendering the foreground (just below the gui stuff). Meant to be only for rendering things. | |
| static int | hookL_rendertop (lua_State *L) |
| Hook that runs during rendering aove everything. Meant to be as an alternative to doing post-processing shader effects. | |
| static int | hookL_mission_done (lua_State *L) |
| Hook that runs when a mission is complete. The entire mission information table is passed similar to player.evtDoneList(). | |
| static int | hookL_event_done (lua_State *L) |
| Hook that runs when a event is complete. The entire event information table is passed similar to player.evtDoneList(). | |
| static int | hookL_standing (lua_State *L) |
| Hooks the function to any faction standing change. | |
| static int | hookL_discover (lua_State *L) |
| Hooks the function to when the player discovers an spob, jump point or the likes. | |
| static int | hookL_asteroidScan (lua_State *L) |
| Hooks the function to when the player scans an asteroid. | |
| static int | hookL_pay (lua_State *L) |
| Hooks the function to when the player receives or loses money through player.pay() (the Lua function only). | |
| static int | hookL_custom (lua_State *L) |
| Hook run once at the end of the next frame regardless when manually triggered. Can be triggered manually with naev.trigger. | |
| static int | hookL_pilot (lua_State *L) |
| Hooks the function to a specific pilot. | |
| static int | hookL_setarg (unsigned int hook, int ind) |
| Sets a Lua argument for a hook. | |
| static unsigned int | hookL_generic (lua_State *L, const char *stack, double sec, int pos, ntime_t date, int arg) |
| Creates a mission hook to a certain stack. | |
| int | nlua_loadHook (nlua_env env) |
| Loads the hook Lua library. | |
| void | hookL_unsetarg (unsigned int hook) |
| Unsets a Lua argument. | |
| int | hookL_getarg (unsigned int hook) |
| Gets a Lua argument for a hook. | |
Variables | |
| static const luaL_Reg | hookL_methods [] |
Lua hook module.
Definition in file nlua_hook.c.
|
static |
Hooks the function to when the player scans an asteroid.
The parameter passed to the function is the asteroid scanned.
Lua function parameter: string funcname Name of the function to run when the hook is triggered. Lua function parameter: arg Argument to pass to the hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: asteroid_scan
Definition at line 846 of file nlua_hook.c.
|
static |
Hooks the function to the player boarding any ship.
The hook receives a single parameter which is the ship being boarded.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: board
Definition at line 510 of file nlua_hook.c.
|
static |
Hooks the function to the player buying any sort of commodity.
The hook receives the commodity bought and the quantity being bought.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: comm_buy
Definition at line 595 of file nlua_hook.c.
|
static |
Hooks the function to the player jettisoning any sort of commodity.
The hook receives the commodity and the quantity jettisoned.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: comm_jettison
Definition at line 629 of file nlua_hook.c.
|
static |
Hooks the function to the player selling any sort of commodity.
The hook receives the commodity sold and the quantity being sold.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: comm_sell
Definition at line 612 of file nlua_hook.c.
|
static |
Hook run once at the end of the next frame regardless when manually triggered. Can be triggered manually with naev.trigger.
Lua function parameter: string hookname Name to give the hook. This should not overlap with standard names. Lua function parameter: string funcname Name of function to run when hook is triggered. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: custom
Definition at line 1005 of file nlua_hook.c.
|
static |
Hooks a date change with custom resolution.
The hook receives only the optional argument.
Lua usage parameter: hook.date( time.new( 0, 0, 1000 ), "some_func", nil ) – Hooks with a 1000 second resolution
Lua function parameter: Time resolution Resolution of the timer (should be a time structure). Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: date
Definition at line 577 of file nlua_hook.c.
|
static |
Hooks the function to when the player discovers an spob, jump point or the likes.
The parameters passed to the function are the type which can be one of:
"jump"
and the actual spob or jump point discovered with the following format:
function f( type, discovery )
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: discover
Definition at line 828 of file nlua_hook.c.
|
static |
Hooks the function to the player entering a system (triggers when taking off too).
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: enter
Definition at line 459 of file nlua_hook.c.
|
static |
Hooks the function to the player equipping or deequipping any outfit.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: equip
Definition at line 696 of file nlua_hook.c.
|
static |
Hook that runs when a event is complete. The entire event information table is passed similar to player.evtDoneList().
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: event_done
Definition at line 987 of file nlua_hook.c.
|
static |
Hooks the function to the player gatehring any sort of commodity in space.
The hook receives the commodity and the quantity being gathered.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: gather
Definition at line 647 of file nlua_hook.c.
|
static |
Creates a mission hook to a certain stack.
Basically a generic approach to hooking.
| L | Lua state. |
| stack | Stack to put the hook in. |
| sec | Seconds to delay (pass stack as NULL to set as timer). |
| pos | Position in the stack of the function name. |
| date | Resolution of the timer. (If passed, create a date-based hook.) |
| arg | Position where the arguments start. |
Definition at line 256 of file nlua_hook.c.
| int hookL_getarg | ( | unsigned int | hook | ) |
Gets a Lua argument for a hook.
| hook | Hook to get argument of. |
Definition at line 224 of file nlua_hook.c.
|
static |
Hooks the function to the player hailing any ship (not a spob).
The hook receives a single parameter which is the ship being hailed.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: hail
Definition at line 493 of file nlua_hook.c.
|
static |
Hooks the function to the player hailing any spob.
The hook receives a single parameter which is the spob being hailed.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: hail_spob
Definition at line 476 of file nlua_hook.c.
|
static |
Hooks the function to the info menu.
Can also be used to hook the various subparts of the info menu. Possible targets for where are:
Lua usage parameter: hook.info( "my_function" ) – Info calls my_function Lua usage parameter: hook.info( "my_function", "equipment" ) – Calls my_function at equipment screen
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter:[opt] string where Where to hook the function. Defaults to any. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: info
Definition at line 371 of file nlua_hook.c.
|
static |
Hooks the function to the player pressing any input.
It returns the name of the key being pressed like "accel" and whether or not it's a press.
Functions should be in format:
function f(
inputname, inputpress, args )
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: input
Definition at line 768 of file nlua_hook.c.
|
static |
Hooks the function to the player jumping (after changing systems).
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: jumpin
Definition at line 443 of file nlua_hook.c.
|
static |
Hooks the function to the player jumping (before changing systems).
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: jumpout
Definition at line 428 of file nlua_hook.c.
|
static |
Hooks the function to the player landing.
Can also be used to hook the various subparts of the landing menu. Possible targets for where are:
Lua usage parameter: hook.land( "my_function" ) – Land calls my_function Lua usage parameter: hook.land( "my_function", "equipment" ) – Calls my_function at equipment screen
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter:[opt] string where Where to hook the function. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: land
Definition at line 333 of file nlua_hook.c.
|
static |
Hooks the function to the player loading the game (starts landed).
Lua usage parameter: hook.load( "my_function" ) – Load calls my_function
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: load
Definition at line 398 of file nlua_hook.c.
|
static |
Hook that runs when a mission is complete. The entire mission information table is passed similar to player.evtDoneList().
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: mission_done
Definition at line 971 of file nlua_hook.c.
|
static |
Hooks the function to the player clicking the mouse.
The parameter passed to the function is the button pressed (1==left,2==middle,3==right), and whether it is a down (true) or up (false) event.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: mouse
Definition at line 787 of file nlua_hook.c.
|
static |
Hooks the function to the player buying any sort of outfit.
The hook receives the name of the outfit and the quantity being bought.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: outfit_buy
Definition at line 664 of file nlua_hook.c.
|
static |
Hooks the function to the player selling any sort of outfit.
The hook receives the name of the outfit and the quantity being sold.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: outfit_sell
Definition at line 681 of file nlua_hook.c.
|
static |
Hooks the function to when the player receives or loses money through player.pay() (the Lua function only).
The amount paid (or taken from the player) and reason (which is nil by default) is passed as a parameter:
function f( amount, reason, args )
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: pay
Definition at line 865 of file nlua_hook.c.
|
static |
Hooks the function to a specific pilot.
These hooks only live in the current system and get reset every time the player enters a new system.
You can hook to different actions. Currently hook system only supports:
If you pass nil as pilot, it will set it as a global hook that will jump for all pilots.
DO NOT DO UNSAFE THINGS IN PILOT HOOKS. THIS MEANS STUFF LIKE player.teleport(). IF YOU HAVE DOUBTS USE A "safe" HOOK.
These hooks all pass the pilot triggering the hook as a parameter, so they should have the structure of:
function my_hook( pilot, arg )
end
The combat hooks also pass the pilot acting on it, so for example the pilot that disabled, attacked or killed the selected pilot. They have the following format:
function combat_hook( pilot, attacker, arg )
end
Please note that in the case of disable or death hook the attacker may be nil indicating that it was killed by other means like for example the shockwave of a dying ship or nebula volatility.
The land and jump hooks also pass the spob or jump point the pilot is landing at or jumped from, respectively:
function land_hook( pilot, spob, arg )
end
function jump_hook( pilot, jump_point, arg )
end
The stealth hook passes whether or not the ship is stealthing or destealthing as a boolean:
function stealth_hook( pilot, status, arg )
end
Lua function parameter: Pilot|nil pilot Pilot identifier to hook (or nil for all). Lua function parameter: string type One of the supported hook types. Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: pilot
Definition at line 1079 of file nlua_hook.c.
|
static |
Hook that runs during rendering the background (just above the static background stuff). Meant to be only for rendering things.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: renderbg
Definition at line 923 of file nlua_hook.c.
|
static |
Hook that runs during rendering the foreground (just below the gui stuff). Meant to be only for rendering things.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: renderfg
Definition at line 939 of file nlua_hook.c.
|
static |
Hook that runs during rendering aove everything. Meant to be as an alternative to doing post-processing shader effects.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: rendertop
Definition at line 955 of file nlua_hook.c.
|
static |
Lua bindings to manipulate hooks.
Hooks allow you to trigger functions to certain actions like when the player jumps or a pilot dies.
They can have arguments passed to them which will then get passed to the called hook function.
Example usage would be:
Lua module: hook
Removes a hook previously created.
Lua usage parameter: hook.rm( h ) – Hook is removed
Lua function parameter: number h Identifier of the hook to remove.
| L | Lua State |
Lua function: rm
Definition at line 160 of file nlua_hook.c.
|
static |
Hook run once at the end of the next frame regardless of anything that can happen.
This hook is a good way to do possibly breaking stuff like for example player.teleport().
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: safe
Definition at line 884 of file nlua_hook.c.
|
static |
Sets a Lua argument for a hook.
| hook | Hook to set argument for. |
| ind | Index of argument to set. |
Definition at line 178 of file nlua_hook.c.
|
static |
Hooks the function to the player buying any sort of ship.
The hook receives the name of the ship type bought.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: ship_buy
Definition at line 713 of file nlua_hook.c.
|
static |
Hooks the function to the player selling any sort of ship.
The hook receives the name of the ship type sold and the player-given name of the ship.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: ship_sell
Definition at line 731 of file nlua_hook.c.
|
static |
Hooks the function to the player swapping their ship.
The hook receives the name of the ship swapped to and the name of the ship swapped from (if applicable).
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: ship_swap
Definition at line 749 of file nlua_hook.c.
|
static |
Hooks the function to any faction standing change.
The parameters passed to the function are faction whose standing is being changed and the amount changed:
function f( faction, change, system, secondary, primary_fct, args )
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: standing
Definition at line 806 of file nlua_hook.c.
|
static |
Hooks the function to the player taking off.
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: takeoff
Definition at line 413 of file nlua_hook.c.
|
static |
Hooks a timer.
The hook receives only the optional argument.
Lua function parameter: number s Seconds to delay. Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: timer
Definition at line 528 of file nlua_hook.c.
|
static |
Clear all timers added by hook.timer. This only affects timers created by the mission or event calling this function.
| L | Lua State |
Lua function: timerClear
Definition at line 542 of file nlua_hook.c.
| void hookL_unsetarg | ( | unsigned int | hook | ) |
Unsets a Lua argument.
Definition at line 201 of file nlua_hook.c.
|
static |
Hook run at the end of each frame when the update routine is run (game is not paused, etc.).
It is closely related to hook.safe(), but you have to manually remove it or it continues forever.
The current delta-tick (time passed in game) and real delta-tick (independent of game status) are passed as parameters:
function f( dt, real_dt, args
)
Lua function parameter: string funcname Name of function to run when hook is triggered. Lua function parameter: arg Argument to pass to hook. Lua return parameter: number Hook identifier.
| L | Lua State |
Lua function: update
Definition at line 907 of file nlua_hook.c.
| int nlua_loadHook | ( | nlua_env | env | ) |
Loads the hook Lua library.
| env | Lua environment. |
Definition at line 125 of file nlua_hook.c.
|
static |
Hook Lua methods.
Definition at line 71 of file nlua_hook.c.