Plugin developement
#11
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 Wink:
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
Reply
Thanks given by:
#12
(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.
i quickly made this i hope it makes sense for you Wink
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?
Reply
Thanks given by:
#13
you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpaccept
Reply
Thanks given by:
#14
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.
Reply
Thanks given by:
#15
(04-15-2013, 12:44 AM)STR_Warrior Wrote: you have to add this to the main.lua: Destination = {} -- Needed for /tpa and /tpaccept
Where? In the end of the file?
Reply
Thanks given by:
#16
(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 /tpaccept
Were? In the end of the file?

Preferably the beginning of the file I think
Reply
Thanks given by:
#17
(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 /tpaccept
Were? In the end of the file?

well you could do it in the initialize function but i added it in line 13 under X = {}
Reply
Thanks given by:
#18
(04-15-2013, 12:47 AM)STR_Warrior Wrote:
(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 /tpaccept
Were? In the end of the file?

well you could do it in the initialize function but i added it in line 13 under X = {}
Thank you very much, now it worked Smile.
But, what is Scratch? I found that it's a graphical engine for games. Is it?
Reply
Thanks given by:
#19
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.
Reply
Thanks given by:
#20
(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
Reply
Thanks given by:




Users browsing this thread: 12 Guest(s)