Jump to content

Id permanente


Recommended Posts

Não está tendo erro o script só estou com medo de que quando entre bastante pessoas bug ent resolvi pedir algumas sugestões e opiniões

function Init ()
        if ( getResourceFromName ( "scoreboard" ) and getResourceState ( getResourceFromName ( "scoreboard" ) ) == "running" ) then
                scoreboard = exports.scoreboard
                _dxver = false
        elseif ( getResourceFromName ( "dxscoreboard" ) and getResourceState ( getResourceFromName ( "dxscoreboard" ) ) == "running" ) then            
                scoreboard = exports.dxscoreboard
                _dxver = true
        else
                outputDebugString ( "No scoreboard resource has been started", 2 )
                _initp = false
        end    
        if _initp then
                scoreboard:addScoreboardColumn ( "ID", getRootElement(), 1, 0.05 ) -- Add the ID column
                sortScoreboard( "ID" )
        end    
        if not _loaded then
                loadID()
        end    
end
addEventHandler ( "onResourceStart", resourceRoot, Init )
 
function loadID ()
        _loaded = true
		for _, player in ipairs ( getElementsByType ( "player" ) ) do
        assignPlayerID ( player ) 
    end
end
    
function assignPlayerID ( player )
	local acc = getPlayerAccount(player)
	if getAccountData(acc, "ID") then
		local IDdeQuemJaTem = getAccountData(acc, "ID")
		return setElementData(player, "ID", IDdeQuemJaTem) 
		else
		local chorID = nil
		local chorID = math.random(1,999)
		if isIDAvailable ( chorID, player ) == true then
		setElementData ( player, "ID", chorID )
        sortScoreboard( "ID" )
        availableID[ chorID ] = false
		else
		end
	end
end    
       
n = {}
function isIDAvailable ( id, player ) 
	local accs = getAccounts()
		for i, accounts in ipairs(accs) do
		if getAccountData(accounts, "ID") then
			local idNew = getAccountData(accounts, "ID")
			if idNew == id then
			n[player] = false
        	break
			else
			n[player] = true
		end
		else
		n[player] = true
		end
		end
		if n[player] == true then
		return true
		else
		assignPlayerID(player)
		return false
		end
	end
	
function onLeave () 
		local acc = getPlayerAccount(source)
		local s_id = getElementData ( source, "ID" ) or getAccountData(acc, "ID")
        availableID[ s_id ] = false
        setAccountData(acc, "ID", s_id)   
end
addEventHandler ( "onPlayerQuit", getRootElement(), onLeave )   

function onLogin (_, c) 
	assignPlayerID(source)
	end
addEventHandler ( "onPlayerLogin", getRootElement(), onLogin )  

 

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