Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. Gameplay
      2. Missions
      3. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Arena War
      2. After Hours
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA Next

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
hybaby9

Script Limit speed not work

Recommended Posts

hybaby9
Posted (edited)

This is my code use to limit current vehicle speed but it does not work.
when I press "Get speed" in menu, the speed set to _listOfSpeed [listIndex] but still increase

void chooseSpeedLimited()
    {
        UIMenu submenu = modMenuPool.AddSubMenu(mainMenu, "Choose Speed Limit");
        List<dynamic> _listOfSpeed = new List<dynamic>();
        dynamic[] speed = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250 };
        _listOfSpeed.AddRange(speed);
        UIMenuListItem _list = new UIMenuListItem("Speed: ", _listOfSpeed, 0);
        submenu.AddItem(_list);
        UIMenuItem getSpeed = new UIMenuItem("Get Speed");
        submenu.AddItem(getSpeed);
       Vehicle vehicle = Game.Player.Character.CurrentVehicle;
        submenu.OnItemSelect += (sender, item, index) =>
        {
            if(item==getSpeed)
            {
                
                int listIndex = _list.Index;
                
                vehicle.Speed = _listOfSpeed[listIndex];

                UI.ShowSubtitle("You have set limit your car");
            }
        };

}
Edited by hybaby9

Share this post


Link to post
Share on other sites
Guest
Posted (edited)

Try

vehicle.MaxSpeed

I have never used that mind you, so I have no idea how (or if) it works.

Edited by Guest

Share this post


Link to post
Share on other sites
hybaby9
4 minutes ago, LeeC2202 said:

Try

vehicle.MaxSpeed

I have never used that mind you, so I have no idea how (or if) it works.

I tried but same result
also try SET_ENTITY_MAX_SPEED

 

Share this post


Link to post
Share on other sites
Guest
Posted (edited)

Actually... I think I did try this at one time and if I remember correctly, it only works if the current speed is lower than the MaxSpeed when you set it. You can't use it to slow a vehicle down, you can only use it to stop the vehicle going faster than that, if you're already going slower.

 

Also, don't forget the value is in m/s, not Km/h or MPH.

Edited by Guest

Share this post


Link to post
Share on other sites
hybaby9

So is there any way to set the speed limit for the car that is driving?

For example, I set the speed limit for my car to 25 MPH when driving in the city and 111 MPH while in the suburbs.

Share this post


Link to post
Share on other sites
Guest
Posted (edited)

Very easily... if the vehicle speed is higher than the speed limit, disable the accelerator control until the car's speed is less than the speed limit and then set the new MaxSpeed value. Then enable the accelerator again.

Edited by Guest

Share this post


Link to post
Share on other sites
hybaby9
Quote

if the vehicle speed is higher than the speed limit, disable the accelerator control until the car's speed is less than the speed limit and then set the new MaxSpeed value. Then enable the accelerator again.

I followed your instructions but it doesn't work

I don't know where it was wrong ??

		int listIndex = _list.Index;
                    int speedLimit = _listOfSpeed[listIndex];
                    float dump = Game.Player.Character.CurrentVehicle.Acceleration;                                                       
                    if (vehicle.Speed > speedLimit)
                    {
                        dump = 0;
                        if (vehicle.Speed < speedLimit)
                        {
                            vehicle.MaxSpeed = _listOfSpeed[listIndex];
                            dump = Game.Player.Character.CurrentVehicle.Acceleration;
                        }
                    }

Share this post


Link to post
Share on other sites
Guest

Here are some things you need to learn about, Global Variables and the OnTick() event.

 

Global Variables:

private float SpeedLimit;
private bool SpeedLimitSet;

Set the SpeedLimit variable when you select the memu option and if the vehicle is going faster than the new speed limit when you set that variable, set SpeedLimitSet = false

 

In your OnTick event handler:

if (!SpeedLimitSet)
{
	if (vehicle.Speed >= SpeedLimit)
	{
		Game.DisableControlThisFrame(2, Control.VehicleAccelerate);
	}
	else
	{
		vehicle.MaxSpeed = SpeedLimit;
		SpeedLimitSet;
	}
}

That should work, although my headache might be clouding my judgement at the moment but give it a try.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.