GetVehicleUpgrades: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 6: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table getVehicleUpgrades ( vehicle theVehicle )
table getVehicleUpgrades ( vehicle theVehicle )
</syntaxhighlight>  
</syntaxhighlight>
 
{{OOP||[[vehicle]]:getUpgrades|upgrades}}
===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The [[vehicle]] you wish to retrieve the upgrades of.
*'''theVehicle:''' The [[vehicle]] you wish to retrieve the upgrades of.
Line 20: Line 20:
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked )
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked )
     local upgrades = getVehicleUpgrades ( theVehicle )
     local upgrades = getVehicleUpgrades ( theVehicle )
     for upgradeKey, upgradeValue in ipairs ( upgrades ) do
     for _, upgrade in ipairs ( upgrades ) do
         outputChatBox ( getVehicleUpgradeSlotName ( upgradeKey - 1 ) .. ": " .. upgradeValue )
         outputChatBox ( getVehicleUpgradeSlotName ( upgrade ) .. ": " .. upgrade )
     end
     end
end
end
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle )
addEventHandler ( "onPlayerVehicleEnter", root, scriptOnPlayerEnterVehicle )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 08:40, 4 November 2020

This function returns a table of all the upgrades on a specifed vehicle.

Syntax

table getVehicleUpgrades ( vehicle theVehicle )

OOP Syntax Help! I don't understand this!

Method: vehicle:getUpgrades(...)
Variable: .upgrades


Required Arguments

  • theVehicle: The vehicle you wish to retrieve the upgrades of.

Returns

Returns a table of all the upgrades on each slot of a vehicle, which may be empty, or false if a valid vehicle is not passed.

Example

Click to collapse [-]
Server

This example prints the name and upgrades on each slot of an entered vehicle to the chat.

function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked )
    local upgrades = getVehicleUpgrades ( theVehicle )
    for _, upgrade in ipairs ( upgrades ) do
        outputChatBox ( getVehicleUpgradeSlotName ( upgrade ) .. ": " .. upgrade )
    end
end
addEventHandler ( "onPlayerVehicleEnter", root, scriptOnPlayerEnterVehicle )

See Also