Jump to content

Help to setAccountData. I Can't make it work


Recommended Posts

Posted (edited)

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
Posted

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!

Posted
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 ;)

Posted

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

use onPlayerLogin.

Posted
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 :/

Posted

Oh.

Try:

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

Posted
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

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

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

Didn't work
Posted
-------------------------------------------------------- 
--  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 ) 
  
-------------------------------------------------------- 
-------------------------------------------------------- 

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

Posted

onPlayerJoin doesnt works with set/getAccountData, becuase he didnt used /login if he connected

Only you have to use command /login and then get/setAccountData

P.S: Are you from brazil? I am from brazil too

Posted
onPlayerJoin doesnt works with set/getAccountData, becuase he didnt used /login if he connected

Only you have to use command /login and then get/setAccountData

P.S: Are you from brazil? I am from brazil too

Have you read the full thread? Você leu o topico inteiro? :/
Posted
Change to
setAccountData(conta,"char."..tostring(i), tonumber(v)) 

Se vc quer ajudar, me add no skype

Ja consegui ageitar. Mas vlw

I've found the problem and fixed this. Thansk everybody for the help :)

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