Okay, In my original/initial post (found at the bottom) I asked if people had some pointers on how to get the current maximum speed (“legally”) for the current road the player is driving on (as in which is the ‘default setting without panic’ for NPC’s drive there).
Well I have found some natives like:
GetVehicleNodeProperties
AddRoadNodeSpeedZone
And RemoveRoadNodeSpeedZone
Well the last two aren’t really useful (for now) due to the fact that I’m not directly able to read the current “speedzone” which is actually all I really need (and I can only assume many of us do for RP/Speeding scripts).
Now there would be the possibility for people to create fully custom arrays with street names and then “linking speed limits” to them, like someone mentioned in this post:
However he also mentions that it would be quite inaccurate due to the fact that some sections of the same road (name) uses different speed limits.
Therefor I have been working on it for a LONG time by collecting a “wide range” of flags and the locations where they are being reported at.
The flags as I have researched and found them so far:
2:
- mainly “50kMh City Roads”
3:
- Road around/connecting to TLAD Trailer park and almost all the way along
Alamo Sea. So I’m considering to treat it as 2 in regards to “zone speeds”
6:
- Roads around/near LS Airport
- LOTS of roads in Vinewood hills report 6 (including many small driveways there)
- Parkinglot right across LS airport terminal (right side)
- Some roads of Paleto Bay report 6 (although most report 2, except the ‘road passing by’ which
identifies as a ‘freeway’ (66)) - Part of LS reports 6 (around Arcadius Business Center for example)
10:
- Many parking and driveways lots
- Gas stations
- LS Airport itself
- (sand) roads around Davis Quartz
- Roads at the PalmerTylor Green Power Station
(Funny thing is that there is also text on the road saying 10!) - The Lost And Damned ‘Trailer Park’
- Nearly entire coastline/beach along Del Perro
- Some sections of Mount Chiliad/Raton Canyon
NOTE: Some highway exits also briefly report 10!
11:
- So far only sand roads
- Sand road/part at Sandy Shores Airport
- Runway part of McKenzie airfield (sand part around it reports flag 10)
- Some sections of Mount Chiliad/Raton Canyon
- Beach/Coastal line a little further from Paleto Bay
13:
- Part of mountains around Zancudo
14:
- Parking lot LS Airport
- Parking lot near Del Perro Pierre
- Begin of LS Airport itself (near Devin Weston)
- Parking GARAGE LS Airport
- Some sections of Mount Chiliad/Raton Canyon (sand roads)
15:
- The ‘Tarmac’ part of Sandy Shores Airport (the runways themselves!)
NOTE: MOST LIKELY not the only location/zone which report 15 so DO NOT
use this as identifier to ‘recognize’ this airport location!!!
18:
Is being reported inside the ‘tunnel’ (normal road tunnel!) near Pillbox
34:
- First part (until near the bridge which goes left) of the road to Catfish View.
Starts Right at the sign which says Cape Catfish - Part of the sand/dirt road between Paleto Bay and the coastal line (up to the stunt jump,
then it changes into 42 for a while, ending in flag 11 for the last part!)
NOTE: The part with 42 also seems to have random cars spawning (driving around)
35:
- Road leading up to Tataviam Mountains
- Road leading up to Catfish View (Dead-end road resulting in a ‘u turn’!)
(The TARMAC PART of this road!, the last section of this road returns 47!)
38:
- Road up to radio station behind Vinewood sign (Mt. Haan Dr.)
40:
- Large portion of Mount Gordo reports flag 40
42:
- Entry road up to Zancudo
- One parking lot near LS Airport (with the yellow Rental buses on it)
- Some Sand Roads leading from Sandy Shores to Grand Senora Desert
- (sand) roads at the ‘inner circles’ of Davis Quartz
- Some Caravan/Trailer parks around Sandy Shores (with sand roads)
- Road up to lighthouse at Mount Gordo
- Some Parking lot’s
- Many of the smaller roads in Vespucci Canals report 42
43:
- Sand Roads at alien worship location (Sandy Shores)
- SAND part road at the middle of Tataviam Mountains (near the dam!)
- Beach next to Paleto Bay
46:
- Parking lot right across LS airport terminal (left side)
47:
- Some (off road?) bicycle tracks/courses
- The last part of the road at Catfish view)
64:
- Freeway Connection/Splits (the “driving over the lines” part?)
- Some parts of mountains also report 64 (around Zancudo some mountain parts for example)
66 = Mainly (if not only!) Freeway
82 = Freeway Tunnels, due to some of the tunnels also being interiors I suppose they need a different flag than 66 for some reason.
Main Observations:
130,144, 256, 258, 260, 262, 194, 320, 322, 512 and many others Seem to be intersections (Nodes overlapping/connecting etc)
2: Mainly “Regular city traffic/speeds”
10: Nearly all (if not all) vehicles I’ve seen at flag 10 locations where driving EXTREMELY slow!
66: is the majority of the free/highways
Another important observation to take into consideration is that most (if not all) tunnels on freeways (NOT underneath bridges in the city!) are considered interiors and report a different ID which is 82 instead of 66
These are just global observations, but unfortunately if you have looked at the list of flags, we can’t just take them ‘blindly’ and assume that for example that flag 6 is a 50KM/h road.
This because this one is also reported by a few parking lots which I have found.
BUT the good news about this, is that it WILL be possible to make a general function/script which can be MUCH more accurate, less CPU intensive and less time consuming than making massive arrays with zones/radius detection or than making arrays with street names and speed limits.
I’m AT THIS MOMENT actually working on a small script/function which will exactly do that, and when it’s done I’ll update this post once more so others can also use this “workaround” until there is a “100% accurate” solution to get the “intended speed” for the current road the player is driving on
[UPDATE WITH EXAMPLE FUNCTION PENDING]
A basic example code
Bellow I’ve included an basic example code on how to use the detected vehicle node flags and the information we have about them (now) as basic “speed limit detection”. Do note that this function does NOT give you a “fine system”, it’s NOT a “speeding ticket system” and nor is it a speed limiter system! However you ARE able to make all of the above with this “system”! Which is actually exactly what I’ve done. As inspiration/idea’s I will list a few of the idea’s which I have made for my own development server with this function:
- A speeding ticket system
- A speed limiter (for players without a drivers license) which automatically adapts the maximum speed to the area the player is driving in.
- A “traffic violations” detection system (speeding, going off-road, detecting different types of behavior like Neon lights allowed on parking lots but NOT on public roads etc).
And more of the alike is all possible with this (for now) limited data, the example code is in this “details box” bellow.
Zone Speed Detection Example (Lua)
function DrawXNLSampleData(sText, Color)
local x = 0.0020
local y = 0.05
local LineHeight = 0.010
local Size = 0.50
local Text = ""
r, g, b = 255, 102, 255 -- XNL SA-MP .GOV Color Pink
a = 255
SetTextFont(0)
SetTextScale(Size, Size)
SetTextColour(r, g, b, a)
SetTextDropShadow(255, 255, 255, 0,255)
SetTextDropShadow()
SetTextEntry("STRING")
AddTextComponentString(sText)
--SetTextRightJustify(true)
DrawText(x, y)
end
local vIsPointOnRoad = false
CurrentAllowedSpeed = -1
local ZoneFlags = 0
Citizen.CreateThread(function()
while true do
if vIsPointOnRoad then
DrawXNLSampleData("XNL GetVehicleNodeProperties Demo: Speed: " .. CurrentAllowedSpeed .. " (ON ROAD) Flag: " .. ZoneFlags)
else
DrawXNLSampleData("XNL GetVehicleNodeProperties Demo: Speed: " .. CurrentAllowedSpeed .. " (OFF-ROAD) Flag: " .. ZoneFlags)
end
Wait(1)
end
end)
Citizen.CreateThread(function()
local CurrentBuffer = 0
local ZoneBuffers = {-1, -1, -1, -1}
local LastKnownZone = -1
while true do
local playerPed = GetPlayerPed(-1)
CurrentBuffer = CurrentBuffer + 1
if CurrentBuffer > 4 then CurrentBuffer = 1 end
cords = GetEntityCoords(playerPed)
Ignored1, Ignored2, ZoneFlags = GetVehicleNodeProperties(cords.x , cords.y , cords.z)
vIsPointOnRoad = IsPointOnRoad(cords.x , cords.y , cords.z, nil)
ZoneBuffers[CurrentBuffer] = ZoneFlags
-- I only want to "process it" when all four buffers contain the same data.
-- because in this TEST i wanted to prevent that it "quickly hops" between zones when a player just passes underneat a bridge on
-- the highway and then gets reported as "speeding" (yup that happens on some locations/intersections if we're not buffering and
-- ignoring certain ID's)
if (ZoneBuffers[1] == ZoneBuffers[2]) and (ZoneBuffers[1] == ZoneBuffers[3]) and (ZoneBuffers[1] == ZoneBuffers[4]) then
local ZT = ZoneBuffers[1] -- Just a short variable to make the code 'smaller' overall.
LastKnownZone = ZoneBuffers[1]
local CurDetectedAllowedSpeed = -1
-- NOTE!!! I'm taking "quite some risk" by just throwing in several zones into "one detection" here!
-- However this is JUST AN EXAMPLE on how you would like to use them!
if ZT == 10 or ZT == 14 then CurDetectedAllowedSpeed = 15 end
if (ZT == 2 or ZT == 3 or ZT == 6 or ZT == 11 or ZT == 13) or (ZT >= 34 and ZT < 48) then CurDetectedAllowedSpeed = 50 end
if ZT == 66 or ZT == 82 then CurDetectedAllowedSpeed = 120 end
if CurDetectedAllowedSpeed > -1 then
CurrentAllowedSpeed = CurDetectedAllowedSpeed
end
end
local vehicle = GetVehiclePedIsIn(playerPed,false)
if CurrentAllowedSpeed == 15 then
end
if CurrentAllowedSpeed == 50 then
end
if CurrentAllowedSpeed == 120 then
end
Wait(200)
end
end)
NOTE: I tried to make the code universal, If I accidentally forgot to remove a reference, call or variable to my own XNLFramework, then please let me know and I will fix that.
To test/use this data and the function you can just copy-paste the above code in a CLIENT SCRIPT There is a very simple reason I’ve NOT made this as a resource:
Because it then will happen again that people start asking:
“How do I make it so people get a ticket”, or “Can you add for me that people have a speed limiter?” and more of the alike. This is meant as RESEARCH and to help other developers along with making their scripts better and adding more dynamic controlled realism to the servers.
NOT for “copy-paste-server “owners””
Bitset needs to be investigated
I’m almost certain that this is flag is a so called bitset and not just an identifier. Which in theory means we should somehow be able to ‘reverse calculate’ the bitset.
Mini explanation on bitsets
Here I will explain (as simple as possible) what a bitset is.
Lets say we have a micro-controller (Chip) with 8 pins to which we connect one LED to each pin. Those pins then have an “8-bit address”. This would be as follows:
Pin 1: 1
Pin 2: 2
Pin 3: 4
Pin 4: 8
Pin 5: 16
Pin 6: 32
Pin 7: 64
Pin 8: 128
If we now ONLY want to enable the LED on pin 1 we just write 1 to the pins/output of the chip. If we ONLY want to enable LED 5 we will write 16 to the pins/output of the chip.
BUT if we want to enable LED 1 AND LED 5 we would instead just write 17 (1 + 16) to the pins/output.
This has obviously nothing to-do with FiveM/GTAV but it’s one of the most simple explanations I could come up with to explain bitsets to those whom are new to it.
If there is a way to figure out the “bit set style” which is used for the roads, we are also able to ‘reverse calculate’ the set, and start comparing those values/results with roads we’re driving on and most likely also to make the system MUCH more accurate
My Original/Initial Post/Question:
Maybe someone has figures this one out already so before diving in further into the scripts and de-compiled stuff:
Does anyone know which native could be used to detect the speed set for the current road node on the current road the player is driving on (or just a function which can get it by passing the road/node coords for example).
I know it should be possible somehow, because it’s in “rough lines” the same way NPC’s use it to alter their speed(s) when driving around the map (just follow one from the highway into the city and you’ll notice it will adapt it’s speed to the current road node to).
The native which are ‘exposed’ already are:
AddRoadNodeSpeedZone and RemoveRoadNodeSpeedZone
I need to detect the current speed “allowed” on the roads for several automated “law enforcement”
scripts.
I know it could be done with all kinds of “funky” workarounds like scanning about 5 cars around the player and reading their “set cruise task speed” etc etc and more of the alike, or by manually entering a (massive) list of road/zone names and assign “legal speeds” to them, but that’s just way overkill if there is a native which can just read the ‘default speed’ per road/zone
So hoping someone has some more insights on a native related to this.