Jump to content

Lloyd Logan

Members
  • Posts

    642
  • Joined

  • Last visited

Posts posted by Lloyd Logan

  1. Why you do update the serial if it already the same in the database?

    You should only insert it if it doesn't exists.

    function getSerial() 
        local serialz = getPlayerSerial(source) 
        local database = dbPoll(dbQuery(server, "SELECT serial FROM accounts WHERE serial = ?", serialz), -1) 
        if database and type(database) == "table" and #database == 0 then 
            dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", serialz) 
        end 
    end 
    addEventHandler("onPlayerJoin", root, getSerial) 
    

    There also another way, but i am not sure if it right or not, you can try it.

    The first on works! Thank you!

    function getSerial() 
        local serialz = getPlayerSerial(source) 
        dbExec(server, "INSERT INTO accounts (serial) VALUES (serialz) WHERE NOT EXISTS (SELECT serial FROM accounts WHERE serial = '"..serialz.."'") 
    end 
    addEventHandler("onPlayerJoin", root, getSerial) 
    

  2. dbPoll is required to get the result of dbQuery.

    So;

    function getSerial() 
        local serialz = getPlayerSerial(source) 
        local queryResult = dbQuery ( server, "SELECT serial FROM accounts WHERE serial = ?", serialz ) 
        local database = dbPoll(queryResult, -1) 
        if #database > 0 then 
        dbExec ( server, "UPDATE accounts SET serial = ? WHERE serial = ?", serial, tostring (serialz)) 
        else 
        dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) 
        end 
    end 
    addEventHandler("onPlayerJoin", getRootElement(), getSerial) 
    

  3. Try This:
    local data = dbQuery ( server, "SELECT serial FROM accounts WHERE serial = ?", serial ) 
    if #data > 0 then 
        dbExec ( server, "UPDATE accounts SET serial = ? WHERE serial = ?", serial, tostring (serialz)) 
    else 
        dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) 
    end 
    

    It gives me the error; attempt to get length of local 'data' a userdata value

  4. function spawnVeh() 
        local serialz = getPlayerSerial(source) 
        carid = dbQuery(server, "SELECT carid FROM accounts WHERE serial = ?", serialz) 
        local cx = dbQuery(server, "SELECT cx FROM accounts WHERE serial = ?", serialz) 
        local cy = dbQuery(server, "SELECT cy FROM accounts WHERE serial = ?", serialz) 
        local cz = dbQuery(server, "SELECT cz FROM accounts WHERE serial = ?", serialz) 
        veh = createVehicle(carid, cx, cy, cz)   
    end 
    addEventHandler("onPlayerJoin", getRootElement(), spawnVeh) 
    

    Expected number for the createvehicle, but the returned should be a number from the table.

  5. Why does this keep INSERTING even if there is already the same serial in the table?

    local data = dbPoll(dbQuery(server, "SELECT serial FROM accounts WHERE serial = ?", serial), -1) 
        if data and type (data) == "table" and #data > 0 then 
        dbExec (server, "UPDATE accounts SET serial = ?, WHERE serial = '"..serial.."'", tostring (serialz)) 
        else 
        dbExec (server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) 
        end 
    

  6. local data = dbPoll(dbQuery(server, "SELECT money FROM accounts WHERE serial = ?", serial), -1) 
            if data and type (data) == "table" and #data > 0 then 
            dbExec (server, "UPDATE accounts SET x = ?, y = ?, z = ?, cx = ?, cy = ?, cz = ?, carid = ? WHERE serial = '"..serial.."'", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname),) 
            else 
            dbExec (server, "INSERT INTO accounts VALUES (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname)) 
        end 
    

    It now gives me the error of unexpected symbol near ) at line 15

  7. Thank you, also those websites you refer me to, I don't fully understand it;

    In MTA It would equal to = dbExec(server, "INSERT INTO accounts blah)

    Whereas

    On that website it says = UPDATE table_name

    SET column1=value1,column2=value2,...

    WHERE some_column=some_value;

    It's different, how do I apply the website syntax into the MTA one.

  8. Why doesn't this INSERT a new value?

    if data and type (data) == "table" and #data > 0 then 
            dbExec (server, "UPDATE accounts SET (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname) "WHERE serial ='"..serial.."'") 
            else 
            dbQuery (server, "INSERT INTO accounts VALUES (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname)) 
         
    

  9. That doesn't make any sense, why do you even use "WHERE" in a insert query?
    serial = getPlayerSerial(source) 
    x, y, z = getElementPosition(newveh) 
    a, b, c = getElementPosition(source) 
    dbExec ( server, "INSERT INTO accounts (serial, x, y, z, cx, cy, cz) VALUES (?, ?, ?, ?, ?, ?, ?)", serial, tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z) ) 
    

    Infact, what the hell am I thinking, disregard this!

  10. Why doesn't this work, it tells me I am returning a string value?

    serial = getPlayerSerial(source) 
        x, y, z = getElementPosition(newveh) 
        a, b, c = getElementPosition(source) 
        dbQuery ( server, "INSERT INTO accounts (x, y, z, cx, cy, cz) VALUES (?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z)" WHERE serial = '".. serial .."'")--THIS BIT HERE!  
    

  11. function renderMyText ( ) 
        dxDrawText ( arguments ) 
    end 
      
    addCommandHandler ( "render", 
        function ( ) 
            addEventHandler ( "onClientRender", root, renderMyText ) -- Begin rendering our text  
        end 
    ) 
      
    addCommandHandler ( "stoprender", 
        function ( ) 
            removeEventHandler ( "onClientRender", root, renderMyText ) -- Stop rendering our text  
        end 
    ) 
    

    That's an example.

    Thank you! All is working.

  12. Why does this instantly delete the text?

    function drawText() 
            dxDrawText("You have successfully bought a vehicle!", 92, 158, 720, 195, tocolor(65, 205, 4, 255), 1.40, "pricedown", "left", "top", false, false, true, false, false) 
            setTimer ( function() 
            triggerEvent("destroy") 
        end, 5000, 1 ) 
        end 
    addEvent("drawSuccess", true) 
    addEventHandler("drawSuccess", root, drawText) 
      
      
    function destroyText() 
        removeEventHandler("drawSuccess", getRootElement(), drawText) 
    end 
    addEvent("destroy", true) 
    addEventHandler("destroy", root, destroyText) 
    

  13. Why is nothing happening with this script?

      
    function buyVeh() 
        local money = getPlayerMoney(source) 
        if (money < 10000) then 
            ("You do not have enough money to purchase this car", 255, 0, 0) 
            else 
            newveh = createVehicle(589, 558.748046875, -1265.380859375, 17.2421875 ) 
            warpPedIntoVehicle(source, newveh) 
            takePlayerMoney (source, 10000) 
            outputChatBox("You have successfully bought a club!", 0, 255, 0) 
        end 
    end 
    addCommandHandler("buyvehclub", getRootElement(), buyVeh) 
    

×
×
  • Create New...