SinaAmp Posted January 27, 2022 Share Posted January 27, 2022 hi guys i want to change the player skin after login . i mean after player logged i want to setplayermodel to the number i saved in the accounts table here is my connecting script and that works well: local db_host = "" local db_username = "" local db_password = "" local db_table = "" local db_port = "" local connection = false function connect() connection = dbConnect("mysql","dbname="..db_table..";host="..db_host..";port="..db_port..";unix_socket=/var/run/mysqld/mysqld.sock",db_username,db_password) if (connection) then outputChatBox("connected") return true else outputChatBox("not connected") setTimer(connect,5000,1) end end addEventHandler("onResourceStart",resourceRoot,connect) and this is my changing skin code: function afterlogin() local skinData = dbQuery(connection,"SELECT * FROM accounts WHERE id=? AND skin=? LIMIT 1",(id),(skin)) local result = dbPoll( qh, -1 ) if (skinData) then setElementData(theplayer,"id",skinData.id) setElementModel (theplayer, skinData.skin ) end end addEventHandler("onPlayerLogin",root, afterlogin) Link to comment
βurak Posted January 27, 2022 Share Posted January 27, 2022 (edited) Change "theplayer" to "source" like this function afterlogin() local skinData = dbQuery(connection,"SELECT * FROM accounts WHERE id=? AND skin=? LIMIT 1",(id),(skin)) local result = dbPoll( qh, -1 ) if (skinData) then setElementData(source,"id",skinData.id) setElementModel (source, skinData.skin ) end end addEventHandler("onPlayerLogin",root, afterlogin) Edited January 27, 2022 by Burak5312 Link to comment
Shady1 Posted January 27, 2022 Share Posted January 27, 2022 (edited) Hello @SinaAmp I don't see a problem with the codes you sent first, you need to review the codes you sent for the second time, for example, if you use the source command instead of theplayer this problem will be fixed, if you still have a problem, please return Then you can fill in the skin ID section you want. function afterlogin() local skinData = dbQuery(connection,"SELECT * FROM accounts WHERE id=? AND skin=? LIMIT 1",(id),(skin)) local result = dbPoll( qh, -1 ) if (skinData) then setElementData(source,"id",skinData.id) --I fixed this part setElementModel(source, skinData.skin ) --I fixed this part end end addEventHandler("onPlayerLogin",root, afterlogin) Edited January 27, 2022 by eoL|Shady Link to comment
SinaAmp Posted January 27, 2022 Author Share Posted January 27, 2022 (edited) guys i changed theplayer to source but nothing changed i disconnected from server and loged again but my skin doesent changed is that connection part in dbquery is true? https://imgur.com/a/W1hOs3w i changed the dbpoll query handle to skinData Edited January 27, 2022 by SinaAmp Link to comment
Shady1 Posted January 27, 2022 Share Posted January 27, 2022 (edited) Hello @SinaAmpHave you tried using the dbExec command https://wiki.multitheftauto.com/wiki/DbQuery Edited January 27, 2022 by eoL|Shady Link to comment
The_GTA Posted January 27, 2022 Share Posted January 27, 2022 local skinData = dbQuery(connection,"SELECT * FROM accounts WHERE id=? AND skin=? LIMIT 1",(id),(skin)) What are the definitions of the global variables "id" and "skin"? Link to comment
Shady1 Posted January 27, 2022 Share Posted January 27, 2022 (edited) i know someone who is more knowledgeable on this subject @The_GTA ahh he was already here Edited January 27, 2022 by eoL|Shady 1 Link to comment
SinaAmp Posted January 27, 2022 Author Share Posted January 27, 2022 Just now, eoL|Shady said: Hello @SinaAmpHave you tried using the dbExec command https://wiki.multitheftauto.com/wiki/DbQuery yes but not work Just now, The_GTA said: local skinData = dbQuery(connection,"SELECT * FROM accounts WHERE id=? AND skin=? LIMIT 1",(id),(skin)) What are the definitions of the global variables "id" and "skin"? id select from column id and skin from column skin Link to comment
Shady1 Posted January 27, 2022 Share Posted January 27, 2022 Can you show us the text where you used the "id" and "skin" variables, we can help you better. 1 Link to comment
The_GTA Posted January 27, 2022 Share Posted January 27, 2022 4 minutes ago, SinaAmp said: id select from column id and skin from column skin You misunderstand how the SQL language works. To get all rows and columns of accounts SQL table, you execute... SELECT * FROM accounts But if you want just id and skin, you execute... SELECT id, skin FROM accounts Thus I recommend you to change the database query to... local skinData = dbQuery(connection,"SELECT skin,id FROM accounts LIMIT 1") 2 Link to comment
SinaAmp Posted January 27, 2022 Author Share Posted January 27, 2022 but how to change element model to received skin number Link to comment
The_GTA Posted January 27, 2022 Share Posted January 27, 2022 2 minutes ago, SinaAmp said: but how to change element model to received skin number Here: if (result) and (result[1]) then setElementData(source,"id",result[1].id) --I fixed this part setElementModel(source, result[1].skin ) --I fixed this part end 1 Link to comment
SinaAmp Posted January 27, 2022 Author Share Posted January 27, 2022 Just now, The_GTA said: Here: if (result) and (result[1]) then setElementData(source,"id",result[1].id) --I fixed this part setElementModel(source, result[1].skin ) --I fixed this part end thank you bro problem solved 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