Jump to content

Destroy vehicle


abu5lf

Recommended Posts

server side :

       addEvent("destroy",true) 
    addEventHandler("destroy",root, 
function( theVehicle ) 
       if destroyElement ( theVehicle ) then 
        local cx = math.random(15461,34641) 
       givePlayerMoney ( source, cx ) 
       outputChatBox ( "* destroy theVehicle   ".. cx .."", source, 255, 0, 0 )         
       else 
        
       outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 )  
       end 
end 
end 
) 

client side :

GUIEditor_Window = {} 
GUIEditor_Button = {} 
  
GUIEditor_Window[1] = guiCreateWindow(417,300,467,219,"destroy",false) 
GUIEditor_Button[1] = guiCreateButton(37,119,148,54,"destroy",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(268,117,148,54,"x",false,GUIEditor_Window[1]) 
  
  
guiSetVisible(GUIEditor_Window[1], false) 
  
function hide(button, state, absoluteX, absoluteY) 
    if ( source == GUIEditor_Button[2] ) then 
    guiSetVisible(GUIEditor_Window[1], false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    end 
end 
addEventHandler ("onClientGUIClick", getRootElement(),hide) 
  
addEventHandler ("onClientGUIClick", getRootElement(), 
function(button, state, absoluteX, absoluteY) 
    if ( source ==  GUIEditor_Button[1] ) then  
    triggerServerEvent("destroy",getLocalPlayer())   
    end  
end 
)  

It's not working to destroy the vehicle .

Edited by Guest
Link to comment
GUIEditor_Window = {} 
GUIEditor_Button = {} 
  
GUIEditor_Window[1] = guiCreateWindow(417, 300, 467, 219, "destroy", false) 
GUIEditor_Button[1] = guiCreateButton(37, 119, 148, 54, "destroy", false, GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(268, 117, 148, 54, "x", false, GUIEditor_Window[1]) 
  
guiSetVisible(GUIEditor_Window[1], false) 
  
addEventHandler("onClientGUIClick", root, 
    function(button, state, absoluteX, absoluteY) 
        if (source == GUIEditor_Button[2]) then 
            guiSetVisible(GUIEditor_Window[1], false) 
            showCursor(false) 
            guiSetInputEnabled(false) 
        end 
    end, 
    false 
) 
  
addEventHandler("onClientGUIClick", root, 
    function(button, state, absoluteX, absoluteY) 
        if (source ==  GUIEditor_Button[1]) then 
            triggerServerEvent("destroy", localPlayer)   
        end 
    end, 
    false 
) 

addEvent("destroy",true) 
addEventHandler("destroy", root, 
    function() 
        local vehicle = getPedOccupiedVehicle(source) 
        if vehicle and destroyElement(vehicle) then 
            local cash = math.random(15461, 34641) 
            givePlayerMoney(source, cash) 
            outputChatBox("* Destroyed your vehicle for $" .. cash, source, 255, 0, 0)        
        else 
            outputChatBox("* Enter a vehicle first.", source, 255, 0, 0) 
        end 
    end 
) 

Edited by Guest
Link to comment

EDIT: sorry didn't sow your post myonlake.

Sever

  
addEvent("destroy",true) 
addEventHandler("destroy",root, 
function( theVehicle ) 
    if ( isElement(theVehicle) ) then 
        destroyElement ( theVehicle ) 
        local cx = math.random(15461,34641) 
        givePlayerMoney ( source, tonumber(cx) ) 
        outputChatBox ( "* destroy theVehicle   ".. tonumber(cx) .."", source, 255, 0, 0 )        
    else 
        outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 ) 
    end 
end ) 
  
 

Client

  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
  
GUIEditor_Window[1] = guiCreateWindow(417,300,467,219,"destroy",false) 
GUIEditor_Button[1] = guiCreateButton(37,119,148,54,"destroy",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(268,117,148,54,"x",false,GUIEditor_Window[1]) 
  
  
guiSetVisible(GUIEditor_Window[1], false) 
  
function hide(button, state, absoluteX, absoluteY) 
    if ( source == GUIEditor_Button[2] ) then 
    guiSetVisible(GUIEditor_Window[1], false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    end 
end 
addEventHandler ("onClientGUIClick", getRootElement(),hide) 
  
addEventHandler ("onClientGUIClick", getRootElement(), 
function(button, state, absoluteX, absoluteY) 
    if ( source ==  GUIEditor_Button[1] ) then 
        pCar = getPedOccupiedVehicle(getLocalPlayer()) 
           triggerServerEvent("destroy",getLocalPlayer(),pCar)   
    end 
end 
) 
  
 
Link to comment

getPedOccupiedVehicle() is automaticly a vehicle element, you're making a check if the occupiedVehicle is a vehicle element, which is unnecessary, also, trigger arguments are not recommend, so that's why you are able to make occupiedVehicle server-side.

And no problem, we kind of have the same script.

Link to comment
Al3grab said:

i put 'getElementType' to make sure it's a car :lol: , and it doesn't really matter :D

Yes but getPedOccupiedVehicle() would not work if it wasn't a car, it would just output an error if he's not in a car. getPedOccupiedVehicle fetches the current VEHICLE so getElementType is unneeded ;)

Link to comment
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
  
GUIEditor_Window[1] = guiCreateWindow(417,300,467,219,"destroy",false) 
GUIEditor_Button[1] = guiCreateButton(37,119,148,54,"destroy",false,GUIEditor_Window[1]) 
GUIEditor_Button[2] = guiCreateButton(268,117,148,54,"x",false,GUIEditor_Window[1]) 
  
  
guiSetVisible(GUIEditor_Window[1], false) 
  
function hide(button, state, absoluteX, absoluteY) 
    if ( source == GUIEditor_Button[2] ) then 
    guiSetVisible(GUIEditor_Window[1], false) 
    showCursor(false) 
    guiSetInputEnabled(false) 
    end 
end 
addEventHandler ("onClientGUIClick", getRootElement(),hide) 
  
addEventHandler ("onClientGUIClick", getRootElement(), 
function(button, state, absoluteX, absoluteY) 
    if ( source ==  GUIEditor_Button[1] ) then 
        pCar = getPedOccupiedVehicle(getLocalPlayer()) 
           triggerServerEvent("destroy",getLocalPlayer(),pCar)   
    end 
end 
) 
  
function oppenz() 
        if guiGetVisible ( GUIEditor_Window[1] ) then  
                guiSetVisible ( GUIEditor_Window[1], false ) 
showCursor(false) 
  guiSetInputEnabled(false) 
        else 
                guiSetVisible ( GUIEditor_Window[1], true ) 
showCursor(true) 
  guiSetInputEnabled(true) 
 end 
end 
bindKey("F6","down",oppenz) 
  

addEvent("destroy",true) 
addEventHandler("destroy",root, 
function( theVehicle ) 
    if ( isElement(theVehicle) and getElementType(theVehicle) == "vehicle" ) then 
        destroyElement ( theVehicle ) 
        local cx = math.random(15461,34641) 
        givePlayerMoney ( source, tonumber(cx) ) 
        outputChatBox ( "* destroy theVehicle   ".. tonumber(cx) .."", source, 255, 0, 0 )        
    else 
        outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 ) 
    end 
end ) 
  
  
function hatmoter(source) 
         local x,y,z = getElementPosition(source) 
         theVehicle = createVehicle(500, x, y, z) 
          warpPedIntoVehicle ( source, theVehicle )    
         
end 
addCommandHandler ( "c", hatmoter ) 

It destroys vehicles freeroam

I do not want it2

Link to comment
  
addEvent("destroy",true) 
addEventHandler("destroy",root, 
function(  ) 
    if ( isElement(hatCars[source]) and getElementType(hatCars[source]) == "vehicle" ) then 
        destroyElement ( hatCars[source] ) 
        local cx = math.random(15461,34641) 
        givePlayerMoney ( source, tonumber(cx) ) 
        outputChatBox ( "* destroy theVehicle   ".. tonumber(cx) .."", source, 255, 0, 0 )       
    else 
        outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 ) 
    end 
end ) 
  
hatCars = {} 
function hatmoter(player) 
        if not hatCars[player] then 
         local x,y,z = getElementPosition(player) 
          
         hatCars[player] = createVehicle(500, x, y, z) 
          warpPedIntoVehicle ( source, hatCars[player])   
         else 
            outputChatBox("you already have  one") 
         end 
end 
addCommandHandler ( "c", hatmoter ) 
  
addEventHandler("onPlayerQuit",root,function() 
    hatCars[source] = nil 
end ) 
  

Server

Link to comment
  
addEvent("destroy",true) 
addEventHandler("destroy",root, 
function(  ) 
    if ( isElement(hatCars[source]) and getElementType(hatCars[source]) == "vehicle" ) then 
        destroyElement ( hatCars[source] ) 
        local cx = math.random(15461,34641) 
        givePlayerMoney ( source, tonumber(cx) ) 
        outputChatBox ( "* destroy theVehicle   ".. tonumber(cx) .."", source, 255, 0, 0 )       
    else 
        outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 ) 
    end 
end ) 
  
