Jump to content

How to store userdata of a player element with no elementData


KariiiM

Recommended Posts

I don't use element datas anymore because of the CPU usage and also for secure reasons.

I use only one table and tree functions :

datas_ = {}
function setElementData_(element,data,value)
  if isElement(element) then
    if not datas_[element] then datas_[element] = {} end
      datas_[element][data] = value
  end
end

function getElementData_(element,data)
  if isElement(element) then
      if not datas_[element] or not datas_[element][data] then return false end
      return datas_[element][data]
  end
end

function dellAllElementData(element)
  datas_[element] = nil
end

 

Link to comment
On 7/13/2017 at 06:49, KariiiM said:

Hey, As the title says, Is there another method to attach the player userdata under a key onLogin without using the elementdatas?

Thanks,

 

An optimized way talking about speed would be this one.

-- VARIABLES

	-- PLAYER
	
	local players = {} -- WHERE THE PLAYER IDS ARE BEING STORED FOR EACH PLAYER ELEMENT
	local players_ids = {}	-- THE PLAYER DATA SAVED UNDER AN INTEGER KEY

-- FUNCTION

	-- INIT PLAYER

	local function initPlayer( thePlayer )
  		if ( thePlayer ) then
    		if not ( players[ thePlayer ] ) then
      			local thePlayerID = #players_ids + 1 or 1
      			players[ thePlayer ] = thePlayerID
      			players_ids[ thePlayerID ] = {} -- NOW WE CAN SAVE DATA FOR THIS PLAYER
      			players_ids[ thePlayerID ][ "logged_in" ] = false
      			players_ids[ thePlayerID ][ "xyz" ] = { 0, 0, 0 } -- IT'S RECOMMENDED TO STORE AS MUCH AS POSSIBLE INTO ONE KEY AVOIDING FRAGMENTATION
      		else
      			local thePlayerID = players[ thePlayer ]
      			players_ids[ thePlayerID ] = nil
      			players[ thePlayer ] = nil
      			return initPlayer( thePlayer )
      		end
    	end
  	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...