Best-Killer Posted January 17, 2016 Share Posted January 17, 2016 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 ? 1 Link to comment
#RooTs Posted January 17, 2016 Share Posted January 17, 2016 It is using the bank system? https://community.multitheftauto.com/in ... ails&id=54 1 Link to comment
Best-Killer Posted January 17, 2016 Author Share Posted January 17, 2016 No it's my own Link to comment
#RooTs Posted January 18, 2016 Share Posted January 18, 2016 No it's my own you can use part of his functions the script is free and open Link to comment
Best-Killer Posted January 20, 2016 Author Share Posted January 20, 2016 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 Link to comment
1LoL1 Posted January 20, 2016 Share Posted January 20, 2016 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 ); Link to comment
Best-Killer Posted January 20, 2016 Author Share Posted January 20, 2016 Not work 0 errors Link to comment
Castillo Posted January 20, 2016 Share Posted January 20, 2016 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? Link to comment
Best-Killer Posted January 20, 2016 Author Share Posted January 20, 2016 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 Link to comment
Castillo Posted January 20, 2016 Share Posted January 20, 2016 How are you "depositing" the money? can you post the bank deposit code? Link to comment
Best-Killer Posted January 20, 2016 Author Share Posted January 20, 2016 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 Link to comment
Castillo Posted January 20, 2016 Share Posted January 20, 2016 (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. Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 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 Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 -- 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. Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 -- 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 Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 Can you be more specific about what "doesn't work"? Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 0 warinig 0 erros and the bank blance not saved Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 Debug the script, see what is not working, if the deposit/withdraw part, or the loading part ( onPlayerLogin ). Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 done i did everything fine but still not saved Shit Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 Did what exactly? did you even understand what I told you to do? Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 Did what exactly? did you even understand what I told you to do? yes it's : outputDebugString("We passed our check!",3) Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 And how does that help with anything? you are supposed to check if 'balance' is the right value. Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 Castillo when i restart the script the blance showed to me Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 Sloved /Lock pls Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now