#1

Hello. I wanted to create a Job. Scavenger. But, I have a problem. When a player enter in first checkpoint, he got payed like he finished all checkpoints. Something like:



Here's my code. Sorry because isn't in English, but if a variable, code it's wrong, can fix it? I want to know what I did wrong, not just the fix code. + Rep of course.

pawn Код:
#include <a_samp>
#include <zcmd>

#define COLOR_LIGHTBLUE 0x33CCFFAA

new Job[MAX_PLAYERS];
new GunoierPick;
new GunoierJob[256];

public OnFilterScriptInit()
{
    GunoierPick = CreatePickup(1239, 2, 2195.8579,-1972.8126,13.5589);
    Create3DTextLabel("Job-ul Gunoier\n\n/Gunoier", 0xFFFFFFFF, 2195.8579,-1972.8126,13.5589, 40.0, 0, 0);
   
    //=========================GUNOIER==========================================
    AddStaticVehicle(408,2191.7610,-1994.1752,14.0901,177.4823,27,210); //
    AddStaticVehicle(408,2185.9167,-1991.8806,14.0914,175.8309,27,210); //
    AddStaticVehicle(408,2162.3123,-1973.5996,14.0898,92.3401,27,210); //
    AddStaticVehicle(408,2169.8967,-1983.0371,14.1012,265.1483,27,210); //
    //==========================================================================
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == GunoierPick)
    {
        SendClientMessage(playerid, -1, "{FFCC33}Pentru a lua job-ul de Gunoier, scrie: {FF0000}/Gunoier {FFCC33}!");
    }
    return 1;
}

CMD:gunoier(playerid, params[])
{
    if(Job[playerid] == 1) return SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FFCC33}Ai deja un job. Scrie: {FF0000}/Demisie {FFCC33}pentru a-ti da demisia!");
    if(IsPlayerInRangeOfPoint(playerid, 5.0, 2195.8579,-1972.8126,13.5589))
    {
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "Te-ai angajat ca si Gunoier!");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "Pentru a incepe munca, va rugam scrieti: {FF0000}/StartG {FFCC33}!");
        Job[playerid] = 1;
    }
    else
    {
        SendClientMessage(playerid, -1, "{FFCC33}Nu esti destul de aproape de job!");
    }
    return 1;
}

CMD:startg(playerid, params[])
{
    GunoierJob[playerid] = 1;
    SetPlayerCheckpoint(playerid, 2418.8784,-1779.1632,14.0185,5.0);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "Ai inceput munca ca fiind un Gunoier!");
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "Urmareste checkpoint-urile rosii de pe harta pentru a fi plătit!");
    return 1;
}

CMD:demisia(playerid, params[])
{
    Job[playerid] = 0;
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FFCC33}Ti-ai dat demisia de la job! Acum iti poti lua alt job!");
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    if(GunoierJob[playerid] == 1)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2741.6865,-1504.8694,30.9064, 5.0);
        GivePlayerMoney(playerid, 5043);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}5043 $ {FFCC33}pentru primul transport al gunoiului!");
        GunoierJob[playerid] = 2;
    }
    if(GunoierJob[playerid] == 2)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2703.7903,-1065.6555,69.8232, 5.0);
        GivePlayerMoney(playerid, 4321);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}4321 $ {FFCC33}pentru al doilea transport al gunoiului!");
        GunoierJob[playerid] = 3;
    }
    if(GunoierJob[playerid] == 3)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2257.4766,-1150.7429,27.3426, 5.0);
        GivePlayerMoney(playerid, 6311);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}6311 $ {FFCC33}pentru al treilea transport al gunoiului!");
        GunoierJob[playerid] = 4;
    }
    if(GunoierJob[playerid] == 4)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2390.6865,-1726.5602,14.0437, 5.0);
        GivePlayerMoney(playerid, 3954);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}3954 $ {FFCC33}pentru al patrulea transport al gunoiului!");
        GunoierJob[playerid] = 5;
    }
    if(GunoierJob[playerid] == 5)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2229.7378,-1977.7834,13.9928, 5.0);
        GivePlayerMoney(playerid, 9213);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}9213 $ {FFCC33}pentru ultimul transport al gunoiului!");
        GunoierJob[playerid] = 6;
    }
    if(GunoierJob[playerid] == 6)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2229.7378,-1977.7834,13.9928, 5.0);
        GivePlayerMoney(playerid, 9213);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "Ti-ai terminat tura! Mai poti face ture suplimentare dacă mai doresti!");
        GunoierJob[playerid] = 0;
    }
    return 1;
}
Reply
#2

pawn Код:
if(GunoierJob[playerid] == 1)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2741.6865,-1504.8694,30.9064, 5.0);
        GivePlayerMoney(playerid, 5043);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}5043 $ {FFCC33}pentru primul transport al gunoiului!");
        GunoierJob[playerid] = 2;
        return 1; // Add this in all if-statements
    }
The problem is that the first if-statement is executed, the next job-step is set (value 2), and the next if-statement is executed as well, because the second if-condition becomes true.
This is done all the way until the end.

Putting "return 1;" in all if-statements skips them all.

Or convert it to a switch-case structure, then only 1 condition is executed, like this:
pawn Код:
switch (GunoierJob[playerid])
{
    case 1:
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2741.6865,-1504.8694,30.9064, 5.0);
        GivePlayerMoney(playerid, 5043);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}5043 $ {FFCC33}pentru primul transport al gunoiului!");
        GunoierJob[playerid] = 2;
    }
    case 2:
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2703.7903,-1065.6555,69.8232, 5.0);
        GivePlayerMoney(playerid, 4321);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}4321 $ {FFCC33}pentru al doilea transport al gunoiului!");
        GunoierJob[playerid] = 3;
    }
    ...
}
Reply
#3

Quote:
Originally Posted by PowerPC603
Посмотреть сообщение
pawn Код:
if(GunoierJob[playerid] == 1)
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2741.6865,-1504.8694,30.9064, 5.0);
        GivePlayerMoney(playerid, 5043);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}5043 $ {FFCC33}pentru primul transport al gunoiului!");
        GunoierJob[playerid] = 2;
        return 1; // Add this in all if-statements
    }
The problem is that the first if-statement is executed, the next job-step is set (value 2), and the next if-statement is executed as well, because the second if-condition becomes true.
This is done all the way until the end.

Putting "return 1;" in all if-statements skips them all.

Or convert it to a switch-case structure, then only 1 condition is executed, like this:
pawn Код:
switch (GunoierJob[playerid])
{
    case 1:
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2741.6865,-1504.8694,30.9064, 5.0);
        GivePlayerMoney(playerid, 5043);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}5043 $ {FFCC33}pentru primul transport al gunoiului!");
        GunoierJob[playerid] = 2;
    }
    case 2:
    {
        DisablePlayerCheckpoint(playerid);
        SetPlayerCheckpoint(playerid, 2703.7903,-1065.6555,69.8232, 5.0);
        GivePlayerMoney(playerid, 4321);
        SendClientMessage(playerid, -1, "{FFCC33}Ai primit {FF0000}4321 $ {FFCC33}pentru al doilea transport al gunoiului!");
        GunoierJob[playerid] = 3;
    }
    ...
}
Love u man.

-
-
-
-
-
-
Just joke man, thank you. +rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)