hedgewars/uScript.pas
changeset 14477 4b678aad50e9
parent 14463 bd1db668b7c0
child 14479 4e5280a9e782
equal deleted inserted replaced
14475:2113296b7a29 14477:4b678aad50e9
  2305     //else
  2305     //else
  2306         //lua_pushnil(L)
  2306         //lua_pushnil(L)
  2307     lc_addteam:= 0;//1;
  2307     lc_addteam:= 0;//1;
  2308 end;
  2308 end;
  2309 
  2309 
       
  2310 function lc_addmissionteam(L : Plua_State) : LongInt; Cdecl;
       
  2311 var colorArg: Int64;
       
  2312     colorStr: shortstring;
       
  2313 begin
       
  2314     if CheckLuaParamCount(L, 1, 'AddMissionTeam', 'color') then
       
  2315         begin
       
  2316         if(MissionTeam = nil) then
       
  2317             begin
       
  2318             OutError('Lua error: AddMissionTeam: Could not add team. Note: This function only works in singleplayer missions!', true);
       
  2319             lc_addmissionteam:= 0;
       
  2320             exit;
       
  2321             end;
       
  2322 
       
  2323         colorArg:= Trunc(lua_tonumber(L, 1));
       
  2324         if (colorArg < 0) and (abs(colorArg) <= cClanColors) then
       
  2325             // Pick clan color from settings (recommended)
       
  2326             colorStr:= IntToStr(ClanColorArray[Pred(abs(colorArg))])
       
  2327         else if (colorArg >= 0) and (colorArg <= $ffffffff) then
       
  2328             // Specify color directly
       
  2329             colorStr:= IntToStr(colorArg)
       
  2330         else
       
  2331             begin
       
  2332             OutError('Lua error: AddMissionTeam: Invalid ''color'' argument, must be between '+IntToStr(-cClanColors)+' and 0xffffffff!', true);
       
  2333             lc_addmissionteam:= 0;
       
  2334             exit;
       
  2335             end;
       
  2336 
       
  2337         ParseCommand('addteam x ' + colorStr + ' ' + MissionTeam^.TeamName, true, true);
       
  2338         ParseCommand('grave ' + MissionTeam^.GraveName, true, true);
       
  2339         ParseCommand('fort ' + MissionTeam^.FortName, true, true);
       
  2340         ParseCommand('voicepack ' + MissionTeam^.Voicepack^.name, true, true);
       
  2341         ParseCommand('flag ' + MissionTeam^.Flag, true, true);
       
  2342         CurrentTeam^.Binds:= DefaultBinds
       
  2343         end;
       
  2344     lc_addmissionteam:= 0;
       
  2345 end;
       
  2346 
  2310 function lc_setteamlabel(L : Plua_State) : LongInt; Cdecl;
  2347 function lc_setteamlabel(L : Plua_State) : LongInt; Cdecl;
  2311 var teamValue: ansistring;
  2348 var teamValue: ansistring;
  2312     i, n: LongInt;
  2349     i, n: LongInt;
  2313     success: boolean;
  2350     success: boolean;
  2314 begin
  2351 begin
  2497 end;
  2534 end;
  2498 
  2535 
  2499 
  2536 
  2500 
  2537 
  2501 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  2538 function lc_addhog(L : Plua_State) : LongInt; Cdecl;
  2502 var temp: ShortString;
  2539 var hatName: ShortString;
  2503 begin
  2540 begin
  2504     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  2541     if CheckLuaParamCount(L, 4, 'AddHog', 'hogname, botlevel, health, hat') then
  2505         begin
  2542         begin
  2506         temp:= lua_tostring(L, 4);
  2543         hatName:= lua_tostring(L, 4);
  2507         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  2544         ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
  2508         ParseCommand('hat ' + temp, true, true);
  2545         ParseCommand('hat ' + hatName, true, true);
  2509         lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
  2546         lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
  2510         end
  2547         end
  2511     else
  2548     else
  2512         lua_pushnil(L);
  2549         lua_pushnil(L);
  2513     lc_addhog:= 1;
  2550     lc_addhog:= 1;
       
  2551 end;
       
  2552 
       
  2553 function lc_addmissionhog(L : Plua_State) : LongInt; Cdecl;
       
  2554 var hatName: ShortString;
       
  2555 begin
       
  2556     if CheckLuaParamCount(L, 1, 'AddMissionHog', 'health') then
       
  2557         begin
       
  2558         if(MissionTeam = nil) then
       
  2559             begin
       
  2560             OutError('Lua error: AddMissionHog: Could not add hog. Mission team is not set!', true);
       
  2561             lua_pushnil(L);
       
  2562             lc_addmissionhog:= 1;
       
  2563             exit;
       
  2564             end;
       
  2565         with MissionTeam^.Hedgehogs[CurrentTeam^.HedgehogsNumber] do
       
  2566             begin
       
  2567             hatName:= Hat;
       
  2568             ParseCommand('addhh ' + IntToStr(BotLevel) + ' ' + lua_tostring(L, 1) + ' ' + Name, true, true);
       
  2569             ParseCommand('hat ' + hatName, true, true);
       
  2570             end;
       
  2571         lua_pushnumber(L, CurrentHedgehog^.Gear^.uid);
       
  2572         end
       
  2573     else
       
  2574         lua_pushnil(L);
       
  2575     lc_addmissionhog:= 1;
  2514 end;
  2576 end;
  2515 
  2577 
  2516 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  2578 function lc_hogturnleft(L : Plua_State) : LongInt; Cdecl;
  2517 var gear: PGear;
  2579 var gear: PGear;
  2518 begin
  2580 begin
  4287 lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);
  4349 lua_register(luaState, _P'SetSoundMask', @lc_setsoundmask);
  4288 lua_register(luaState, _P'GetTeamName', @lc_getteamname);
  4350 lua_register(luaState, _P'GetTeamName', @lc_getteamname);
  4289 lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);
  4351 lua_register(luaState, _P'GetTeamIndex', @lc_getteamindex);
  4290 lua_register(luaState, _P'GetTeamClan', @lc_getteamclan);
  4352 lua_register(luaState, _P'GetTeamClan', @lc_getteamclan);
  4291 lua_register(luaState, _P'AddTeam', @lc_addteam);
  4353 lua_register(luaState, _P'AddTeam', @lc_addteam);
       
  4354 lua_register(luaState, _P'AddMissionTeam', @lc_addmissionteam);
  4292 lua_register(luaState, _P'SetTeamLabel', @lc_setteamlabel);
  4355 lua_register(luaState, _P'SetTeamLabel', @lc_setteamlabel);
  4293 lua_register(luaState, _P'AddHog', @lc_addhog);
  4356 lua_register(luaState, _P'AddHog', @lc_addhog);
       
  4357 lua_register(luaState, _P'AddMissionHog', @lc_addmissionhog);
  4294 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  4358 lua_register(luaState, _P'AddAmmo', @lc_addammo);
  4295 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
  4359 lua_register(luaState, _P'GetAmmoCount', @lc_getammocount);
  4296 lua_register(luaState, _P'HealHog', @lc_healhog);
  4360 lua_register(luaState, _P'HealHog', @lc_healhog);
  4297 lua_register(luaState, _P'SetHealth', @lc_sethealth);
  4361 lua_register(luaState, _P'SetHealth', @lc_sethealth);
  4298 lua_register(luaState, _P'GetHealth', @lc_gethealth);
  4362 lua_register(luaState, _P'GetHealth', @lc_gethealth);