Jump to content

Get wasted player vehicle?


Martyz

Recommended Posts

Posted

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) 

Posted

Ye, I've knew this way to do it, but I thought there is some another simple function/event which I didn't notice, but big thanks for you anyways ! :)

Posted

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) 

Posted

uh, sorry, I first named the table "vehicle", but then, as its commonly used name, changed it to playerVehicle and forgot the change it on other places :(

  • Moderators
Posted

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.

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