Crosshair Posted June 3, 2012 Share Posted June 3, 2012 I got a marker and: function biroutranzactii(element) if getElementType(element) == "player" and (element == localPlayer) then build_Banca() guiSetText( sold, "Sold: "..getElementData( localPlayer, "cash") ) showCursor(true) end end addEventHandler("onClientMarkerHit", marker2, biroutranzactii) in server file i got function banca() for _,v in ipairs(getElementsByType("player")) do local banca = mysql_query(handler, "SELECT * FROM accounts WHERE username = 'Crosshair';") if (banca) then local bancarow = mysql_fetch_assoc(banca) local bank = bancarow.bank setElementData( v, "cash", bank) end mysql_free_result(banca) end end setTimer(banca, 1000,0) on mysql_query function i want to change "Crosshair" with getPlayerName(source) but i don`t know how to define source. I get the error Bed argument data. if i put function banca(source) still nothing. How can i define it ? Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 I really don't recommend using a 1 second timer to loop all players and do a MySQL query. Link to comment
Crosshair Posted June 3, 2012 Author Share Posted June 3, 2012 Do you have any suggestion instead ? Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 You can do the following: On login: Set the element data of his "banca" and when you update it. On logout/quit: Get that element data and update the MySQL table. Link to comment
Crosshair Posted June 3, 2012 Author Share Posted June 3, 2012 like this ? function banca() local banca = mysql_query(handler, "SELECT * FROM accounts WHERE username = '"..getPlayerName(source).."';") if (banca) then local bancarow = mysql_fetch_assoc(banca) local bank = bancarow.bank setElementData(source, "cash", bank) end mysql_free_result(banca) end addEventHandler ( "onPlayerJoin", getRootElement(), banca) and when i exit the marker to trrigger an event that runs the function again ? Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 Yeah, and now when you enter the marker, it'll get that element data. Now instead of updating the table when you want to change the "bank", you update the element data of the player and when logout/quit, you get that element data and then update the MySQL. Link to comment
Crosshair Posted June 3, 2012 Author Share Posted June 3, 2012 you update the element data of the player Is there a function that does that or how do i do it? Link to comment
Castillo Posted June 3, 2012 Share Posted June 3, 2012 I meant when you want to change the "bank" value, you change the element data instead of the MySQL row. 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