Jump to content

Need help - destroy vehicle


manve1

Recommended Posts

I'm making another script for MTA and i can't find and can't make that if there is already a vehicle created by that player, and when he tries to take another vehicle, first one gets destroyed.

vehicles = 
        { 
        {"BMX", 481}, 
        {"Bike", 509},  
        {"Mountain Bike", 510}, 
        {"Faggio", 462}, 
        } 
  
grid = guiCreateGridList ( 0.01, 0.2, 0.99, 0.5, true, Wnd ) 
guiGridListAddColumn( grid, "Vehicles", 0.85 ) 
  
    for i,veh in ipairs( vehicles ) do 
        row = guiGridListAddRow( grid ) 
        -- 
        guiGridListSetItemText ( grid, row, 1, tostring( veh [ 1 ] ), false, false ) 
        guiGridListSetItemData ( grid, row, 1, tostring( veh [ 2 ] ) ) 
    end 
     
    function use ( ) 
    local row, col = guiGridListGetSelectedItem ( grid )     
    if ( row and col and row ~= -1 and col ~= -1 ) then 
    local model = tonumber ( guiGridListGetItemData ( grid, row, 1 ) ) 
    local x, y, z = getElementPosition ( localPlayer ) 
    if ( isElement ( object ) ) then 
    destroyElement ( object ) 
    end 
    createVehicle( model, x + 1, y, z, 0, 0, 0 ) 
    end 
    end 
    addEventHandler ( "onClientDoubleClick", root, use, false ) 

Link to comment

-- Client Side --

vehicles = 
        { 
        {"BMX", 481}, 
        {"Bike", 509}, 
        {"Mountain Bike", 510}, 
        {":O", 462}, 
        } 
  
grid = guiCreateGridList(0.01, 0.2, 0.99, 0.5, true, Wnd) 
guiGridListAddColumn(grid, "Vehicles", 0.85) 
  
for i,veh in ipairs(vehicles) do 
     row = guiGridListAddRow(grid) 
     -- 
     guiGridListSetItemText(grid, row, 1, tostring(veh[1]), false, false) 
     guiGridListSetItemData(grid, row, 1, tostring(veh[2])) 
end 
  
function use() 
     local row, col = guiGridListGetSelectedItem(grid)    
     if (row and col and row ~= -1 and col ~= -1) then 
          local model = tonumber(guiGridListGetItemData(grid, row, 1)) 
          if model ~= "" then 
               triggerServerEvent("CreVehice", localPlayer, model) 
          end 
     end 
end 
addEventHandler("onClientDoubleClick", grid, use, false) 

-- Server Side --

local vehicles = {} 
  
function spawnVeh(id) 
    local x, y, z = getElementPosition(source) 
    if isElement(vehicles[source]) then destroyElement(vehicles[source]) end 
    vehicles[source] = createVehicle(id, x + 1, y, z) 
end 
addEvent("CreVehice",true) 
addEventHandler("CreVehice", root, spawnVeh) 
  
addEventHandler("onPlayerQuit", root, 
function() 
     if isElement(vehicles[source]) then 
          destroyElement(vehicles[source]) 
          vehicles[source] = nil 
     end 
end) 

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