Jump to content

Remove vehicles


Bonsai

Recommended Posts

Hey peeps,

I got a little problem with removing vehicles of dead players. It seems to work fine as long as the vehicles did not explode.

But if that happened, it will stay until resource is restarted.

function enterVehicle(player) 
  
    playerVehicle[player] = source 
  
end 
addEventHandler("onVehicleEnter", root, enterVehicle) 

function kill(p) 
  
if p then source = p end 
unbindKey(source, "enter", "down", "suicide") 
  
if isPedDead(source) == false then 
    killPed(source) 
    destroyElement(source) 
end 
  
if playerVehicle[source] then 
    setTimer(destroyPlayerVehicle, 5000, 1, playerVehicle[source]) 
end 
  
end 
addEventHandler("onPlayerQuit", root, kill) 
addCommandHandler("suicide", kill) 
addEvent("onRequestKillPlayer", true) 
addEventHandler("onRequestKillPlayer", root, kill) 
  
  
function destroyPlayerVehicle(vehicle) 
  
    destroyElement(vehicle) 
  
end 

This is my code and most of the time its working good.

But sometimes dead peds don't disappear either.

Is it even possible to destroy dead peds by destroyElement?

killPed only seems to kill them, but they aren't disappearing after that.

Bonsai

Link to comment
  • Moderators
function kill(p) 
      
        if p and isElement(p) and getElementType(p) == "player" then source = p end -- here was your bug. 
        unbindKey(source, "enter", "down", "suicide") 
          
        if isPedDead(source) == false then 
            killPed(source) 
            if getElementType(source) ~= "player"  then 
                destroyElement(source)-- you can't destroy players 
            end 
        end 
        local vehicle = playerVehicle[source]  
        if isElement(vehicle) then 
            setTimer(destroyPlayerVehicle, 5000, 1, vehicle) 
        end 
      
    end 
    addEventHandler("onPlayerQuit", root, kill) 
    addCommandHandler("suicide", kill) 
    addEvent("onRequestKillPlayer", true) 
    addEventHandler("onRequestKillPlayer", root, kill) 
      
      
    function destroyPlayerVehicle(vehicle) 
        if isElement(vehicle) then 
            destroyElement(vehicle) 
        end 
    end 
     
-- the big bad bug -- (BBB) 
--[[onPlayerQuit 
Serverside event 
  
This event is triggered when a player disconnects from the server. 
Parameters 
  
string quitType, string reason, element responsibleElement]] <<<<<<<<<<<<<< 

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