implementation
uses
+<<<<<<< HEAD
lua, g_console;
+=======
+ lua, lauxlib,
+ g_player, g_map, Math, g_gfx, g_game, g_textures,
+ g_console, g_monsters, g_items, g_phys, g_weapons,
+ g_main, SysUtils, e_log, g_language, g_basic,
+ g_options, g_net, g_netmsg, g_triggers, g_panel,
+ g_sound, MAPDEF;
+
+function CheckArgs(L: PScriptContext; MinArgs: Integer; Error: Boolean = True): Boolean; inline;
+begin
+ Result := True;
+ if lua_gettop(L) < MinArgs then
+ begin
+ if Error then g_Console_Add('SCRIPT: ERROR: expected at least ' + IntToStr(MinArgs) + ' argument(s)');
+ Result := False;
+ end;
+end;
+
+// system //
+>>>>>>> 3132944... made TRIGGER_SCRIPT work
function SP_Lua_ConPrint(L: PScriptContext): Integer; cdecl;
begin
function g_Scripts_Init(): Boolean;
procedure g_Scripts_Reset(What: Integer);
-function g_Scripts_ProcExec(PName: string; const Args: array of const): Integer;
+function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer;
function g_Scripts_ProcExists(PName: string): Boolean;
function g_Scripts_ProcInstall(PName: string; PPtr: PScriptProc): Boolean;
function g_Scripts_Load(Text: string): Boolean;
if not g_Scripts_ProcInstall('conprint', SP_Lua_ConPrint) then Exit;
+ if not g_Scripts_ProcInstall('spawn_item', SP_Lua_SpawnItem) then Exit;
+ if not g_Scripts_ProcInstall('spawn_shot', SP_Lua_SpawnShot) then Exit;
+ if not g_Scripts_ProcInstall('spawn_effect', SP_Lua_SpawnEffect) then Exit;
+ if not g_Scripts_ProcInstall('spawn_monster', SP_Lua_SpawnMonster) then Exit;
+
Result := True;
end;
Result := True;
end;
-function g_Scripts_ProcExec(PName: string; const Args: array of const): Integer;
+function g_Scripts_ProcExec(PName: string; const Args: array of const; Namespace: string = ''): Integer;
var
i: Integer;
begin
Result := -255;
if not gScriptInit then Exit;
- lua_getglobal(gScriptCtx, 'game');
- lua_pushstring(gScriptCtx, PName);
- lua_gettable(gScriptCtx, -2);
+ if Namespace = '' then
+ lua_getglobal(gScriptCtx, PChar(PName))
+ else
+ begin
+ lua_getglobal(gScriptCtx, PChar(Namespace));
+ lua_pushstring(gScriptCtx, PName);
+ lua_gettable(gScriptCtx, -2);
+ end;
+
if not lua_isfunction(gScriptCtx, -1) then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: no such function');
+ g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: no such function');
Exit;
end;
if lua_pcall(gScriptCtx, Length(Args), 1, 0) <> 0 then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: ' + lua_tostring(gScriptCtx, -1));
+ g_Console_Add('SCRIPT: ProcExec(' + Namespace + '.' + PName + ') error: ' + lua_tostring(gScriptCtx, -1));
Exit;
end;
- if not lua_isnumber(gScriptCtx, -1) then
+ Result := 0;
+ if lua_isnumber(gScriptCtx, -1) then
begin
- g_Console_Add('SCRIPT: ProcExec(' + PName + ') error: return value is not a number');
- Exit;
+ Result := lua_tointeger(gScriptCtx, -1);
+ lua_pop(gScriptCtx, 1);
end;
-
- Result := lua_tointeger(gScriptCtx, -1);
- lua_pop(gScriptCtx, 1);
end;
function g_Scripts_Load(Text: string): Boolean;
g_player, g_map, Math, g_gfx, g_game, g_textures,
g_console, g_monsters, g_items, g_phys, g_weapons,
wadreader, g_main, SysUtils, e_log, g_language,
- g_options, g_net, g_netmsg;
+ g_options, g_net, g_netmsg, g_scripts;
const
TRIGGER_SIGNATURE = $52475254; // 'TRGR'
MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1');
end;
-
with gWalls[PanelID] do
begin
if gPlayers <> nil then
end;
TimeOut := Data.FXWait;
end;
+
+ TRIGGER_SCRIPT:
+ begin
+ g_Scripts_ProcExec(Data.SCRProc, [ID, ActivateUID, Data.SCRArg], 'map');
+ TimeOut := 1;
+ Result := True;
+ end;
end;
end;