Turbe$Z Posted May 6, 2017 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? My Fun server: My DD server:
^iiEcoo'x_) Posted May 6, 2017 Posted May 6, 2017 setAccountData getAccountData - Hashemite Kingdom Of Jordan -
1B0Y Posted May 7, 2017 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 Founder of Kutmode - http://kutmode.com | https://discord.gg/P3FXVnF (Retired) Leading Developer of Grand Theft International (Retired) Leading Developer of Full Theft Auto. (Retired) Owner of SourceMod.
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 5 hours ago, 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 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) My Fun server: My DD server:
undefined Posted May 7, 2017 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
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 11 minutes ago, 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) attempt to call global 'getAccountCoinValue' (a nil value) My Fun server: My DD server:
Simi23 Posted May 7, 2017 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)
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 8 minutes ago, 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) now when i have xy coin, and i reconnect, and login, the coins reduce to 0 My Fun server: My DD server:
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 1 minute ago, Simi23 said: And there is no errors or warns in the debugscript? c_server.lua:13: Bad argument @ 'getAccountData' [expected account at argument 1, got player] My Fun server: My DD server:
Simi23 Posted May 7, 2017 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
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 3 minutes ago, 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) 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 My Fun server: My DD server:
Simi23 Posted May 7, 2017 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
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 2 minutes ago, Simi23 said: Your welcome, I dont know why you get that error, but i think it's fine cuz its working. #wearethevr 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 My Fun server: My DD server:
Simi23 Posted May 7, 2017 Posted May 7, 2017 Instead of row 7, use local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) 1 1
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 2 minutes ago, Simi23 said: Instead of row 7, use local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) Now I do not get warning(s), but why show false instead of 0? 1 My Fun server: My DD server:
Simi23 Posted May 7, 2017 Posted May 7, 2017 local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) or tostring(0) Maybe this will do it 1 1
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 1 minute ago, Simi23 said: local playerCoins = tostring(getElementData(getLocalPlayer(), "moneycoins")) or tostring(0) Maybe this will do it No, same kind 1 My Fun server: My DD server:
Simi23 Posted May 7, 2017 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
Turbe$Z Posted May 7, 2017 Author Posted May 7, 2017 2 minutes ago, 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") thank you 1 1 My Fun server: My DD server:
undefined Posted May 7, 2017 Posted May 7, 2017 2 hours ago, Turbo777 said: attempt to call global 'getAccountCoinValue' (a nil value) Because i wrote it for 1B0Y's code. You should use both. 1
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