From: FGSFDSFGS Date: Sat, 25 Jun 2016 16:51:04 +0000 (+0300) Subject: made TRIGGER_SCRIPT work X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c0e0a28f9c2ac9eb8e62791655d9baa3b6f978a0;p=d2df-sdl.git made TRIGGER_SCRIPT work Conflicts: src/game/g_scriptprocs.pas --- diff --git a/src/game/g_scriptprocs.pas b/src/game/g_scriptprocs.pas index 082346e..343f85f 100644 --- a/src/game/g_scriptprocs.pas +++ b/src/game/g_scriptprocs.pas @@ -26,7 +26,28 @@ function SP_Lua_ConPrint(L: PScriptContext): Integer; cdecl; 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 43fe3af..31a8a00 100644 --- a/src/game/g_scripts.pas +++ b/src/game/g_scripts.pas @@ -38,7 +38,7 @@ var 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; @@ -70,6 +70,11 @@ begin 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; @@ -167,19 +172,25 @@ begin 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; @@ -197,18 +208,16 @@ begin 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; diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 97c135b..1628613 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -88,7 +88,7 @@ uses 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' @@ -209,7 +209,6 @@ begin MH_SEND_Sound(X, Y, 'SOUND_GAME_SWITCH1'); end; - with gWalls[PanelID] do begin if gPlayers <> nil then @@ -1946,6 +1945,13 @@ begin 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;