Jump to content

Script not work


Dimos7

Recommended Posts

local optimize = true  
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 
  
function showIDs (option) 
    if option == false then 
       gameShowIDs = false 
       call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "ID") 
    else 
       gameShowIDs = true 
       call(getResourceFromName("scoreboard"), "addScoreboardColumn", "ID") 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, showIDs) 

0rycSB9.png

Edited by Guest
Link to comment
  • 3 weeks later...
local optimize = true  
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 
  
function showIDs (option) 
    if option == false then 
       gameShowIDs = false 
       call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "ID") 
    else 
       gameShowIDs = true 
       call(getResourceFromName("scoreboard"), "addScoreboardColumn", "ID") 
       scoreboardSetColumnTextFunction ( "ID", function() return getPlayerID(localPlayer)  end) 
       scoreboardSetColumnPriority ( "ID", 1) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, showIDs) 

This should work,next time check

https://wiki.multitheftauto.com/wiki/Dxscoreboard

Link to comment

Replace showIDs function with this one:

function showIDs (option) 
    if option == false then 
       gameShowIDs = false 
       exports["scoreboard"]:scoreboardRemoveColumn ( "id", root ) 
    else 
       gameShowIDs = true 
       exports["scoreboard"]:scoreboardAddColumn ( "id", root, 50, "ID", 1 ) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, showIDs) 

Link to comment
local optimize = true 
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 
  
function showIDs (option) 
    if option == false then 
       gameShowIDs = false 
       exports["Scoreboard"]:scoreboardRemoveColum("id") 
    else 
       gameShowIDs = true 
       exports["Scoreboard"]:scoreboardAddColumn("id", function() return getPlayerID(player) end, 20, "ID", 1) 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, showIDs) 

xUTyxnA.png

still no show the id number

Link to comment

hmm, i remade the script, try:

ID = {} 
  
exports["scoreboard"]:scoreboardAddColumn ( "ID", root, 20, "ID", 1 ) 
  
--------------------------- [ Events ] --------------------------- 
  
addEventHandler ( "onPlayerJoin", root, 
function( ) 
    for i = 0, getMaxPlayers() do 
        if not ID[i] then 
            ID[i] = source 
            setElementData ( source, "ID", i ) 
            break; 
        end 
    end 
end) 
  
-- 
  
addEventHandler ( "onPlayerQuit", root, 
function( ) 
    ID[getPlayerID(source)] = nil 
end) 
  
-- 
  
addEventHandler ( "onResourceStart", resourceRoot, 
function( ) 
    for _,v in ipairs(getElementsByType("player")) do 
        for i = 0, getMaxPlayers() do 
            if not ID[i] then 
                ID[i] = v 
                setElementData ( v, "ID", i ) 
                break; 
            end 
        end  
    end 
end) 
  
--------------------------- [ Functions ] --------------------------- 
  
function getPlayerID (player) 
    if player and isElement(player) and getElementType(player) == "player" and getElementData ( player, "ID" ) then 
        return getElementData ( player, "ID" ) 
    end 
    return false 
end 
  
-- 
  
function getPlayerFromID (id) 
    if id and tonumber(id) and ID[tonumber(id)] then 
        return ID[tonumber(id)] 
    end 
    return false 
end 

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