More efficient player detecting system -
edyun - 07.09.2018
Good afternoon everyone, I am trying to make a "speedgun" like system, for the cops so that they can track other players. The only problem that I have is that the system I did tracks everything too fast so it just crashes. How can I make this more efficient, any ideas?
Код:
public SpeedChecker(playerid)
{
while(radarstatus[playerid] == 1)
{
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(GetDistanceBetweenPlayers(playerid,i) < 100.00)
{
if(player_vehicle_speed[i] > 159.99)
{
new numeplayervit[256];
GetCharacterName(i, numeplayervit);
new mesajviteza[256];
format(mesajviteza,sizeof(mesajviteza), "{FFA500} %s a fost surprins cu viteza de {FF4C4C}%f km/h!", numeplayervit, player_vehicle_speed[i]);
SendClientMessage(playerid, -1, mesajviteza);
}
}
}
}
}
Re: More efficient player detecting system -
edyun - 07.09.2018
Well, it will, I have a command that changes the "radarstatus[playerid]" every time it is executed, but the thing is not that it will not end, it goes through it too fast.
Re: More efficient player detecting system -
edyun - 07.09.2018
Yeah, that's the problem, I need an alternative to that. Cuz that loop crashes anything so it can't be stopped, I did a huge rookie mistake over there, but I am out of ideas.
Re: More efficient player detecting system -
edyun - 07.09.2018
The problem is that, there is no other way to check through the whole players every time it ends the for loop, to see if they approached me, cuz what this system does it just checks through the whole server, if they are near me, it will just check the speed, if they are not near me, it will continue to search for players they are. I was thinking for some sort of an update, everytime a player comes in my radius to start looping, but I don't have the experience for something like that so I don't really know how to do it.
Re: More efficient player detecting system -
edyun - 07.09.2018
I know, but if I eliminate that loop, it will just go once through the players, and then I will need to run the command again, that's not really the effect that I want.
Re: More efficient player detecting system -
edyun - 07.09.2018
Well, i did the checker so I can use it in "/radar" command, being or not being in a function is not really a thing, I just didn't wanted the code to be all over in the command, so I made a quick function, it would've worked in the command itself but I just putted in a function to clear the code.
Re: More efficient player detecting system -
edyun - 07.09.2018
Just randomly done like that, is there any problem with it? I just felt doing it like that for future, you never know.
Re: More efficient player detecting system -
edyun - 07.09.2018
I know, really, I am just out of ideas, tried for 2 hours solving it, still haven't got to anything.
Re: More efficient player detecting system -
edyun - 07.09.2018
Well, usually public functions can be called via CallLocalFunction CallRemoteFunctio, SetTimer SetTimerEx, and they need to be forwarded. I know I should've made a simple plain function, but does that affect the usabilty of the function?
Re: More efficient player detecting system -
ShihabSoft - 07.09.2018
If you want the speedgun checker to run repeatedly, just put it in a timer. A while loop would never rest, until it is broken out, and also it would cease rest of the operations, as SAMP is single threaded.