Jump to content

Como pegar o id do player?


Recommended Posts

Olá, eu uso um sistema de id e queria saber como eu pego o id pra mostrar no chat. Exemplo: aparecer meu nome e meu id no chat Dan[31]

tô tentando mas o script nem inicia no server:


 

local chat_range=100 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
    local px,py,pz=getElementPosition(player) 
    return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end

function onPlayerChatHandler( message, messageType )
    if (messageType == 0) then
        cancelEvent()
    
        local px,py,pz=getElementPosition(source)
        local id = getPlayerID(source)
        local nick=getPlayerName(source) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox("#32CD32[BVL]#FFFF00 • ʟᴏᴄᴀʟ • #FFFFFF"..nick.." ["..id.."]"": #FFFF00"..message,v,30,30,200,true) 
            end 
        end 
    end
end
addEventHandler( "onPlayerChat", root, onPlayerChatHandler )

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)

Codigo do script ID SYSTEM

function Start_Id ( _, acc )
    if eventName == "onPlayerLogin" then
        setElementData ( source, "ID", getAccountID(acc) or "N/A" )
        outputChatBox ( "", root, 255,255,255,true)
    elseif eventName == "onPlayerLogout" then
        removeElementData( source, "ID" )
        outputChatBox ( "", root, 255,255,255,true)
    elseif eventName == "onResourceStart" then
        for _, player in pairs(getElementsByType("player")) do
            local acc = getPlayerAccount(player)
            if not isGuestAccount(acc) then
                setElementData( source, "ID", getAccountID(acc) or "N/A" )
            end
        end
    end
end
addEventHandler("onResourceStart", resourceRoot, Start_Id)
addEventHandler("onPlayerLogout", root, Start_Id)
addEventHandler("onPlayerLogin", root, Start_Id)

function getPlayerID(id)
    v = false
    for i, player in ipairs (getElementsByType("player")) do
        if getElementData(player, "ID") == id then
            v = player
            break
        end
    end
    return v
end
--============================================================================================================================--
                                   --=============================--
                                   ----------- ID PLAYER ------------
                                   --=============================--
function getnick(player, command, id, ...)
    if(id) then
        local playerID = tonumber(id)
        if(playerID) then
            local Player2 = getPlayerID(playerID)
            if(Player2) then    
                outputChatBox ( "#00ff00✘ #ffffffINFO #00ff00✘➺ #ffffff Nome do Jogador #00ff00" .. getPlayerName(Player2) .."", player, 255,255,255,true)
            else
                outputChatBox ( "#00ff00✘ #ffffffERRO #00ff00✘➺ #ffffff O Jogador(a) de ID: #00ff00( " .. id .. " ) #ffffffNão Foi Encontrado!", player, 255,255,255,true)
            end 
        else
            outputChatBox ( "#00ff00✘ #ffffffERRO #00ff00✘➺ #ffffff ID: #00ff00( " .. id .. " ) #ffffffInválido!", player, 255,255,255,true)
        end
    else
        outputChatBox ( "#00ff00✘ #ffffffERRO #00ff00✘➺ #ffffffUse /id #00ff00[#ffffffID#00ff00]", player, 255,255,255,true)
    end
end
addCommandHandler("id", getnick)

 

Link to comment

Simples, você não definiu getPlayerID... tente:

local chat_range=100 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
    local px,py,pz=getElementPosition(player) 
    return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end

function onPlayerChatHandler( message, messageType )
    if (messageType == 0) then
        cancelEvent()
    
        local px,py,pz=getElementPosition(source)
        local id = getPlayerID(source)
        local nick=getPlayerName(source) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox("#32CD32[BVL]#FFFF00 • ʟᴏᴄᴀʟ • #FFFFFF"..nick.." ["..id.."]"": #FFFF00"..message,v,30,30,200,true) 
            end 
        end 
    end
end
addEventHandler( "onPlayerChat", root, onPlayerChatHandler )

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)

function getPlayerID(id)
    v = false
    for i, player in ipairs (getElementsByType("player")) do
        if getElementData(player, "ID") == id then
            v = player
            break
        end
    end
    return v
end

 

Link to comment

Consegui.. o codigo ficou assim:

local chat_range=100 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
    local px,py,pz=getElementPosition(player) 
    return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end

function onPlayerChatHandler( message, messageType )
    if (messageType == 0) then
        cancelEvent()
    
        local px,py,pz=getElementPosition(source)
        local ID = getElementData(source, "ID")
        local nick=getPlayerName(source) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox("#FFFFFF• #32CD32[BVL]#FFFF00 • ʟᴏᴄᴀʟ • #FFFFFF"..nick.." ["..ID.."]: #FFFF00"..message,v,30,30,200,true) 
            end 
        end 
    end
end
addEventHandler( "onPlayerChat", root, onPlayerChatHandler )

function disableChat (message, messageType)
    cancelEvent ()
end
addEventHandler ("onPlayerChat", getRootElement(), disableChat)

 

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...