From 945d01fd9efe93e892a6a2be2467373e3c684300 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 26 Nov 2011 03:20:19 +0200 Subject: on_newplayer and on_respawnplayer callbacks --- src/player.h | 6 ++++ src/scriptapi.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++------- src/scriptapi.h | 4 +++ src/server.cpp | 26 ++++++++-------- 4 files changed, 104 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/player.h b/src/player.h index 56bb5083c..e133c7afb 100644 --- a/src/player.h +++ b/src/player.h @@ -208,6 +208,12 @@ public: u8 getType() const {return ACTIVEOBJECT_TYPE_PLAYER;} + + virtual void setPos(v3f pos) + { setPosition(pos); } + virtual void moveTo(v3f pos, bool continuous) + { setPosition(pos); } + virtual std::string getDescription(){return getName();} // Returns a reference virtual InventoryItem* getWieldedItem(); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 4a746c8f4..fd9d10195 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -41,9 +41,8 @@ extern "C" { /* TODO: -- Node definition - Random node triggers (like grass growth) -- Deterministic node triggers (like falling sand) +- All kinds of callbacks - Object visual client-side stuff - Blink effect - Spritesheets and animation @@ -848,6 +847,20 @@ static int l_register_on_punchnode(lua_State *L) return register_lua_callback(L, "registered_on_punchnodes"); } +// register_on_newplayer(function) +static int l_register_on_newplayer(lua_State *L) +{ + infostream<<"register_on_newplayer"<getServerMap()); - player->setPosition(pos); player->hp = 20; + ServerRemotePlayer *srp = (ServerRemotePlayer*)player; + bool repositioned = scriptapi_on_respawnplayer(m_lua, srp); + if(!repositioned){ + v3f pos = findSpawnPos(m_env->getServerMap()); + player->setPosition(pos); + } SendMovePlayer(player); SendPlayerHP(player); } @@ -4617,9 +4621,7 @@ Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id m_authmanager.setPrivs(name, stringToPrivs(g_settings->get("default_privs"))); - /* - Set player position - */ + /* Set player position */ infostream<<"Server: Finding spawn place for player \"" <addPlayer(player); - /* - Add stuff to inventory - */ - + /* Run scripts */ + ServerRemotePlayer *srp = (ServerRemotePlayer*)player; + scriptapi_on_newplayer(m_lua, srp); + + /* Add stuff to inventory */ if(g_settings->getBool("creative_mode")) { // Warning: double code above -- cgit v1.2.3