Jump to content

Save Blance Problem


Best-Killer

Recommended Posts

Posted
function onPlayerLogin() 
account = getPlayerAccount(source) 
money = getAccountData(account,"bankmoney") 
setElementData(source,"bankmoney",money) 
setElementData(source,"account",account) 
end 
addEventHandler("onPlayerLogin",root,onPlayerLogin) 
  
function onPlayerLogout() 
account = getPlayerAccount(source) 
money = getElementData(source,"bankmoney") 
setAccountData(account,"bankmoney",money) 
end 
addEventHandler("onPlayerQuit",root,onPlayerLogout) 

0 errors

when i deposit money in bank and i recconect the money in bank back to 0 :/ any solution ?

  • Like 1
Posted

new code

addEventHandler ( 'onPlayerLogin', root, 
    function ( _,account )   
        local accountName = getAccountName ( account ); 
        local balance = getAccountData ( account, 'bankmoney' ); 
        setElementData ( source, 'AccountName', accountName ); 
        if balance then 
            setElementData ( source, 'bankmoney', tonumber( balance ) ); 
        else 
            setElementData ( source, 'bankmoney', '0' ); 
        end 
    end 
); 
  
addEventHandler ( 'onPlayerLogout', root, 
    function ( account ) 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 
  
addEventHandler ( 'onPlayerQuit', root, 
    function ( ) 
        local account = getPlayerAccount ( source ); 
        if isGuestAccount ( account ) then 
            return 
        end 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 

but still not saved :/

Posted
new code
addEventHandler ( 'onPlayerLogin', root, 
    function ( _,account )   
        local accountName = getAccountName ( account ); 
        local balance = getAccountData ( account, 'bankmoney' ); 
        setElementData ( source, 'AccountName', accountName ); 
        if balance then 
            setElementData ( source, 'bankmoney', tonumber( balance ) ); 
        else 
            setElementData ( source, 'bankmoney', '0' ); 
        end 
    end 
); 
  
addEventHandler ( 'onPlayerLogout', root, 
    function ( account ) 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 
  
addEventHandler ( 'onPlayerQuit', root, 
    function ( ) 
        local account = getPlayerAccount ( source ); 
        if isGuestAccount ( account ) then 
            return 
        end 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 

but still not saved :/

Try this.

addEventHandler("onPlayerLogin", getRootElement(), 
    function ()  
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        if balance then 
            setAccountData(account, "bankmoney", balance) 
        else 
            setAccountData(account, "bankmoney", 0) 
        end 
    end 
) 
  
addEventHandler("onPlayerLogout", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        setAccountData(account, "bankmoney", balance) 
    end 
) 
  
addEventHandler("onPlayerQuit", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") 
        setAccountData(account, "bankmoney", balance) 
    end 
); 

Posted
new code
addEventHandler ( 'onPlayerLogin', root, 
    function ( _,account )   
        local accountName = getAccountName ( account ); 
        local balance = getAccountData ( account, 'bankmoney' ); 
        setElementData ( source, 'AccountName', accountName ); 
        if balance then 
            setElementData ( source, 'bankmoney', tonumber( balance ) ); 
        else 
            setElementData ( source, 'bankmoney', '0' ); 
        end 
    end 
); 
  
addEventHandler ( 'onPlayerLogout', root, 
    function ( account ) 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 
  
addEventHandler ( 'onPlayerQuit', root, 
    function ( ) 
        local account = getPlayerAccount ( source ); 
        if isGuestAccount ( account ) then 
            return 
        end 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 

but still not saved :/

Try this.

addEventHandler("onPlayerLogin", getRootElement(), 
    function ()  
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        if balance then 
            setAccountData(account, "bankmoney", balance) 
        else 
            setAccountData(account, "bankmoney", 0) 
        end 
    end 
) 
  
addEventHandler("onPlayerLogout", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        setAccountData(account, "bankmoney", balance) 
    end 
) 
  
addEventHandler("onPlayerQuit", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") 
        setAccountData(account, "bankmoney", balance) 
    end 
); 

Your code doesn't make any sense, you are basically obtaining the bank, then setting it back? how does that make sense?

@Best-Killer: Are you trying to save the money players have?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
new code
addEventHandler ( 'onPlayerLogin', root, 
    function ( _,account )   
        local accountName = getAccountName ( account ); 
        local balance = getAccountData ( account, 'bankmoney' ); 
        setElementData ( source, 'AccountName', accountName ); 
        if balance then 
            setElementData ( source, 'bankmoney', tonumber( balance ) ); 
        else 
            setElementData ( source, 'bankmoney', '0' ); 
        end 
    end 
); 
  
addEventHandler ( 'onPlayerLogout', root, 
    function ( account ) 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 
  
addEventHandler ( 'onPlayerQuit', root, 
    function ( ) 
        local account = getPlayerAccount ( source ); 
        if isGuestAccount ( account ) then 
            return 
        end 
        local balance = getElementData ( source, 'bankmoney' ); 
        setAccountData ( account, 'bankmoney', balance ); 
    end 
); 

but still not saved :/

Try this.

addEventHandler("onPlayerLogin", getRootElement(), 
    function ()  
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        if balance then 
            setAccountData(account, "bankmoney", balance) 
        else 
            setAccountData(account, "bankmoney", 0) 
        end 
    end 
) 
  
addEventHandler("onPlayerLogout", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        setAccountData(account, "bankmoney", balance) 
    end 
) 
  
addEventHandler("onPlayerQuit", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") 
        setAccountData(account, "bankmoney", balance) 
    end 
); 

Your code doesn't make any sense, you are basically obtaining the bank, then setting it back? how does that make sense?

@Best-Killer: Are you trying to save the money players have?

Yes Castillo

Posted

How are you "depositing" the money? can you post the bank deposit code?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function depoistMoney() 
    local text = tonumber (guiGetText(GUIEditor.edit[2])) 
    local text2 = tonumber(guiGetText(GUIEditor.edit[1])) 
    if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then 
        if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then 
        guiSetText(GUIEditor.edit[1],"Transferring...") 
        setTimer(guiSetText,2000,1,GUIEditor.edit[1],tonumber(text + text2)) 
        setTimer(takePlayerMoney,2000,1,tonumber(text)) 
        exports['SAEGMessages']:sendClientMessage ( "You've withdrawn "..tonumber(text + text2)" from your bank account", source, 200, 200, 200 ) 
        setElementData(localPlayer,"bankmoney",tonumber(text + text2)) 
        elseif getPlayerMoney() == 0 then -- 
         
            exports['SAEGMessages']:sendClientMessage ( "You don't have that ammount money in your bank", 255, 0, 0 ) 
        elseif getPlayerMoney() < 0 then 
            outputChatBox("You can't deposit negative numbers.") 
        end 
    end 
end 
  
function withdrawMoney() 
local text = guiGetText(GUIEditor.edit[2]) 
local text2 = guiGetText(GUIEditor.edit[1]) 
if (guiRadioButtonGetSelected(GUIEditor.radiobutton[2])) then 
if tonumber(text2) >= tonumber(text) and tonumber(text) > 0 then 
guiSetText(GUIEditor.edit[1],"Transferring...") 
setTimer(guiSetText,2000,1,GUIEditor.edit[1],tostring(text2 - text)) 
setTimer(givePlayerMoney,2000,1,tonumber(text)) 
setElementData(localPlayer,"bankmoney",tonumber(text2 - text)) 
elseif tonumber(text2) < tonumber(text) then 
exports['SAEGMessages']:sendClientMessage ( "You don't have that ammount money in your bank", 255, 0, 0 ) 
elseif tonumber(text) < 0 then 
outputChatBox("You can't withdraw negative numbers.") 
end 
end 
end 

Posted

(take/give)PlayerMoney when used client side, won't really give/take anything from the player, since the money won't be synchronized with the server.

You should do the withdraw/deposit parts server-side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Castillo everything work fine only blance not saving :/ help pls

server-side

addEventHandler("onPlayerLogin", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        if balance then 
            setAccountData(account, "bankmoney", balance) 
        else 
            setAccountData(account, "bankmoney", 0) 
        end 
    end 
) 
  
addEventHandler("onPlayerLogout", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney") or 0) 
        setAccountData(account, "bankmoney", balance) 
    end 
) 
  
addEventHandler("onPlayerQuit", getRootElement(), 
    function () 
        local account = getPlayerAccount(source) 
        local balance = (getAccountData(account, "bankmoney")) 
        setAccountData(account, "bankmoney", balance) 
    end 
); 
  
  
function depoist ( text ) 
if not (tonumber(text) <= 0) then 
local moneybank = getAccountData (getPlayerAccount (source), "bankmoney") 
mbank = moneybank + text 
setTimer(takePlayerMoney,2000,1,source,text) 
exports['SAEGMessages']:sendClientMessage ( "You've deposited $"..text.." from your bank account", source, 200, 200, 200 ) 
setAccountData (getPlayerAccount (source), "bankmoney", mbank) 
else 
exports['SAEGMessages']:sendClientMessage ( "You don't have enough money for deposit  $"..text.." from your bank account", source, 200, 200, 200 ) 
end 
end 
addEvent ("depoist", true) 
addEventHandler( "depoist", getRootElement(), depoist ) 
  
function withdraw (text) 
local bankcash = getAccountData (getPlayerAccount (source), "bankmoney")         
if (tonumber(text) <= tonumber(bankcash)) then 
        if(tonumber(text) >= 1) then 
        mbank2 = bankcash-text 
        setAccountData (getPlayerAccount (source), "bankmoney", mbank2) 
        givePlayerMoney(source, text) 
        exports['SAEGMessages']:sendClientMessage ( "You've withdrawn  $"..text.." from your bank account", source, 200, 200, 200 ) 
        else 
        exports['SAEGMessages']:sendClientMessage ( "You don't have enough money for withdraw $"..text.." from your bank account", source, 200, 200, 200 ) 
        end 
    end 
end 
addEvent ("withdraw",true) 
addEventHandler( "withdraw", getRootElement(), withdraw )    

Client-side

function depoistMoney() 
    local text = tonumber (guiGetText(GUIEditor.edit[2])) 
    local text2 = tonumber(guiGetText(GUIEditor.edit[1])) 
    if (guiRadioButtonGetSelected(GUIEditor.radiobutton[1])) then 
        if tonumber(text) and getPlayerMoney() >= tonumber(text) and tonumber(text) >= 0 then 
        guiSetText(GUIEditor.edit[1],"Transferring...") 
        setTimer(guiSetText,2000,1,GUIEditor.edit[1],tonumber(text + text2)) 
        triggerServerEvent ("depoist", getLocalPlayer(), text) 
        setElementData(localPlayer,"bankmoney",tonumber(text2 + text)) 
        end 
    end 
end 
  
function withdrawMoney() 
local text = guiGetText(GUIEditor.edit[2]) 
local text2 = guiGetText(GUIEditor.edit[1]) 
if (guiRadioButtonGetSelected(GUIEditor.radiobutton[2])) then 
if tonumber(text2) >= tonumber(text) and tonumber(text) > 0 then 
guiSetText(GUIEditor.edit[1],"Transferring...") 
setTimer(guiSetText,2000,1,GUIEditor.edit[1],tostring(text2 - text)) 
triggerServerEvent ("withdraw", getLocalPlayer(), text) 
setElementData(localPlayer,"bankmoney",tonumber(text2 - text)) 
end 
end 
end 

Posted

-- client side:

function depoistMoney ( ) 
    local text = tonumber ( guiGetText ( GUIEditor.edit[2] ) ) or 0 
    local text2 = tonumber ( guiGetText ( GUIEditor.edit[1] ) ) or 0 
    if guiRadioButtonGetSelected ( GUIEditor.radiobutton[1] ) then 
        if ( text and getPlayerMoney ( ) >= text and text >= 0 ) then 
            guiSetText ( GUIEditor.edit[1], "Transferring..." ) 
            setTimer ( guiSetText, 2000, 1, GUIEditor.edit[1], tostring ( text + text2 ) ) 
            triggerServerEvent ( "bank_deposit", localPlayer, text ) 
        end 
    end 
end 
  
function withdrawMoney ( ) 
    local text = tonumber ( guiGetText ( GUIEditor.edit[2] ) ) or 0 
    local text2 = tonumber ( guiGetText ( GUIEditor.edit[1] ) ) or 0 
    if guiRadioButtonGetSelected ( GUIEditor.radiobutton[2] ) then 
        if ( text2 >= text and text > 0 ) then 
            guiSetText ( GUIEditor.edit[1], "Transferring..." ) 
            setTimer ( guiSetText, 2000, 1, GUIEditor.edit[1], tostring ( text2 - text ) ) 
            triggerServerEvent ( "bank_withdraw", localPlayer, text ) 
        end 
    end 
end 

-- server side:

addEventHandler ( "onPlayerLogin", getRootElement(), 
    function ( _, account ) 
        if ( not isGuestAccount ( account ) ) then 
            local balance = tonumber ( getAccountData ( account, "bankmoney" ) ) or 0 
            setElementData ( source, "bankmoney", balance ) 
        end 
    end 
) 
  
function bank_deposit ( text ) 
    if ( text > 0 ) then 
        local moneyBank = getAccountData ( getPlayerAccount ( source ), "bankmoney" ) 
        local newBalance = ( moneyBank + text ) 
        takePlayerMoney ( source, text ) 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You have deposited $".. text .." to your bank account", source, 200, 200, 200 ) 
        setAccountData ( getPlayerAccount ( source ), "bankmoney", newBalance ) 
        setElementData ( source, "bankmoney", newBalance ) 
    else 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You don't have enough money to deposit  $".. text .." to your bank account.", source, 200, 200, 200 ) 
    end 
end 
addEvent ( "bank_deposit", true ) 
addEventHandler ( "bank_deposit", root, bank_deposit ) 
  
function bank_withdraw ( text ) 
    if ( text > 0 ) then 
        local moneyBank = getAccountData ( getPlayerAccount ( source ), "bankmoney" ) 
        local newBalance = ( moneyBank - text ) 
        givePlayerMoney ( source, text ) 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You have withdrawn $".. text .." from your bank account", source, 200, 200, 200 ) 
        setAccountData ( getPlayerAccount ( source ), "bankmoney", newBalance ) 
        setElementData ( source, "bankmoney", newBalance ) 
    else 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You don't have enough money in your bank account to withdraw  $".. text ..".", source, 200, 200, 200 ) 
    end 
end 
addEvent ( "bank_withdraw", true ) 
addEventHandler ( "bank_withdraw", root, bank_withdraw ) 

I have removed the onPlayerQuit/Logout events, since you set the account data on deposit/withdraw, so there should be no need to save it again.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
-- client side:
function depoistMoney ( ) 
    local text = tonumber ( guiGetText ( GUIEditor.edit[2] ) ) or 0 
    local text2 = tonumber ( guiGetText ( GUIEditor.edit[1] ) ) or 0 
    if guiRadioButtonGetSelected ( GUIEditor.radiobutton[1] ) then 
        if ( text and getPlayerMoney ( ) >= text and text >= 0 ) then 
            guiSetText ( GUIEditor.edit[1], "Transferring..." ) 
            setTimer ( guiSetText, 2000, 1, GUIEditor.edit[1], tostring ( text + text2 ) ) 
            triggerServerEvent ( "bank_deposit", localPlayer, text ) 
        end 
    end 
end 
  
function withdrawMoney ( ) 
    local text = tonumber ( guiGetText ( GUIEditor.edit[2] ) ) or 0 
    local text2 = tonumber ( guiGetText ( GUIEditor.edit[1] ) ) or 0 
    if guiRadioButtonGetSelected ( GUIEditor.radiobutton[2] ) then 
        if ( text2 >= text and text > 0 ) then 
            guiSetText ( GUIEditor.edit[1], "Transferring..." ) 
            setTimer ( guiSetText, 2000, 1, GUIEditor.edit[1], tostring ( text2 - text ) ) 
            triggerServerEvent ( "bank_withdraw", localPlayer, text ) 
        end 
    end 
end 

-- server side:

addEventHandler ( "onPlayerLogin", getRootElement(), 
    function ( _, account ) 
        if ( not isGuestAccount ( account ) ) then 
            local balance = tonumber ( getAccountData ( account, "bankmoney" ) ) or 0 
            setElementData ( source, "bankmoney", balance ) 
        end 
    end 
) 
  
function bank_deposit ( text ) 
    if ( text > 0 ) then 
        local moneyBank = getAccountData ( getPlayerAccount ( source ), "bankmoney" ) 
        local newBalance = ( moneyBank + text ) 
        takePlayerMoney ( source, text ) 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You have deposited $".. text .." to your bank account", source, 200, 200, 200 ) 
        setAccountData ( getPlayerAccount ( source ), "bankmoney", newBalance ) 
        setElementData ( source, "bankmoney", newBalance ) 
    else 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You don't have enough money to deposit  $".. text .." to your bank account.", source, 200, 200, 200 ) 
    end 
end 
addEvent ( "bank_deposit", true ) 
addEventHandler ( "bank_deposit", root, bank_deposit ) 
  
function bank_withdraw ( text ) 
    if ( text > 0 ) then 
        local moneyBank = getAccountData ( getPlayerAccount ( source ), "bankmoney" ) 
        local newBalance = ( moneyBank - text ) 
        givePlayerMoney ( source, text ) 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You have withdrawn $".. text .." from your bank account", source, 200, 200, 200 ) 
        setAccountData ( getPlayerAccount ( source ), "bankmoney", newBalance ) 
        setElementData ( source, "bankmoney", newBalance ) 
    else 
        exports [ 'SAEGMessages' ]:sendClientMessage ( "You don't have enough money in your bank account to withdraw  $".. text ..".", source, 200, 200, 200 ) 
    end 
end 
addEvent ( "bank_withdraw", true ) 
addEventHandler ( "bank_withdraw", root, bank_withdraw ) 

I have removed the onPlayerQuit/Logout events, since you set the account data on deposit/withdraw, so there should be no need to save it again.

i test it not work :/ castillo pls slove the me that problem pls :/

Posted

Can you be more specific about what "doesn't work"?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Debug the script, see what is not working, if the deposit/withdraw part, or the loading part ( onPlayerLogin ).

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Did what exactly? did you even understand what I told you to do?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

And how does that help with anything? you are supposed to check if 'balance' is the right value.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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