AddVehicleUpgrade: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(updated)
Line 16: Line 16:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- add a console command
-- add a console command
addCommandHandler ( "addupgrade", "consoleAddUpgrade" )
function consoleAddUpgrade ( thePlayer, commandName, id )
function consoleAddUpgrade ( thePlayer, commandName, id )
    if ( thePlayer ) then
         -- make sure the player is in a vehicle
         -- make sure the player is in a vehicle
         if ( isPlayerInVehicle ( thePlayer ) ) then
         if ( isPlayerInVehicle ( thePlayer ) ) then
Line 36: Line 34:
             outputConsole ( "You must be in a vehicle!", thePlayer )
             outputConsole ( "You must be in a vehicle!", thePlayer )
         end
         end
    end
end
end
addCommandHandler ( "addupgrade", consoleAddUpgrade )
</syntaxhighlight>
</syntaxhighlight>
'''Example 2:''' This client-side script gives vehicles a nitro upgrade whenever they pass through a certain collision shape:
'''Example 2:''' This client-side script gives vehicles a nitro upgrade whenever they pass through a certain collision shape:
Line 45: Line 43:


-- attach the collision shape to an 'onClientColShapeHit' event
-- attach the collision shape to an 'onClientColShapeHit' event
addEventHandler ( "onClientColShapeHit", nitroColShape, "onNitroColShapeHit" )
function onNitroColShapeHit ( hitElement, matchingDimension )
function onNitroColShapeHit ( hitElement, matchingDimension )
     if ( getElementType ( hitElement ) == "vehicle" ) then
     if ( getElementType ( hitElement ) == "vehicle" ) then
Line 53: Line 49:
     end
     end
end
end
addEventHandler ( "onClientColShapeHit", nitroColShape, onNitroColShapeHit )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 20:04, 15 July 2007

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

Example 1: This example allows the user to get an upgrade by typing a command:

-- add a console command
function consoleAddUpgrade ( thePlayer, commandName, id )
        -- make sure the player is in a vehicle
        if ( isPlayerInVehicle ( thePlayer ) ) then
            -- convert the given ID from a string to a number
            id = tonumber ( id )
            -- get the player's vehicle
            local theVehicle = getPlayerOccupiedVehicle ( 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
addCommandHandler ( "addupgrade", consoleAddUpgrade )

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