AddVehicleUpgrade

From Multi Theft Auto: Wiki
Revision as of 05:35, 18 June 2007 by Erorr404 (talk | contribs) (→‎Example: changed example to use command handler rather than onConsole event)
Jump to navigation Jump to search

This function adds an upgrade to an existing vehicle, eg: nos, hyrdraulics. Defined in San Andreas\data\maps\veh_mods\veh_mods.ide.

Syntax

bool addVehicleUpgrade ( vehicle theVehicle, int upgrade )

Required Arguments

  • theVehicle: The element representing the vehicle you wish to add the upgrade to.
  • upgrade: The id of the upgrade you wish to add.

Returns

Returns true if the upgrade was successfully added to the vehicle, otherwise false.

Example

-- add a console command
addCommandHandler ( "addupgrade", "consoleAddUpgrade" )
function consoleAddUpgrade ( player, commandName, id )
    if ( player ) then
        if ( isPlayerInVehicle ( player ) ) then
            -- conver the ID to a number
            id = tonumber ( id )
            -- get the player's vehicle
            local vehicle = getPlayerOccupiedVehicle ( player )
            -- add the requested upgrade to the vehicle
            local success = addVehicleUpgrade ( vehicle, id )
            if ( success ) then
                -- get the name of the upgrade and display it
                outputConsole ( getVehicleUpgradeSlotName ( id ) .. " upgrade added.", player )
            else
                outputConsole ( "Failed to add upgrade.", player )
            end
        else
            outputConsole ( "You must be in a vehicle!", player )
        end
    end
end

See Also