[Help] About fail else in if..
#1

Hi .. i have problem with if in OnPlayerKeyStateChange for police on control closest players.. But when player (i) is wanted and he is close from police, so send SCM "Nobody in yours closer not wanted" + GameText "THIS PLAYER IS WANTED", but i want show only gametexts for police "THIS PLAYER IS WANTED" when player (i) is wanted and he is close from police. Sorry for poorly explained. Maybe you can understand from the script.

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(PRESSED(KEY_ACTION) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && iPlayerRole[playerid] == 4)
	{
	   
		for(new i=0;i<MAX_PLAYERS;i++)
		{
			if(GetDistanceBetweenPlayers(playerid, i) <= 10 && GetPlayerWantedLevel(i) >= 1 && i != playerid)
			{
				GameTextForPlayer(i,"~h~~w~Police want you to stop!~n~~r~STOP",5000,4 ); //message for wanted player from police
				GameTextForPlayer(playerid,"~h~~r~This player is wanted!", 5000, 4); //message for police
				lastcolor = GetPlayerColor(i);
				SetPlayerMarkerForPlayer(playerid, i, COLOR_RED);
				SetTimerEx("oldcolor", 5000, 0,"i",i); //in next public give wanted player his old color..
			} else {
			SendClientMessage(playerid, COLOR_BLUE, "Nobody in yours close not wanted");	
			}
		}
	
	}
	
	return 1;
}
Reply
#2

I really could not understand what you were asking. Try this though.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_ACTION) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && iPlayerRole[playerid] == 4)
    {
        for(new i=0;i<MAX_PLAYERS;i++)
        {
            if(GetDistanceBetweenPlayers(playerid, i) <= 10 && GetPlayerWantedLevel(i) >= 1)
            {
                GameTextForPlayer(i,"~h~~w~Police want you to stop!~n~~r~STOP",5000,4 ); //message for wanted player from police
                GameTextForPlayer(playerid,"~h~~r~This player is wanted!", 5000, 4); //message for police
                lastcolor = GetPlayerColor(i);
                SetPlayerMarkerForPlayer(playerid, i, COLOR_RED);
                SetTimerEx("oldcolor", 5000, 0,"i",i); //in next public give wanted player his old color..
                return 1;
            }
        }
        SendClientMessage(playerid, COLOR_BLUE, "Nobody in yours close not wanted");
        return 1;
    }
}
Reply
#3

You had the message inside the loop itself, which made it spam. Simply put the text after the loop and return the callback when you've found the wanted player.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_ACTION) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && iPlayerRole[playerid] == 4)
    {
        for(new i; i < MAX_PLAYERS; i++)
        {
            if(i == playerid || !IsPlayerConnected(i)) continue;

            if(GetDistanceBetweenPlayers(playerid, i) <= 10.0)
            {
                if(0 < GetPlayerWantedLevel(i))
                {
                    GameTextForPlayer(i, "~h~~w~Police want you to stop!~n~~r~STOP", 5000, 4); //message for wanted player from police
                    GameTextForPlayer(playerid, "~h~~r~This player is wanted!", 5000, 4); //message for police

                    lastcolor = GetPlayerColor(i);
                    SetPlayerMarkerForPlayer(playerid, i, COLOR_RED);
                    SetTimerEx("oldcolor", 5000, 0, "i", i); //in next public give wanted player his old color..
                    return 1;
                }
            }
        }

        SendClientMessage(playerid, COLOR_BLUE, "There aren't any wanted players near you.");
        return 1;
    }
    return 1;
}
Edit: Sorry I was writing this post and didn't notice this thread was replied meanwhile.
Reply
#4

Thank you very much boys.. .))
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)