Is player facing speed camera - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is player facing speed camera (
/showthread.php?tid=636623)
Is player facing speed camera -
Bigwebicek - 01.07.2017
Hello there,
I need to check if is player's vehicle facing speed camera (with maximum difference about 40 degrees), so that if player'd speed over the camera, it will trigger alert to the police. But, if player won't be facing the camera (he would be not like this ( > < ), it won't get triggered.
I need it to be triggered just like this, > <, not like this > > or >
V or this >
^
It shouldn't be constant, I will place more speed cameras and I need it to work on every camera.
Camera angle is stored in
spdcamEnum[i][scam_RZ], then in
spdcma, vehicle's angle is stored in
angle.
Here is my actual code.
Код:
new
Float:spdcma= spdcamEnum[i][scam_RZ]-180,
Float:angle;
GetVehicleZAngle(GetPlayerVehicleID(playerid), angle);
ValidateDegree(spdcma); // After editing object degrees can be negative or bigger than 360 degrees, so lets fix it.
ValidateDegree(angle);
if(spdcma < angle + 45 && spdcma > angle - 45)
continue; //Player shouldn't be facing speed camera
//-------------------------
ValidateDegree(&Float:degree)
{
if(degree < 0.0)
degree = degree * -1 + 180;
if(degree > 360)
degree -= 360.0;
}
This code appears to not work, as it is working just in some cases, it appears to be random. Does anyone have better solution, please?
> - speed cam
< / v / ^ - player's vehicle
Re: Is player facing speed camera -
Nero_3D - 01.07.2017
The first case in ValidateDegree is strange, changed it to + 360.0, also added a while loop
PHP код:
ValidateDegree(& Float:degree) {
if(degree < 0.0) {
while((degree += 360.0) < 0.0) {}
} else if(degree >= 360) {
while((degree -= 360.0) >= 360.0) {}
}
}
PHP код:
new
vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid) { // check if player is in a vehicle
new
Float: angle,
Float: offset;
GetVehicleZAngle(vehicleid, angle); // get angle before the loop, no need to recall this function x times
angle += 180.0; // adding offset before the loop
for(new i; i < sizeof spdcamEnum; ++i) {
offset = angle - spdcamEnum[i][scam_RZ];
ValidateDegree(offset); // you need to validate the result otherwise it could be that spdcam is 355 and angle is 5.0 and it wouldn't trigger
if(offset < 45.0 || offset > 315.0) {
printf("Playerid %d got caught by speed cam!", playerid);
break; // abort loop
}
}
Re: Is player facing speed camera -
Bigwebicek - 01.07.2017
Working, thanks.