MDE Scripting: Snippets

From Nomad DB
Revision as of 02:12, 16 October 2020 by Deewarz (talk | contribs) (Created page with "== Get the Player entity == <syntaxhighlight lang="lua"> local Player = game.game:GetActivePlayer() </syntaxhighlight> * MDE Scripting: G...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

    local Motorcycle = Vehicle:GetComponent("C_RuntimeMotorcycleComponent")
    if Motorcycle then
        Vehicle = Motorcycle
    end

    return Vehicle
end
local Vehicle = GetPlayerCurrentVehicle()