SA-MP Forums Archive
Why does it send the same thing for 3 times? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Why does it send the same thing for 3 times? (/showthread.php?tid=304242)



Why does it send the same thing for 3 times? - vent - 17.12.2011

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.


Respuesta: Why does it send the same thing for 3 times? - [DOG]irinel1996 - 17.12.2011

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!


Re: Why does it send the same thing for 3 times? - Neo Karls - 17.12.2011

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


Re: Why does it send the same thing for 3 times? - vent - 17.12.2011

Thanks, works and +rep for you.


Respuesta: Why does it send the same thing for 3 times? - [DOG]irinel1996 - 17.12.2011

You're welcome.

Thank you.