What's wrong?
#7

You really shouldn't be using else statements in player loops. For instance, if there are 100 people on your server and only one of them is within 5 units of you, it'll spam "~w~Salia jusu ~r~nera ~w~ieskomu zaideju!" 99 times. It only says there isn't a wanted player near you because at the time, the loop was going through your ID. You need to make sure you exclude the player pressing the key from the loop.

pawn Код:
if(PRESSED(KEY_ACTION)) {
        if(iClass[playerid] != ClassPolice || iCopStop[playerid] + 3000 > GetTickCount()) return 1;
       
        new Float: fX, Float: fY, Float: fZ, iWantedFound = 0;
        GetPlayerPos(playerid, fX, fY, fZ);
       
        foreach(new i: Player) {
            if(i != playerid && GetPlayerWantedLevel(i) > 0) { // Exclude the player himself + Run the wanted level code first, so it only checks against people who are actually wanted.
                if(IsPlayerInRangeOfPoint(i, 5, fX, fY, fZ)) {
               
                    GameTextForPlayer(i, "~b~POLICIJA:~n~~b~PRASOME SUSTOTI, ARBA BUS IMTASI KITU VEIKSMU!", 3000, 4);
                    iCopStop[playerid] = GetTickCount();
                    iWantedFound = 1; // Change WantedFound to 1, to indicate that we did find a wanted player.
                    break; // Exit the loop so it doesn't arrest more than one person.
                   
                }
            }
        }
       
        if(!iWantedFound) { // We did not find any wanted players near the player, send error message.
            ShowInfoBox(playerid, "~w~Sis zaidлjas ~g~nera ~w~ieskomas!");
        }
    }
I've commented the alterations I made so you can understand the logic behind the code properly. Hope it helps.
James Carson.
Reply


Messages In This Thread
What's wrong? - by BaubaS - 15.02.2012, 22:06
Re: What's wrong? - by N0FeaR - 15.02.2012, 22:19
Re: What's wrong? - by BaubaS - 16.02.2012, 09:20
Re: What's wrong? - by JamesC - 16.02.2012, 09:29
Re: What's wrong? - by BaubaS - 16.02.2012, 16:30
Re: What's wrong? - by BaubaS - 16.02.2012, 19:54
Re: What's wrong? - by JamesC - 17.02.2012, 12:45

Forum Jump:


Users browsing this thread: 1 Guest(s)