Reduce Wanted Level
#1

Here is my code to reduce the players wanted level every 5 minutes (if they have stars and are not near a cop)
It did work at once point, but either i changed the code or something out of the ordinary is happening
Even if no cops are connect it still doesnt remove a star
pawn Код:
forward WantedLevelReduce();
pawn Код:
public OnGameModeInit()
{
    SetTimer("WantedLevelReduce",300_000, true);
pawn Код:
public WantedLevelReduce()
{
    new string[100];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new cop = Info[i][Team] == BP;
        new plwl = GetPlayerWantedLevel(i);
        if(Info[i][Team] != BP) return SendClientMessageToAll(COLOR_GREEN, "You should have lost a star"); //Just for debug to see if the star was supposed to be removed
        if(plwl <= 0)
        {
            return 0;
        }
        if(plwl >= 1)
        {
            if(GetDistanceBetweenPlayers(i,cop) >= 80 || !IsPlayerConnected(cop))
            {
                SetPlayerWantedLevel(i, plwl -1);
                plwl = GetPlayerWantedLevel(i);
                format(string, sizeof(string), "Wanted Level Decreased To: %d",plwl);
                SendClientMessage(i, GetPlayerColor(i), string);
            }
        }
    }
    return 1;
}
The message "You should have lost a star" does appear in game but stars are not removed
Reply
#2

Well yeah ding-dong, your code "stops" after that debug message because you "return" there.
Also what's with this var assignment here, shouldn't it just equal the players team?
Код:
new cop = Info[i][Team] == BP;
Also your IsPlayerConnected check is useless there as you're already checking the distance between two (connected) players.
Reply
#3

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Well yeah ding-dong, your code "stops" after that debug message because you "return" there.
Also what's with this var assignment here, shouldn't it just equal the players team?
Код:
new cop = Info[i][Team] == BP;
Also your IsPlayerConnected check is useless there as you're already checking the distance between two (connected) players.
I just added the debug message before posting to forums, the code wasnt working before the message either. But i see how that would affect the code.
Fixed new cop to just
pawn Код:
if(GetDistanceBetweenPlayers(i,Info[i][Team] == BP) >= 80)
and removed isplayerconnected


pawn Код:
public WantedLevelReduce()
{
    new string[100];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        new plwl = GetPlayerWantedLevel(i);
        if(plwl >= 1)
        {
            if(GetDistanceBetweenPlayers(i,Info[i][Team] == BP) >= 80)
            {
                plwl--;
                SetPlayerWantedLevel(i, plwl);
                format(string, sizeof(string), "Wanted Level Decreased To: %d",plwl);
                SendClientMessage(i, GetPlayerColor(i), string);
            }
        }
    }
    return 1;
}
Reply
#4

Yeah, you just don't need (again) to stop the loop at the first player that isn't wanted, remove ANY "returns", you're already checking "if (plwl >= 1)" you do not need to make the opposite!
Also, use "plwl--; " before SetPlayerWantedLevel, because (afaik) you do not need to call the GetPlayerWantedLevel again as you already have it in a variable.
One cardinal mistake though: both of the inputs for GetDistanceBetweenPlayers have to be player IDs!
Reply
#5

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Yeah, you just don't need (again) to stop the loop at the first player that isn't wanted, remove ANY "returns", you're already checking "if (plwl >= 1)" you do not need to make the opposite!
Also, use "plwl--; " before SetPlayerWantedLevel, because (afaik) you do not need to call the GetPlayerWantedLevel again as you already have it in a variable.
One cardinal mistake though: both of the inputs for GetDistanceBetweenPlayers have to be player IDs!
Thank you very much for your help, the code looks a lot more clean.
Also "One cardinal mistake though: both of the inputs for GetDistanceBetweenPlayers have to be player IDs! " What do you mean?
Reply
#6

new cop = Info[i][Team] == BP;

The value stored in cop would be of boolean algebra. Change it.
Reply
#7

Quote:
Originally Posted by Norrin
Посмотреть сообщение
new cop = Info[i][Team] == BP;

The value stored in cop would be of boolean algebra. Change it.
This line is already removed.
Reply
#8

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
Thank you very much for your help, the code looks a lot more clean.
Also "One cardinal mistake though: both of the inputs for GetDistanceBetweenPlayers have to be player IDs! " What do you mean?
I meant specifically this line:
Код:
if(GetDistanceBetweenPlayers(i,Info[i][Team] == BP) >= 80)
The part in red evaluates to either true or false (1 or 0), which I believe, is not what you want. Both parameters must be valid playerids.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)