summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0aed9f9)
raw | patch | inline | side by side (parent: 0aed9f9)
author | FGSFDSFGS <derp.primus@gmail.com> | |
Sat, 25 Jun 2016 16:51:04 +0000 (19:51 +0300) | ||
committer | FGSFDSFGS <derp.primus@gmail.com> | |
Tue, 28 Jun 2016 18:48:18 +0000 (21:48 +0300) |
Conflicts:
src/game/g_scriptprocs.pas
src/game/g_scriptprocs.pas
src/game/g_scriptprocs.pas | patch | blob | history | |
src/game/g_scripts.pas | patch | blob | history | |
src/game/g_triggers.pas | patch | blob | history |
index 082346e666d3ff1decb4ff74e1ee7cbdaf6f7405..343f85f694da9fe6ee4b2f5382a35647d7fdc388 100644 (file)
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
diff --git a/src/game/g_scripts.pas b/src/game/g_scripts.pas
index 43fe3afc42227e6d453417bc604a2b7e2265de7f..31a8a0060623abb48fc99720a0af4147a27898c9 100644 (file)
--- a/src/game/g_scripts.pas
+++ b/src/game/g_scripts.pas
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;
index 97c135b207d454b9bf6d87af002df3286fbd6f23..162861306ae12742371fae18fcc1e59e3dad27f4 100644 (file)
--- a/src/game/g_triggers.pas
+++ b/src/game/g_triggers.pas
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;