aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index a064cd688..23063a3c8 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -45,6 +45,7 @@ extern "C" {
#include "mapblock.h" // For getNodeBlockPos
#include "content_nodemeta.h"
#include "utility.h"
+#include "serverlinkableobject.h"
static void stackDump(lua_State *L, std::ostream &o)
{
@@ -2211,7 +2212,7 @@ private:
get_server(L)->SendMovePlayer(player);
return 0;
}
-
+
// moveto(self, pos, continuous=false)
static int l_moveto(lua_State *L)
{
@@ -2540,6 +2541,62 @@ private:
return 1;
}
+ // link(parent, offset)
+ static int l_link(lua_State *L)
+ {
+ ObjectRef *ref_child = checkobject(L, 1);
+ ObjectRef *ref_parent = checkobject(L, 2);
+ v3f offset = checkFloatPos(L, 3);
+
+ ServerActiveObject *child = getobject(ref_child);
+ ServerActiveObject *parent = getobject(ref_parent);
+
+ if ((child == NULL) || (parent == NULL)) {
+ errorstream << "LUA: link(): invalid parameters" << std::endl;
+ return 0;
+ }
+
+
+ ServerLinkableObject* child_lua = dynamic_cast<ServerLinkableObject*>(child);
+ ServerLinkableObject* parent_lua = dynamic_cast<ServerLinkableObject*>(parent);
+
+ if (child_lua == NULL) return 0;
+ if (parent_lua == NULL) return 0;
+
+ if (child_lua->linkEntity(parent,offset)) {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
+ // unlink()
+ static int l_unlink(lua_State *L)
+ {
+ ObjectRef *ref = checkobject(L, 1);
+
+ ServerActiveObject *obj = getobject(ref);
+
+ if (obj == NULL) {
+ errorstream << "LUA: unlink(): invalid parameters" << std::endl;
+ return 0;
+ }
+
+ ServerLinkableObject* tolink = dynamic_cast<ServerLinkableObject*>(obj);
+
+ if (tolink == NULL) return 0;
+
+ if (tolink->unlinkEntity()) {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+ else {
+ return 0;
+ }
+ }
+
public:
ObjectRef(ServerActiveObject *object):
m_object(object)
@@ -2633,6 +2690,8 @@ const luaL_reg ObjectRef::methods[] = {
method(ObjectRef, get_look_dir),
method(ObjectRef, get_look_pitch),
method(ObjectRef, get_look_yaw),
+ method(ObjectRef, link),
+ method(ObjectRef, unlink),
{0,0}
};
@@ -2913,6 +2972,35 @@ private:
return 1;
}
+ // EnvRef:get_objects_inside_radius(pos, radius)
+ static int l_get_nodes_inside_radius(lua_State *L)
+ {
+ // Get the table insert function
+ lua_getglobal(L, "table");
+ lua_getfield(L, -1, "insert");
+ int table_insert = lua_gettop(L);
+ // Get environemnt
+ EnvRef *o = checkobject(L, 1);
+ ServerEnvironment *env = o->m_env;
+ if(env == NULL) return 0;
+ // Do it
+ v3s16 pos = read_v3s16(L, 2);
+ float radius = luaL_checknumber(L, 3);// * BS;
+ core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
+ lua_newtable(L);
+ int table = lua_gettop(L);
+ for(core::list<MapNode>::Iterator
+ i = nodes.begin(); i != nodes.end(); i++){
+ // Insert object reference into table
+ lua_pushvalue(L, table_insert);
+ lua_pushvalue(L, table);
+ pushnode(L, *i, env->getGameDef()->ndef());
+ if(lua_pcall(L, 2, 0, 0))
+ script_error(L, "error: %s", lua_tostring(L, -1));
+ }
+ return 1;
+ }
+
// EnvRef:set_timeofday(val)
// val = 0...1
static int l_set_timeofday(lua_State *L)
@@ -3022,6 +3110,7 @@ const luaL_reg EnvRef::methods[] = {
method(EnvRef, get_meta),
method(EnvRef, get_player_by_name),
method(EnvRef, get_objects_inside_radius),
+ method(EnvRef, get_nodes_inside_radius),
method(EnvRef, set_timeofday),
method(EnvRef, get_timeofday),
{0,0}