SA-MP Forums Archive
Help: Array must be indexed? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Help: Array must be indexed? (/showthread.php?tid=191235)



Help: Array must be indexed? - Kyle_Olsen - 18.11.2010

Got a little problem here that I can't figure out.

Here's the error code:
Quote:

error 033: array must be indexed (variable "name")

The line is commented out

Code:
if (!strcmp(cmdtext, "/lock", true, 5))
	{
		new closestcar = GetClosestVehicle(playerid);
		if(IsPlayerInAnyVehicle(playerid) || GetDistanceToVehicle(playerid, closestcar) <= 10){
		   
			new file[128];
			     format(file, sizeof(file), SERVER_VEHICLE_FILE, closestcar);
			     new Locked = dini_Int(file, "Locked");
			     new vehfaction = dini_Int(file, "Faction");
			     new vehowner = dini_Int(file, "Owner");
			     new name[MAX_PLAYER_NAME], usrfile[256];

                 GetPlayerName(playerid, name, sizeof(name));
                 format(usrfile, sizeof(usrfile), SERVER_USER_FILE, name);
			     new Faction = dini_Int(usrfile, "Faction");
			     new AdminLevel = dini_Int(usrfile, "AdminLevel");
			     if(Faction == vehfaction || vehowner == name || AdminLevel >= 2){ // error is at this line, it says.
			     new loccet;
            
			if(Locked == 2){
				  loccet = 1;
				  SendClientMessage(playerid, WHITE, "Vehicle was locked" );
			}else{
				  loccet = 0;
				  SendClientMessage(playerid, WHITE, "Vehicle was unlocked" );
			}
                 for(new u = 0; u < MAX_PLAYERS; u++)
	            {

		            SetVehicleParamsForPlayer( closestcar, u, 0, loccet );
		            if(loccet == 1){
		            
		            
		            dini_IntSet(file, "Locked", 2);
		            }else{
		            
		            dini_IntSet(file, "Locked", 1);
		            }
				}
				}else{
					  SendClientMessage(playerid, WHITE, "You may only lock a vehicle belonging to you or your faction." );
				}

		}else{
			SendClientMessage(playerid, WHITE, "You have to be in or near the vehicle you want to lock." );
		}



Re: Help: Array must be indexed? - willsuckformoney - 18.11.2010

Change in that line where it says 'name' and replace it with 'playerid' that will work.


Re: Help: Array must be indexed? - JaTochNietDan - 18.11.2010

Okay here is the issue, you're comparing an integer with an array, which won't work.

I'm guessing you meant for them to be strings, in which case you need to modify your code slightly. Here is what you need to change:

pawn Code:
new vehfaction = dini_Int(file, "Faction");
new vehowner = dini_Int(file, "Owner");

new Faction = dini_Int(usrfile, "Faction");
Should now be

pawn Code:
new vehfaction[24] = dini_Get(file, "Faction");
new vehowner[24] = dini_Get(file, "Owner");

new Faction[24] = dini_Get(usrfile, "Faction");
Also this now makes the checks invalid, as you cannot compare strings in Pawn like that, it requires the function strcmp, so you need to change the following:

pawn Code:
if(Faction == vehfaction || vehowner == name || AdminLevel >= 2)
to

pawn Code:
if(!strcmp(Faction,vehfaction,true) || !strcmp(vehowner,name,true) || AdminLevel >= 2)
Hope that helps!