PDA

View Full Version : Why can't I do this?


Scenario
17/01/2012, 11:21 PM
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:

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! :D

Snowman12
17/01/2012, 11:24 PM
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?

Scenario
17/01/2012, 11:27 PM
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! :D

jamesbond007
17/01/2012, 11:53 PM
sizeof BotZones


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

Scenario
18/01/2012, 12:07 AM
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!