Jump to content

Unique ID


Recommended Posts

Hello.

I have a question about vehicle id`s. I want to add all the vehicles in sql(add and delete in game). Adding is easy, but let`s say i want to delete a vehicle. How do i do that ? Using set/getElementData should do it, but there will be dozens of vehicles in the database. Anyone has some idea ?

Link to comment
  • 1 month later...
Hello.

I have a question about vehicle id`s. I want to add all the vehicles in sql(add and delete in game). Adding is easy, but let`s say i want to delete a vehicle. How do i do that ? Using set/getElementData should do it, but there will be dozens of vehicles in the database. Anyone has some idea ?

Are you using any specific script, (Vg etc), does the cars id come up, and yes setElementData

Link to comment

If you wish to permanently delete it from the database you will have to execute an SQL query to the database for the removal of the row which holds the vehicle's data.

Something like this, if you're using the vG/Vedic script.

  
local mysql = exports.sql 
  
function deleteVehicle( thePlayer, commandName, vehicleID ) 
    if ( vehicleID ) then 
         
        local vehicleID = tonumber( vehicleID ) 
        local didFind = false 
         
        for key, theVehicle in ipairs ( getElementsByType("vehicle") ) do 
            if ( tonumber( getElementData( theVehicle, "id" ) ) == vehicleID ) then 
                 
                destroyElement( theVehicle ) 
                didFind = true 
                break 
            end 
        end 
         
        if ( didFind ) then 
             
            local delete = mysql:query_free("DELETE FROM `vehicles` WHERE `id`=".. mysql:escape_string( tostring( vehicleID ) ) .."") 
            if ( delete ) then 
                 
                outputChatBox("The vehicle was successfully deleted!", thePlayer, 0, 255, 0) 
            else 
                outputChatBox("MySQL Error!", thePlayer, 255, 0, 0) 
            end 
        else 
            outputChatBox("Couldn't find vehicle with ID ".. vehicleID, thePlayer, 255, 0, 0) 
        end  
    else 
        outputChatBox("SYNTAX: /".. commandName .." [ Vehicle ID ]", thePlayer, 255, 194, 14) 
    end  
end 
addCommandHandler("delveh", deleteVehicle, false, false ) 

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