[FilterScript] KeepYourLane - Dynamic Ghost-Driving Detector + Creator

[FS]Keep your Lane V2
-Dynamic Ghost- and Train track-Driving Detector-

Keep your Lane is a filterscript that analyzes the players position on the road and detects when the player is driving against traffic. This FS also includes an editor so you can apply this system on your own custom-mapped roads and change existing roads to one-way roads. In this release I have included a file which contains over 21.000 pre-made so-called 'RoadPoints' made by me. These RoadPoints already cover more than 100 kilometers (60 miles) of roads in the game. All highways and most large roads are covered so you can use this script right away and add more RoadPoints as you go (they will work instantly).

Since the release of V2 this system also detects players driving on the Traintracks.

This script gives an extra touch to your server if 'Realistic Driving' is an important element of your gamemode. (Think about Trucking- or Roleplay-games). This filterscript gives you the ability to do anything you want to a player who's driving on the wrong side of the road or driving on the traintracks. (Warn him, fine him, make him wanted or whatever you want).

As I stated above, this system works with 'RoadPoints'. These points are placed on the roads and contain only 5 values: Obviously the X-, Y- and Z-coordinate, the angle the players are supposed to drive and finally the radius (which should cover the width of the lane(s). All RoadPoints are stored in 1 file (1 line per RoadPoint).

The script will loop (on default every 200ms) through all players who are driving a vehicle and check if they are driving near a RoadPoint (the map is divided into 145 smaller zones for efficiency), if so, his current driving-direction will be compared to the supposed driving-direction (defined in the current Roadpoint) and if he's driving the opposed direction the script it will trigger a callback "OnPlayerGhostDriving" which you can place in your gamemode and do whatever you want with that player.

The Dynamic Creator:
I've created an in-game tool which you can use to easily add or delete RoadPoints. You only have to set the preferred dimensions (Road-width and distance between roadpoints) and you're good to to: Just carefully drive in the middle of the road and this tool will automatically create new RoadPoints based on your settings.

To start creating you have to be Rcon-admin, get in a car and type /createRP. Textdraws will show up at the bottom of your screen and 2 red arrows (markers) will appear on both sides of your car. These markers represent the total width of the road-half.
By clicking the left-mouse button you can click on the textdraw-bottons to adjust their values, the red arrows will be updated instantly. Make sure the width is set correct so the left arrow does NOT exceed the border with the other driving-direction. Now drive in along the road in the right direction and new RoadPoints will be created automatically on intervals set by you (distance).

I've also added the ability to create 2 RoadPoints at the same time, 1 for each direction. To enable this, just click on the 'Double On/Off' textdraw at the bottom of the screen. You'll now see 4 arrows beside your car as well as an extra textdraw with a value-setting called 'Space'. This value represents the width of the median between both directions.

Where to drive in which mode:
- Single-direction mode (1 lane in each direction): Drive in the middle of that lane
- Single-direction mode (2 lanes in each direction): Drive in the middle of these 2 lanes. (see 1st photo here below)
- Double-direction mode (1 or 2 lanes in each direction): Drive on the border that separates both directions. (see 2nd photo here below)

In both single- and double-mode you can pause/enable the automatic creation by pressing the handbrake. And you can adjust any value on the go.

If you are in the creation-mode, white arrows (pickups) and yellow map-icons will represent the locations of all created roadpoints. (Streamer Plugin is required!).

If you want to delete an RoadPoint, get near it and click the 'delete' button on the bottom of the screen. You can also mass-delete RoadPoints by typing the command /deleteRP and every RoadPoint you drive through will be deleted automatically until you hit the handbrake.

Using /createRP again, or leaving the car will close the creation-tool.

You can also save up to 5 presets by using /savepreset [1-5]. To show the current presets-textdraw use /presets and click on any preset to apply the settings.


Required plugins and includes:
- streamer by Incognito
- sscanf2 by ******
- zcmd by Zeex
- vehiclematrix by Gamer_Z

How to install:
- Download KeepYourLaneV2.rar as well as the required plugins/includes if you haven't got them yet.
- Extract the files to the right folders. (keepyourlane(lite).pwn and keepyourlane(lite).amx should go into your filterscripts-folder and 'KYLRoadPoints.txt, KYLTrainRoadPoints.txt and KYLSettings.txt should go into your scriptfiles-folder.
- Add 'filterscripts keepyourlane' in your server.cfg
- Optionally adjust the settings (defines) at the top of the script.
- Add to your gamemode the following callbacks and add whatever you want to it:
pawn Код:
forward OnPlayerGhostDriving(playerid, zone, Float:X, Float:Y, Float:Z, Float:A);
public OnPlayerGhostDriving(playerid, zone, Float:X, Float:Y, Float:Z, Float:A)
    GameTextForPlayer(playerid, "~r~Wrong lane!", 1000, 4);
    return 1;

forward OnPlayerDrivingOnTrainTrack(playerid, zone, Float:X, Float:Y, Float:Z);
public OnPlayerDrivingOnTrainTrack(playerid, zone, Float:X, Float:Y, Float:Z)
    GameTextForPlayer(playerid, "~r~Do not drive on~n~the train tracks!", 1000, 4);
    return 1;
- If you start the server you might see a warning after 2 seconds in your server log, suggesting to set the MAX_ROADPOINTS_PER_ZONE define to a certain value. It's recommended to do this to optimize the performance, but only if you won't be creating any more new RoadPoints. (You can always increase the value if the max roadpoints in a certain zone is reached (it will give an ingame warning).

Here are 2 more pictures of the creation-tool:
(do not mind the 2 green bars on screen, these are not part of this filterscript)

This is the single-direction mode. Usefull to create highway-ramps and one-way-streets.

..and this is the double-direction mode. Notice the 4 red arrows (1 is hidden behind car):

Known Bugs:
- I haven't found a bug so far, but I have not been able to test this system with multiple players online. It is pretty straight-forward, it should work (i hope :P). But if you experience any problems, please let me know!

- ****** (sscanf plugin)
- Incognito (streamer pluging)
- Gamer_Z (vehiclematrix include)
- Zeex (zcmd include)
- Sacky (fdeleteline function)
- Pottus (Game me several tips on efficiency)
- Samp Team
- Jeroen52 (Created some additional RoadPoints)

Last Words:
It's a lot of text, but it sounds more complicated than it actually is.
If you have any questions, found any bugs, or have suggestions please let me know! And please ask questions/problems regarding the required plugins in their respective topics, not here.
I've added as many comments in the .pwn file as possible to explain each function and step.


V1.0: Initial release

V1.2: Created a lite-version (keepyourlanelite.pwn/amx) that does NOT contain the creator.
You can use the full script to create/delete RoadPoints and when you're done, unload the filterscript and load the lite version. It will read the RoadPoints from the same file (KYLRoadPoints.txt).

- Added and optional system that detects players driving on the train tracks (with any vehicle except a train).
- Improved efficiency by using Dynamic Areas (from Streamer plugin) (thanks to Pottus!)

- Schneider

- Mediafire - KYLRoadPoints.txt (Updated: January 31th 2015) (22.723 RoadPoints).
- Mediafire (Full package, including scriptfiles)
- Pastebin (Full version)
- Pastebin (Lite version)

Of what I've read and seen it seems like an amazing job! Congratulations.


I think this is something unique, that I will definitely use to my roleplay server.
It seems you really put some effort on it.
Thanks a lot mate!

Thank you!
I just made a video that shows how it works:


Awesome work dude.

Very nice work, really appreciated.
nice video too, how much time it took you to make this ?

Originally Posted by TRTDM
Посмотреть сообщение
Very nice work, really appreciated.
nice video too, how much time it took you to make this ?
Thank you! I've worked about 3 or 4 days on this system itself (it went through numerous revisions to improve the efficiency) and when I was finally done with the system itself, i drove around San Andreas for about 3 hours to create the included 21.000 roadpoints.

I think it's a neat idea but you should make a separate include for implementation this FS is mostly an editor so it doesn't make sense to load it along with all the code that won't be used.

Thank you very much Pottus, great idea and you're absolutely right!
Working on it right now!

Forum Jump:

Users browsing this thread: 1 Guest(s)