Why does it send the same thing for 3 times?
#1

pawn Code:
CMD:takejob(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pJob] == 0)
        {
            if (IsPlayerInRangeOfPoint(playerid, 4, -323.0505,2675.5161,63.6797)) //Mechanic
            {
                PlayerInfo[playerid][pJob] = 1;
                SendClientMessage(playerid, COLOR_WHITE,"You are mechanic now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY,"You are not in the right place.");
            }

            if (IsPlayerInRangeOfPoint(playerid, 4, -245.1974,2724.2322,62.6875)) //Streetsweeper
            {
                PlayerInfo[playerid][pJob] = 2;
                SendClientMessage(playerid, COLOR_WHITE,"You are streetsweeper now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY,"You are not in the right place.");
            }

            if (IsPlayerInRangeOfPoint(playerid,4, -227.7350,2721.9934,62.6875)) //Postman
            {
                PlayerInfo[playerid][pJob] = 3;
                SendClientMessage(playerid, COLOR_WHITE,"You are postman now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY,"You are not in the right place.");
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "You already have an job. Write /quitjob to quit job.");
        }
    }
    return 1;
}
Here is the command. The problem is it sends "You are not in the right place" three times.
Reply
#2

Try now.
pawn Code:
CMD:takejob(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pJob] == 0)
        {
            if(IsPlayerInRangeOfPoint(playerid, 4, -323.0505,2675.5161,63.6797)) //Mechanic
            {
                PlayerInfo[playerid][pJob] = 1;
                SendClientMessage(playerid, COLOR_WHITE,"You are mechanic now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
            }
            else if(IsPlayerInRangeOfPoint(playerid, 4, -245.1974,2724.2322,62.6875)) //Streetsweeper
            {
                PlayerInfo[playerid][pJob] = 2;
                SendClientMessage(playerid, COLOR_WHITE,"You are streetsweeper now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
            }
            else if(IsPlayerInRangeOfPoint(playerid,4, -227.7350,2721.9934,62.6875)) //Postman
            {
                PlayerInfo[playerid][pJob] = 3;
                SendClientMessage(playerid, COLOR_WHITE,"You are postman now.");
                SendClientMessage(playerid, COLOR_WHITE,"You should check /help for new commands.");
            }
            else SendClientMessage(playerid, COLOR_GREY,"You are not in the right place.");
        }
        else SendClientMessage(playerid, COLOR_GREY, "You already have an job. Write /quitjob to quit job.");
    }
    return 1;
}
Best regards!
Reply
#3

I think its because you had put else condition in between every if condition try else if
Reply
#4

Thanks, works and +rep for you.
Reply
#5

You're welcome.

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)