Plugin developement - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: Plugin developement (/thread-857.html) |
RE: Plugin developement - NiLSPACE - 04-15-2013 well since a tpa is different from a normal teleport i'd suggest writing it from scratch. i quickly made this i hope it makes sense for you : function HandleTPACommand( Split, Player ) if Split[2] == nil then Player:SendMessage( cChatColor.Green .. "Usage: /tpa [Player]" ) return true end local loopPlayer = function( OtherPlayer ) if OtherPlayer:GetName() == Split[2] then OtherPlayer:SendMessage( cChatColor.Green .. Player:GetName() .. " send a teleport request" ) Player:SendMessage( cChatColor.Green .. "You send a teleport request to " .. OtherPlayer:GetName() ) Destination[OtherPlayer:GetName()] = Player:GetName() end end local loopWorlds = function( World ) World:ForEachPlayer( loopPlayer ) end cRoot:Get():ForEachWorld( loopWorlds ) return true end function HandleTPAcceptCommand( Split, Player ) if Destination[Player:GetName()] == nil then Player:SendMessage( cChatColor.Green .. "Nobody has send you a teleport request" ) return true end local loopPlayer = function( OtherPlayer ) if Destination[Player:GetName()] == OtherPlayer:GetName() then if OtherPlayer:GetWorld():GetName() ~= Player:GetWorld():GetName() then OtherPlayer:MoveToWorld( Player:GetWorld():GetName() ) end OtherPlayer:TeleportToEntity( Player ) Player:SendMessage( cChatColor.Green .. OtherPlayer:GetName() .. " teleported to you" ) OtherPlayer:SendMessage( cChatColor.Green .. "You teleported to " .. Player:GetName() ) Destination[Player:GetName()] = nil end end local loopWorlds = function( World ) World:ForEachPlayer( loopPlayer ) end cRoot:Get():ForEachWorld( loopWorlds ) return true end RE: Plugin developement - tonibm19 - 04-15-2013 (04-15-2013, 12:33 AM)STR_Warrior Wrote: well since a tpa is different from a normal teleport i'd suggest writing it from scratch.It gives me the following error when typing /tpaccept: LUA: Plugins/Core/tpa.lua:10: attempt to index global 'Destination' (a nil value) LUA: Plugins/Core/tpa.lua:25: attempt to index global 'Destination' (a nil value) LUA error in HandleCommand. Stack size: 3 What is scratch? RE: Plugin developement - NiLSPACE - 04-15-2013 you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpaccept RE: Plugin developement - FakeTruth - 04-15-2013 You could also use cRoot:FindAndDoWithPlayer() instead of manually looping each world and each player to find the player you're looking for. /// Finds a player from a partial or complete player name and calls the callback - case-insensitive bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); But yeah, like STR_Warrior demonstrated you should store the teleport request in one way or the other to later retrieve it again when the teleport request was accepted. RE: Plugin developement - tonibm19 - 04-15-2013 (04-15-2013, 12:44 AM)STR_Warrior Wrote: you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpacceptWhere? In the end of the file? RE: Plugin developement - FakeTruth - 04-15-2013 (04-15-2013, 12:46 AM)tonibm19 Wrote:(04-15-2013, 12:44 AM)STR_Warrior Wrote: you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpacceptWere? In the end of the file? Preferably the beginning of the file I think RE: Plugin developement - NiLSPACE - 04-15-2013 (04-15-2013, 12:46 AM)tonibm19 Wrote:(04-15-2013, 12:44 AM)STR_Warrior Wrote: you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpacceptWere? In the end of the file? well you could do it in the initialize function but i added it in line 13 under X = {} RE: Plugin developement - tonibm19 - 04-15-2013 (04-15-2013, 12:47 AM)STR_Warrior Wrote:Thank you very much, now it worked .(04-15-2013, 12:46 AM)tonibm19 Wrote:(04-15-2013, 12:44 AM)STR_Warrior Wrote: you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpacceptWere? In the end of the file? But, what is Scratch? I found that it's a graphical engine for games. Is it? RE: Plugin developement - NiLSPACE - 04-15-2013 from scratch is that you start while having nothing. so you don't use any other code from somewhere else. becouse you now used code from the teleport.lua but that would not realy work with a /tpa command. RE: Plugin developement - tonibm19 - 04-15-2013 (04-15-2013, 12:53 AM)STR_Warrior Wrote: from scratch is that you start while having nothing. so you don't use any other code from somewhere else. becouse you now used code from the teleport.lua but that would not realy work with a /tpa command.Ok, I didn't know. Thank you |