Jump to content

Speed limit


isa_Khamdan

Recommended Posts

you can use
  
-- to store 
setElementData(theVehicle, "maxVelocity", theValue); 
-- to obtain 
getElementData(theVehicle, "maxVelocity"); 
  

This will not affect the vehicle itself. You still need to use setVehicleHandling, since there is getVehicleHandling there is no need to store element data.

They will still be able to change the speed because I have in-game handling editor so is there another way to add limit for max speed?

like if get element speed ( Vehcile < 75 ) then set element speed to 75?

Link to comment

exmple:

local x,y,z = 0, 0, 0 
local colcircler = createColCircle ( x,y,z,50 ) 
local before 
  
function hit(hitElement, matchingDimension) 
    if (getElementType ( hitElement ) == "vehicle") then 
        local oldmaxVelocity = getVehicleHandlingProperty ( hitElement,  "maxVelocity" ) 
        setElementData(theVehicle, "maxVelocity", oldmaxVelocity) 
        setVehicleHandling ( hitElement, "maxVelocity",  value ) 
    end 
end 
addEventHandler("onColShapeHit", colcircler, hit) 
  
function leave(leaveElement, matchingDimension) 
    if (getElementType ( leaveElement ) == "vehicle") then 
        local oldmaxVelocity = getElementData(theVehicle, "maxVelocity"); 
        if (oldmaxVelocity) then 
            setVehicleHandling ( leaveElement, "maxVelocity",  oldmaxVelocity ) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", colcircler, leave) 
  
function getVehicleHandlingProperty ( element, property ) 
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string 
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable 
        local value = handlingTable[property] -- Get the value from the table 
        if value then -- If there's a value (valid property) 
            return value -- Return it 
        end 
    end 
    return false -- Not an element, not a vehicle or no valid property string. Return failure 
end 

Link to comment
exmple:
local x,y,z = 0, 0, 0 
local colcircler = createColCircle ( x,y,z,50 ) 
local before 
  
function hit(hitElement, matchingDimension) 
    if (getElementType ( hitElement ) == "vehicle") then 
        local oldmaxVelocity = getVehicleHandlingProperty ( hitElement,  "maxVelocity" ) 
        setElementData(theVehicle, "maxVelocity", oldmaxVelocity) 
        setVehicleHandling ( hitElement, "maxVelocity",  value ) 
    end 
end 
addEventHandler("onColShapeHit", colcircler, hit) 
  
function leave(leaveElement, matchingDimension) 
    if (getElementType ( leaveElement ) == "vehicle") then 
        local oldmaxVelocity = getElementData(theVehicle, "maxVelocity"); 
        if (oldmaxVelocity) then 
            setVehicleHandling ( leaveElement, "maxVelocity",  oldmaxVelocity ) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", colcircler, leave) 
  
function getVehicleHandlingProperty ( element, property ) 
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string 
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable 
        local value = handlingTable[property] -- Get the value from the table 
        if value then -- If there's a value (valid property) 
            return value -- Return it 
        end 
    end 
    return false -- Not an element, not a vehicle or no valid property string. Return failure 
end 

People still can change the max speed from the in game handling editor

I want to force the element to slow when the speed get more than 75

Link to comment
exmple:
local x,y,z = 0, 0, 0 
local colcircler = createColCircle ( x,y,z,50 ) 
local before 
  
function hit(hitElement, matchingDimension) 
    if (getElementType ( hitElement ) == "vehicle") then 
        local oldmaxVelocity = getVehicleHandlingProperty ( hitElement,  "maxVelocity" ) 
        setElementData(theVehicle, "maxVelocity", oldmaxVelocity) 
        setVehicleHandling ( hitElement, "maxVelocity",  value ) 
    end 
end 
addEventHandler("onColShapeHit", colcircler, hit) 
  
function leave(leaveElement, matchingDimension) 
    if (getElementType ( leaveElement ) == "vehicle") then 
        local oldmaxVelocity = getElementData(theVehicle, "maxVelocity"); 
        if (oldmaxVelocity) then 
            setVehicleHandling ( leaveElement, "maxVelocity",  oldmaxVelocity ) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", colcircler, leave) 
  
function getVehicleHandlingProperty ( element, property ) 
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string 
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable 
        local value = handlingTable[property] -- Get the value from the table 
        if value then -- If there's a value (valid property) 
            return value -- Return it 
        end 
    end 
    return false -- Not an element, not a vehicle or no valid property string. Return failure 
end 

Where can I set the max speed in your code? :S

Link to comment

That's because WASSim made a mistake.

local x,y,z = 0, 0, 0 
local colcircler = createColCircle ( x,y,z,50 ) 
local before 
  
function hit(hitElement, matchingDimension) 
    if (getElementType ( hitElement ) == "vehicle") then 
        local oldmaxVelocity = getVehicleHandlingProperty ( hitElement,  "maxVelocity" ) 
        setElementData(hitElement, "maxVelocity", oldmaxVelocity) 
        setVehicleHandling ( hitElement, "maxVelocity",  value ) 
    end 
end 
addEventHandler("onColShapeHit", colcircler, hit) 
  
function leave(leaveElement, matchingDimension) 
    if (getElementType ( leaveElement ) == "vehicle") then 
        local oldmaxVelocity = getElementData(leaveElement, "maxVelocity"); 
        if (oldmaxVelocity) then 
            setVehicleHandling ( leaveElement, "maxVelocity",  oldmaxVelocity ) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", colcircler, leave) 
  
function getVehicleHandlingProperty ( element, property ) 
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string 
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable 
        local value = handlingTable[property] -- Get the value from the table 
        if value then -- If there's a value (valid property) 
            return value -- Return it 
        end 
    end 
    return false -- Not an element, not a vehicle or no valid property string. Return failure 
end 

Link to comment
That's because WASSim made a mistake.
local x,y,z = 0, 0, 0 
local colcircler = createColCircle ( x,y,z,50 ) 
local before 
  
function hit(hitElement, matchingDimension) 
    if (getElementType ( hitElement ) == "vehicle") then 
        local oldmaxVelocity = getVehicleHandlingProperty ( hitElement,  "maxVelocity" ) 
        setElementData(hitElement, "maxVelocity", oldmaxVelocity) 
        setVehicleHandling ( hitElement, "maxVelocity",  value ) 
    end 
end 
addEventHandler("onColShapeHit", colcircler, hit) 
  
function leave(leaveElement, matchingDimension) 
    if (getElementType ( leaveElement ) == "vehicle") then 
        local oldmaxVelocity = getElementData(leaveElement, "maxVelocity"); 
        if (oldmaxVelocity) then 
            setVehicleHandling ( leaveElement, "maxVelocity",  oldmaxVelocity ) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", colcircler, leave) 
  
function getVehicleHandlingProperty ( element, property ) 
    if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there's a valid vehicle and a property string 
        local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable 
        local value = handlingTable[property] -- Get the value from the table 
        if value then -- If there's a value (valid property) 
            return value -- Return it 
        end 
    end 
    return false -- Not an element, not a vehicle or no valid property string. Return failure 
end 

Thanks a lot Castillo , Can you please view my other theard " Little help needed " ?

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...