Jump to content

change playername for playerID


Recommended Posts

Hello, sorry for bothering you again.

I want to change this code so that I call the ID instead of its name, note that in line 1  another code is called "game_id2" in which he define the ID, I want to replace the / checkbinds playername with / checkbinds playerID
example: /checkbinds 2

Code:

Spoiler

function getPlayerFromID(id)
return call(getResourceFromName("game_id2"), "getPlayerFromID", tonumber(id))
end
 
function getPlayerID(player)
return  getElementData(player,"id")
end

function RGBToHex(red, green, blue, alpha)
	if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then
		return nil
	end
	if(alpha) then
		return string.format("#%.2X%.2X%.2X%.2X", red,green,blue,alpha)
	else
		return string.format("#%.2X%.2X%.2X", red,green,blue)
	end
end

_outputChatBox = outputChatBox
function outputChatBox(text,to,r,g,b)
	if not to then
		to = root
	end
	if not text then
		text = "?"
	end
	hex = RGBToHex(r,g,b,false)
	_outputChatBox("[BINDS]" .. hex .. " "..text,to,255,255,255,true)
end

function outputChatBoxWithoutG(text,to,r,g,b)
	if not to then
		to = root
	end
	if not text then
		text = "?"
	end
	hex = RGBToHex(r,g,b,false)
	_outputChatBox(hex .. ""..text,to,255,255,255,true)
end
-- the core of the script
function checkPlayerBinds(checker,player)
	if checker and player then
		outputChatBox(getPlayerName(checker) .. "#FF0000 checou as binds de #FFFFFF" .. getPlayerName(player),root,255,255,255)
		triggerClientEvent(player,"returnBinds",player)
	end
end
lastTick = -971202
function onCommand(source,command,playerr)
	if not hasObjectPermissionTo(source,"function.kickPlayer",false) then 
		outputChatBox("Você possui binds que oferecem vantagens.",source,255,0,0)
		return
	end
	if lastTick >= getTickCount()-5000 then
		outputChatBox("Espera " .. tostring(math.ceil(5-((getTickCount()-lastTick)/1000))) .. " segundos para usar este comando novamente",source,255,0,0)
		return
	end
	lastTick = getTickCount()
	if source and playerr then
		player,errorType = getPlayerFromPartialName(playerr)
		if errorType then
			if errorType == "OK" then
				checkPlayerBinds(source,player)
			elseif errorType == "ERROR_MORE_PLAYERS" then
				p_String = ""
				for q,w in pairs(player) do
					if p_String == "" then
						p_String = getPlayerName(w)
					else
						p_String = p_String .. "," .. getPlayerName(w)
					end
				end
				outputChatBox(tostring(#player) .. " Jogador encontrado. (" .. p_String .. ")",source,255,0,0)
			elseif errorType == "ERROR_NO_PLAYERS" then
				outputChatBox("Nenhum jogador com o nome:#FFFFFF " .. playerr,source,255,0,0)
			end
		else
			outputChatBox("Erro",root,255,0,0)
		end
	end
end
addCommandHandler("checkbinds",onCommand)

function outputMyKeys(tbl_Keys)
	if tbl_Keys then
		for e,c in pairs(tbl_Keys) do
			for q,w in pairs(c) do
				if type(w) ~= "table" then
					--outputChatBox(tostring(w),root,0,255,0
					lastControlName = tostring(w)
				else
					k_String = ""
					for key,state in pairs(w) do
						if k_String == "" then
							k_String = tostring(key)
						else
							k_String = k_String .. "," .. tostring(key)
						end
					end
					outputChatBoxWithoutG(tostring(lastControlName) .. ": #FFFFFF" .. tostring(k_String),root,0,255,0)
				end
			end
		end
	end
end

addEvent("sendMyKeys",true)
addEventHandler("sendMyKeys",root,outputMyKeys)

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
	playerTable = {}
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                playerTable[#playerTable+1] = player
            end
        end
    end
	if #playerTable >= 2 then
		return playerTable,"ERROR_MORE_PLAYERS"
	end
	if #playerTable == 1 then
		return playerTable[1],"OK"
	end
	if #playerTable == 0 then
		return false,"ERROR_NO_PLAYERS"
	end
end


 

I know it's not allowed to ask to edit scripts, if you can't, guide me on how to do this.

Thanks.

Edited by '~DaLesTe^'
i forgout the code
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...