151 |
151 |
152 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
152 function lc_writelntoconsole(L : Plua_State) : LongInt; Cdecl; |
153 begin |
153 begin |
154 if lua_gettop(L) = 1 then |
154 if lua_gettop(L) = 1 then |
155 begin |
155 begin |
156 WriteLnToConsole('Lua: ' + StrPas(lua_tostring(L ,1))); |
156 WriteLnToConsole('Lua: ' + lua_tostring(L ,1)); |
157 end |
157 end |
158 else |
158 else |
159 LuaError('Lua: Wrong number of parameters passed to WriteLnToConsole!'); |
159 LuaError('Lua: Wrong number of parameters passed to WriteLnToConsole!'); |
160 lc_writelntoconsole:= 0; |
160 lc_writelntoconsole:= 0; |
161 end; |
161 end; |
162 |
162 |
163 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
163 function lc_parsecommand(L : Plua_State) : LongInt; Cdecl; |
164 begin |
164 begin |
165 if lua_gettop(L) = 1 then |
165 if lua_gettop(L) = 1 then |
166 begin |
166 begin |
167 ParseCommand(StrPas(lua_tostring(L ,1)), true); |
167 ParseCommand(lua_tostring(L ,1), true); |
168 end |
168 end |
169 else |
169 else |
170 LuaError('Lua: Wrong number of parameters passed to ParseCommand!'); |
170 LuaError('Lua: Wrong number of parameters passed to ParseCommand!'); |
171 lc_parsecommand:= 0; |
171 lc_parsecommand:= 0; |
172 end; |
172 end; |
173 |
173 |
174 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
174 function lc_showmission(L : Plua_State) : LongInt; Cdecl; |
175 begin |
175 begin |
176 if lua_gettop(L) = 5 then |
176 if lua_gettop(L) = 5 then |
177 begin |
177 begin |
178 ShowMission(StrPas(lua_tostring(L, 1)), StrPas(lua_tostring(L, 2)), StrPas(lua_tostring(L, 3)), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
178 ShowMission(lua_tostring(L, 1), lua_tostring(L, 2), lua_tostring(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5)); |
179 end |
179 end |
180 else |
180 else |
181 LuaError('Lua: Wrong number of parameters passed to ShowMission!'); |
181 LuaError('Lua: Wrong number of parameters passed to ShowMission!'); |
182 lc_showmission:= 0; |
182 lc_showmission:= 0; |
183 end; |
183 end; |
190 end; |
190 end; |
191 |
191 |
192 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
192 function lc_addcaption(L : Plua_State) : LongInt; Cdecl; |
193 begin |
193 begin |
194 if lua_gettop(L) = 1 then |
194 if lua_gettop(L) = 1 then |
195 AddCaption(StrPas(lua_tostring(L, 1)), cWhiteColor, capgrpMessage) |
195 AddCaption(lua_tostring(L, 1), cWhiteColor, capgrpMessage) |
196 else if lua_gettop(L) = 3 then |
196 else if lua_gettop(L) = 3 then |
197 begin |
197 begin |
198 AddCaption(StrPas(lua_tostring(L, 1)), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3))); |
198 AddCaption(lua_tostring(L, 1), lua_tointeger(L, 2) shr 8, TCapGroup(lua_tointeger(L, 3))); |
199 end |
199 end |
200 else |
200 else |
201 LuaError('Lua: Wrong number of parameters passed to AddCaption!'); |
201 LuaError('Lua: Wrong number of parameters passed to AddCaption!'); |
202 lc_addcaption:= 0; |
202 lc_addcaption:= 0; |
203 end; |
203 end; |
718 else |
718 else |
719 begin |
719 begin |
720 gear:= GearByUID(lua_tointeger(L, 1)); |
720 gear:= GearByUID(lua_tointeger(L, 1)); |
721 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
721 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
722 |
722 |
723 hogName:= StrPas(lua_tostring(L, 2)); |
723 hogName:= lua_tostring(L, 2); |
724 gear^.Hedgehog^.Name:= hogName; |
724 gear^.Hedgehog^.Name:= hogName; |
725 |
725 |
726 FreeTexture(gear^.Hedgehog^.NameTagTex); |
726 FreeTexture(gear^.Hedgehog^.NameTagTex); |
727 gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16); |
727 gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16); |
728 |
728 |
855 if gear <> nil then |
855 if gear <> nil then |
856 begin |
856 begin |
857 vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true); |
857 vgear:= AddVisualGear(0, 0, vgtSpeechBubble, s, true); |
858 if vgear <> nil then |
858 if vgear <> nil then |
859 begin |
859 begin |
860 vgear^.Text:= StrPas(lua_tostring(L, 2)); |
860 vgear^.Text:= lua_tostring(L, 2); |
861 vgear^.Hedgehog:= gear^.Hedgehog; |
861 vgear^.Hedgehog:= gear^.Hedgehog; |
862 vgear^.FrameTicks:= lua_tointeger(L, 3); |
862 vgear^.FrameTicks:= lua_tointeger(L, 3); |
863 if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then vgear^.FrameTicks:= 1; |
863 if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then vgear^.FrameTicks:= 1; |
864 lua_pushinteger(L, vgear^.Uid) |
864 lua_pushinteger(L, vgear^.Uid) |
865 end |
865 end |
1128 (* |
1128 (* |
1129 FIXME FIXME FIXME FIXME |
1129 FIXME FIXME FIXME FIXME |
1130 Something is very wrong here. |
1130 Something is very wrong here. |
1131 For some reason, if I assign voice after fort (or don't use the variable) it is empty. |
1131 For some reason, if I assign voice after fort (or don't use the variable) it is empty. |
1132 *) |
1132 *) |
1133 voice:= StrPas(lua_tostring(L, 5)); |
1133 ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true); |
1134 ParseCommand('addteam x ' + StrPas(lua_tostring(L, 2)) + ' ' + StrPas(lua_tostring(L, 1)), true); |
1134 voice:= lua_tostring(L, 5); |
1135 ParseCommand('grave ' + StrPas(lua_tostring(L, 3)), true); |
1135 ParseCommand('grave ' + lua_tostring(L, 3), true); |
1136 ParseCommand('fort ' + StrPas(lua_tostring(L, 4)), true); |
1136 ParseCommand('fort ' + lua_tostring(L, 4), true); |
1137 ParseCommand('voicepack ' + voice, true); |
1137 ParseCommand('voicepack ' + voice, true); |
1138 if (np = 6) then ParseCommand('flag ' + StrPas(lua_tostring(L, 6)), true); |
1138 if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true); |
1139 CurrentTeam^.Binds:= DefaultBinds |
1139 CurrentTeam^.Binds:= DefaultBinds |
1140 // fails on x64 |
1140 // fails on x64 |
1141 //lua_pushinteger(L, LongInt(CurrentTeam)); |
1141 //lua_pushinteger(L, LongInt(CurrentTeam)); |
1142 end; |
1142 end; |
1143 lc_addteam:= 0;//1; |
1143 lc_addteam:= 0;//1; |
1151 LuaError('Lua: Wrong number of parameters passed to AddHog!'); |
1151 LuaError('Lua: Wrong number of parameters passed to AddHog!'); |
1152 lua_pushnil(L) |
1152 lua_pushnil(L) |
1153 end |
1153 end |
1154 else |
1154 else |
1155 begin |
1155 begin |
1156 temp:= StrPas(lua_tostring(L, 4)); |
1156 temp:= lua_tostring(L, 4); |
1157 ParseCommand('addhh ' + StrPas(lua_tostring(L, 2)) + ' ' + StrPas(lua_tostring(L, 3)) + ' ' + StrPas(lua_tostring(L, 1)), true); |
1157 ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true); |
1158 ParseCommand('hat ' + temp, true); |
1158 ParseCommand('hat ' + temp, true); |
1159 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1159 lua_pushinteger(L, CurrentHedgehog^.Gear^.uid); |
1160 end; |
1160 end; |
1161 lc_addhog:= 1; |
1161 lc_addhog:= 1; |
1162 end; |
1162 end; |
1456 end |
1456 end |
1457 else |
1457 else |
1458 begin |
1458 begin |
1459 gear:= GearByUID(lua_tointeger(L, 1)); |
1459 gear:= GearByUID(lua_tointeger(L, 1)); |
1460 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1460 if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then |
1461 hat:= StrPas(lua_tostring(L, 2)); |
1461 hat:= lua_tostring(L, 2); |
1462 gear^.Hedgehog^.Hat:= hat; |
1462 gear^.Hedgehog^.Hat:= hat; |
1463 LoadHedgehogHat(gear, hat); |
1463 LoadHedgehogHat(gear, hat); |
1464 end; |
1464 end; |
1465 lc_sethoghat:= 0; |
1465 lc_sethoghat:= 0; |
1466 end; |
1466 end; |
1492 begin |
1492 begin |
1493 n:= lua_gettop(luaState); |
1493 n:= lua_gettop(luaState); |
1494 WriteLnToConsole('Lua: Stack (' + inttostr(n) + ' elements):'); |
1494 WriteLnToConsole('Lua: Stack (' + inttostr(n) + ' elements):'); |
1495 for i:= 1 to n do |
1495 for i:= 1 to n do |
1496 if not lua_isboolean(luaState, i) then |
1496 if not lua_isboolean(luaState, i) then |
1497 WriteLnToConsole('Lua: ' + inttostr(i) + ': ' + StrPas(lua_tostring(luaState, i))) |
1497 WriteLnToConsole('Lua: ' + inttostr(i) + ': ' + lua_tostring(luaState, i)) |
1498 else if lua_toboolean(luaState, i) then |
1498 else if lua_toboolean(luaState, i) then |
1499 WriteLnToConsole('Lua: ' + inttostr(i) + ': true') |
1499 WriteLnToConsole('Lua: ' + inttostr(i) + ': true') |
1500 else |
1500 else |
1501 WriteLnToConsole('Lua: ' + inttostr(i) + ': false'); |
1501 WriteLnToConsole('Lua: ' + inttostr(i) + ': false'); |
1502 end; |
1502 end; |
1532 end; |
1532 end; |
1533 |
1533 |
1534 function ScriptGetString(name : shortstring) : shortstring; |
1534 function ScriptGetString(name : shortstring) : shortstring; |
1535 begin |
1535 begin |
1536 lua_getglobal(luaState, Str2PChar(name)); |
1536 lua_getglobal(luaState, Str2PChar(name)); |
1537 ScriptGetString:= StrPas(lua_tostring(luaState, -1)); |
1537 ScriptGetString:= lua_tostring(luaState, -1); |
1538 lua_pop(luaState, 1); |
1538 lua_pop(luaState, 1); |
1539 end; |
1539 end; |
1540 |
1540 |
1541 procedure ScriptOnGameInit; |
1541 procedure ScriptOnGameInit; |
1542 begin |
1542 begin |
1609 if not FileExists(s) then s:= Pathz[ptData] + '/' + name; |
1609 if not FileExists(s) then s:= Pathz[ptData] + '/' + name; |
1610 ret:= luaL_loadfile(luaState, Str2PChar(s)); |
1610 ret:= luaL_loadfile(luaState, Str2PChar(s)); |
1611 if ret <> 0 then |
1611 if ret <> 0 then |
1612 begin |
1612 begin |
1613 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
1613 LuaError('Lua: Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); |
1614 LuaError('Lua: ' + StrPas(lua_tostring(luaState, -1))); |
1614 LuaError('Lua: ' + lua_tostring(luaState, -1)); |
1615 end |
1615 end |
1616 else |
1616 else |
1617 begin |
1617 begin |
1618 WriteLnToConsole('Lua: ' + name + ' loaded'); |
1618 WriteLnToConsole('Lua: ' + name + ' loaded'); |
1619 // call the script file |
1619 // call the script file |
1645 exit; |
1645 exit; |
1646 SetGlobals; |
1646 SetGlobals; |
1647 lua_getglobal(luaState, Str2PChar(fname)); |
1647 lua_getglobal(luaState, Str2PChar(fname)); |
1648 if lua_pcall(luaState, 0, 0, 0) <> 0 then |
1648 if lua_pcall(luaState, 0, 0, 0) <> 0 then |
1649 begin |
1649 begin |
1650 LuaError('Lua: Error while calling ' + fname + ': ' + StrPas(lua_tostring(luaState, -1))); |
1650 LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
1651 lua_pop(luaState, 1) |
1651 lua_pop(luaState, 1) |
1652 end; |
1652 end; |
1653 GetGlobals; |
1653 GetGlobals; |
1654 end; |
1654 end; |
1655 |
1655 |
1660 lua_getglobal(luaState, Str2PChar('ParseCommandOverride')); |
1660 lua_getglobal(luaState, Str2PChar('ParseCommandOverride')); |
1661 lua_pushstring(luaState, Str2PChar(key)); |
1661 lua_pushstring(luaState, Str2PChar(key)); |
1662 lua_pushstring(luaState, Str2PChar(value)); |
1662 lua_pushstring(luaState, Str2PChar(value)); |
1663 if lua_pcall(luaState, 2, 1, 0) <> 0 then |
1663 if lua_pcall(luaState, 2, 1, 0) <> 0 then |
1664 begin |
1664 begin |
1665 LuaError('Lua: Error while calling ParseCommandOverride: ' + StrPas(lua_tostring(luaState, -1))); |
1665 LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1)); |
1666 lua_pop(luaState, 1) |
1666 lua_pop(luaState, 1) |
1667 end |
1667 end |
1668 else |
1668 else |
1669 begin |
1669 begin |
1670 ParseCommandOverride:= StrPas(lua_tostring(luaState, -1)); |
1670 ParseCommandOverride:= lua_tostring(luaState, -1); |
1671 lua_pop(luaState, 1) |
1671 lua_pop(luaState, 1) |
1672 end; |
1672 end; |
1673 end; |
1673 end; |
1674 |
1674 |
1675 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
1675 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt; |
1698 lua_pushinteger(luaState, par3); |
1698 lua_pushinteger(luaState, par3); |
1699 lua_pushinteger(luaState, par4); |
1699 lua_pushinteger(luaState, par4); |
1700 ScriptCall:= 0; |
1700 ScriptCall:= 0; |
1701 if lua_pcall(luaState, 4, 1, 0) <> 0 then |
1701 if lua_pcall(luaState, 4, 1, 0) <> 0 then |
1702 begin |
1702 begin |
1703 LuaError('Lua: Error while calling ' + fname + ': ' + StrPas(lua_tostring(luaState, -1))); |
1703 LuaError('Lua: Error while calling ' + fname + ': ' + lua_tostring(luaState, -1)); |
1704 lua_pop(luaState, 1) |
1704 lua_pop(luaState, 1) |
1705 end |
1705 end |
1706 else |
1706 else |
1707 begin |
1707 begin |
1708 ScriptCall:= lua_tointeger(luaState, -1); |
1708 ScriptCall:= lua_tointeger(luaState, -1); |