Jump to content

setElementData & mysql


kasya85

Recommended Posts

local mysql = exports.MySQL

addEvent("loginPlayer", true)
addEventHandler("loginPlayer", root, function(player, login, pass, types)

    local query, result = mysql:Query(MySQL, "SELECT * FROM db_accounts WHERE BINARY Name=? and Password=?", login, md5(pass))
    if (query) then 
        if (result > 0) then 
              triggerClientEvent(player, "hideLogin", player)
              outputChatBox("You have successfully logged in.", player)
			  setElementData(player, "acc:skin", query.skin) -- THIS, I don't know how load info from MySQL
              setPedSkin ( source, query.skin ) -- THIS, I don't know how load info from MySQL
              setElementData(player, "acc:loggedin", true)
              setElementData(player, "acc:Name", login)
        else
            triggerClientEvent(player, "errorMsg", player, "Wrong username or password")
        end
    end
    --triggerClientEvent(player, "hideLogin", player)
end)

 

WARNING: login\server.lua: Bad argument @ 'setPedSkin' [Expected number at argument 2, got nil]

 

Something wrong with load SKIN from mysql, need help

Edited by kasya85
Link to comment
  • Discord Moderators

You haven't showed us the "Query" function in your resource MySQL so we can't tell for sure what's going on. Is "result" a table or a number? If it's a table you need to do #result to get the number of rows.

Normally the results from queries are returned in a 2-dimensional table, with the rows being numerically indexed in order and each containing a table of key=value pairs corresponding to the columns in your SQL table. As you are selecting a user account, there should only be 1 row returned, or 0 if the user/password combination doesn't exist. So the length of "result" table should be 1, and the user you want is result[1]. The field you want is "skin", which is accessed like result[1].skin.

You should post the code for mysql:Query or clarify what the variables are in this snippet.

Edited by Zango
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...