SA-MP Forums Archive
Why can't I do this? - 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 can't I do this? (/showthread.php?tid=311712)



Why can't I do this? - Scenario - 17.01.2012

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!


Re: Why can't I do this? - Snowman12 - 17.01.2012

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?


Re: Why can't I do this? - Scenario - 17.01.2012

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!


Re: Why can't I do this? - jamesbond007 - 17.01.2012

sizeof BotZones


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


Re: Why can't I do this? - Scenario - 17.01.2012

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!