#include "common/c_content.h"
#include "log.h"
#include "tool.h"
-#include "serverobject.h"
-#include "content_sao.h"
#include "remoteplayer.h"
#include "server.h"
#include "hud.h"
#include "scripting_server.h"
+#include "server/luaentity_sao.h"
+#include "server/player_sao.h"
+#include "server/serverinventorymgr.h"
/*
ObjectRef
ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
{
ServerActiveObject *co = ref->m_object;
+ if (co && co->isGone())
+ return NULL;
return co;
}
return NULL;
if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY)
return NULL;
- if (obj->isGone())
- return NULL;
return (LuaEntitySAO*)obj;
}
return NULL;
if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER)
return NULL;
- if (obj->isGone())
- return NULL;
return (PlayerSAO*)obj;
}
ObjectRef *ref = checkobject(L, 1);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
- v3f pos = co->getBasePosition() / BS;
- lua_newtable(L);
- lua_pushnumber(L, pos.X);
- lua_setfield(L, -2, "x");
- lua_pushnumber(L, pos.Y);
- lua_setfield(L, -2, "y");
- lua_pushnumber(L, pos.Z);
- lua_setfield(L, -2, "z");
+ push_v3f(L, co->getBasePosition() / BS);
return 1;
}
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- //LuaEntitySAO *co = getluaobject(ref);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
// pos
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- //LuaEntitySAO *co = getluaobject(ref);
ServerActiveObject *co = getobject(ref);
if (co == NULL) return 0;
// pos
if (co == NULL) return 0;
// Do it
InventoryLocation loc = co->getInventoryLocation();
- if (getServer(L)->getInventory(loc) != NULL)
+ if (getServerInventoryMgr(L)->getInventory(loc) != NULL)
InvRef::create(L, loc);
else
lua_pushnil(L); // An object may have no inventory (nil)
// get_local_animation(self)
int ObjectRef::l_get_local_animation(lua_State *L)
{
- NO_MAP_LOCK_REQUIRED
+ NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref);
if (player == NULL)
ServerActiveObject *parent = getobject(parent_ref);
if (co == NULL)
return 0;
+
if (parent == NULL)
return 0;
+
+ if (co == parent)
+ throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");
+
// Do it
int parent_id = 0;
std::string bone;
ObjectRef *ref = checkobject(L, 1);
v3f vel = checkFloatPos(L, 2);
- RemotePlayer *player = getplayer(ref);
PlayerSAO *co = getplayersao(ref);
- if (!player || !co)
+ if (!co)
return 0;
- session_t peer_id = player->getPeerId();
- if (peer_id == PEER_ID_INEXISTENT)
- return 0;
// Do it
co->setMaxSpeedOverride(vel);
- getServer(L)->SendPlayerSpeed(peer_id, vel);
+ getServer(L)->SendPlayerSpeed(co->getPeerID(), vel);
return 0;
}
return 1;
}
-// set_fov(self, degrees[, is_multiplier])
+// set_fov(self, degrees[, is_multiplier, transition_time])
int ObjectRef::l_set_fov(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
if (!player)
return 0;
- player->setFov({ static_cast<f32>(luaL_checknumber(L, 2)), readParam<bool>(L, 3) });
+ player->setFov({
+ static_cast<f32>(luaL_checknumber(L, 2)),
+ readParam<bool>(L, 3, false),
+ lua_isnumber(L, 4) ? static_cast<f32>(luaL_checknumber(L, 4)) : 0.0f
+ });
getServer(L)->SendPlayerFov(player->getPeerId());
return 0;
PlayerFovSpec fov_spec = player->getFov();
lua_pushnumber(L, fov_spec.fov);
lua_pushboolean(L, fov_spec.is_multiplier);
+ lua_pushnumber(L, fov_spec.transition_time);
- return 2;
+ return 3;
}
// set_breath(self, breath)
lua_setfield(L, -2, "LMB");
lua_pushboolean(L, control.RMB);
lua_setfield(L, -2, "RMB");
+ lua_pushboolean(L, control.zoom);
+ lua_setfield(L, -2, "zoom");
return 1;
}
lua_pop(L, 1);
// Prevent flickering clouds at dawn/dusk:
- skybox_params.sun_tint = video::SColor(255, 255, 255, 255);
+ skybox_params.fog_sun_tint = video::SColor(255, 255, 255, 255);
lua_getfield(L, -1, "fog_sun_tint");
- read_color(L, -1, &skybox_params.sun_tint);
+ read_color(L, -1, &skybox_params.fog_sun_tint);
lua_pop(L, 1);
- skybox_params.moon_tint = video::SColor(255, 255, 255, 255);
+ skybox_params.fog_moon_tint = video::SColor(255, 255, 255, 255);
lua_getfield(L, -1, "fog_moon_tint");
- read_color(L, -1, &skybox_params.moon_tint);
+ read_color(L, -1, &skybox_params.fog_moon_tint);
lua_pop(L, 1);
lua_getfield(L, -1, "fog_tint_type");
if (!lua_isnil(L, -1))
- skybox_params.tint_type = luaL_checkstring(L, -1);
+ skybox_params.fog_tint_type = luaL_checkstring(L, -1);
lua_pop(L, 1);
// Because we need to leave the "sky_color" table.
push_ARGB8(L, skybox_params.sky_color.indoors);
lua_setfield(L, -2, "indoors");
}
- push_ARGB8(L, skybox_params.sun_tint);
- lua_setfield(L, -2, "sun_tint");
- push_ARGB8(L, skybox_params.moon_tint);
- lua_setfield(L, -2, "moon_tint");
- lua_pushstring(L, skybox_params.tint_type.c_str());
- lua_setfield(L, -2, "tint_type");
+ push_ARGB8(L, skybox_params.fog_sun_tint);
+ lua_setfield(L, -2, "fog_sun_tint");
+ push_ARGB8(L, skybox_params.fog_moon_tint);
+ lua_setfield(L, -2, "fog_moon_tint");
+ lua_pushstring(L, skybox_params.fog_tint_type.c_str());
+ lua_setfield(L, -2, "fog_tint_type");
return 1;
}
ratio = readParam<float>(L, 2);
}
- if (!getServer(L)->overrideDayNightRatio(player, do_override, ratio))
- return 0;
-
+ getServer(L)->overrideDayNightRatio(player, do_override, ratio);
lua_pushboolean(L, true);
return 1;
}