More efficient player detecting system
#1

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);
			}
		}
	    }
	}
}
Reply
#2

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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7

Just randomly done like that, is there any problem with it? I just felt doing it like that for future, you never know.
Reply
#8

I know, really, I am just out of ideas, tried for 2 hours solving it, still haven't got to anything.
Reply
#9

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)