Why can't I do this?
#1

I'm trying to make a custom function for determining if a player entered a gang zone (or in this case, bot zone). This is my code:

pawn Код:
new Float:BotZones[][] =
{
    {-1654.446289,-161.187805,-1334.446289,-561.187805}
};

stock IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if (x > minx && x < maxx && y > miny && y < maxy) return 1;
    else return 0;
}

timer OnPlayerEnterBotZone[10000](playerid)
{
    for(new z = 0; z < BotZones; z++) // line 394
    {
        if(IsPlayerInArea(playerid, BotZones[z][0], BotZones[z][1], BotZones[z][2], BotZones[z][3]))
        {
            if(!GetPVarType(playerid, "InBotZone"))
            {
                SetPVarInt(playerid, "InBotZone", 1);
                // TextDrawSetString(SFAirportWarnTD[playerid], "~w~Please note that there are ~r~bots ~w~driving around this area.~n~~n~Leave the ~r~bots ~w~alone, or you will be ~r~admin-jailed~w~!");
            }
        }
    }
}

timer OnPlayerExitBotZone[10000](playerid)
{
    for(new z = 0; z < BotZones; z++) // line 409
    {
        if(!IsPlayerInArea(playerid, BotZones[z][0], BotZones[z][1], BotZones[z][2], BotZones[z][3]))
        {
            if(GetPVarType(playerid, "InBotZone"))
            {
                DeletePVar(playerid, "InBotZone");
                //TextDrawShowForPlayer(playerid, SFAirportWarnTD[playerid]);
            }
        }
    }
}
These are the errors:

Код:
(394) : error 033: array must be indexed (variable "BotZones")
(409) : error 033: array must be indexed (variable "BotZones")
I'm sure it has something to do with BotZones being a float and the loop doesn't want to process it because of that- but why not? And what's the other option for doing this?

Oh and I know I only have a single value in BotZones, but I'll be adding a few more later.

EDIT: This was my mistake. I solved it by replacing "BotZones" in the loop with "sizeof(BotZones)" because I'm an idiot!
Reply
#2

pawn Код:
new Float:BotZones[][4] =
{
    {-1654.446289,-161.187805,-1334.446289,-561.187805}
};

stock IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if (x > minx && x < maxx && y > miny && y < maxy) return 1;
    else return 0;
}

timer OnPlayerEnterBotZone[10000](playerid)
{
    for(new z = 0; z < BotZones; z++) // line 394
    {
        if(IsPlayerInArea(playerid, BotZones[z][0], BotZones[z][1], BotZones[z][2], BotZones[z][3]))
        {
            if(!GetPVarType(playerid, "InBotZone"))
            {
                SetPVarInt(playerid, "InBotZone", 1);
                // TextDrawSetString(SFAirportWarnTD[playerid], "~w~Please note that there are ~r~bots ~w~driving around this area.~n~~n~Leave the ~r~bots ~w~alone, or you will be ~r~admin-jailed~w~!");
            }
        }
    }
}

timer OnPlayerExitBotZone[10000](playerid)
{
    for(new z = 0; z < BotZones; z++) // line 409
    {
        if(!IsPlayerInArea(playerid, BotZones[z][0], BotZones[z][1], BotZones[z][2], BotZones[z][3]))
        {
            if(GetPVarType(playerid, "InBotZone"))
            {
                DeletePVar(playerid, "InBotZone");
                //TextDrawShowForPlayer(playerid, SFAirportWarnTD[playerid]);
            }
        }
    }
}
Try that?
Reply
#3

That's not going to help, leaving the [][]'s empty mean there can be unlimited values in the array.

EDIT: This was my mistake. I solved it by replacing "BotZones" in the loop with "sizeof(BotZones)" because I'm an idiot!
Reply
#4

sizeof BotZones


.. reading the error carefully might give u a hint on which line the problem is
Reply
#5

Quote:
Originally Posted by jamesbond007
Посмотреть сообщение
sizeof BotZones


.. reading the error carefully might give u a hint on which line the problem is
I knew what line the problem was on and I already resolved the issue myself. Thanks for the response though!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)