Jump to content

Mysql Query


Recommended Posts

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

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

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

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...