RobbedRecently Function (Some Problem)
#1

pawn Код:
//Enumerator
enum ShopRobbedRecently
{
    TatooRobbedRecently = 0,
    GymRobbedRecently = 0,
    WellStackPizzaRobbedRecently[2] = 0,
    CluckinBellRobbedRecently[2] = 0
}
new RobbedRecently[ShopRobbedRecently];

//Loop || short code || inside a 1000 mileseconds timer
for(new s; ShopRobbedRecently:s < ShopRobbedRecently; s++)
{
    if(RobbedRecently[ShopRobbedRecently:s] > 1)
    {
        RobbedRecently[ShopRobbedRecently:s] --;
    }
}

//Function || inside /robstore command
RobbedRecently[TatooRobbedRecently] = 100;
if(RobbedRecently[TatooRobbedRecently] >= 1) //if the TatooRobbedRecently is more than 1
    return SendClientMessage(playerid, COLOR_WHITE, "Error: This shop has been robbed recently, please try again later!");
// and so on..

Problem: If that variable is set to 100, automatically all variables inside that enumerator is set to 100 and all shops says 'Error: This shop etc..' it should only
show the error if he's trying to rob that shop that has been robbed recently by someone, but not all the shop. I can't find the problem, that is why I brought this in sa-mp forums
Reply
#2

The problem is how you declared the enum
pawn Код:
enum ShopRobbedRecently
{
    TatooRobbedRecently,
    GymRobbedRecently,
    WellStackPizzaRobbedRecently[2],
    CluckinBellRobbedRecently[2]
}
That should fix it, read the enum section up in pawn-lang.pdf maybe you will find the reason on your own, otherwise just ask again
Reply
#3

Alright, I found something similar, but I don't get it, maybe you could explain it in a simple way?

By the way, as soon as I changed that enumerator, the command /robstore won't work

