Add ObjectRef:punch and ObjectRef:right_click to Lua API
authorPerttu Ahola <celeron55@gmail.com>
Wed, 30 Nov 2011 18:54:54 +0000 (20:54 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Wed, 30 Nov 2011 18:54:54 +0000 (20:54 +0200)
data/mods/default/init.lua
src/scriptapi.cpp

index 0e42974ef2bfc88d8fb38b5b286845841472647d..5b94a13a05fb0f2d7c8a49a6f565e6b6841cf28e 100644 (file)
@@ -81,6 +81,8 @@
 -- - getpos(): returns {x=num, y=num, z=num}
 -- - setpos(pos); pos={x=num, y=num, z=num}
 -- - moveto(pos, continuous=false): interpolated move
+-- - punch(puncher); puncher = an another ObjectRef
+-- - right_click(clicker); clicker = an another ObjectRef
 -- - get_wielded_itemstring()
 -- - get_wielded_item()
 -- - damage_wielded_item(num) (item damage/wear range is 0-65535)
@@ -89,9 +91,9 @@
 -- - get_hp(): returns number of hitpoints (2 * number of hearts)
 -- - set_hp(hp): set number of hitpoints (2 * number of hearts)
 -- LuaEntitySAO-only:
--- - setvelocity(self, {x=num, y=num, z=num})
--- - setacceleration(self, {x=num, y=num, z=num})
--- - getacceleration(self)
+-- - setvelocity({x=num, y=num, z=num})
+-- - setacceleration({x=num, y=num, z=num})
+-- - getacceleration()
 -- - settexturemod(mod)
 -- - setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
 -- -           select_horiz_by_yawpitch=false)
index fbdbf4a124df373e2b0030c141b6259436e6c4eb..8a3d4a4964e76e5f39e6a5fdb9d92b40a2650722 100644 (file)
@@ -1642,6 +1642,34 @@ private:
                return 0;
        }
 
+       // punch(self, puncher); puncher = an another ObjectRef
+       static int l_punch(lua_State *L)
+       {
+               ObjectRef *ref = checkobject(L, 1);
+               ObjectRef *ref2 = checkobject(L, 2);
+               ServerActiveObject *co = getobject(ref);
+               ServerActiveObject *co2 = getobject(ref2);
+               if(co == NULL) return 0;
+               if(co2 == NULL) return 0;
+               // Do it
+               co->punch(co2);
+               return 0;
+       }
+
+       // right_click(self, clicker); clicker = an another ObjectRef
+       static int l_right_click(lua_State *L)
+       {
+               ObjectRef *ref = checkobject(L, 1);
+               ObjectRef *ref2 = checkobject(L, 2);
+               ServerActiveObject *co = getobject(ref);
+               ServerActiveObject *co2 = getobject(ref2);
+               if(co == NULL) return 0;
+               if(co2 == NULL) return 0;
+               // Do it
+               co->rightClick(co2);
+               return 0;
+       }
+
        // get_wielded_itemstring(self)
        static int l_get_wielded_itemstring(lua_State *L)
        {
@@ -1954,6 +1982,8 @@ const luaL_reg ObjectRef::methods[] = {
        method(ObjectRef, getpos),
        method(ObjectRef, setpos),
        method(ObjectRef, moveto),
+       method(ObjectRef, punch),
+       method(ObjectRef, right_click),
        method(ObjectRef, get_wielded_itemstring),
        method(ObjectRef, get_wielded_item),
        method(ObjectRef, damage_wielded_item),