Difference between revisions of "MDE Scripting: Snippets"

From Nomad DB
(Created page with "== Get the Player entity == <syntaxhighlight lang="lua"> local Player = game.game:GetActivePlayer() </syntaxhighlight> * MDE Scripting: G...")
 
Line 26: Line 26:
 
     if not Vehicle then
 
     if not Vehicle then
 
         return nil
 
         return nil
    end
 
 
    local Motorcycle = Vehicle:GetComponent("C_RuntimeMotorcycleComponent")
 
    if Motorcycle then
 
        Vehicle = Motorcycle
 
 
     end
 
     end
  
Line 38: Line 33:
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local Vehicle = GetPlayerCurrentVehicle()
+
local Vehicle = GetPlayerCurrentVehicle() -- return the vehicle scene object
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 44: Line 39:
 
* [[MDE Scripting: GetOwner|Player:GetOwner]]
 
* [[MDE Scripting: GetOwner|Player:GetOwner]]
 
* [[MDE Scripting: GetOwnerSceneObject|Player:GetOwnerSceneObject]]
 
* [[MDE Scripting: GetOwnerSceneObject|Player:GetOwnerSceneObject]]
* [[MDE Scripting: GetComponent|Vehicle:GetComponent]]
 
* [[MDE Scripting: C_RuntimeMotorcycleComponent|C_RuntimeMotorcycleComponent]]
 
  
  

Revision as of 03:50, 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() -- return the vehicle scene object