Vehicle Cruise Control (Server Side Script)

Discussion in 'Scripting/Addon Discussion' started by Allen Kaganovsky, Feb 17, 2014.

  1. Allen Kaganovsky

    Allen Kaganovsky Member

    Joined:
    Feb 27, 2013
    Messages:
    35
    Likes Received:
    16
    HELLO! I didn't make a post in a while, thought I would share a script I wrote a few weeks ago.
    I originally created this for an Altis Life server, having speed limits and 25km one way trips made something like this essential. But I don't see why this can't work on any dayz server - even arma 2 (May need some adjustments in the hints formatting, since the hint box is not as wide in arma 2 as it is in arma 3).


    How it works:
    There are 4 preset cruising speeds: 50, 70, 120, 160 km/h <you'll need to understand the code and change it yourself if you like>

    The vehicle must already be moving +/-5 km/h from the cruising speed so that the jump in velocity isn't that noticeable. From the mouse scroll menu, simply select Cruise Control.
    If the vehicle is not within any speed range then a hint message comes up to display the possible cruising speeds.
    If the vehicle is within a cruising speed range, then a loop activates that constantly gets the vehicle direction and sets its appropriate velocity. It also checks for vehicle fuel and damaged vehicles.

    There is also a key listener that deactivates the cruising speed when the breaks (S) are applied.

    [​IMG]

    Script Download:
    https://github.com/allen-k/Arma3CruiseControl/blob/master/mod_cruiseControl.sqf

    Script Install:
    This is meant to go server side, so put the file server side.. I'll use the example from altis life, you'll need to figure out the proper path based on the mod your using this script on.

    1. Create a folder called "mods" in the root directory of life_server folder.
    2. Place the mod_cruiseControl.sqf file into the mods folder
    3. In the servers init.sqf file, you'll want to add this line at the end of the file:
    // cruise control
    [] execVM "\life_server\mods\mod_cruiseControl.sqf";
    4. In the Mission side of things, edit the init.sqf, at the end of the file add:
    // mod cruise control
    call mod_cruiseControl;

    Lastly:
    enjoy!
    Also let me know if any of you try it out in Arma 2, and if the hints need to be adjusted due to text size.

    EDIT!!!!! FOR ARMA 2 YOU NEED TO CHANGE THE FONT FOR THE HINTS!
    change all instances of puristaLight and puristaMedium to Bitstream
     
  2. Gagi2

    Gagi2 Valued Member!

    Joined:
    Mar 30, 2013
    Messages:
    444
    Likes Received:
    59
    well... this could come in handy... :cool:

    thnx for sharing this piece of code ;)
     
  3. Antoine_UFS

    Antoine_UFS New Member

    Joined:
    May 16, 2014
    Messages:
    1
    Likes Received:
    0
    Where are the two init.sqf, they are same or different locations ?
     
  4. Gagi2

    Gagi2 Valued Member!

    Joined:
    Mar 30, 2013
    Messages:
    444
    Likes Received:
    59
    one is in your mission file and the other one is in the serverside file...
     
  5. Gagi2

    Gagi2 Valued Member!

    Joined:
    Mar 30, 2013
    Messages:
    444
    Likes Received:
    59
    i got an error now in my altis life setup...
    its working... but still getting an error...

    Code:
    16:50:01 Error in expression <{isNull (findDisplay 49)};
    };
    };
    
    
    call mod_cruiseControl;>
    16:50:01   Error position: <mod_cruiseControl;>
    16:50:01   Error Undefined variable in expression: mod_cruisecontrol
    16:50:01 File mpmissions\Altis_Life.Altis\init.sqf, line 49
    
     
  6. Allen Kaganovsky

    Allen Kaganovsky Member

    Joined:
    Feb 27, 2013
    Messages:
    35
    Likes Received:
    16
    It could be your server variables aren't being initialized fast enough.. (mp mission loads before server sends variables)

    on the mpmission side, you'd want to add something like this:

    waitUntil { !isNil "mod_cruiseControl" }; <- double check the syntax, I didn't do anything with arma for a few months now.
     
  7. Gagi2

    Gagi2 Valued Member!

    Joined:
    Mar 30, 2013
    Messages:
    444
    Likes Received:
    59
    yeah.... this seems to work ^^

    Code:
    // mod cruise control
    waitUntil {!isNil "mod_cruiseControl"};
    call mod_cruiseControl;
    no error message so far...
     
  8. Allen Kaganovsky

    Allen Kaganovsky Member

    Joined:
    Feb 27, 2013
    Messages:
    35
    Likes Received:
    16
    Gagi2, A better way would be something like this:

    spawn[] <- check the exact syntax of this, I dont remember exactly
    {
    waitUntil {!isNil "mod_cruiseControl"};
    call mod_cruiseControl;
    }

    That way, any code afterwards isn't being held up if it doesn't have to.
     
  9. Gagi2

    Gagi2 Valued Member!

    Joined:
    Mar 30, 2013
    Messages:
    444
    Likes Received:
    59
    it should be
    Code:
    [] spawn
    {
    waitUntil {!isNil "mod_cruiseControl"};
    call mod_cruiseControl;
    };
    
    then i guess?

    its the last entry in my init.sqf so its fine for the moment.. but i will try it this way...
     
  10. Allen Kaganovsky

    Allen Kaganovsky Member

    Joined:
    Feb 27, 2013
    Messages:
    35
    Likes Received:
    16
    That looks like it should be good to go ;)
     
  11. Rite

    Rite Member

    Joined:
    Oct 21, 2013
    Messages:
    47
    Likes Received:
    4
    ahhaaaaa it is not breaking or stopping with S..
    Helllp even if i shutdown the engine it still cruising like a electric car
     

Share This Page