on_activate = function(self, staticdata)
self.object:set_armor_groups({immortal = 1})
-
+
local ds = core.deserialize(staticdata)
if ds and ds.node then
self:set_node(ds.node, ds.meta)
##### LuaEntitySAO-only (no-op for other objects)
* `set_velocity(vel)`
* `vel` is a vector, e.g. `{x=0.0, y=2.3, z=1.0}`
+* `add_velocity(vel)`
+ * `vel` is a vector, e.g. `{x=0.0, y=2.3, z=1.0}`
+ * In comparison to using get_velocity, adding the velocity and then using
+ set_velocity, add_velocity is supposed to avoid synchronization problems.
* `get_velocity()`: returns the velocity, a vector
* `set_acceleration(acc)`
* `acc` is a vector
s16 getHP() const;
/* LuaEntitySAO-specific */
void setVelocity(v3f velocity);
+ void addVelocity(v3f velocity)
+ {
+ m_velocity += velocity;
+ }
v3f getVelocity();
void setAcceleration(v3f acceleration);
v3f getAcceleration();
return 0;
}
+// add_velocity(self, {x=num, y=num, z=num})
+int ObjectRef::l_add_velocity(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ LuaEntitySAO *co = getluaobject(ref);
+ if (!co)
+ return 0;
+ v3f pos = checkFloatPos(L, 2);
+ // Do it
+ co->addVelocity(pos);
+ return 0;
+}
+
// get_velocity(self)
int ObjectRef::l_get_velocity(lua_State *L)
{
luamethod(ObjectRef, get_nametag_attributes),
// LuaEntitySAO-only
luamethod_aliased(ObjectRef, set_velocity, setvelocity),
+ luamethod(ObjectRef, add_velocity),
luamethod_aliased(ObjectRef, get_velocity, getvelocity),
luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
// set_velocity(self, {x=num, y=num, z=num})
static int l_set_velocity(lua_State *L);
+ // add_velocity(self, {x=num, y=num, z=num})
+ static int l_add_velocity(lua_State *L);
+
// get_velocity(self)
static int l_get_velocity(lua_State *L);