add getter for effects. untested.
authornemo
Mon, 01 Aug 2011 13:29:01 -0400
changeset 5489 f7ec6e5ad054
parent 5488 fef456439238
child 5490 18c6049b5ae3
add getter for effects. untested.
hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Mon Aug 01 10:08:02 2011 +0400
+++ b/hedgewars/uScript.pas	Mon Aug 01 13:29:01 2011 -0400
@@ -986,11 +986,28 @@
         LuaError('Lua: Wrong number of parameters passed to SetEffect!')
     else begin
         gear := GearByUID(lua_tointeger(L, 1));
-        if gear <> nil then
+        if (gear <> nil) and (gear^.Hedgehog <> nil) then
             gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))]:= lua_toboolean(L, 3);
     end;
     lc_seteffect := 0;
 end;
+function lc_geteffect(L : Plua_State) : LongInt; Cdecl;
+var gear : PGear;
+begin
+    if lua_gettop(L) <> 2 then
+        begin
+        LuaError('Lua: Wrong number of parameters passed to GetEffect!');
+        end
+    else
+        begin
+        gear:= GearByUID(lua_tointeger(L, 1));
+        if (gear <> nil) and (gear^.Hedgehog <> nil) then
+            lua_pushboolean(L, gear^.Hedgehog^.Effects[THogEffect(lua_tointeger(L, 2))])
+        else
+            lua_pushboolean(L, false)
+        end;
+    lc_geteffect:= 1
+end;
 
 function lc_setstate(L : Plua_State) : LongInt; Cdecl;
 var gear : PGear;
@@ -1840,6 +1857,7 @@
 lua_register(luaState, 'SetHealth', @lc_sethealth);
 lua_register(luaState, 'GetHealth', @lc_gethealth);
 lua_register(luaState, 'SetEffect', @lc_seteffect);
+lua_register(luaState, 'GetEffect', @lc_geteffect);
 lua_register(luaState, 'GetHogClan', @lc_gethogclan);
 lua_register(luaState, 'GetClanColor', @lc_getclancolor);
 lua_register(luaState, 'SetClanColor', @lc_setclancolor);