xXMADEXx Posted April 25, 2013 Share Posted April 25, 2013 Hello all, im making VIP system, and im not sure how to get the data from my SQL when the player logs in.... Here is my code: addEventHandler("onPlayerJoin", root, function () dbQuery(loadPlayersVIP, dbConnection, "SELECT * FROM Freeroam_VIP_Players", source) end ) function loadPlayersVIP(hand,who) sql = dbPoll(hand, 0) for i,v in ipairs (sql) do if (v["account"]==getAccountName(getPlayerAccount(who))) then setElementData(who, "VIP", v["level"], true) end end end and here is an image of the MySQL Link to comment
Castillo Posted April 26, 2013 Share Posted April 26, 2013 Instead of looping every single row, just select the one that matches his account. Link to comment
xXMADEXx Posted April 26, 2013 Author Share Posted April 26, 2013 Instead of looping every single row, just select the one that matches his account. lol, sorry, but im noob at MySQL, how do i find it? Link to comment
Castillo Posted April 26, 2013 Share Posted April 26, 2013 addEventHandler ( "onPlayerLogin", root, function ( _, account ) dbQuery ( loadPlayersVIP, { source }, dbConnection, "SELECT level FROM Freeroam_VIP_Players WHERE account = ? LIMIT 1", getAccountName ( account ) ) end ) function loadPlayersVIP ( query, who ) local sql, numrows, errmsg = dbPoll ( query, 0 ) if ( type ( sql ) == "table" and numrows > 0 ) then setElementData ( who, "VIP", sql [ 1 ] [ "level" ] ) end end Link to comment
xXMADEXx Posted April 26, 2013 Author Share Posted April 26, 2013 addEventHandler ( "onPlayerLogin", root, function ( _, account ) dbQuery ( loadPlayersVIP, { source }, dbConnection, "SELECT level FROM Freeroam_VIP_Players WHERE account = ? LIMIT 1", getAccountName ( account ) ) end ) function loadPlayersVIP ( query, who ) local sql, numrows, errmsg = dbPoll ( query, 0 ) if ( type ( sql ) == "table" and numrows > 0 ) then setElementData ( who, "VIP", sql [ 1 ] [ "level" ] ) end end Didn't work... Link to comment
Castillo Posted April 26, 2013 Share Posted April 26, 2013 That's weird, it should work. 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