hedgewars/uScript.pas
changeset 12952 c8b7bc04eb4c
parent 12944 0112ef349ddc
child 13023 0248cf0da834
equal deleted inserted replaced
12951:1a1a514aef2e 12952:c8b7bc04eb4c
  1687     lc_switchhog:= 0
  1687     lc_switchhog:= 0
  1688 end;
  1688 end;
  1689 
  1689 
  1690 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1690 function lc_addammo(L : Plua_State) : LongInt; Cdecl;
  1691 var gear : PGear;
  1691 var gear : PGear;
  1692     at, n: LongInt;
  1692     at, n, c: LongInt;
  1693 const
  1693 const
  1694     call = 'AddAmmo';
  1694     call = 'AddAmmo';
  1695     params = 'gearUid, ammoType [, ammoCount]';
  1695     params = 'gearUid, ammoType [, ammoCount]';
  1696 begin
  1696 begin
  1697     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1697     if CheckAndFetchParamCount(L, 2, 3, call, params, n) then
  1698         begin
  1698         begin
  1699         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1699         at:= LuaToAmmoTypeOrd(L, 2, call, params);
  1700         if at >= 0 then
  1700         if (at >= 0) and (TAmmoType(at) <> amNothing) then
  1701             begin
  1701             begin
  1702             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1702             gear:= GearByUID(Trunc(lua_tonumber(L, 1)));
  1703             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1703             if (gear <> nil) and (gear^.Hedgehog <> nil) then
  1704                 if n = 2 then
  1704                 if n = 2 then
  1705                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1705                     AddAmmo(gear^.Hedgehog^, TAmmoType(at))
  1706                 else
  1706                 else
  1707                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), Trunc(lua_tonumber(L, 3)))
  1707                     begin
       
  1708                     c:= Trunc(lua_tonumber(L, 3));
       
  1709                     if (c = 0) and (CurrentHedgehog = gear^.Hedgehog) and (gear^.Hedgehog^.CurAmmoType = TAmmoType(at)) then
       
  1710                         ParseCommand('setweap ' + char(0), true, true);
       
  1711                     SetAmmo(gear^.Hedgehog^, TAmmoType(at), c);
       
  1712                     end;
  1708             end;
  1713             end;
  1709         end;
  1714         end;
  1710     lc_addammo:= 0
  1715     lc_addammo:= 0
  1711 end;
  1716 end;
  1712 
  1717