hatCars = {} 
function hatmoter(player) 
        if not hatCars[player] then 
         local x,y,z = getElementPosition(player) 
          
         hatCars[player] = createVehicle(500, x, y, z) 
          warpPedIntoVehicle ( source, hatCars[player])   
         else 
            outputChatBox("you already have  one") 
         end 
end 
addCommandHandler ( "c", hatmoter ) 
  
addEventHandler("onPlayerQuit",root,function() 
    hatCars[source] = nil 
end ) 
  

Server

I'm sorry that it is working Thank you

Link to comment
  
addEvent("destroy",true) 
addEventHandler("destroy",root, 
function(  ) 
    if ( isElement(hatCars[source]) and getElementType(hatCars[source]) == "vehicle" ) then 
        destroyElement ( hatCars[source] ) 
        local cx = math.random(15461,34641) 
        givePlayerMoney ( source, tonumber(cx) ) 
        outputChatBox ( "* destroy theVehicle   ".. tonumber(cx) .."", source, 255, 0, 0 )       
    else 
        outputChatBox ( "* Enter theVehicle   ", source, 255, 0, 0 ) 
    end 
end ) 
  
hatCars = {} 
function hatmoter(player) 
        if not hatCars[player] then 
         local x,y,z = getElementPosition(player) 
          
         hatCars[player] = createVehicle(500, x, y, z) 
          warpPedIntoVehicle ( source, hatCars[player])   
         else 
            outputChatBox("you already have  one") 
         end 
end 
addCommandHandler ( "c", hatmoter ) 
  
addEventHandler("onPlayerQuit",root,function() 
    hatCars[source] = nil 
end ) 
  

Server

I'm sorry that it is working Thank you

Any time :)

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