From eb942797b8a1321f7460cea7763bb6891affd475 Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 26 Dec 2011 21:54:08 +0000 Subject: Players can switch worlds on the fly with the command /gotoworld [worldName]. This uses the function cPlayer::MoveToWorld() Changed isValidItem to IsValidItem in Core.lua git-svn-id: http://mc-server.googlecode.com/svn/trunk@126 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlayer.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'source/cPlayer.cpp') diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 5fe31c8c9..dcc9de177 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -701,6 +701,33 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ ) } } +bool cPlayer::MoveToWorld( const char* a_WorldName ) +{ + cWorld* World = cRoot::Get()->GetWorld( a_WorldName ); + if( World ) + { + /* Remove all links to the old world */ + GetWorld()->RemovePlayer( this ); + GetClientHandle()->RemoveFromAllChunks(); + cChunk* Chunk = GetWorld()->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); + if( Chunk ) + { + Chunk->RemoveEntity( *this ); + Chunk->Broadcast( cPacket_DestroyEntity( this ) ); // Remove player entity from all clients in old world + } + + /* Add player to all the necessary parts of the new world */ + SetWorld( World ); + GetWorld()->AddPlayer( this ); + MoveToCorrectChunk(true); + GetClientHandle()->StreamChunks(); + + return true; + } + + return false; +} + bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player { cIniFile IniFile("users.ini"); -- cgit v1.2.3