Jump to content

Help to setAccountData. I Can't make it work


Recommended Posts

Well. Im trying to figure out why every script i did with setAccountData failed. By the way. Now im here to ask for help :D

Here it is the code

-------------------------------------------------------- 
--  Salvar informações no LOGIN/EXIT  ------------------ 
  
  
  
  
    function onPlayerQuit ( ) 
     
    local conta = getPlayerAccount ( source ) 
    if ( conta ) then 
       
             
            armas = {} 
             
            for i = 0,12 do 
            local arma = getPedweapon(source,i) 
            local ammu = getPedTotalAmmo(source,i) 
                 
                if ammu > 0 then 
                table.insert(armas, {arma,ammu}) 
                end 
            end 
  
       
       
         
        local x,y,z = getElementPosition(source) 
        local rx,ry,rz = getElementRotation(source) 
  
             
        local salvarConta = {  
            ["dinheiro"] = getPlayerMoney ( source ); 
            ["skin"] = getElementModel(source);      
            ["posX"] = x; 
            ["posY"] = y; 
            ["posZ"] = z;                
            ["rot"] = rx; 
            ["dim"] = getElementDimension(source); 
            ["int"] = getElementInterior(source) 
            } 
  
            setAccountData(conta,"char.armas",armas) 
             
            for i,v in ipairs(salvarConta) do 
            setAccountData(conta,"char."..i,tostring(v)) 
            end 
             
             
             
    end 
end 
  
  
  
    function onPlayerJoin ( ) 
     
        local conta = getPlayerAccount ( source ) 
             
        local din = getAccountData(conta,"char.dinheiro") 
  
  
        setPlayerMoney(source,din) 
     
    end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerJoin ) 
  
-------------------------------------------------------- 
-------------------------------------------------------- 

When i log in nothing happens. And no errors in /debugscript 3 and in the server console.

Edit: Yes, the script is in the ACL as admin

Edited by Guest
Link to comment

I dont see setPlayerData in your script... If you want to write to account use setAccountData, writing to element is setElementData ( will be destroyed when player leaves )

EDIT: You already have setAccountData, sorry. I cant really help you with this ( my LUA is bad ) Good luck tough!

Link to comment
I dont see setPlayerData in your script... If you want to write to account use setAccountData, writing to element is setElementData ( will be destroyed when player leaves )

EDIT: You already have setAccountData, sorry. I cant really help you with this ( my LUA is bad ) Good luck tough!

Yeah. I misspelled it again. My head can't just think right when im confused >__<

But thanks for your help bro ;)

Link to comment
Here is the thing, how do you expect the player to have an account, (which is not guest) when he joins?

use onPlayerLogin.

Take a look at the script. Look the 2 last lines. Look the event handlers, i did this just to see who would try this without reading it all :)

But i still need help after all :/

Link to comment
Oh.

Try:

    function onPlayerJoin ( _ , conta ) 
            
        local din = getAccountData(conta,"char.dinheiro") 
  
  
        setPlayerMoney(source,din) 
    
    end 

Didn't worked. I Loged in, Set my money, quit, connect, login, and nothing :/

No debugscript or console errors

Link to comment
function onPlayerJoin ( ) 
    
        local conta = getPlayerAccount ( source ) 
            
        local din = getAccountData(conta,"char.1") 
  
  
        setPlayerMoney(source,din) 
    
    end 

Link to comment
-------------------------------------------------------- 
--  Salvar informações no LOGIN/EXIT  ------------------ 
  
  
  
  
    function onPlayerQuit ( ) 
    
    local conta = getPlayerAccount ( source ) 
    if ( conta ) then 
      
            
            armas = {} 
            
            for i = 0,12 do 
            local arma = getPedweapon(source,i) 
            local ammu = getPedTotalAmmo(source,i) 
                
                if ammu > 0 then 
                table.insert(armas, {arma,ammu}) 
                end 
            end 
  
      
      
        
        local x,y,z = getElementPosition(source) 
        local rx,ry,rz = getElementRotation(source) 
  
            
        local salvarConta = { 
            [1] = getPlayerMoney ( source ); 
            [2] = getElementModel(source);     
            [3] = x; 
            [4] = y; 
            [5] = z;               
            [6] = rx; 
            [7] = getElementDimension(source); 
            [8] = getElementInterior(source) 
            } 
  
            setAccountData(conta,"char.armas",armas) 
            
            for i,v in ipairs(salvarConta) do 
            setAccountData(conta,"char."..tostring(i),tostring(v)) 
            end 
            
            
            
    end 
end 
  
  
  
    function onPlayerJoin ( ) 
    
        local conta = getPlayerAccount ( source ) 
            
        local din = getAccountData(conta,"char.1") 
  
  
        setPlayerMoney(source,din) 
    
    end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerJoin ) 
  
-------------------------------------------------------- 
-------------------------------------------------------- 

Link to comment
-------------------------------------------------------- 
--  Salvar informações no LOGIN/EXIT  ------------------ 
  
  
  
  
    function onPlayerQuit ( ) 
    
    local conta = getPlayerAccount ( source ) 
    if ( conta ) then 
      
            
            armas = {} 
            
            for i = 0,12 do 
            local arma = getPedweapon(source,i) 
            local ammu = getPedTotalAmmo(source,i) 
                
                if ammu > 0 then 
                table.insert(armas, {arma,ammu}) 
                end 
            end 
  
      
      
        
        local x,y,z = getElementPosition(source) 
        local rx,ry,rz = getElementRotation(source) 
  
            
        local salvarConta = { 
            [1] = getPlayerMoney ( source ); 
            [2] = getElementModel(source);     
            [3] = x; 
            [4] = y; 
            [5] = z;               
            [6] = rx; 
            [7] = getElementDimension(source); 
            [8] = getElementInterior(source) 
            } 
  
            setAccountData(conta,"char.armas",armas) 
            
            for i,v in ipairs(salvarConta) do 
            setAccountData(conta,"char."..tostring(i),tostring(v)) 
            end 
            
            
            
    end 
end 
  
  
  
    function onPlayerJoin ( ) 
    
        local conta = getPlayerAccount ( source ) 
            
        local din = getAccountData(conta,"char.1") 
  
  
        setPlayerMoney(source,din) 
    
    end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerJoin ) 
  
-------------------------------------------------------- 
-------------------------------------------------------- 

Ive tryed alot, and i found the problem was the table. All i want is to save the informations using a table and a loop. Using the "char.itemname". But looks like the only way to do this is with numbers... Isn't there another way?

Like, getAccountData ( conta, "char.dinheiro" )) would return the money. Not getAccountData(conta,"char.1"). i Want to make it easy to change you know... but im failing for like 2 months trying to make this work xD

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