Jump to content

[AJUDA] SISTEMA DE ID |


Recommended Posts

Posted (edited)

Olá,

Se você está lendo isso já te dou obrigado por tentar me ajudar ❤️

Bom eu estava fazendo este script (Comecei ontém a programar)

Um script que troca um Nome por Um ID Ficando somente o ID Na cabeça ou no torso do player, o ID Não pode ser repetido... e Por aí vai.

Sinceramente tou meio perdido sobre isto...

Mais espero que você compreenda ❤️ 

O erro é basicamente não fazer nada.

Tou usando meta.xml e server.lua.

Exportei os Functions mais ainda está dando erro, Se não der pra salvar este alguém pode me indicar algum script parecido???

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

 

Edited by Jonas <#C
  • Other Languages Moderators
Posted (edited)
58 minutes ago, Jonas <#C said:

Exportei os Functions mais ainda está dando erro

Qual erro que está aparecendo?

E cadê o meta.xml?

Edited by Lord Henry
Posted
local idname = get ( "idDataCaption" ) or "ID"
 
g_Players = {}
 
function table.find(t, ...)
        if type(t) ~= 'table' then
                return false
        end
        local args = { ... }
        if #args == 0 then
                for k,v in pairs(t) do
                        if v then
                                return k, v
                        end
                end
                return false
        end   
        local value = table.remove(args)
        if value == '[nil]' then
                value = nil
        end
        for k,v in pairs(t) do
                for i,index in ipairs(args) do
                        if type(index) == 'function' then
                                v = index(v)
                        else
                                if index == '[last]' then
                                        index = #v
                                end
                                v = v[index]
                        end
                end
                if v == value then
                        return k, t[k]
                end
        end
        return false
end
 
function addElem(list, elem)
        local id
        local globList
        local newtable = { elem = elem }
        if not id then
                id = 1
                while list[id] do
                        id = id + 1
                end
        end
        list[id] = newtable
        setElemID(elem, id)
        return id, newtable
end
 
function removeElem(list, elem)
        local id = table.find(list, 'elem', elem)
        if id then
                list[id] = nil
                setElemID(elem, nil)
                return id
        end
end
 
function getPlayerFromID(id)
        return g_Players[id] and isElement(g_Players[id].elem) and g_Players[id].elem
end
  
function getPlayerID(player)
        return getElemID(player)
end

function getElemID(elem)
        return elem and isElement(elem) and getElementData(elem, idname)
end
 
function setElemID(elem, id) 
        if elem and isElement(elem) then
                setElementData(elem, idname, id)
        end
end
 
function onResourceStart ()
--call ( getResourceFromName ( "scoreboard" ), "addScoreboardColumn", idname, root,1,0.04 ) 
for k, v in ipairs(getElementsByType("player")) do 
addElem(g_Players, v)
end
end
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart )
 
function onPlayerJoin()
	addElem(g_Players, source)
	setElementData (source, "pmb", false)
	setElementData (source, "pmm", false)
end
addEventHandler ( "onPlayerJoin", root, onPlayerJoin )

function onPlayerQuit (reason)
 
        local playerID = getElemID(source)
 
        g_Players[playerID] = nil
 
end 
addEventHandler('onPlayerQuit', root, onPlayerQuit)

Codigo pronto que costumo usar!

Posted
23 hours ago, danilin said:

local idname = get ( "idDataCaption" ) or "ID"
 
g_Players = {}
 
function table.find(t, ...)
        if type(t) ~= 'table' then
                return false
        end
        local args = { ... }
        if #args == 0 then
                for k,v in pairs(t) do
                        if v then
                                return k, v
                        end
                end
                return false
        end   
        local value = table.remove(args)
        if value == '[nil]' then
                value = nil
        end
        for k,v in pairs(t) do
                for i,index in ipairs(args) do
                        if type(index) == 'function' then
                                v = index(v)
                        else
                                if index == '[last]' then
                                        index = #v
                                end
                                v = v[index]
                        end
                end
                if v == value then
                        return k, t[k]
                end
        end
        return false
end
 
function addElem(list, elem)
        local id
        local globList
        local newtable = { elem = elem }
        if not id then
                id = 1
                while list[id] do
                        id = id + 1
                end
        end
        list[id] = newtable
        setElemID(elem, id)
        return id, newtable
end
 
function removeElem(list, elem)
        local id = table.find(list, 'elem', elem)
        if id then
                list[id] = nil
                setElemID(elem, nil)
                return id
        end
end
 
function getPlayerFromID(id)
        return g_Players[id] and isElement(g_Players[id].elem) and g_Players[id].elem
end
  
function getPlayerID(player)
        return getElemID(player)
end

function getElemID(elem)
        return elem and isElement(elem) and getElementData(elem, idname)
end
 
function setElemID(elem, id) 
        if elem and isElement(elem) then
                setElementData(elem, idname, id)
        end
end
 
function onResourceStart ()
--call ( getResourceFromName ( "scoreboard" ), "addScoreboardColumn", idname, root,1,0.04 ) 
for k, v in ipairs(getElementsByType("player")) do 
addElem(g_Players, v)
end
end
addEventHandler ( "onResourceStart", resourceRoot, onResourceStart )
 
function onPlayerJoin()
	addElem(g_Players, source)
	setElementData (source, "pmb", false)
	setElementData (source, "pmm", false)
end
addEventHandler ( "onPlayerJoin", root, onPlayerJoin )

function onPlayerQuit (reason)
 
        local playerID = getElemID(source)
 
        g_Players[playerID] = nil
 
end 
addEventHandler('onPlayerQuit', root, onPlayerQuit)

Codigo pronto que costumo usar!

Esse código é seu ou ele é público? Apenas para evitar problemas, é recomendado que evite postar códigos privados aqui no fórum, se não for privado sem problemas.

  • 2 weeks later...
Posted

Foi mal demorar '-'

Tentei usar DataBase mais não é meu forte, tentei alterar o meta então decide criar outro, então sobre isso do meta podem em ajudar novamente?

 

Desde já agradeço

  • Other Languages Moderators
Posted

Cara, poste o meta. Não temos como adivinhar o erro sem ler o código.

Use o botão <> do fórum pra postar código.

Posted
39 minutes ago, Lord Henry said:

Cara, poste o meta. Não temos como adivinhar o erro sem ler o código.

Use o botão <> do fórum pra postar código.

Lord, desculpa vir neste tópico invadir assim, pode me ajudar com meu tópico? agradeço ..

  • Other Languages Moderators
Posted
3 minutes ago, Lukkas2201 said:

Lord, desculpa vir neste tópico invadir assim, pode me ajudar com meu tópico? agradeço ..

Já tinha visto seu tópico, mas ignorei.

Posted
3 minutes ago, Lord Henry said:

Pq eu não entendi nada. '-'

Poderia comentar lá ? para eu tentar explicar melhor, assim podemos sair deste tópico também, para não poluir com mensagens desnecessárias.

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