SinaAmp Posted January 29, 2022 Share Posted January 29, 2022 (edited) Hello guys i want to get player account to save his name in database but i got this error: script: function BuySkin159 (theplayer) local account = getPlayerAccount(theplayer) local accName = getAccountName(account) local skinprice = 5000 if account then if getPlayerMoney(theplayer) >= skinprice then takePlayerMoney(theplayer, 5000) setTimer(function() fadeCamera(theplayer,true) setElementModel(theplayer, 159) local ID = getFreeID() local skinid = 159 local myData = dbExec(db,"INSERT INTO SkinShop VALUES (?, ?, ?)",ID,accName,skinid) skin = getElementModel(theplayer) outputChatBox("#00ff00 [Done]: #ffffffskin shoma be id #ff0000"..skin.."#ffffff taghir kard",theplayer, 255,255,255,true) end,1000,1) fadeCamera(theplayer,false) end end end addEventHandler("onMarkerHit", marker1, BuySkin159) Edited January 29, 2022 by SinaAmp Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) I think here it gives a warning message because something other than the player element enters the marker. You can check it with getElementType function BuySkin159 (theplayer) if(getElementType(theplayer) ~= "player") then return end -- if theplayer not player stop continue local account = getPlayerAccount(theplayer) local skinprice = 5000 if(account) then -- Does the player have an account? if(isGuestAccount(account)) then return end -- if account guest account stop continue local accName = getAccountName(account) if getPlayerMoney(theplayer) >= skinprice then takePlayerMoney(theplayer, 5000) setTimer(function() fadeCamera(theplayer,true) setElementModel(theplayer, 159) local ID = getFreeID() local skinid = 159 local myData = dbExec(db,"INSERT INTO SkinShop VALUES (?, ?, ?)",ID,accName,skinid) skin = getElementModel(theplayer) outputChatBox("#00ff00 [Done]: #ffffffskin shoma be id #ff0000"..skin.."#ffffff taghir kard",theplayer, 255,255,255,true) end,1000,1) fadeCamera(theplayer,false) end end end addEventHandler("onMarkerHit", marker1, BuySkin159) Edited January 29, 2022 by Burak5312 1 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 thank you @Burak5312 after runing your script the errors had disapared but i got dbexec fail error and null account name in my account column in database the id and skinid had no issue and saved data well Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) I think I forgot this part, I edited the code above again local accName = getAccountName(account) Edited January 29, 2022 by Burak5312 1 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 Thank you bro problem solved i want to wrote the script that get skin id from database after login and set player model to it but again my script not work: function afterlogin() local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop") local result = dbPoll(skinData,-1) if (result) and (result[1]) and (result[2]) then setElementModel(source, result[1].skin ) end end addEventHandler("onPlayerLogin",root, afterlogin) Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 2 minutes ago, SinaAmp said: Thank you bro problem solved i want to wrote the script that get skin id from database after login and set player model to it but again my script not work: function afterlogin() local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop") local result = dbPoll(skinData,-1) if (result) and (result[1]) and (result[2]) then setElementModel(source, result[1].skin ) end end addEventHandler("onPlayerLogin",root, afterlogin) Can you show the data coming with outputDebugString outputDebugString(result[1].skin) Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) hmm maybe try changing "skin" to "Skin"? function afterlogin() local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop") local result = dbPoll(skinData,-1) if (result) and (result[1]) and (result[2]) then setElementModel(source, result[1].Skin ) end end addEventHandler("onPlayerLogin",root, afterlogin) Edited January 29, 2022 by Burak5312 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 this is my database https://s6.uupload.ir/files/mysqlda_60e3.png this problem solved but when every player loged in, their skin change to saved skin in database @Burak5312 Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 so when you exit the game, doesn't it save the current skin to the database again? Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 skin save in database when the player buy the skin but not when player disconnected from server i want to get and use that saved data from shop Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 I don't know much about database, if you want, ask someone else about this I don't want to give you wrong information. 1 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 thank you bro maybe @The_GTA can help 1 Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) yes he knows a lot more than me he will help you good luck Edited January 29, 2022 by Burak5312 1 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 finally solved this issue function afterlogin(theplayer) if isElement(theplayer) and getElementType(theplayer) ~= "player" then return end local SkinData = dbPoll(dbQuery(db,"SELECT Account,Skin,ID FROM SkinShop"), -1) local account = getPlayerAccount(source) local accName = getAccountName(account) if (SkinData) and (SkinData[1]) and (SkinData[2]) then if (SkinData[1].Account == tostring(accName)) then setElementModel(source, SkinData[2].Skin ) end end end addEventHandler("onPlayerLogin",root, afterlogin) Link to comment
βurak Posted January 29, 2022 Share Posted January 29, 2022 (edited) actually you don't need some lines here like getPlayerAccount because the onPlayerLogin event carries the account you are logged into so change it like this function afterlogin(_,account) -- this account local SkinData = dbPoll(dbQuery(db,"SELECT Account,Skin,ID FROM SkinShop"), -1) --local account = getPlayerAccount(source) -- no need this local accName = getAccountName(account) if (SkinData) and (SkinData[1]) and (SkinData[2]) then if (SkinData[1].Account == tostring(accName)) then setElementModel(source, SkinData[2].Skin ) end end end addEventHandler("onPlayerLogin",root, afterlogin) Edited January 29, 2022 by Burak5312 1 Link to comment
SinaAmp Posted January 29, 2022 Author Share Posted January 29, 2022 Thank you bro for improvement 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