SA-MP Forums Archive
Pickup armour - 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: Pickup armour (/showthread.php?tid=597070)



Pickup armour - SilverStand - 26.12.2015

Error on server log

Код:
[20:53:31] [debug] Run time error 4: "Array index out of bounds"
[20:53:31] [debug]  Accessing element at index 200 past array upper bound 199
[20:53:31] [debug] AMX backtrace:
[20:53:31] [debug] #0 000071ec in public OnPlayerPickUpDynamicPickup () from ArmourRegen.amx
[20:53:31] [debug] #1 native Streamer_CallbackHook () [648ab720] from streamer.DLL
[20:53:31] [debug] #2 00000710 in public OnPlayerPickUpPickup () from ArmourReg
OnPlayerPickUpDynamicPickUp

Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
	for(new i = 1; i <= MAX_REGEN; i++)
	{
		if(pickupid == ArmourRegen[i][APickup])
		{
			if(PlayerArmour(playerid) > 98)
			{
				SetPlayerArmour(playerid, 100);
				GameTextForPlayer(playerid,"~r~~h~~<~ Armour Full ~>~",2500,4);
			}
			else 
			{
				SetPlayerArmour(playerid, PlayerArmour(playerid)+ArmourRegen[i][AValue]);
				GameTextForPlayer(playerid,"~g~~h~~<~ Refill Armour ~>~",2500,4);
			}
                }
       }
       return 1;
}



Re: Pickup armour - Larceny - 26.12.2015

Quote:
Originally Posted by SilverStand
Посмотреть сообщение
Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
	for(new i = 1; i <= MAX_REGEN; i++)
        //...
}
You are accessing a value out of the array bounds.

ArmourRegen can only store 200 values (0-199) and MAX_REGEN is 200.

Change to
Код:
for(new i = 1; i < MAX_REGEN; i++)
Also, arrays start at 0 index, not sure if you intended to skip the first value of the array.
Код:
for(new i = 1; i < MAX_REGEN; i++)



Re: Pickup armour - SilverStand - 26.12.2015

ty so much :> +REP