Second and third checkpoint isnt showing up!
#1

I have scripted a sweeper job, the first checkpoins shows up but the second and third not.

The CMD:

pawn Код:
if(strcmp(cmd, "/startsweeping", true) == 0)
    {
        new tmpcar = GetPlayerVehicleID(playerid);
        if(PlayerInfo[playerid][pJob] == 2)
        {
            if(Sweeping[playerid] == 0)
            {
                if(IsASweepingCar(tmpcar))
                {
                    SendClientMessage(playerid, COLOR_LIGHTBLUE, "You can now start sweeping.");
                    CP[playerid] = 1;
                    Sweeping[playerid] = 1;
                    SetPlayerCheckpoint(playerid, 2140.5813,-2115.7019,13.2051, 5);
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_CREAM, "You are not in a street sweeping car.");
                    return 1;
                }
            }
            else
            {
                SendClientMessage(playerid, COLOR_CREAM, "You are already sweeping.");
                return 1;
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_CREAM, "You are not a street sweeper.");
            return 1;
        }
    }

public OnPlayerEnterCheckpoint:

pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
    new pveh = GetPlayerVehicleID(playerid);
    if(CP[playerid]==1)
    {
        if(IsASweepingCar(pveh) && Sweeping[playerid] == 1)
        {
            DisablePlayerCheckpoint(playerid);
            SetPlayerCheckpoint(playerid, 1987.5314,-2108.5859,13.1661, 5);
            CP[playerid] = 2;
            GameTextForPlayer(playerid, "~g~+$50", 2000, 3);
            GivePlayerMoney(playerid, 50);
            Sweeping[playerid] = 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not in a sweeper.");
        }
    }
    else if(CP[playerid]==2 && Sweeping[playerid] == 1)
    {
        if(IsASweepingCar(pveh))
        {
            DisablePlayerCheckpoint(playerid);
            SetPlayerCheckpoint(playerid, 2045.5214,-1935.0801,13.1432, 5);
            CP[playerid] = 3;
            GameTextForPlayer(playerid, "~g~+$50", 2000, 3);
            GivePlayerMoney(playerid, 50);
            Sweeping[playerid] = 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not in a sweeper.");
        }
    }
    else if(CP[playerid]==3 && Sweeping[playerid] == 1)
    {
        if(IsASweepingCar(pveh))
        {
            DisablePlayerCheckpoint(playerid);
            SetPlayerCheckpoint(playerid, 2083.7595,-1831.7170,13.2008, 5);
            CP[playerid] = 4;
            GameTextForPlayer(playerid, "~g~+$50", 2000, 3);
            GivePlayerMoney(playerid, 50);
            Sweeping[playerid] = 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not in a sweeper.");
        }
    }
    return 1;
}
Reply
#2

HOw about using streamer?
Reply
#3

What do you mean :3
Reply
#4

Wouldn't it be much simpler if you used a single variable? If you simply save the checkpoint count in Sweeping[playerid], you can still check if it's not zero. You should also always try to avoid double code. If you were to change the reward, for example, you would've to change the lines one by one which isn't very practical. I optimized your script:

pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
    new pveh = GetPlayerVehicleID(playerid);

    // --------------------------------------------------------------------
    if(Sweeping[playerid])
    {
        DisablePlayerCheckpoint(playerid);
       
        if(!IsASweepingCar(pveh))
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not in a sweeper.");
            Sweeping[playerid] = 0; //end
            return 1;
        }

        switch(Sweeping[playerid])
        {
            case 1: SetPlayerCheckpoint(playerid, 1987.5314,-2108.5859,13.1661, 5);
            case 2: SetPlayerCheckpoint(playerid, 2045.5214,-1935.0801,13.1432, 5);
            case 3: SetPlayerCheckpoint(playerid, 2083.7595,-1831.7170,13.2008, 5);
            case 4: Sweeping[playerid] = -1; // this will reset back to 0 by the ++ statement that follows; -1 + 1 = 0
           
            default: SendClientMessage(playerid, COLOR_GREY, "Script Error: Unknown checkpoint.");
        }
       
        Sweeping[playerid]++;
        GameTextForPlayer(playerid, "~g~+$50", 2000, 3);
        GivePlayerMoney(playerid, 50);
    }
    // --------------------------------------------------------------------
    return 1;
}
Reply
#5

Thank you vince, also what about the cmd? How should I make it? if(strcmp(cmd, "/startsweeping", true) == 0).......... Sweeping[playerid] = 1; and with which checkpoint I should start? The cmd is displayed on top
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)