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



array must be indexed - DonBonanno - 31.03.2015

Hello..what i need to do ?

Код:
D:\Los Santos Roleplay\lsrp\gamemodes\ls-rp.pwn(10259) : error 033: array must be indexed (variable "bodypart")
D:\Los Santos Roleplay\lsrp\gamemodes\ls-rp.pwn(10259) : error 033: array must be indexed (variable "bodypart")

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
{
	if(PlayerIsWounded(playerid))
	{
		SetPlayerHealth(playerid, 1000.0);
	}
	if((0 <= weaponid <= 46) || weaponid == 54)
	{
	    new bodypart[128];
		if(BODY_PART_TORSO <= bodypart <= BODY_PART_HEAD) Damage[playerid][(bodypart - 3)][weaponid]++;
	}
    return 1;
}
Here i heve this errors:

Код:
if(BODY_PART_TORSO <= bodypart <= BODY_PART_HEAD) Damage[playerid][(bodypart - 3)][weaponid]++;



Re : array must be indexed - StreetRP - 31.03.2015

Show bodypart


Re: array must be indexed - DonBonanno - 31.03.2015

Код:
GetBodyPartName(bodypart)
{
	new part[20];
	switch(bodypart)
	{
		case BODY_PART_TORSO: part = "BUST";
		case BODY_PART_GROIN: part = "SOLD";
		case BODY_PART_LEFT_ARM: part = "MANA STANGA";
		case BODY_PART_RIGHT_ARM: part = "MANA DREAPTA";
		case BODY_PART_LEFT_LEG: part = "PICIORUL STANG";
		case BODY_PART_RIGHT_LEG: part = "PICIORUL DREPT";
		case BODY_PART_HEAD: part = "CAP";
		default: part = "NIMIC";
	}
	return part;
}
This ?


Re: array must be indexed - DonBonanno - 31.03.2015

Anyone please ?


Re: array must be indexed - zT KiNgKoNg - 31.03.2015

pawn Код:
if(BODY_PART_TORSO <= bodypart <= BODY_PART_HEAD) Damage[playerid][(bodypart - 3)][weaponid]++;
Your issue is here, as far as I can tell. "<= bodypart <=" & "bodypart", as you've used 'new bodypart[INDEX]', and you're not using it correctly.


Re: array must be indexed - DonBonanno - 31.03.2015

if(BODY_PART_TORSO <= "bodypart" <= BODY_PART_HEAD) Damage[playerid][(bodypart - 3)][weaponid]++;

It's correctly ?


Re: array must be indexed - DonBonanno - 02.04.2015

Anybody ?


Re: array must be indexed - Lordzy - 02.04.2015

"bodypart" is supposed to be a variable and it can be retrieved from the callback itself than defining an array. This is how it should look like:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    if(PlayerIsWounded(playerid))
    {
        SetPlayerHealth(playerid, 1000.0);
    }
    if((0 <= weaponid <= 46) || weaponid == 54)
    {
       // new bodypart[128];
        if(BODY_PART_TORSO <= bodypart <= BODY_PART_HEAD) Damage[playerid][(bodypart - 3)][weaponid]++;
    }
    return 1;
}



Re: array must be indexed - DonBonanno - 02.04.2015

Now i have a error : function heading differs from prototype

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)


Re: array must be indexed - PowerPC603 - 02.04.2015

You were using integer operations on strings, you can't compare strings that way.

pawn Код:
new bodypart[128];
if(BODY_PART_TORSO <= bodypart <= BODY_PART_HEAD)
You are checking 2 integer values (BODY_PART_TORSO and BODY_PART_HEAD) against a string-type variable (bodypart), which btw is empty as you just declared it but you didn't put anything inside it.

As for the bodypart parameter, you need to upgrade your server to 0.3z.
https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage