Jump to content

Set Vehicle Max Speed


nwmafia

Recommended Posts

I want a script to be able to set the max speed of a vehicle based on it model number. (example of model number for Bufallo = 402).

I want this script to be based on km/h. If you know where I can find a script like this, it would be appreciated. If not, if someone could teach me how to script this, it would be ideal as well. Thanks.

Link to comment

The code that Wiki showed me, doesn't work..

function handlingChange() 
    setModelHandling(541, "mass", 1890) 
    setModelHandling(541, "turnMass", 3780) 
    setModelHandling(541, "dragCoeff", 0.7) 
    setModelHandling(541, "centerOfMass", {0.0, 0.1, -0.2} ) 
    setModelHandling(541, "percentSubmerged", 75) 
    setModelHandling(541, "tractionMultiplier", 0.70) 
    setModelHandling(541, "tractionLoss", 0.90) 
    setModelHandling(541, "tractionBias", 0.50) 
    setModelHandling(541, "numberOfGears", 5) 
    setModelHandling(541, "maxVelocity", 407) 
    setModelHandling(541, "engineAcceleration", 50) 
    setModelHandling(541, "engineInertia", 10) 
    setModelHandling(541, "driveType", "awd") 
    setModelHandling(541, "engineType", "petrol") 
    setModelHandling(541, "brakeDeceleration", 11) 
    setModelHandling(541, "brakeBias", 0.45) 
    setModelHandling(541, "ABS", false) 
    setModelHandling(541, "steeringLock", 30) 
    setModelHandling(541, "suspensionForceLevel", 0.80) 
    setModelHandling(541, "suspensionDamping", 0.20) 
    setModelHandling(541, "suspensionHighSpeedDamping", 0.0) 
    setModelHandling(541, "suspensionUpperLimit", 0.10) 
    setModelHandling(541, "suspensionLowerLimit", -0.09) 
    setModelHandling(541, "suspensionFrontRearBias", 0.5) 
    setModelHandling(541, "suspensionAntiDiveMultiplier", 0.6) 
    setModelHandling(541, "seatOffsetDistance", 0.3) 
    setModelHandling(541, "collisionDamageMultiplier", 0.50) 
    setModelHandling(541, "monetary", 1460000) 
    setModelHandling(541, "modelFlags", 0xC0222004) 
    setModelHandling(541, "handlingFlags", 0x1400000) 
    setModelHandling(541, "headLight", 1) 
    setModelHandling(541, "tailLight", 1) 
    setModelHandling(541, "animGroup", 0) 
end 
addEventHandler("onResourceStart", resourceRoot, handlingChange) 

Link to comment
function handlingChange( ) 
    local theVehicle = getPedOccupiedVehicle( source ) 
    if theVehicle then 
        if carModel == getElementModel( theVehicle ) and carModel == 541 then 
            setModelHandling( carModel, "mass", 1890 ) 
            setModelHandling( carModel, "turnMass", 3780 ) 
            setModelHandling( carModel, "dragCoeff", 0.7 ) 
            setModelHandling( carModel, "centerOfMass", {0.0, 0.1, -0.2} ) 
            setModelHandling( carModel, "percentSubmerged", 75 ) 
            setModelHandling( carModel, "tractionMultiplier", 0.70 ) 
            setModelHandling( carModel, "tractionLoss", 0.90 ) 
            setModelHandling( carModel, "tractionBias", 0.50 ) 
            setModelHandling( carModel, "numberOfGears", 5 ) 
            setModelHandling( carModel, "maxVelocity", 407 ) 
            setModelHandling( carModel, "engineAcceleration", 50 ) 
            setModelHandling( carModel, "engineInertia", 10 ) 
            setModelHandling( carModel, "driveType", "awd" ) 
            setModelHandling( carModel, "engineType", "petrol" ) 
            setModelHandling( carModel, "brakeDeceleration", 11 ) 
            setModelHandling( carModel, "brakeBias", 0.45 ) 
            setModelHandling( carModel, "ABS", false ) 
            setModelHandling( carModel, "steeringLock", 30 ) 
            setModelHandling( carModel, "suspensionForceLevel", 0.80 ) 
            setModelHandling( carModel, "suspensionDamping", 0.20 ) 
            setModelHandling( carModel, "suspensionHighSpeedDamping", 0.0 ) 
            setModelHandling( carModel, "suspensionUpperLimit", 0.10 ) 
            setModelHandling( carModel, "suspensionLowerLimit", -0.09 ) 
            setModelHandling( carModel, "suspensionFrontRearBias", 0.5 ) 
            setModelHandling( carModel, "suspensionAntiDiveMultiplier", 0.6 ) 
            setModelHandling( carModel, "seatOffsetDistance", 0.3 ) 
            setModelHandling( carModel, "collisionDamageMultiplier", 0.50 ) 
            setModelHandling( carModel, "monetary", 1460000 ) 
            setModelHandling( carModel, "modelFlags", 0xC0222004 ) 
            setModelHandling( carModel, "handlingFlags", 0x1400000 ) 
            setModelHandling( carModel, "headLight", 1 ) 
            setModelHandling( carModel, "tailLight", 1 ) 
            setModelHandling( carModel, "animGroup", 0 ) 
        end 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, handlingChange) 

* Edit

