Random Chitchat 2012-2016
then it should be more like this:
if Split[2] == "creative" then
Player:MoveToWorld(Split[2])
Player:SetGameMode(1)
Player:SendMessage( cChatColor.Green .. "Moved successfully to \'" .. Split[2] .. "\'! " )
return true
end
Thanks given by: tonibm19
Thank you veery much Smile
Thanks given by:
1, Don't use magic numbers in your code, use named constants:
Player:SetGameMode(gmCreative);

2, Players should already inherit the gamemode of the world they are moved to, unless they issued the /gm command, which pins their gamemode forever. So for regular players there's no need to set their gamemode. There's even a special value for SetGameMode() that has this effect, gmNotSet.

3, If you want to set the gamemode, read the gamemode of the destination world; this way it'll work for any world names and any number of worlds:
Player:SetGameMode(cRoot:Get():GetWorld(WorldName):GetGameMode());
Thanks given by: NiLSPACE , tonibm19
(06-27-2013, 05:40 AM)xoft Wrote:
Player:SetGameMode(cRoot:Get():GetWorld(WorldName):GetGameMode());
Thank you but don't work.
LUA: Plugins/Core/gotoworld.lua:21: attemp to index a nil value
LUA error in cPlugin_NewLua::HandleCommand. Stack size: 3

my gotoworld.lua.
function HandleGotoWorldCommand( Split, Player )
	if( #Split ~= 2 ) then
		Player:SendMessage( cChatColor.Green .. "Usage: /gotoworld [WorldName]" )
		return true	
	end
	
	if( Player:MoveToWorld(Split[2]) == false ) then
		Player:SendMessage( cChatColor.Green .. "Could not move to world '" .. Split[2] .. "'!" )
		return true
	end
	


	
	Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'!Big Grin" )
	World = Player:GetWorld()
	X[Player:GetName()] = Player:GetPosX()
	Y[Player:GetName()] = Player:GetPosY()
	Z[Player:GetName()] = Player:GetPosZ()
	Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() )
	Player:SetGameMode(cRoot:Get():GetWorld(WorldName):GetGameMode());
	return true
end
Thanks given by:
change the world = player:getworld() to
WorldName = Player:GetWorld():GetName()
Thanks given by:
(06-27-2013, 06:02 PM)STR_Warrior Wrote: change the world = player:getworld() to
WorldName = Player:GetWorld():GetName()
Don't work, If i do it I get an error and player is not teleported to the spawn on changing world.
I tried with this but player gamemode doesn't change.
function HandleGotoWorldCommand( Split, Player )
	if( #Split ~= 2 ) then
		Player:SendMessage( cChatColor.Green .. "Usage: /gotoworld [WorldName]" )
		return true	
	end
	
	if( Player:MoveToWorld(Split[2]) == false ) then
		Player:SendMessage( cChatColor.Green .. "Could not move to world '" .. Split[2] .. "'!" )
		return true
	end
	


	
	Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'!Big Grin" )
	WorldName = Player:GetWorld():GetName()
	World = Player:GetWorld()
	X[Player:GetName()] = Player:GetPosX()
	Y[Player:GetName()] = Player:GetPosY()
	Z[Player:GetName()] = Player:GetPosZ()
	Player:TeleportTo( World:GetSpawnX(), World:GetSpawnY(), World:GetSpawnZ() )
	Player:SetGameMode(cRoot:Get():GetWorld(WorldName):GetGameMode());
	return true
end
Thanks given by:
What is the error message, and on what line of the code snippet?

Line 7: Don't compare boolean values, use them directly:
if (not(Player:MoveToWorld(Split[2]))) then

Line 15: The message seems badly escaped at the HTML quotes:
Player:SendMessage( cChatColor.Green .. "Moved successfully to '" .. Split[2] .. "'! <img src=\"images/smilies/biggrin.gif\" style=\"vertical-align: middle;\" border=\"0\" alt=\"Big Grin\" title=\"Big Grin\">" )

On a side note, it seems that the cPlayer::MoveToWorld() function could benefit from additional parameters:
Player:MoveToWorld(WorldName, PosX, PosY, PosZ);

Oh, it seems the forum's Lua syntax highlighter does some escaping on its own. Anyway, get the Decoda Lua IDE and edit the Lua files in it, it will help you by syntax-highlighting and you can even debug the code there. Here's a guide:
https://forum.cuberite.org/showthread.php?tid=1141
Thanks given by:
I did it Smile, now gamemode changes.
The correct code is the latest I posted. What I did wrong was that all worlds had gamemode set to 1 (the default) so gamemode don't changed.
Now I need to clear inventory when a player changes from a survival world to a creative world
Thanks given by:
That will be difficult, if not impossible, if you wanted to do it properly and completely. There's no way to save the entire inventory in one API call, and if I remember correctly, there's still no way of specifying enchantments in item strings understood by StringToItem() / ItemToString(), so you'll need to handle enchantments by hand.
Thanks given by:
(06-27-2013, 07:29 PM)xoft Wrote: That will be difficult, if not impossible, if you wanted to do it properly and completely. There's no way to save the entire inventory in one API call, and if I remember correctly, there's still no way of specifying enchantments in item strings understood by StringToItem() / ItemToString(), so you'll need to handle enchantments by hand.
I will basically clear inventory when changing from a creative world to a survival.
Thanks given by:




Users browsing this thread: 98 Guest(s)