Turbe$Z Posted May 6, 2017 Share Posted May 6, 2017 i downloaded this script https://community.multitheftauto.com/index.php?p=resources&s=details&id=10944 but this doesn't save the player coint to account, how to ad this function? Link to comment
^iiEcoo'x_) Posted May 6, 2017 Share Posted May 6, 2017 setAccountData getAccountData Link to comment
1B0Y Posted May 7, 2017 Share Posted May 7, 2017 function setAccountCoinValue(player,amount) if not player or not (isElement(player)) then return false end --Prevents errors from occuring when the player element isn't defined. local account = getPlayerAccount(player) --Make sure the player is logged in if isGuestAccount(account) then return false end --Set the coins value in the player's account setAccountData(account,"coins",amount) return true end function getAccountCoinValue(player) if not player or not (isElement(player)) then return false end local account = getPlayerAccount(player) if isGuestAccount(account) then return false end return getAccountData(account,"coins") or 0 end Create a function to call these functions when the player joins, quits, and when the player's coin value is changed to save it to their account Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 00:22, 1B0Y said: function setAccountCoinValue(player,amount) if not player or not (isElement(player)) then return false end --Prevents errors from occuring when the player element isn't defined. local account = getPlayerAccount(player) --Make sure the player is logged in if isGuestAccount(account) then return false end --Set the coins value in the player's account setAccountData(account,"coins",amount) return true end function getAccountCoinValue(player) if not player or not (isElement(player)) then return false end local account = getPlayerAccount(player) if isGuestAccount(account) then return false end return getAccountData(account,"coins") or 0 end Create a function to call these functions when the player joins, quits, and when the player's coin value is changed to save it to their account Expand i added events, but doesn't working, why? function setAccountCoinValue(player,amount) if not player or not (isElement(player)) then return false end local account = getPlayerAccount(player) if isGuestAccount(account) then return false end setAccountData(account,"coins",amount) return true end function getAccountCoinValue(player) if not player or not (isElement(player)) then return false end local account = getPlayerAccount(player) if isGuestAccount(account) then return false end return getAccountData(account,"coins") or 0 end addEventHandler("onPlayerJoin",root,setAccountCoinValue) addEventHandler("onPlayerQuit",root,getAccountCoinValue) addEventHandler("onResourceStart",resourceRoot,setAccountCoinValue) Link to comment
undefined Posted May 7, 2017 Share Posted May 7, 2017 (edited) addEventHandler("onPlayerLogin", root, function() local coin = getAccountCoinValue(source) or 0 setElementData(source, "moneycoins", coin) end) addEventHandler("onPlayerQuit", root, function() local coin = getElementData(source, "moneycoins") or 0 setAccountCoinValue(source, coin) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local coin = getAccountCoinValue(player) if coin then setElementData(player, "moneycoins", coin) end end end) Edited May 7, 2017 by ZoRRoM 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 06:47, ZoRRoM said: addEventHandler("onPlayerLogin", root, function() local coin = getAccountCoinValue(source) or 0 setElementData(source, "moneycoins", coin) end) addEventHandler("onPlayerQuit", root, function() local coin = getElementData(source, "moneycoins") or 0 setAccountCoinValue(source, coin) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local coin = getAccountCoinValue(player) if coin then setElementData(player, "moneycoins", coin) end end end) Expand attempt to call global 'getAccountCoinValue' (a nil value) Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 because this function does not exist. Try this: addEventHandler("onPlayerLogin", root, function() local coin = getAccountData(source, "coins") or 0 setElementData(source, "moneycoins", tonumber(coin)) end) addEventHandler("onPlayerQuit", root, function() local coin = getElementData(source, "moneycoins") or 0 setAccountData(source, "coins", tonumber(coin)) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local coin = getAccountData(player, "coins") if coin then setElementData(player, "moneycoins", tonumber(coin)) end end end) Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 07:49, Simi23 said: because this function does not exist. Try this: addEventHandler("onPlayerLogin", root, function() local coin = getAccountData(source, "coins") or 0 setElementData(source, "moneycoins", tonumber(coin)) end) addEventHandler("onPlayerQuit", root, function() local coin = getElementData(source, "moneycoins") or 0 setAccountData(source, "coins", tonumber(coin)) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local coin = getAccountData(player, "coins") if coin then setElementData(player, "moneycoins", tonumber(coin)) end end end) Expand now when i have xy coin, and i reconnect, and login, the coins reduce to 0 Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 And there is no errors or warns in the debugscript? Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:01, Simi23 said: And there is no errors or warns in the debugscript? Expand c_server.lua:13: Bad argument @ 'getAccountData' [expected account at argument 1, got player] Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 Try this: addEventHandler("onPlayerLogin", root, function() local acc = getPlayerAccount(source) local coin = getAccountData(acc, "coins") or 0 setElementData(source, "moneycoins", tonumber(coin)) end) addEventHandler("onPlayerQuit", root, function() local acc = getPlayerAccount(source) local coin = getElementData(source, "moneycoins") or 0 setAccountData(acc, "coins", tonumber(coin)) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(source) local coin = getAccountData(acc, "coins") if coin then setElementData(player, "moneycoins", tonumber(coin)) end end end) 1 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:07, Simi23 said: Try this: addEventHandler("onPlayerLogin", root, function() local acc = getPlayerAccount(source) local coin = getAccountData(acc, "coins") or 0 setElementData(source, "moneycoins", tonumber(coin)) end) addEventHandler("onPlayerQuit", root, function() local acc = getPlayerAccount(source) local coin = getElementData(source, "moneycoins") or 0 setAccountData(acc, "coins", tonumber(coin)) end) addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType("player")) do local acc = getPlayerAccount(source) local coin = getAccountData(acc, "coins") if coin then setElementData(player, "moneycoins", tonumber(coin)) end end end) Expand now working the script, save my coins, thanks but i got a warning: "Bad argument @ 'getAccountData' [Expected account at argument 1, got boolean]" Why got this warning? 1 Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 Your welcome, I dont know why you get that error, but i think it's fine cuz its working. #wearethevr 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:14, Simi23 said: Your welcome, I dont know why you get that error, but i think it's fine cuz its working. #wearethevr Expand Lol, and when i join the game, the counter does not appear jut when i logged in, and got this warning @ Bad argument @ 'dxDrawText' [Expected string at argument 1, got nil] How to fix this? ..:s This is the client code: local screenW, screenH = guiGetScreenSize() local x, y = (screenW/1024), (screenH/768) local size = y*1.50 function drawText() local playerCoins = getPlayerCoin(getLocalPlayer()); -- local gPlayerCoins = string.format("%08d", playerCoins); dxDrawRectangle(screenW * 0.6972, screenH * 0.0711, screenW * 0.1500, screenH * 0.0256, tocolor(0, 0, 0, 170), false) dxDrawText("Coin:", screenW * 0.7000, screenH * 0.0711, screenW * 0.7431, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "center", false, false, false, false, false) dxDrawText(playerCoins, screenW * 0.7431, screenH * 0.0711, screenW * 0.8472, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) end addEventHandler("onClientRender", root, drawText) function getPlayerCoin() local data = getElementData(getLocalPlayer(), "moneycoins"); thePoints = tonumber(data); return thePoints end fileDelete("c_client.lua") And yeah, #WeAreTheVR 1 Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 Instead of row 7, use local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) 1 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:22, Simi23 said: Instead of row 7, use local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) Expand Now I do not get warning(s), but why show false instead of 0? 1 Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) or tostring(0) Maybe this will do it 1 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:30, Simi23 said: local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) or tostring(0) Maybe this will do it Expand No, same kind 1 Link to comment
Simi23 Posted May 7, 2017 Share Posted May 7, 2017 local screenW, screenH = guiGetScreenSize() local x, y = (screenW/1024), (screenH/768) local size = y*1.50 function drawText() local playerCoins = getElementData(getLocalPlayer(), "moneycoins") if not playerCoins then playerCoins = "0" end dxDrawRectangle(screenW * 0.6972, screenH * 0.0711, screenW * 0.1500, screenH * 0.0256, tocolor(0, 0, 0, 170), false) dxDrawText("Coin:", screenW * 0.7000, screenH * 0.0711, screenW * 0.7431, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "center", false, false, false, false, false) dxDrawText(playerCoins, screenW * 0.7431, screenH * 0.0711, screenW * 0.8472, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) end addEventHandler("onClientRender", root, drawText) function getPlayerCoin() local data = getElementData(getLocalPlayer(), "moneycoins"); thePoints = tonumber(data); return thePoints end fileDelete("c_client.lua") 1 1 Link to comment
Turbe$Z Posted May 7, 2017 Author Share Posted May 7, 2017 On 07/05/2017 at 08:37, Simi23 said: local screenW, screenH = guiGetScreenSize()local x, y = (screenW/1024), (screenH/768)local size = y*1.50 function drawText() local playerCoins = getElementData(getLocalPlayer(), "moneycoins") if not playerCoins then playerCoins = "0" end dxDrawRectangle(screenW * 0.6972, screenH * 0.0711, screenW * 0.1500, screenH * 0.0256, tocolor(0, 0, 0, 170), false) dxDrawText("Coin:", screenW * 0.7000, screenH * 0.0711, screenW * 0.7431, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "center", false, false, false, false, false) dxDrawText(playerCoins, screenW * 0.7431, screenH * 0.0711, screenW * 0.8472, screenH * 0.0967, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false) endaddEventHandler("onClientRender", root, drawText)function getPlayerCoin() local data = getElementData(getLocalPlayer(), "moneycoins"); thePoints = tonumber(data); return thePointsendfileDelete("c_client.lua") Expand thank you 1 1 Link to comment
undefined Posted May 7, 2017 Share Posted May 7, 2017 On 07/05/2017 at 06:59, Turbo777 said: attempt to call global 'getAccountCoinValue' (a nil value) Expand Because i wrote it for 1B0Y's code. You should use both. 1 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