Jump to content

Ajuda Chat Local


Recommended Posts

Olá, 

estou com uma duvida em meu script.

Como faço para que esse Chatbox fica local ? só aparece ao redor de quem usou o comando, e ao redor da pessou que puxado pelo comando.

function getPlayer(player, cmd, id)
	if tonumber(id) then
		local mx, my, mz = getElementPosition(player)
		local player2 = getPlayerFromID ( tonumber(id) )
		local trplayername = getPlayerName(player):gsub("#%x%x%x%x%x%x","")
		if not player2 or not isElement(player2) then
			return outputChatBox( "Player Offline", player )
		end
		local rand = math.random(1, 5)
		outputChatBox ( "#c9c9c9[#1a6cefFW-COMANDO#c9c9c9]O #1a6cef".. trplayername .."#c9c9c9 Puxou o #1a6cef".. id .."", source, 255, 0, 0, true );
		setElementPosition(player2, mx+rand, my+rand, mz + 1)
	end
end
addCommandHandler("tr", getPlayer)

 

Link to comment
On 25/07/2019 at 17:24, giovanymito said:

Olá, 

estou com uma duvida em meu script.

Como faço para que esse Chatbox fica local ? só aparece ao redor de quem usou o comando, e ao redor da pessou que puxado pelo comando.


function getPlayer(player, cmd, id)
	if tonumber(id) then
		local mx, my, mz = getElementPosition(player)
		local player2 = getPlayerFromID ( tonumber(id) )
		local trplayername = getPlayerName(player):gsub("#%x%x%x%x%x%x","")
		if not player2 or not isElement(player2) then
			return outputChatBox( "Player Offline", player )
		end
		local rand = math.random(1, 5)
		outputChatBox ( "#c9c9c9[#1a6cefFW-COMANDO#c9c9c9]O #1a6cef".. trplayername .."#c9c9c9 Puxou o #1a6cef".. id .."", source, 255, 0, 0, true );
		setElementPosition(player2, mx+rand, my+rand, mz + 1)
	end
end
addCommandHandler("tr", getPlayer)

 

Tentei procurar alguma função para fazer isso e falhei.

Estou querendo que o chatbox aparece somente perto de quem ultizou ou comando e de quem foi puxado pelo comando

Oque teria que usar para isso

Edited by giovanymito
Link to comment
function getPlayer(player, cmd, id)
	if tonumber(id) then
		local mx, my, mz = getElementPosition(player)
		local player2 = getPlayerFromID ( tonumber(id) )
		local trplayername = getPlayerName(player):gsub("#%x%x%x%x%x%x","")
		if not player2 or not isElement(player2) then
			return outputChatBox( "Player Offline", player )
		end
		local rand = math.random(1, 5)
		for i=1, #players do   -- fastest loop 
		local xp, yp, zp = getElementPosition ( players[i] ) 
		if getDistanceBetweenPoints3D ( x, y, z, xp, yp, zp ) <= 50 then
		outputChatBox ( "#c9c9c9[#1a6cefFW-COMANDO#c9c9c9]O #1a6cef".. trplayername .."#c9c9c9 Puxou o #1a6cef".. id .."", players[i], 255, 0, 0, true );
		setElementPosition(player2, mx+rand, my+rand, mz + 1)
        end
		end
	end
end
addCommandHandler("tr", getPlayer)

Seria assim ??

Edited by giovanymito
Link to comment

Não vai deixar lento.

Tente:

function getPlayer(player, cmd, id)
	if tonumber(id) then
		local mx, my, mz = getElementPosition(player)
		local player2 = getPlayerFromID ( tonumber(id) )
		if not player2 or not isElement(player2) then
			return outputChatBox( "Player Offline", player )
		end
		local trplayername = getPlayerName(player):gsub("#%x%x%x%x%x%x","")
		
		setElementPosition(player2, mx+rand, my+rand, mz + 1)
		
		for i, p in ipairs(getElementsByType("player")) do
			local xp, yp, zp = getElementPosition ( p )
			
			if getDistanceBetweenPoints3D ( mx, my, mz, xp, yp, zp ) <= 50 then
				outputChatBox ( "#c9c9c9[#1a6cefFW-COMANDO#c9c9c9]O #1a6cef".. trplayername .."#c9c9c9 Puxou o #1a6cef".. tostring(id), p, 255, 0, 0, true );
			end
		end
	end
end
addCommandHandler("tr", getPlayer)

 

  • Thanks 1
Link to comment
On 27/07/2019 at 10:59, DNL291 said:

Não vai deixar lento.

Tente:


function getPlayer(player, cmd, id)
	if tonumber(id) then
		local mx, my, mz = getElementPosition(player)
		local player2 = getPlayerFromID ( tonumber(id) )
		if not player2 or not isElement(player2) then
			return outputChatBox( "Player Offline", player )
		end
		local trplayername = getPlayerName(player):gsub("#%x%x%x%x%x%x","")
		
		setElementPosition(player2, mx+rand, my+rand, mz + 1)
		
		for i, p in ipairs(getElementsByType("player")) do
			local xp, yp, zp = getElementPosition ( p )
			
			if getDistanceBetweenPoints3D ( mx, my, mz, xp, yp, zp ) <= 50 then
				outputChatBox ( "#c9c9c9[#1a6cefFW-COMANDO#c9c9c9]O #1a6cef".. trplayername .."#c9c9c9 Puxou o #1a6cef".. tostring(id), p, 255, 0, 0, true );
			end
		end
	end
end
addCommandHandler("tr", getPlayer)

 

ERROR: [FW]Comandos\Server.Lua:10: attempt to perform arithmetic on global 'rand' (a nil value)

Chega esse erro

Edited by giovanymito
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...