SA-MP Forums Archive
error 033: array must be indexed + Rep - 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: error 033: array must be indexed + Rep (/showthread.php?tid=499659)



error 033: array must be indexed + Rep - Blademaster680 - 09.03.2014

Please help me I have this problem.
error 033: array must be indexed (variable "VehiclePos")
I am trying to make it so when the player buys the vehicle it will spawn it in one the of locations I have set.
Here is my code:
Код:
new Float:Dealership1Pos[2][3] =
	{
	    { 1671.8918,-1072.8073,25.7088 },
	    { 1667.2391,-1124.2771,26.3949 }
	};
Under OnDIalogResponse
Код:
GivePlayerMoney(playerid, -VehicleValue[id]);
			PlayerInfo[playerid][pCash] -= VehicleValue[id];
			format(str, sizeof(str), "MoneyTrace: %s bought a cellphone for $%i", GetName(playerid), VehicleValue[id]);
   			Log("/logs/moneytrace.txt", str);
			new dealerid = strval(VehicleOwner[id]);
            new rand = random(sizeof(Dealership1Pos));
			VehicleCreated[freeid] = VEHICLE_PLAYER;
			VehicleModel[freeid] = VehicleModel[id];
			//VehiclePos[freeid] = DealershipPos[dealerid];
			VehiclePos[freeid] = Dealership1Pos[rand][0], Dealership1Pos[rand][1], Dealership1Pos[rand][2];
			VehicleColor[freeid] = VehicleColor[id];
			VehicleInterior[freeid] = VehicleInterior[id];
			VehicleWorld[freeid] = VehicleWorld[id];
			VehicleValue[freeid] = VehicleValue[id];
			GetPlayerName(playerid, VehicleOwner[freeid], sizeof(VehicleOwner[]));
			VehicleOwner[freeid] = GetPlayerNameEx(playerid);
			VehicleNumberPlate[freeid] = DEFAULT_NUMBER_PLATE;



Re: error 033: array must be indexed + Rep - Aerotactics - 09.03.2014

pawn Код:
new Float:Dealership1Pos[][3] =
{
    { 1671.8918,-1072.8073,25.7088 },
    { 1667.2391,-1124.2771,26.3949 }
};
I don't think Dealership1Pos[rand][] will give you the correct random location unless you've specified a random number generator somewhere else.


Re: error 033: array must be indexed + Rep - Blademaster680 - 09.03.2014

Tried that exactly the same problem


Re: error 033: array must be indexed + Rep - Aerotactics - 09.03.2014

Oh, misread your topic, sorry.

Instead of:
pawn Код:
VehiclePos[freeid] = Dealership1Pos[rand][0], Dealership1Pos[rand][1], Dealership1Pos[rand][2];
Do:
pawn Код:
new rand = random(sizeof(Dealership1Pos));
VehiclePos[freeid] = Dealership1Pos[rand][0], Dealership1Pos[rand][1], Dealership1Pos[rand][2];
This will give you a random number correctly.