Jonas <#C

ID SYSTEM SCRIPT. PTBR/EU

Recommended Posts

English
Hello.

Hello, I'm sorry for my English. Well I made this script to change the nick of the player to an ID, and it was not duplicated, it's not working as it should. Could you help with this or see something similar? OBS: I've started to script.

Português (Brazil)

Olá já venho desculpar meu inglês, Bom eu fiz este script para que trocasse o nick do player para um ID, E não fosse Duplicado, ele não está funcionando como deveria, Poderia ajudar com este ou ver algo semelhante ? OBS: Começei ontém a fazer script

local ids = {}

function assignID()
    for i=1,getMaxPlayers() do
        if not ids[i] then
            ids[i] = source
            setElementData(source,"id",i)
            break
        end
    end
end
addEventHandler("onPlayerJoin",root,assignID)

function startup()
    ids = {}
    for k, v in ipairs(getElementsByType("player")) do
        local id = setElementData(v,"id",k)
        ids[k] = v 
    end
end
addEventHandler("onResourceStart",resourceRoot,startup)

function freeID()
    local id = getElementData(source,"id")
    if not id then return end
    ids[id] = nil
end
addEventHandler("onPlayerQuit",root,freeID)

function getPlayerID ( player )
    return  getElementData( player, "id")
end
function getPlayerFromId ( theID )
    if theID then
        local theID = tonumber(theID)
        local theplayer
        for index,player in ipairs(getElementsByType("player")) do
            if getElementData(player ,"id") == theID then
                theplayer = player
            end
        end
        return theplayer
    else 
        return false 
    end
end

 

Share this post


Link to post
local ids = {}

function assignID()
    for i=1,getMaxPlayers() do
        if not ids[i] then
            ids[i] = source
            setElementData(source,"id",i)
            break
        end
    end
end
addEventHandler("onPlayerJoin",root,assignID)

function startup()
    ids = {}
    for _, player in ipairs(getElementsByType("player")) do
		local id = getElementData(player,"id")
		if id then
			ids[id] = player
		end
    end
end
addEventHandler("onResourceStart",resourceRoot,startup)

function freeID()
    local id = getElementData(source,"id")
    if not id then return end
    ids[id] = nil
end
addEventHandler("onPlayerQuit",root,freeID)

function getPlayerID ( player )
    return  getElementData( player, "id")
end
function getPlayerFromId ( theID )
    if theID then
        local theID = tonumber(theID)
        for _,player in ipairs(getElementsByType("player")) do
            if getElementData(player ,"id") == theID then
                return player
            end
        end
        return false
    else 
        return false 
    end
end

 

Share this post


Link to post
14 hours ago, Jonas <#C said:

English
Hello.

Hello, I'm sorry for my English. Well I made this script to change the nick of the player to an ID, and it was not duplicated, it's not working as it should. Could you help with this or see something similar? OBS: I've started to script.

Português (Brazil)

Olá já venho desculpar meu inglês, Bom eu fiz este script para que trocasse o nick do player para um ID, E não fosse Duplicado, ele não está funcionando como deveria, Poderia ajudar com este ou ver algo semelhante ? OBS: Começei ontém a fazer script


local ids = {}

function assignID()
    for i=1,getMaxPlayers() do
        if not ids[i] then
            ids[i] = source
            setElementData(source,"id",i)
            break
        end
    end
end
addEventHandler("onPlayerJoin",root,assignID)

function startup()
    ids = {}
    for k, v in ipairs(getElementsByType("player")) do
        local id = setElementData(v,"id",k)
        ids[k] = v 
    end
end
addEventHandler("onResourceStart",resourceRoot,startup)

function freeID()
    local id = getElementData(source,"id")
    if not id then return end
    ids[id] = nil
end
addEventHandler("onPlayerQuit",root,freeID)

function getPlayerID ( player )
    return  getElementData( player, "id")
end
function getPlayerFromId ( theID )
    if theID then
        local theID = tonumber(theID)
        local theplayer
        for index,player in ipairs(getElementsByType("player")) do
            if getElementData(player ,"id") == theID then
                theplayer = player
            end
        end
        return theplayer
    else 
        return false 
    end
end

 

Se você é português poste na seção portuguesa do fórum.

Share this post


Link to post

Ok obrigada irei fazer, é que pensei que americanos poderiam resolver mais rápido mais me enganei irei postar lá obrigado pelo dica. 

<#

Share this post


Link to post

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.