Jump to content

"Permanent" ID System


Juniorr

Recommended Posts

Posted

Hello everyone, I come first to apologize for my English ? (google translator)

 

I have this ID system code below, but I wanted it when the player enters the server, save the ID of it, and when it returns on the server it is with the same ID.

 

local playerid = { }

function newPlayerID( player )
	for i = 1, getMaxPlayers( ) do
		if not ( playerid[ i ] ) then
			playerid[ i ] = player
			setElementData( player, "roleplayid", i )
			break
		end
	end
end

function getPlayerByID( id )
	for i = 1, getMaxPlayers( ) do
		if ( playerid[ i ] ) then
			print( getPlayerName( playerid[ i ] ) )
			return playerid[ i ]
		end
	end
end

addEventHandler( "onPlayerQuit", root,
	function( )
		for i = 1, getMaxPlayers do
			if ( playerid[ i ] == source ) then
				playerid[ i ] = nil
				break
			end
		end
	end
)

addEventHandler( "onPlayerJoin", root, function( ) newPlayerID( source ) end )
addEventHandler( "onResourceStart", resourceRoot, function( ) local players = getElementsByType( "player" ) for i = 1, #players do newPlayerID( players[ i ] ) end end )
Posted

If you want to have permanent IDs, it's best to simply assign ID numbers to accounts — and then insert and remove the player from the playerid table on login (and on resource start), logout and quit.

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