hedgewars/uScript.pas
changeset 4243 bbf7451f6b4e
parent 4236 fa2680cfff86
child 4319 81391b54b078
equal deleted inserted replaced
4241:835fd7a0e1bf 4243:bbf7451f6b4e
    50     uAmmos,
    50     uAmmos,
    51     uSound,
    51     uSound,
    52     uTeams,
    52     uTeams,
    53     uKeys,
    53     uKeys,
    54     uChat,
    54     uChat,
    55     uStats;
    55     uStats,
       
    56     uRandom;
    56 
    57 
    57 var luaState : Plua_State;
    58 var luaState : Plua_State;
    58     ScriptAmmoLoadout : shortstring;
    59     ScriptAmmoLoadout : shortstring;
    59     ScriptAmmoProbability : shortstring;
    60     ScriptAmmoProbability : shortstring;
    60     ScriptAmmoDelay : shortstring;
    61     ScriptAmmoDelay : shortstring;
   114 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   115 function lc_hidemission(L : Plua_State) : LongInt; Cdecl;
   115 begin
   116 begin
   116     L:= L; // avoid compiler hint
   117     L:= L; // avoid compiler hint
   117     HideMission;
   118     HideMission;
   118     lc_hidemission:= 0;
   119     lc_hidemission:= 0;
       
   120 end;
       
   121 
       
   122 function lc_addcaption(L : Plua_State) : LongInt; Cdecl;
       
   123 begin
       
   124     if lua_gettop(L) = 1 then
       
   125         begin
       
   126         AddCaption(lua_tostring(L, 1), cWhiteColor, capgrpMessage);
       
   127         end
       
   128     else
       
   129         LuaError('Lua: Wrong number of parameters passed to AddCaption!');
       
   130     lc_addcaption:= 0;
   119 end;
   131 end;
   120 
   132 
   121 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   133 function lc_campaignlock(L : Plua_State) : LongInt; Cdecl;
   122 begin
   134 begin
   123     if lua_gettop(L) = 1 then
   135     if lua_gettop(L) = 1 then
   784     else if np = 4 then
   796     else if np = 4 then
   785         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
   797         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), 1)
   786     else
   798     else
   787         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   799         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
   788     lc_setammo:= 0
   800     lc_setammo:= 0
       
   801 end;
       
   802 
       
   803 function lc_getrandom(L : Plua_State) : LongInt; Cdecl;
       
   804 var m : LongInt;
       
   805 begin
       
   806     if lua_gettop(L) <> 1 then
       
   807         begin
       
   808         LuaError('Lua: Wrong number of parameters passed to GetRandom!');
       
   809         lua_pushnil(L); // return value on stack (nil)
       
   810         end
       
   811     else
       
   812         begin
       
   813         m:= lua_tointeger(L, 1);
       
   814         if (m > 0) then
       
   815             lua_pushinteger(L, GetRandom(m))
       
   816         else
       
   817             begin
       
   818             LuaError('Lua: Tried to pass 0 to GetRandom!');
       
   819             lua_pushnil(L);
       
   820             end
       
   821         end;
       
   822     lc_getrandom:= 1
   789 end;
   823 end;
   790 ///////////////////
   824 ///////////////////
   791 
   825 
   792 procedure ScriptPrintStack;
   826 procedure ScriptPrintStack;
   793 var n, i : LongInt;
   827 var n, i : LongInt;
  1142 lua_register(luaState, 'SetGearPosition', @lc_setgearposition);
  1176 lua_register(luaState, 'SetGearPosition', @lc_setgearposition);
  1143 lua_register(luaState, 'GetGearPosition', @lc_getgearposition);
  1177 lua_register(luaState, 'GetGearPosition', @lc_getgearposition);
  1144 lua_register(luaState, 'ParseCommand', @lc_parsecommand);
  1178 lua_register(luaState, 'ParseCommand', @lc_parsecommand);
  1145 lua_register(luaState, 'ShowMission', @lc_showmission);
  1179 lua_register(luaState, 'ShowMission', @lc_showmission);
  1146 lua_register(luaState, 'HideMission', @lc_hidemission);
  1180 lua_register(luaState, 'HideMission', @lc_hidemission);
       
  1181 lua_register(luaState, 'AddCaption', @lc_addcaption);
  1147 lua_register(luaState, 'SetAmmo', @lc_setammo);
  1182 lua_register(luaState, 'SetAmmo', @lc_setammo);
  1148 lua_register(luaState, 'PlaySound', @lc_playsound);
  1183 lua_register(luaState, 'PlaySound', @lc_playsound);
  1149 lua_register(luaState, 'AddTeam', @lc_addteam);
  1184 lua_register(luaState, 'AddTeam', @lc_addteam);
  1150 lua_register(luaState, 'AddHog', @lc_addhog);
  1185 lua_register(luaState, 'AddHog', @lc_addhog);
  1151 lua_register(luaState, 'SetHealth', @lc_sethealth);
  1186 lua_register(luaState, 'SetHealth', @lc_sethealth);
  1172 lua_register(luaState, 'HogTurnLeft', @lc_hogturnleft);
  1207 lua_register(luaState, 'HogTurnLeft', @lc_hogturnleft);
  1173 lua_register(luaState, 'CampaignLock', @lc_campaignlock);
  1208 lua_register(luaState, 'CampaignLock', @lc_campaignlock);
  1174 lua_register(luaState, 'CampaignUnlock', @lc_campaignunlock);
  1209 lua_register(luaState, 'CampaignUnlock', @lc_campaignunlock);
  1175 lua_register(luaState, 'GetGearMessage', @lc_getgearmessage);
  1210 lua_register(luaState, 'GetGearMessage', @lc_getgearmessage);
  1176 lua_register(luaState, 'SetGearMessage', @lc_setgearmessage);
  1211 lua_register(luaState, 'SetGearMessage', @lc_setgearmessage);
       
  1212 lua_register(luaState, 'GetRandom', @lc_getrandom);
  1177 
  1213 
  1178 
  1214 
  1179 ScriptClearStack; // just to be sure stack is empty
  1215 ScriptClearStack; // just to be sure stack is empty
  1180 ScriptLoaded:= false;
  1216 ScriptLoaded:= false;
  1181 end;
  1217 end;