Add Player.instance & Player:teleport()

This commit is contained in:
CPunch 2021-04-17 19:40:37 -05:00 committed by gsemaj
parent c2853d9271
commit b25b229eb2
2 changed files with 63 additions and 4 deletions

View File

@ -1,15 +1,23 @@
print("Hello world!") print("Hello wtf!")
World.onPlayerAdded:listen(function(plr) function onJoin(plr)
print(plr.type .. " " .. plr.name .. " joined from LUA!!") print(plr.type .. " " .. plr.name .. " joined from LUA!!")
plr.onChat:listen(function(msg) plr.onChat:listen(function(msg)
print(plr.name .. " said : " .. msg) print(plr.name .. " said : \'" .. msg .. "\'")
if msg == "kickme" then if msg == "kickme" then
plr:kick() plr:kick()
elseif msg == "hi" then
print("hello " .. plr.name)
end end
end) end)
end) end
World.onPlayerAdded:listen(onJoin)
for i, plr in ipairs(World.players) do
onJoin(plr)
end
wait(2) wait(2)
print("Hello world ~2 seconds later! running protcol version " .. World.version) print("Hello world ~2 seconds later! running protcol version " .. World.version)

View File

@ -62,6 +62,16 @@ static int plr_getName(lua_State *state) {
return 1; return 1;
} }
static int plr_getInstance(lua_State *state) {
Player *plr = grabPlayer(state, 1);
if (plr == NULL)
return 0;
lua_pushnumber(state, plr->instanceID);
return 1;
}
static int plr_getChatted(lua_State *state) { static int plr_getChatted(lua_State *state) {
Player *plr = grabPlayer(state, 1); Player *plr = grabPlayer(state, 1);
@ -79,13 +89,32 @@ static int plr_getChatted(lua_State *state) {
static const luaL_Reg plr_getters[] = { static const luaL_Reg plr_getters[] = {
{"name", plr_getName}, {"name", plr_getName},
{"instance", plr_getInstance},
{"onChat", plr_getChatted}, {"onChat", plr_getChatted},
{0, 0} {0, 0}
}; };
// =============================================== [[ SETTERS ]] =============================================== // =============================================== [[ SETTERS ]] ===============================================
static int plr_setInstance(lua_State *state) {
EntityRef *ref = grabEntityRef(state, 1);
int newInst = luaL_checkint(state, 2);
Player *plr;
CNSocket *sock;
// sanity check
if (ref == NULL)
return 0;
plr = (Player*)ref->getEntity();
sock = ref->sock;
PlayerManager::sendPlayerTo(sock, plr->x, plr->y, plr->z, newInst);
return 0;
}
static const luaL_Reg plr_setters[] = { static const luaL_Reg plr_setters[] = {
{"instance", plr_setInstance},
{0, 0} {0, 0}
}; };
@ -118,8 +147,30 @@ static int plr_kick(lua_State *state) {
return 0; return 0;
} }
static int plr_teleport(lua_State *state) {
EntityRef *ref = grabEntityRef(state, 1);
Player *plr;
CNSocket *sock;
// sanity check
if (ref == NULL)
return 0;
plr = (Player*)ref->getEntity();
sock = ref->sock;
int X = luaL_checkint(state, 2);
int Y = luaL_checkint(state, 3);
int Z = luaL_checkint(state, 4);
int inst = luaL_optint(state, 5, plr->instanceID);
PlayerManager::sendPlayerTo(sock, X, Y, Z, inst);
return 0;
}
static const luaL_Reg plr_methods[] = { static const luaL_Reg plr_methods[] = {
{"kick", plr_kick}, {"kick", plr_kick},
{"teleport", plr_teleport},
{0, 0} {0, 0}
}; };