Jump to content

Change skin after login using mysql


SinaAmp

Recommended Posts

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

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 by Burak5312
Link to comment

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 by eoL|Shady
Link to comment
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")

 

  • Like 2
Link to comment
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

 

  • Thanks 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...