[Include] Traffic light detection
#1

[INC] Traffic light detection

Hi, as you know, traffic lights are synced in SA-MP but we can't get their state. I wanted to get their state, then I created that advanced counter.

Things you should know before using

- After you launch SA-MP and while you're seeing Santa Maria Beach, GTA's traffic lights system activating in here, after you wait approximately 5 seconds in here, with the connection to server, if you are the first one who entered server, your traffic lights infos are being sent to server and it's being shared between all players, it is okay until here but there is no way to learn the delay between game opening and server connection time, so we don't know when first players' traffic light system start - so this script take it 5 seconds and makes calculations based on that - but you can calibrate it always, and calibrating it once is enough up to 23 days, details are on below.

- Probably most of people will use traffic light callback for "instant" things, but there could be lag anytime (independently from this script). So I added lag detection ability to script and through that, script can pass traffic light callback if it detects any lag, and you can wait for same color next time. For example; Red(sent to callback) -> Green(sent to callback) -> Yellow(not sent to callback because server started to lag) -> Red(sent to callback) etc.
To activate it, add this to top:
pawn Код:
#define DONT_CALL_TL_CB_IF_DELAYED
- All lights facing to North/South and all lights facing to East/West are same in GTA. So there is 5 state ID you should know: (N/S are north/south and E/W are east/west)
Код:
1- Green (N/S) Red (E/W)
2- Yellow (N/S) Red (E/W)
3- Red (N/S) Green (E/W)
4- Red (N/S) Yellow (E/W)
5- Red (N/S) Red (E/W)(Server starts in that state)
- It's recommended to use one of the "timer fix" plugins.

How to use

Firstly include to your gamemode
pawn Код:
#include <trafficlights>
--------------------------

- GetTrafficLightState()

Returns one of the states in above.

- OnTrafficLightStateChange(state)

Gives one of the states in above.

- CalibrateTrafficLightCounter(state)

Okay, this is most important one. There will be delays always, server can be online for a long time, or first player's connection delay can be more/less from 5 seconds.
To fix that, you can run that function with the one of the states above. I.e. using
pawn Код:
CalibrateTrafficLightCounter(5)
means "All lights turned to red just right now" and script will calibrate itself according to that. Or using
pawn Код:
CalibrateTrafficLightCounter(1)
will mean "All N/S lights turned to green and all E/W lights turned to red right now". You can use it in-game anytime.

Normally game starts with red-red and stays 20 seconds like that but sometimes it becomes green-red quickly, so sometimes you really need to use that function.

Changelog

v1
- Initial release
v1.1
- Bug fix

Download
http://pastebin.com/Cn4Xz856

Enjoy! Waiting feedbacks =)
Reply


Messages In This Thread
Traffic light detection v1.1 - by erorcun - 28.04.2014, 22:48
Re: Traffic light detection - by SkittlesAreFalling - 29.04.2014, 00:09
Re: Traffic light detection - by Pottus - 29.04.2014, 00:23
Re: Traffic light detection - by SkittlesAreFalling - 29.04.2014, 00:47
Re: Traffic light detection - by erorcun - 29.04.2014, 04:19
AW: Traffic light detection - by ThomasTailor93 - 29.04.2014, 22:03
Re: Traffic light detection - by Mauzen - 29.04.2014, 23:11
Re: Traffic light detection - by Pottus - 30.04.2014, 00:07
Re: Traffic light detection - by Calgon - 30.04.2014, 00:09
Re: Traffic light detection - by Pottus - 30.04.2014, 00:17

Forum Jump:


Users browsing this thread: 2 Guest(s)