Jump to content

Get wasted player vehicle?


Martyz

Recommended Posts

try this.

g_me = getLocalPlayer() 
  
function bolt() 
vehicles = getPedOccupiedVehicle (localPlayer) 
setElementData(localPlayer,"vehic",vehicles) 
aoi = getElementData(localPlayer,"vehic") 
outputChatBox(aoi) 
end 
setTimer(bolt,500,-1) 
  
function kill(thePlayer, vehicles) 
setElementDimension(aoi, 5) 
        triggerServerEvent('onRequestKillPlayer', g_me) 
end 
addCommandHandler('kill',kill) 
addCommandHandler('Commit suicide',kill) 
bindKey ( next(getBoundKeys"enter_exit"), "down", "Commit suicide") 

server

  
addEvent('onRequestKillPlayer', true) 
addEventHandler('onRequestKillPlayer', getRootElement(),function() 
for player, dead in ipairs(getElementsByType("player")) do 
  
            setElementHealth(dead, 0) 
            end 
end) 
  
addEventHandler('onVehicleStartExit', getRootElement(), function() cancelEvent() end) 

Link to comment

This is the worst way to do it...

Here's a nice way:

local playerVehicle = {} 
  
function enterVehicle(player) 
    vehicle[player] = source 
end 
function exitVehicle(player) 
    vehicle[player] = nil 
end 
  
function playerDied() 
    local vehicle = playerVehicle[source] 
    playerVehicle[source] = nil 
  
    setElementDimension(vehicle, 0) 
end 
  
addEventHandler("onPlayerWasted", root, playerDied) 
addEventHandler("onVehicleEnter", root, enterVehicle) 
addEventHandler("onVehicleExit", root, exitVehicle) 

Link to comment
  • Moderators

it isn't smart to set a vehicle to dimension 0, when you don't even know the vehicle still does exist. Next to that you don't clear the table when a player leaves the server, the userdata will remain there until the resource stops/restart.

Even so it was a good example how it should be done, table systems are making the code very, very, fast.

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