[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
#2

Not practical but you did your timings right.
+Rep for effort bro.
Reply
#3

I don't really see this working correctly no I didn't test it but it seems unlikely you could know the state on the client correctly. Your making assumptions which is always unreliable.
Reply
#4

^ What the genius said.
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I don't really see this working correctly no I didn't test it but it seems unlikely you could know the state on the client correctly. Your making assumptions which is always unreliable.
Yeah unreliable but it finds the state correctly. Isn't it all about timers? If you set them right they will give correct result. You're making decision without trying it.

Quote:
Originally Posted by ******
Посмотреть сообщение
It would be VASTLY more reliable to find the address in the server and use a plugin to extract it (or even PAWN, but only if you really know what you're doing).
Yes I know but isn't it forbidden?
Reply
#6

Well, about the timer problem: you can add y_timers compatibility.
Reply
#7

I like that idea. Its probably the best you can do without replacing the objects and without accessing the memory.
I also like that you obviously spent some time for finding out how the traffic lights work, thats the stuff I find most interesting about samp scripting.

Good work!
Reply
#8

Quote:
Originally Posted by erorcun
Посмотреть сообщение
Yeah unreliable but it finds the state correctly. Isn't it all about timers? If you set them right they will give correct result. You're making decision without trying it.
That is all fine and dandy but what happens when the player pauses?
Reply
#9

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
That is all fine and dandy but what happens when the player pauses?
Doesn't the server sync it? I remember reading something about it being synced in an older SA-MP version.
Reply
#10

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Doesn't the server sync it? I remember reading something about it being synced in an older SA-MP version.
I looked into a bit more and apparently you are correct it says they are synced so maybe this will work?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)