Jump to content

[Help] Change command handler to bind key


RAF3345

Recommended Posts

I have a script to call administrators by phone, but for the administrator to accept he needs to type / ac (call number) I would like to change this command to bind, "Q" to accept and "E" to stop refusing

Some charitable soul to help me?

local staffCall = {}
local staffCount = 0
addEvent( "SendMsgToTeamstaff", true )
addEventHandler( "SendMsgToTeamstaff", root,
function (  )
	--if isTimer(timer) then return end
	--timer = setTimer(function() end, 10000, 1)



	local pX,pY,pZ = getElementPosition(source)
	for k,v in ipairs(getElementsByType("player")) do
		vX,vY,vZ = getElementPosition(v)
		local dist = getDistanceBetweenPoints3D(pX,pY,pZ,vX,vY,vZ)
		if dist <= 5 then
			if v ~= source then
			if getPedWeapon(v) > 0 then
				outputChatBox("#D24D57[btc~Items] #ffffffAlguem armado está proximo de você então não pode fazer chamada!", source, 255, 255, 255, true)
				return
			end
		end
	end
end


	if getElementData(source, "call:staff") then outputChatBox("#dc143c[BRPMTA - ERRO]:#ffffff Você já tem uma chamada em andamento aguarde 1 minuto para fazer novamente.", source, 255, 255, 255, true) return end


		outputChatBox("#bebebeVocê chamou o staff, aguarde.", source, 255, 255, 255, true)
		exports.btc_hud:dm(" "..getPlayerName(source).." Você chamou o staff, aguarde.", source, 255, 200, 0)


		staffCount = staffCount + 1
		staffCall[staffCount] = source
		setElementData(source, "call:staff", staffCount)


		setTimer ( setElementData, 600, 1, source, "call:staff", false)
		tirarchamadostaffCall = setTimer(function()
			staffCall[staffCount] = nil
		end, 25000, 1 )


		local x, y, z = getElementPosition(source)
		setElementData(source, "call:staffposx", x)
		setElementData(source, "call:staffposy", y)
		setElementData(source, "call:staffposz", z)
		for theKey,player in ipairs (getElementsByType("player")) do
			if getElementData(player, "char:adminduty") == 1  then
				outputChatBox("#bebebe"..getPlayerName(source).." chamou o staff utilize /ac " .. staffCount .. " para aceitar o pedido", player, 255, 255, 255, true)
				displayServerMessage(player, ""..getPlayerName(source).." chamou  o staff utilize /ac " .. staffCount .. " para aceitar o pedido", "warning")
			  end
		end
end )

ChamadasS = {}



function aceitarstaff(thePlayer, commandName, acceptID)
	if getElementData(thePlayer, "char:adminduty") == 1  then
		if (acceptID) then
			local acceptID = tonumber(acceptID)
			if staffCall[acceptID] then
				exports.btc_hud:dm("Você aceitou o chamado " .. acceptID .. "", thePlayer, 255, 200, 0)
				exports.btc_hud:dm("O staff "..getPlayerName(thePlayer).." aceitou sua chamada", staffCall[acceptID], 255, 200, 0)

				--if isTimer(chamadostaffCall) then
				--	killTimer(chamadostaffCall)
				--end
				if isTimer(tirarchamadostaffCall) then
						killTimer(tirarchamadostaffCall)
				end

				for theKey,player in ipairs (getElementsByType("player")) do
					if getElementData(player, "char:adminduty") == 1  then
						outputChatBox(" ", player, 255, 255, 255, true)
						outputChatBox("#dc143c[BRPMTA - CHAMADA] #bebebeStaff "..getPlayerName(thePlayer).." aceitou o chamado " .. staffCount .. "", player, 255, 255, 255, true)
						outputChatBox(" ", player, 255, 255, 255, true)
						--setChamada (thePlayer)
					  end
				end

				setChamada (thePlayer)

				local x, y, z = getElementData(staffCall[acceptID], "call:staffposx"), getElementData(staffCall[acceptID], "call:staffposy"), getElementData(staffCall[acceptID], "call:staffposz")
				setElementPosition(thePlayer, x, y, z)
				setElementData(thePlayer, "call:staff", nil)
				--triggerClientEvent(thePlayer, "createstaffMarker", thePlayer, thePlayer, acceptID, staffCall[acceptID], x, y, z)
				staffCall[acceptID] = nil




				--staffCount = staffCount - 1
			else
				outputChatBox("#dc143c[BRPMTA - ERRO]:#ffffff Não existe essa chamada ou a chamada já foi aceita.", thePlayer, 255, 255, 255, true)
			end
		end
	
	end
end
addCommandHandler("ac", aceitarstaff)

 

Edited by RAF3345
Link to comment
20 hours ago, RAF3345 said:

you can do for me ? I do not know how to do this :(

If the accept id is always the same just write it inside the function like local acceptID = value.

And use bindKey to bind function to key. If the acceptid isn't the same every time then it can't be done with bindKey and command handler is ok 

  • Like 1
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...