OnPedVehicleExit: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server event}} {{New feature/item|3.0160|1.5.8|20740|This event is triggered when a ped leaves a vehicle.}} ==Parameters== <syntaxhighlight lang="lua"> vehicle...")
 
Line 18: Line 18:
==Example==  
==Example==  
{{Needs Example}}
{{Needs Example}}
 
<section name="Example 1" class="server" show="true">
Destroy the vehicle when ped has been jacked and kick the jacker if exists
<syntaxhighlight lang="lua">
function destroyVehicle(theVehicle, seat, jacker, forcedByScript)
  if seat==0 then -- If ped was a driver
      if forcedByScript then
        destroyElement(theVehicle) -- If the exit was forced using removePedFromVehicle then destroy the vehicle
      elseif jacker then
        kickPlayer(jacker)
        destroyElement(theVehicle)
      end
  end
end
addEventHandler("onPedVehicleExit", root, destroyVehicle)
</syntaxhighlight>
</section>
{{See also/Server event|Ped events}}
{{See also/Server event|Ped events}}

Revision as of 11:15, 29 January 2021

This event is triggered when a ped leaves a vehicle.

Parameters

vehicle theVehicle, int seat, ped jacker, bool forcedByScript
  • theVehicle: a vehicle element representing the vehicle in which the ped exited from.
  • seat: an int representing the seat in which the ped was before exiting.
  • jacker: a player or ped element representing who jacked the driver.
  • forcedByScript: a boolean representing whether the exit was forced using removePedFromVehicle or by the ped.

Source

The source of this event is the ped that left the vehicle.

Example

Accessories-text-editor.png Script Example Missing Event OnPedVehicleExit needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.
Click to collapse [-]
Example 1

Destroy the vehicle when ped has been jacked and kick the jacker if exists

function destroyVehicle(theVehicle, seat, jacker, forcedByScript)
   if seat==0 then -- If ped was a driver
      if forcedByScript then
         destroyElement(theVehicle) -- If the exit was forced using removePedFromVehicle then destroy the vehicle
      elseif jacker then
         kickPlayer(jacker)
         destroyElement(theVehicle)
      end
   end
end
addEventHandler("onPedVehicleExit", root, destroyVehicle)

See Also

Ped events


Event functions