Jump to content

[SOLVED] Need player id system or script/resource


Brolis

Recommended Posts

Posted (edited)

Hello everyone, I am using this resource:

local optimize = true -- Should the script be optimized? (if optimized, cannot be used client-side) 
local ids = {} 
  
function assignID() 
    for i=1,getMaxPlayers() do 
        if not ids[i] then 
            ids[i] = source 
            setElementData(source,"id",i,not optimize) 
            break 
        end 
    end 
end 
addEventHandler("onPlayerJoin",root,assignID) 
  
function startup() 
    for k, v in ipairs(getElementsByType("player")) do 
        local id = getElementData(v,"id") 
        if id then ids[id] = v end 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,startup) 
  
function getPlayerID(player) 
    for k, v in ipairs(ids) do 
        if v == player then return k end 
    end 
end 
  
function freeID() 
    local id = getElementData(source,"id") 
    if not id then return end 
    ids[id] = nil 
end 
addEventHandler("onPlayerQuit",root,freeID) 
  
function getPlayerByID(id) 
    local player = ids[id] 
    return player or false 
end 

But then I press TAB, there I can't see ids and player id or whatever, is here any player id system?

I am using simple default scoreboard...

Edited by Guest
Posted
local optimize = true -- Should the script be optimized? (if optimized, cannot be used client-side) 
local ids = {} 
  
function assignID() 
    for i=1,getMaxPlayers() do 
        if not ids[i] then 
            ids[i] = source 
            setElementData(source,"id",i,not optimize) 
            break 
        end 
    end 
end 
addEventHandler("onPlayerJoin",root,assignID) 
  
function startup() 
    exports [ "scoreboard" ]:scoreboardAddColumn( "id" ) 
    for k, v in ipairs(getElementsByType("player")) do 
        local id = getElementData(v,"id") 
        if id then ids[id] = v end 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,startup) 
  
function getPlayerID(player) 
    for k, v in ipairs(ids) do 
        if v == player then return k end 
    end 
end 
  
function freeID() 
    local id = getElementData(source,"id") 
    if not id then return end 
    ids[id] = nil 
end 
addEventHandler("onPlayerQuit",root,freeID) 
  
function getPlayerByID(id) 
    local player = ids[id] 
    return player or false 
end 

That'll add a column called "id" to the scoreboard.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
local optimize = true -- Should the script be optimized? (if optimized, cannot be used client-side) 
local ids = {} 
  
function assignID() 
    for i=1,getMaxPlayers() do 
        if not ids[i] then 
            ids[i] = source 
            setElementData(source,"id",i,not optimize) 
            break 
        end 
    end 
end 
addEventHandler("onPlayerJoin",root,assignID) 
  
function startup() 
    exports [ "scoreboard" ]:scoreboardAddColumn( "id" ) 
    for k, v in ipairs(getElementsByType("player")) do 
        local id = getElementData(v,"id") 
        if id then ids[id] = v end 
    end 
end 
addEventHandler("onResourceStart",resourceRoot,startup) 
  
function getPlayerID(player) 
    for k, v in ipairs(ids) do 
        if v == player then return k end 
    end 
end 
  
function freeID() 
    local id = getElementData(source,"id") 
    if not id then return end 
    ids[id] = nil 
end 
addEventHandler("onPlayerQuit",root,freeID) 
  
function getPlayerByID(id) 
    local player = ids[id] 
    return player or false 
end 

That'll add a column called "id" to the scoreboard.

But no

I'd comes up for the player???

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

Posted

I don't understand your question, please explain yourself further.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
I don't understand your question, please explain yourself further.

Okay, when I press TAB, it comes up The name of the player, and the ping, when i add this resource, it adds an id column,

but no ID appears,

Please Help?

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

Posted

Have you tried reconnecting? if the 'id' element data was set successfully, then it should show it on scoreboard as well.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Have you tried reconnecting? if the 'id' element data was set successfully, then it should show it on scoreboard as well.

Aww, Thanks, Reconnecting did the trick!!

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

  • 9 years later...

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