AddVehicleUpgrade: Difference between revisions
Jump to navigation
Jump to search
(→Example: added an example) |
m (→Example) |
||
Line 17: | Line 17: | ||
-- add a console command | -- add a console command | ||
addCommandHandler ( "addupgrade", "consoleAddUpgrade" ) | addCommandHandler ( "addupgrade", "consoleAddUpgrade" ) | ||
function consoleAddUpgrade ( | function consoleAddUpgrade ( thePlayer, commandName, id ) | ||
if ( | if ( thePlayer ) then | ||
-- make sure the player is in a vehicle | -- make sure the player is in a vehicle | ||
if ( isPlayerInVehicle ( | if ( isPlayerInVehicle ( 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 ) | id = tonumber ( id ) | ||
-- get the player's vehicle | -- get the player's vehicle | ||
local vehicle = getPlayerOccupiedVehicle ( | local vehicle = getPlayerOccupiedVehicle ( thePlayer ) | ||
-- add the requested upgrade to the vehicle | -- add the requested upgrade to the vehicle | ||
local success = addVehicleUpgrade ( vehicle, id ) | local success = addVehicleUpgrade ( vehicle, id ) | ||
-- inform the player of whether the upgrade was added successfully | -- inform the player of whether the upgrade was added successfully | ||
if ( success ) then | if ( success ) then | ||
outputConsole ( getVehicleUpgradeSlotName ( id ) .. " upgrade added.", | outputConsole ( getVehicleUpgradeSlotName ( id ) .. " upgrade added.", thePlayer ) | ||
else | else | ||
outputConsole ( "Failed to add upgrade.", | outputConsole ( "Failed to add upgrade.", thePlayer ) | ||
end | end | ||
else | else | ||
outputConsole ( "You must be in a vehicle!", | outputConsole ( "You must be in a vehicle!", thePlayer ) | ||
end | end | ||
end | end |
Revision as of 07:39, 18 June 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 addCommandHandler ( "addupgrade", "consoleAddUpgrade" ) function consoleAddUpgrade ( thePlayer, commandName, id ) if ( thePlayer ) then -- 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 vehicle = getPlayerOccupiedVehicle ( thePlayer ) -- add the requested upgrade to the vehicle local success = addVehicleUpgrade ( vehicle, 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 end
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 addEventHandler ( "onClientColShapeHit", nitroColShape, "onNitroColShapeHit" ) 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
See Also
- addVehicleUpgrade
- attachTrailerToVehicle
- blowVehicle
- createVehicle
- detachTrailerFromVehicle
- fixVehicle
- getOriginalHandling
- getTrainDirection
- getTrainPosition
- getTrainSpeed
- getTrainTrack
- getVehicleColor
- getVehicleCompatibleUpgrades
- getVehicleController
- getVehicleDoorOpenRatio
- getVehicleDoorState
- getVehicleEngineState
- getVehicleHandling
- getVehicleHeadLightColor
- getVehicleLandingGearDown
- getVehicleLightState
- getVehicleMaxPassengers
- getVehicleModelFromName
- getVehicleName
- getVehicleNameFromModel
- getVehicleOccupant
- getVehicleOccupants
- getVehicleOverrideLights
- getVehiclePaintjob
- getVehiclePanelState
- getVehiclePlateText
- getVehicleSirenParams
- getVehicleSirens
- getVehicleSirensOn
- getVehicleTowedByVehicle
- getVehicleTowingVehicle
- getVehicleTurretPosition
- getVehicleType
- getVehicleUpgradeOnSlot
- getVehicleUpgradeSlotName
- getVehicleUpgrades
- getVehicleVariant
- getVehicleWheelStates
- isTrainDerailable
- isTrainDerailed
- isVehicleBlown
- isVehicleDamageProof
- isVehicleFuelTankExplodable
- isVehicleLocked
- isVehicleOnGround
- isVehicleTaxiLightOn
- removeVehicleUpgrade
- setTrainDerailable
- setTrainDerailed
- setTrainDirection
- setTrainPosition
- setTrainSpeed
- setTrainTrack
- setVehicleColor
- setVehicleDamageProof
- setVehicleDoorOpenRatio
- setVehicleDoorState
- setVehicleDoorsUndamageable
- setVehicleEngineState
- setVehicleFuelTankExplodable
- setVehicleHandling
- setVehicleHeadLightColor
- setVehicleLandingGearDown
- setVehicleLightState
- setVehicleLocked
- setVehicleOverrideLights
- setVehiclePaintjob
- setVehiclePanelState
- setVehiclePlateText
- setVehicleSirens
- setVehicleSirensOn
- setVehicleTaxiLightOn
- setVehicleTurretPosition
- setVehicleVariant
- setVehicleWheelStates