Enumerator
pawn Код:
enum ShopRobbedRecently
{
    TatooRobbedRecently,
    GymRobbedRecently,
    WellStackPizzaRobbedRecently[2],
    CluckinBellRobbedRecently[3]
}
new RobbedRecently[ShopRobbedRecently];
/robstore command
pawn Код:
CMD:robstore(playerid, params[])
{
    new
        string[ 256 ],
        current_zone = player_zone[playerid]
    ;
   
    if(pTeam[playerid] == TPolice || pTeam[playerid] == TArmy && IsPlayerLEO[playerid] == true) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": You can not rob a store while you are in Law Enforcement!");

    if(IsPlayerInDynamicCP(playerid, rCheckpoints[7]))
    {
        if(zones[current_zone][zone_name] >= zones[93][zone_name] && zones[current_zone][zone_name]  <= zones[95][zone_name]) //Espelanade East Tatoo Shop
        {
            if(RobbedRecently[TatooRobbedRecently] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][RobbingTatoo] = 20;
            RobbedRecently[TatooRobbedRecently] = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Tatoo Shop | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
    }
    if(IsPlayerInDynamicCP(playerid, rCheckpoints[9]))
    {
        if(zones[current_zone][zone_name] == zones[116][zone_name] || zones[current_zone][zone_name] == zones[117][zone_name]) // Garcia Gym
        {
            if(RobbedRecently[GymRobbedRecently] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][RobbingGym] = 20;
            RobbedRecently[GymRobbedRecently] = 300;
            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Gym | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
    }
    if(IsPlayerInDynamicCP(playerid, rCheckpoints[10]))
    {
        if(zones[current_zone][zone_name] >= zones[96][zone_name] && zones[current_zone][zone_name] <= zones[98][zone_name]) //Espelanade North Well Stack Pizza
        {
            if(RobbedRecently[ WellStackPizzaRobbedRecently ][ 0 ] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][ RobbingWellStackPizza ][ 0 ] = 20;
            RobbedRecently[ WellStackPizzaRobbedRecently][ 0 ] = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Well Stack Pizza | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
        if(zones[current_zone][zone_name] == zones[102][zone_name]) //Financial Well Stack Pizza
        {
            if(RobbedRecently[ WellStackPizzaRobbedRecently ][ 1 ] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][ RobbingWellStackPizza ][ 1 ]= 20;
            RobbedRecently[WellStackPizzaRobbedRecently ][ 1 ] = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Well Stack Pizza 1 | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
    }
    if(IsPlayerInDynamicCP(playerid, rCheckpoints[1]))
    {
        if(zones[current_zone][zone_name] >= zones[49][zone_name] && zones[current_zone][zone_name] <= zones[54][zone_name]) //Downton Cluckin Bell
        {
            if(RobbedRecently[ CluckinBellRobbedRecently ][ 0 ]  >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][ CluckinBell ][ 0 ]  = 20;
            RobbedRecently[ CluckinBellRobbedRecently ][ 0 ]  = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Cluckin Bell | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
        if(zones[current_zone][zone_name] >= zones[233][zone_name] && zones[current_zone][zone_name] <= zones[236][zone_name]) //Ocean Flats Cluckin Bell
        {
            if(RobbedRecently[ CluckinBellRobbedRecently ][ 1 ] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][ CluckinBell ][ 1 ] = 20;
            RobbedRecently[ CluckinBellRobbedRecently ][ 1 ] = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Cluckin Bell 1 | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
        if(zones[current_zone][zone_name] >= zones[93][zone_name] && zones[current_zone][zone_name]  <= zones[95][zone_name]) //Espelanade East Cluckin Bell
        {
            if(RobbedRecently[ CluckinBellRobbedRecently ][ 2 ] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
            Robbing[playerid][ CluckinBell ][ 2 ] = 20;
            RobbedRecently[ CluckinBellRobbedRecently ][ 2 ] = 300;

            format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Cluckin Bell 2 | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
            SendLEOMessage(string);

            TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
            SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
            ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
        }
    }
    return 1;
}
Reply
#4

Just read over it, looks fine, I just dont know why you compare "zone_name" like integers

The problem with the enum was that if you set an value in the enum it is the index, means that all constants of the enum pointed to the index 0, thus changing all

Could you tell me what exactly isnt working with the command anymore?
Do you get the Unknown command response, did you checked any case with the crash dedect plugin ?
If no way works use prints till you find the line where the code stops
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just read over it, looks fine, I just dont know why you compare "zone_name" like integers

The problem with the enum was that if you set an value in the enum it is the index, means that all constants of the enum pointed to the index 0, thus changing all

Could you tell me what exactly isnt working with the command anymore?
Do you get the Unknown command response, did you checked any case with the crash dedect plugin ?
If no way works use prints till you find the line where the code stops
I did some debug, and the debug stops and doesn't show when the function zone[...][...] >= ... but when i tried doing zone[...][...] == .. || zone[...][...] == .. the command works

Code that doesn't work
pawn Код:
if(IsPlayerInDynamicCP(playerid, rCheckpoints[7]))
{
    if(zones[current_zone][zone_name] >= zones[93][zone_name] && zones[current_zone][zone_name]  <= zones[95][zone_name]) //Espelanade East Tatoo Shop
    {
        if(RobbedRecently[TatooRobbedRecently] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
        Robbing[playerid][RobbingTatoo] = 20;
        RobbedRecently[TatooRobbedRecently] = 300;

        format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Tatoo Shop | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
        SendLEOMessage(string);

        TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
        SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
        ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
    }
}
Code that does work
pawn Код:
if(IsPlayerInDynamicCP(playerid, rCheckpoints[7]))
{
    if(zones[current_zone][zone_name] == zones[93][zone_name] || zones[current_zone][zone_name]  == zones[94][zone_name] ||
    zones[current_zone][zone_name]  == zones[95][zone_name]) //Espelanade East Tatoo Shop
    {
        if(RobbedRecently[TatooRobbedRecently] >= 1) return SendClientMessage(playerid, COLOR_RED, "Error"COL_WHITE": This shop/store has been robbed recently, please try again later!");
        Robbing[playerid][RobbingTatoo] = 20;
        RobbedRecently[TatooRobbedRecently] = 300;

        format(string,sizeof(string),"[DISPATCH]"COL_GREY": There's a robbery in progress! Suspect: %s | Shop Name: Tatoo Shop | Shop Location: %s",PlayerName(playerid), playerid, GetZoneName(playerid));
        SendLEOMessage(string);

        TextDrawShowForPlayer(playerid, RobberyTD[playerid]);
        SetPlayerAttachedObject(playerid, 1, 1550, 1, 0.1, -0.2, 0, 0, 90, 0.5, 0.8, 0.8, 0.8);
        ApplyAnimation(playerid, "SHOP", "ROB_Shifty", 3.0, 0, 0, 0, 0, 0, 1);
    }
}
Simple Words:

I'm just making my code shorter
using >= 93 and 95 <= instead of == 93 or == 94 or == 95
Reply
#6

Sorry for the wait, I am not constantly watching this

The question what is saved in zones[index][zone_name]
If it is the name (a string) you need to use strcmp (string compare) otherwise you are just comparing the first character
Normally this should give an error but arrays with enums are special and the compiler can't differ them

But what if you just compare the zone ids not their names
pawn Код:
if(93 <= current_zone <= 95)
Reply
#7

This is the variable of the array
pawn Код:
new Float:zones[][zoneinfo] =
{
... //all the zones by Makabos
}
The code you gave me is the same, doesn't work. I'm off to bed, so I'll check more replies tommorow, thanks for helping me though.
Reply
#8

Use the working code and print out the ids and the names of the zones where the command works (test all places)
Put something like that behind the if(zones... so we only get the working results

pawn Код:
printf("%d %s - %s %s %s", current_zone, zones[current_zone][zone_name], zones[93][zone_name], zones[94][zone_name], zones[95][zone_name]);
Also I dont understand why you use checkpoints and zones at the same time
That must be a huge checkpoint which covers 3 zones?
Reply
#9

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Use the working code and print out the ids and the names of the zones where the command works (test all places)
Put something like that behind the if(zones... so we only get the working results

pawn Код:
printf("%d %s - %s %s %s", current_zone, zones[current_zone][zone_name], zones[93][zone_name], zones[94][zone_name], zones[95][zone_name]);
Also I dont understand why you use checkpoints and zones at the same time
That must be a huge checkpoint which covers 3 zones?
WOW, silly me, I remember that I made some changes on the zones and deleted some, without you giving me that DEBUG I didn't notice my problem.. thanks bro I got it fixed now!, atlast I can move it, I was frustrated for the past 2 days, LoL
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)