AddVehicleUpgrade: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(updated)
(Add documentation for "all" upgrade)
 
(10 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function adds an upgrade to an existing vehicle, eg: nos, hyrdraulics. Defined in San Andreas\data\maps\veh_mods\veh_mods.ide.
{{Server client function}}
This function adds an upgrade to a [[vehicle]], e.g. nitrous, hydraulics.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool addVehicleUpgrade ( vehicle theVehicle, int upgrade )</syntaxhighlight>
<syntaxhighlight lang="lua">bool addVehicleUpgrade ( vehicle theVehicle, string/int upgrade )</syntaxhighlight>
 
{{OOP||[[vehicle]]:addUpgrade}}
===Required Arguments===
===Required Arguments===
*'''theVehicle''': The [[element]] representing the [[vehicle]] you wish to add the upgrade to.
*'''theVehicle''': The [[element]] representing the [[vehicle]] you wish to add the upgrade to.
*'''upgrade''': The id of the upgrade you wish to add.
*'''upgrade''': The id of the upgrade you wish to add: 1000 to 1193 (''see [[Vehicle Upgrades]]'') or "'''all"''' to add all upgrades.
'''Note:''' setCameraTarget will behave strangely if you use hydraulics (upgrade id: 1087) server sided and when your camera target is the player inside the vehicle with hydraulics and if the player is not you.


==Returns==
==Returns==
Line 13: Line 15:


==Example==
==Example==
'''Example 1:''' This example allows the user to get an upgrade by typing a command:
<section name="Example 1" class="server" show="true">
This serverside function allows the user to get an upgrade by typing a command:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- add a console command
-- define the handler function for our command
function consoleAddUpgrade ( thePlayer, commandName, id )
function consoleAddUpgrade ( thePlayer, commandName, id )
         -- make sure the player is in a vehicle
         -- make sure the player is in a vehicle
         if ( isPlayerInVehicle ( thePlayer ) ) then
         if ( isPedInVehicle ( thePlayer ) ) then
             -- convert the given ID from a string to a number
             -- convert the given ID from a string to a number
             id = tonumber ( id )
             local id = tonumber ( id )
             -- get the player's vehicle
             -- get the player's vehicle
             local theVehicle = getPlayerOccupiedVehicle ( thePlayer )
             local theVehicle = getPedOccupiedVehicle ( thePlayer )
             -- add the requested upgrade to the vehicle
             -- add the requested upgrade to the vehicle
             local success = addVehicleUpgrade ( theVehicle, id )
             local success = addVehicleUpgrade ( theVehicle, id )
Line 35: Line 38:
         end
         end
end
end
-- add the function as a handler for the "addupgrade" command
addCommandHandler ( "addupgrade", consoleAddUpgrade )
addCommandHandler ( "addupgrade", consoleAddUpgrade )
</syntaxhighlight>
</syntaxhighlight>
'''Example 2:''' This client-side script gives vehicles a nitro upgrade whenever they pass through a certain collision shape:
</section>
 
<section name="Example 2" class="client" show="true">
This client-side script gives vehicles a nitro upgrade whenever they pass through a certain collision shape:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- create a collision shape
-- create a collision shape
Line 51: Line 58:
addEventHandler ( "onClientColShapeHit", nitroColShape, onNitroColShapeHit )
addEventHandler ( "onClientColShapeHit", nitroColShape, onNitroColShapeHit )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Vehicle functions}}
{{Vehicle functions}}

Latest revision as of 21:24, 19 March 2021

This function adds an upgrade to a vehicle, e.g. nitrous, hydraulics.

Syntax

bool addVehicleUpgrade ( vehicle theVehicle, string/int upgrade )

OOP Syntax Help! I don't understand this!

Method: vehicle:addUpgrade(...)


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: 1000 to 1193 (see Vehicle Upgrades) or "all" to add all upgrades.

Note: setCameraTarget will behave strangely if you use hydraulics (upgrade id: 1087) server sided and when your camera target is the player inside the vehicle with hydraulics and if the player is not you.

Returns

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

Example

Click to collapse [-]
Example 1

This serverside function allows the user to get an upgrade by typing a command:

-- define the handler function for our command
function consoleAddUpgrade ( thePlayer, commandName, id )
        -- make sure the player is in a vehicle
        if ( isPedInVehicle ( thePlayer ) ) then
            -- convert the given ID from a string to a number
            local id = tonumber ( id )
            -- get the player's vehicle
            local theVehicle = getPedOccupiedVehicle ( thePlayer )
            -- add the requested upgrade to the vehicle
            local success = addVehicleUpgrade ( theVehicle, id )
            -- inform the player of whether the upgrade was added successfully
            if ( success ) then
                outputConsole ( getVehicleUpgradeSlotName ( id ) .. " upgrade added.", thePlayer )
            else
                outputConsole ( "Failed to add upgrade.", thePlayer )
            end
        else
            outputConsole ( "You must be in a vehicle!", thePlayer )
        end
end
-- add the function as a handler for the "addupgrade" command
addCommandHandler ( "addupgrade", consoleAddUpgrade )
Click to collapse [-]
Example 2

This client-side script gives vehicles a nitro upgrade whenever they pass through a certain collision shape:

-- create a collision shape
local nitroColShape = createColSphere ( 1337, 100, 12, 2 )

-- attach the collision shape to an 'onClientColShapeHit' event
function onNitroColShapeHit ( hitElement, matchingDimension )
    if ( getElementType ( hitElement ) == "vehicle" ) then
        -- add a nitro upgrade if the element that hit the colshape is a vehicle
        addVehicleUpgrade ( hitElement, 1010 )
    end
end
addEventHandler ( "onClientColShapeHit", nitroColShape, onNitroColShapeHit )

See Also