Jump to content

Guardando una licencia


Markn1

Recommended Posts

Por favor ayuda No entiendo mucho. Se guarda solo cuando vas al servidor (or "logout"). ¡Si reinicia el recurso, no se guarda!

local saveableData = { ["car"] = true, ["moto"] = true, ["air"] = true } 

function onStartorLogin (_,acc) 
       setElementData ( source, "car", getAccountData ( acc, "car" ) or false ) 
       setElementData ( source, "moto", getAccountData ( acc, "moto" ) or false ) 
       setElementData ( source, "air", getAccountData ( acc, "air" ) or false ) 
    end
addEventHandler("onPlayerLogin", getRootElement(), onStartorLogin )

function onResRestrt (_,acc) 
       setAccountData ( source, "car", getElementData ( acc, "car" ) or false ) 
       setAccountData ( source, "moto", getElementData ( acc, "moto" ) or false ) 
       setAccountData ( source, "air", getElementData ( acc, "air" ) or false ) 
    end
addEventHandler("onResourceStop", getRootElement(), onResRestrt )
--// addEventHandler("onResourceStart", getRootElement(), onResRestrt )

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" then 
        if saveableData[dataName] then 
        setAccountData ( getPlayerAccount ( source ), dataName, getElementData ( source, dataName ) ) 
        end 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 

 

Edited by Markn1
Link to comment
function onStartorLogin (_,acc) 
       for k, player in ipairs(getElementType("player")) do
	      local acc = getPlayerAccount(player)
		  if acc then
             setElementData ( player, "car", getAccountData ( acc, "car" ) or false ) 
             setElementData ( player, "moto", getAccountData ( acc, "moto" ) or false ) 
             setElementData ( player, "air", getAccountData ( acc, "air" ) or false ) 
		  end
	   end
    end
addEventHandler("onPlayerLogin", getRootElement(), onStartorLogin )

function onResRestrt (_,acc) 
      for k, player in ipairs(getElementType("player")) do
	      local acc = getPlayerAccount(player)
		  if acc then
            setAccountData ( acc, "car", getElementData ( player, "car" ) or false ) 
            setAccountData ( acc, "moto", getElementData ( player, "moto" ) or false ) 
            setAccountData ( acc, "air", getElementData ( player, "air" ) or false ) 
		  end
	   end
    end
addEventHandler("onResourceStop", getRootElement(), onResRestrt )

los eventos  onResourceStop y onResourceStart no tienen como argumentos a un jugador ni a una cuenta utiliza el codigo que te acabo de pasar

Link to comment
1 hour ago, alex17" said:
  1. function onStartorLogin (_,acc)
  2. for k, player in ipairs(getElementType("player")) do
  3. local acc = getPlayerAccount(player)
  4. if acc then
  5. setElementData ( player, "car", getAccountData ( acc, "car" ) or false )
  6. setElementData ( player, "moto", getAccountData ( acc, "moto" ) or false )
  7. setElementData ( player, "air", getAccountData ( acc, "air" ) or false )
  8. end
  9. end
  10. end
  11. addEventHandler("onPlayerLogin", getRootElement(), onStartorLogin )
  12.  
  13. function onResRestrt (_,acc)
  14. for k, player in ipairs(getElementType("player")) do
  15. local acc = getPlayerAccount(player)
  16. if acc then
  17. setAccountData ( acc, "car", getElementData ( player, "car" ) or false )
  18. setAccountData ( acc, "moto", getElementData ( player, "moto" ) or false )
  19. setAccountData ( acc, "air", getElementData ( player, "air" ) or false )
  20. end
  21. end
  22. end
  23. addEventHandler("onResourceStop", getRootElement(), onResRestrt )

no :(  ( function onResRestrt ) - warning and error
DEBUG: 
1. bad argument @ 'getElementType' [ expected ....... at argument 1, got string 'player']
2. ERROR: bad argument #1 to 'ipairs' (table expected, got boolean)

Link to comment
12 minutes ago, Markn1 said:

no :(  ( function onResRestrt ) - warning and error
DEBUG: 
1. bad argument @ 'getElementType' [ expected ....... at argument 1, got string 'player']
2. ERROR: bad argument #1 to 'ipairs' (table expected, got boolean)

error mio cambia getElementType por getElementsByType

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