naev 0.12.5
nlua_evt.c File Reference

Handles the event Lua bindings. More...

#include "nlua_evt.h"
#include "event.h"
#include "land.h"
#include "log.h"
#include "ndata.h"
#include "nlua.h"
#include "nlua_system.h"
#include "nlua_tex.h"
#include "nluadef.h"
#include "npc.h"
#include "player.h"
Include dependency graph for nlua_evt.c:

Go to the source code of this file.

Functions

static int evtL_npcAdd (lua_State *L)
 Event system Lua bindings.
static int evtL_npcRm (lua_State *L)
 Removes an NPC.
static int evtL_finish (lua_State *L)
 Finishes the event.
static int evtL_save (lua_State *L)
 Saves an event.
static int evtL_claim (lua_State *L)
 Tries to claim systems or strings.
int nlua_loadEvt (nlua_env env)
 Loads the event Lua library.
void event_runStart (unsigned int eventid, const char *func)
 Starts running a function, allows programmer to set up arguments.
int event_run (unsigned int eventid, const char *func)
 Runs the event function.
Event_tevent_getFromLua (lua_State *L)
 Gets the current running event from user data.
int event_runFunc (unsigned int eventid, const char *func, int nargs)
 Runs a function previously set up with event_runStart.

Variables

static const luaL_Reg evtL_methods []

Detailed Description

Handles the event Lua bindings.

Definition in file nlua_evt.c.

Function Documentation

◆ event_getFromLua()

Event_t * event_getFromLua ( lua_State * L)

Gets the current running event from user data.

This should ONLY be called below an nlua_pcall, so __NLUA_CURENV is set

Definition at line 103 of file nlua_evt.c.

◆ event_run()

int event_run ( unsigned int eventid,
const char * func )

Runs the event function.

Parameters
eventidID of the event to run Lua function on.
funcName of the function to run.
Returns
0 on success.

Definition at line 90 of file nlua_evt.c.

◆ event_runFunc()

int event_runFunc ( unsigned int eventid,
const char * func,
int nargs )

Runs a function previously set up with event_runStart.

Returns
-1 on error, 1 on misn.finish() call, 2 if event got deleted and 0 normally.

Definition at line 120 of file nlua_evt.c.

◆ event_runStart()

void event_runStart ( unsigned int eventid,
const char * func )

Starts running a function, allows programmer to set up arguments.

Definition at line 67 of file nlua_evt.c.

◆ evtL_claim()

int evtL_claim ( lua_State * L)
static

Tries to claim systems or strings.

Claiming systems and strings is a way to avoid mission collisions preemptively.

Note it does not actually perform the claim if it fails to claim. It also does not work more than once.

Lua usage parameter: if not evt.claim( { system.get("Gamma Polaris") } ) then evt.finish( false ) end Lua usage parameter: if not evt.claim( system.get("Gamma Polaris") ) then evt.finish( false ) end Lua usage parameter: if not evt.claim( 'some_string' ) then evt.finish( false ) end Lua usage parameter: if not evt.claim( { system.get("Gamma Polaris"), 'some_string' } ) then evt.finish( false ) end

Lua function parameter: System|String|{System,String...} params Table of systems/strings to claim or a single system/string. Lua function parameter:[opt=false] boolean inclusive Whether or not to allow the claim to include other inclusive claims. Multiple missions/events can inclusively claim the same system, but only one system can exclusively claim it. Lua return parameter: boolean true if was able to claim, false otherwise.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: claim

Definition at line 313 of file nlua_evt.c.

◆ evtL_finish()

int evtL_finish ( lua_State * L)
static

Finishes the event.

Lua function parameter:[opt=false] boolean properly If true and the event is unique it marks the event as completed. If false it deletes the event but doesn't mark it as completed.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: finish

Definition at line 251 of file nlua_evt.c.

◆ evtL_npcAdd()

int evtL_npcAdd ( lua_State * L)
static

Event system Lua bindings.

Adds an NPC.

An example would be:

evt.finish() -- finishes the event

Lua module: evt

Lua usage parameter: npc_id = evt.npcAdd( "my_func", "Mr. Test", "none.webp", "A test." ) – Creates an NPC.

Lua function parameter: string func Name of the function to run when approaching, gets passed the npc_id when called. Lua function parameter: string name Name of the NPC Lua function parameter: string portrait Portrait file name to use for the NPC (from GFX_PATH/portraits/). Lua function parameter: string desc Description associated to the NPC. Lua function parameter:[opt=5] number priority Optional priority argument (highest is 0, lowest is 10). Lua function parameter:[opt=nil] string background Background file name to use (from GFX_PATH/portraits/). Lua return parameter: number The ID of the NPC to pass to npcRm.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: npcAdd

Definition at line 180 of file nlua_evt.c.

◆ evtL_npcRm()

int evtL_npcRm ( lua_State * L)
static

Removes an NPC.

Lua usage parameter: evt.npcRm( npc_id )

Lua function parameter: number id ID of the NPC to remove.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: npcRm

Definition at line 225 of file nlua_evt.c.

◆ evtL_save()

int evtL_save ( lua_State * L)
static

Saves an event.

Lua usage parameter: evt.save() – Saves an event, which is by default disabled.

Lua function parameter:[opt=true] boolean enable If true sets the event to save, otherwise tells the event to not save.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: save

Definition at line 276 of file nlua_evt.c.

◆ nlua_loadEvt()

int nlua_loadEvt ( nlua_env env)

Loads the event Lua library.

Parameters
envLua environment.

Definition at line 58 of file nlua_evt.c.

Variable Documentation

◆ evtL_methods

const luaL_Reg evtL_methods[]
static
Initial value:
= {
{ "npcAdd", evtL_npcAdd }, { "npcRm", evtL_npcRm },
{ "save", evtL_save }, { "finish", evtL_finish },
{ "claim", evtL_claim }, { 0, 0 } }
static int evtL_claim(lua_State *L)
Tries to claim systems or strings.
Definition nlua_evt.c:313
static int evtL_finish(lua_State *L)
Finishes the event.
Definition nlua_evt.c:251
static int evtL_npcAdd(lua_State *L)
Event system Lua bindings.
Definition nlua_evt.c:180
static int evtL_npcRm(lua_State *L)
Removes an NPC.
Definition nlua_evt.c:225
static int evtL_save(lua_State *L)
Saves an event.
Definition nlua_evt.c:276

Mission Lua methods.

Definition at line 46 of file nlua_evt.c.