Jump to content

[HELP] Vehicle system [MYSQL]


Recommended Posts

Hi!

I'm still learning mysql , and i started writing a vehicle system script. I stuck...

I want to get  that, is any vehicle already on that slot. How can i get that? I tried like 20 way, but just failed.

 

I want something like this:

I want to get is the player have vehicle on their Slot 1..

If yes, returning false.
    

    local result = (mysql:singleQuery("SELECT Slot=1 FROM vehicles WHERE VehicleOwnerAccountID=?", getElementData(source, "Player:AccountID")))
        if tonumber(result) == 0 then
           

            local inserVehicle = mysql:execute("INSERT INTO vehicles (VehicleOwnerAccountID, Slot , VehicleID, Color, Plate, Spawned) VALUES (?, ?, ?, ?, ?, ?)", getElementData(source, "Player:AccountID"), 1, 411, 0, 0, 0)
            outputChatBox("ID:"..inserVehicle.VehicleDBID)
            mysql:singleQuery("UPDATE `accounts` SET `VehiclePerPlayerCount`=? WHERE `AccountID`=?", SlotQuery.VehiclePerPlayerCount + 1, getElementData(source, "Player:AccountID")) 
            
            
                    outputChatBox("Vehicle successfully inserted.", source)
        else
            outputChatBox("slot.")        
    outputChatBox(tostring(result))
        end
    
    
    

 

 

Edited by TheMOG
Link to comment
local result = mysql:singleQuery("SELECT COUNT(*) as cnt FROM vehicles WHERE VehicleOwnerAccountID=? AND Slot=1", getElementData(source, "Player:AccountID"))
local count = result.cnt or result[1].cnt -- depending on whether singleQuery returns a list of rows or the first row, but this code should work for both situations (?)
if count >= 1 then
  -- slot occupied
else
  -- slot free
end

 

Edited by MrTasty
  • Thanks 1
Link to comment
5 hours ago, MrTasty said:

local result = mysql:singleQuery("SELECT COUNT(*) as cnt FROM vehicles WHERE VehicleOwnerAccountID=? AND Slot=1", getElementData(source, "Player:AccountID"))
local count = result.cnt or result[1].cnt -- depending on whether singleQuery returns a list of rows or the first row, but this code should work for both situations (?)
if count >= 1 then
  -- slot occupied
else
  -- slot free
end

 

Thank you.

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