Edited by Guest
Link to comment
function handlingChange( ) 
    local theVehicle = getPedOccupiedVehicle( source ) 
    if theVehicle then 
        if carModel == getElementModel( theVehicle ) and carModel == 541 then 
            setModelHandling( carModel, "mass", 1890 ) 
            setModelHandling( carModel, "turnMass", 3780 ) 
            setModelHandling( carModel, "dragCoeff", 0.7 ) 
            setModelHandling( carModel, "centerOfMass", {0.0, 0.1, -0.2} ) 
            setModelHandling( carModel, "percentSubmerged", 75 ) 
            setModelHandling( carModel, "tractionMultiplier", 0.70 ) 
            setModelHandling( carModel, "tractionLoss", 0.90 ) 
            setModelHandling( carModel, "tractionBias", 0.50 ) 
            setModelHandling( carModel, "numberOfGears", 5 ) 
            setModelHandling( carModel, "maxVelocity", 407 ) 
            setModelHandling( carModel, "engineAcceleration", 50 ) 
            setModelHandling( carModel, "engineInertia", 10 ) 
            setModelHandling( carModel, "driveType", "awd" ) 
            setModelHandling( carModel, "engineType", "petrol" ) 
            setModelHandling( carModel, "brakeDeceleration", 11 ) 
            setModelHandling( carModel, "brakeBias", 0.45 ) 
            setModelHandling( carModel, "ABS", false ) 
            setModelHandling( carModel, "steeringLock", 30 ) 
            setModelHandling( carModel, "suspensionForceLevel", 0.80 ) 
            setModelHandling( carModel, "suspensionDamping", 0.20 ) 
            setModelHandling( carModel, "suspensionHighSpeedDamping", 0.0 ) 
            setModelHandling( carModel, "suspensionUpperLimit", 0.10 ) 
            setModelHandling( carModel, "suspensionLowerLimit", -0.09 ) 
            setModelHandling( carModel, "suspensionFrontRearBias", 0.5 ) 
            setModelHandling( carModel, "suspensionAntiDiveMultiplier", 0.6 ) 
            setModelHandling( carModel, "seatOffsetDistance", 0.3 ) 
            setModelHandling( carModel, "collisionDamageMultiplier", 0.50 ) 
            setModelHandling( carModel, "monetary", 1460000 ) 
            setModelHandling( carModel, "modelFlags", 0xC0222004 ) 
            setModelHandling( carModel, "handlingFlags", 0x1400000 ) 
            setModelHandling( carModel, "headLight", 1 ) 
            setModelHandling( carModel, "tailLight", 1 ) 
            setModelHandling( carModel, "animGroup", 0 ) 
        end 
    end 
end 
addEventHandler("onResourceStart", resourceRoot, handlingChange) 

* Edit

It still won't work because there's no source neither there is a "carModel" variable.

Link to comment
local myVehicles = { 541 , 507 } 
  
addEventHandler("onResourceStart", resourceRoot, 
    function( ) 
        for index, value in ipairs( myVehicles ) do 
            setModelHandling( value, "mass", 1890 ) 
            setModelHandling( value, "turnMass", 3780 ) 
            setModelHandling( value, "dragCoeff", 0.7 ) 
            setModelHandling( value, "centerOfMass", {0.0, 0.1, -0.2} ) 
            setModelHandling( value, "percentSubmerged", 75 ) 
            setModelHandling( value, "tractionMultiplier", 0.70 ) 
            setModelHandling( value, "tractionLoss", 0.90 ) 
            setModelHandling( value, "tractionBias", 0.50 ) 
            setModelHandling( value, "numberOfGears", 5 ) 
            setModelHandling( value, "maxVelocity", 407 ) 
            setModelHandling( value, "engineAcceleration", 50 ) 
            setModelHandling( value, "engineInertia", 10 ) 
            setModelHandling( value, "driveType", "awd" ) 
            setModelHandling( value, "engineType", "petrol" ) 
            setModelHandling( value, "brakeDeceleration", 11 ) 
            setModelHandling( value, "brakeBias", 0.45 ) 
            setModelHandling( value, "ABS", false ) 
            setModelHandling( value, "steeringLock", 30 ) 
            setModelHandling( value, "suspensionForceLevel", 0.80 ) 
            setModelHandling( value, "suspensionDamping", 0.20 ) 
            setModelHandling( value, "suspensionHighSpeedDamping", 0.0 ) 
            setModelHandling( value, "suspensionUpperLimit", 0.10 ) 
            setModelHandling( value, "suspensionLowerLimit", -0.09 ) 
            setModelHandling( value, "suspensionFrontRearBias", 0.5 ) 
            setModelHandling( value, "suspensionAntiDiveMultiplier", 0.6 ) 
            setModelHandling( value, "seatOffsetDistance", 0.3 ) 
            setModelHandling( value, "collisionDamageMultiplier", 0.50 ) 
            setModelHandling( value, "monetary", 1460000 ) 
            setModelHandling( value, "modelFlags", 0xC0222004 ) 
            setModelHandling( value, "handlingFlags", 0x1400000 ) 
            setModelHandling( value, "headLight", 1 ) 
            setModelHandling( value, "tailLight", 1 ) 
            setModelHandling( value, "animGroup", 0 ) 
        end 
    end 
) 

Link to comment

To be honest, I don't know why the model handling switch didn't work... probably it did and nwmafia is blind or then MTA is bugged and should be reported in the Bug Tracker. I think you should try using setVehicleHandling instead for now, that works perfectly at least.

Link to comment

The code work if you create the vehicle after using the code NOT before.

This means, if you use the code and set the maxVelocity to 100, any new created vehicle will have maxVelocity = 100 if you again set maxVelocity to 200 any new created vehicle will have maxVelocity = 200 but the previous vehicle will stay at maxVelocity = 100.

So this code does't change the current created vehicle but the newer.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...