Skip to content

Commit

Permalink
Add staticdata parameter to add_entity (#5009)
Browse files Browse the repository at this point in the history
* Add staticdata parameter to add_entity
* Add add_entity_with_staticdata to core.features
  • Loading branch information
Rui authored and nerzhul committed Jan 9, 2017
1 parent 8e7449e commit ec30d49
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions builtin/game/features.lua
Expand Up @@ -9,6 +9,7 @@ core.features = {
no_legacy_abms = true,
texture_names_parens = true,
area_store_custom_ids = true,
add_entity_with_staticdata = true,
}

function core.has_feature(arg)
Expand Down
2 changes: 1 addition & 1 deletion doc/lua_api.txt
Expand Up @@ -2173,7 +2173,7 @@ and `minetest.auth_reload` call the authetification handler.
* `minetest.get_node_timer(pos)`
* Get `NodeTimerRef`

* `minetest.add_entity(pos, name)`: Spawn Lua-defined entity at position
* `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at position
* Returns `ObjectRef`, or `nil` if failed
* `minetest.add_item(pos, item)`: Spawn item
* Returns `ObjectRef`, or `nil` if failed
Expand Down
6 changes: 4 additions & 2 deletions src/script/lua_api/l_env.cpp
Expand Up @@ -440,7 +440,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L)
return 1;
}

// add_entity(pos, entityname) -> ObjectRef or nil
// add_entity(pos, entityname, [staticdata]) -> ObjectRef or nil
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_add_entity(lua_State *L)
{
Expand All @@ -450,8 +450,10 @@ int ModApiEnvMod::l_add_entity(lua_State *L)
v3f pos = checkFloatPos(L, 1);
// content
const char *name = luaL_checkstring(L, 2);
// staticdata
const char *staticdata = luaL_optstring(L, 3, "");
// Do it
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, "");
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
int objectid = env->addActiveObject(obj);
// If failed to add, return nothing (reads as nil)
if(objectid == 0)
Expand Down

0 comments on commit ec30d49

Please sign in to comment.