Difference between revisions of "MDE Scripting: Snippets"

From Nomad DB
Line 40: Line 40:
 
* [[MDE Scripting: GetOwnerSceneObject|Player:GetOwnerSceneObject]]
 
* [[MDE Scripting: GetOwnerSceneObject|Player:GetOwnerSceneObject]]
  
 +
 +
==Get the Vehicle's current Motorcycle component==
 +
{| class="wikitable"
 +
!Tip
 +
|You need to [[MDE Scripting: Snippets#Get the Player's current Vehicle entity|Get the Player's current Vehicle entity]] first.
 +
|}
 +
 +
<syntaxhighlight lang="lua">
 +
local Motorcycle = Vehicle:GetComponent("C_RuntimeMotorcycleComponent")
 +
</syntaxhighlight>
 +
 +
*[[MDE Scripting: Snippets#Get the Player's current Vehicle entity|Get the Player's current Vehicle entity]]
 +
*[[MDE Scripting: GetComponent|Vehicle:GetComponent]]
 +
*[[MDE Scripting: C_RuntimeMotorcycleComponent|C_RuntimeMotorcycleComponent]]
  
  

Revision as of 04:44, 17 October 2020

Get the Player entity

local Player = game.game:GetActivePlayer()


Get the Player's current Vehicle entity

Returns the vehicle entity the player is currently sitting in.

local function GetPlayerCurrentVehicle()
    local Player = game.game:GetActivePlayer()

    if not Player then
        return nil
    end

    local Vehicle = Player:GetOwner()

    if not Vehicle then
        Vehicle = Player:GetOwnerSceneObject()
    end

    if not Vehicle then
        return nil
    end

    return Vehicle
end
local Vehicle = GetPlayerCurrentVehicle() -- returns the vehicle scene object


Get the Vehicle's current Motorcycle component

Tip You need to Get the Player's current Vehicle entity first.
local Motorcycle = Vehicle:GetComponent("C_RuntimeMotorcycleComponent")