Server Crashing When Armor Shot?
#1

This is my error log:
Код:
[09:17:35] [debug]  Accessing element at index 65535 past array upper bound 99
[09:17:35] [debug] AMX backtrace:
[09:17:35] [debug] #0 000b0ba8 in public OnPlayerTakeDamage (0x00000000, 0x0000ffff, 0x40533334, 0x00000036, 0x00000003) from roleplay.amx
[09:17:37] [debug] Run time error 4: "Array index out of bounds"
[09:17:37] [debug]  Accessing element at index 65535 past array upper bound 99
[09:17:37] [debug] AMX backtrace:
[09:17:37] [debug] #0 000b0ba8 in public OnPlayerTakeDamage (0x00000000, 0x0000ffff, 0x40533334, 0x00000036, 0x00000003) from roleplay.amx
[09:17:39] [debug] Run time error 4: "Array index out of bounds"
[09:17:39] [debug]  Accessing element at index 65535 past array upper bound 99
[09:17:39] [debug] AMX backtrace:
[09:17:39] [debug] #0 000b0ba8 in public OnPlayerTakeDamage (0x00000000, 0x0000ffff, 0x40533334, 0x00000036, 0x00000003) from roleplay.amx
This is my OnPlayerTakeDamage:
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
	new	Float: health;
    new Float: armour;
	GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
	if(issuerid != INVALID_PLAYER_ID && weaponid == 24)
	{
		switch(armour)
		{
			case 0:
			{
				switch(bodypart)
				{
					case 3: SetPlayerHealth(playerid, health - 25); // Torso.
					case 4: SetPlayerHealth(playerid, health - 20); // Groin.
					case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
					case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
					case 7: SetPlayerHealth(playerid, health - 10);  // Left Leg.
					case 8: SetPlayerHealth(playerid, health - 10); // Right Leg.
					case 9: SetPlayerHealth(playerid, health - 50); // Head.
				}
			}
			default:
			{
				switch(bodypart)
				{
					case 3: SetPlayerArmour(playerid, armour - 13); // Torso.
					case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
					case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
					case 6: SetPlayerArmour(playerid, armour - 5); // Right Arm.
					case 7: SetPlayerArmour(playerid, armour - 5);  // Left Leg.
					case 8: SetPlayerArmour(playerid, armour - 5); // Right Leg.
					case 9: SetPlayerArmour(playerid, armour - 25); // Head.
				}
			}
		}
	}
	else if(issuerid != INVALID_PLAYER_ID && weaponid == 25)
	{
		switch(armour) // Creates a switch that switches through the armour float, and checks the value.
		{
			case 0: // If the value is 0, the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerHealth(playerid, health - 40); // Torso.
					case 4: SetPlayerHealth(playerid, health - 20); // Groin.
					case 5: SetPlayerHealth(playerid, health - 15);  // Left Arm.
					case 6: SetPlayerHealth(playerid, health - 15); // Right Arm.
					case 7: SetPlayerHealth(playerid, health - 15);  // Left Leg.
					case 8: SetPlayerHealth(playerid, health - 15); // Right Leg.
					case 9: SetPlayerHealth(playerid, health - 100); // Head.
				}
			}
			default: // Otherwise the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerArmour(playerid, armour - 20); // Torso.
					case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
					case 5: SetPlayerArmour(playerid, armour - 7);  // Left Arm.
					case 6: SetPlayerArmour(playerid, armour - 7); // Right Arm.
					case 7: SetPlayerArmour(playerid, armour - 7);  // Left Leg.
					case 8: SetPlayerArmour(playerid, armour - 7); // Right Leg.
					case 9: SetPlayerArmour(playerid, armour - 50); // Head.
				}
			}
		}
	}
	else if(issuerid != INVALID_PLAYER_ID && weaponid == 30)
	{
		switch(armour) // Creates a switch that switches through the armour float, and checks the value.
		{
			case 0: // If the value is 0, the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerHealth(playerid, health - 35); // Torso.
					case 4: SetPlayerHealth(playerid, health - 35); // Groin.
					case 5: SetPlayerHealth(playerid, health - 20);  // Left Arm.
					case 6: SetPlayerHealth(playerid, health - 20); // Right Arm.
					case 7: SetPlayerHealth(playerid, health - 14);  // Left Leg.
					case 8: SetPlayerHealth(playerid, health - 14); // Right Leg.
					case 9: SetPlayerHealth(playerid, health - 50); // Head.
				}
			}
			default: // Otherwise the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerArmour(playerid, armour - 15); // Torso.
					case 4: SetPlayerArmour(playerid, armour - 15); // Groin.
					case 5: SetPlayerArmour(playerid, armour - 10);  // Left Arm.
					case 6: SetPlayerArmour(playerid, armour - 10); // Right Arm.
					case 7: SetPlayerArmour(playerid, armour - 7);  // Left Leg.
					case 8: SetPlayerArmour(playerid, armour - 7); // Right Leg.
					case 9: SetPlayerArmour(playerid, armour - 50); // Head.
				}
			}
		}
	}
	else if(issuerid != INVALID_PLAYER_ID && weaponid == 31)
	{
		switch(armour) // Creates a switch that switches through the armour float, and checks the value.
		{
			case 0: // If the value is 0, the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerHealth(playerid, health - 20); // Torso.
					case 4: SetPlayerHealth(playerid, health - 20); // Groin.
					case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
					case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
					case 7: SetPlayerHealth(playerid, health - 7);  // Left Leg.
					case 8: SetPlayerHealth(playerid, health - 7); // Right Leg.
					case 9: SetPlayerHealth(playerid, health - 100); // Head.
				}
			}
			default: // Otherwise the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerArmour(playerid, armour - 10); // Torso.
					case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
					case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
					case 6: SetPlayerArmour(playerid, armour - 4); // Right Arm.
					case 7: SetPlayerArmour(playerid, armour - 4);  // Left Leg.
					case 8: SetPlayerArmour(playerid, armour - 4); // Right Leg.
					case 9: SetPlayerArmour(playerid, armour - 50); // Head.
				}
			}
		}
	}
	else if(issuerid != INVALID_PLAYER_ID && weaponid == 34)
	{
		switch(armour) // Creates a switch that switches through the armour float, and checks the value.
		{
			case 0: // If the value is 0, the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerHealth(playerid, health - 50); // Torso.
					case 4: SetPlayerHealth(playerid, health - 25); // Groin.
					case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
					case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
					case 7: SetPlayerHealth(playerid, health - 10);  // Left Leg.
					case 8: SetPlayerHealth(playerid, health - 10); // Right Leg.
					case 9: SetPlayerHealth(playerid, health - 100); // Head.
				}
			}
			default: // Otherwise the codes underneath will activate.
			{
				switch(bodypart)
				{
					case 3: SetPlayerArmour(playerid, armour - 25); // Torso.
					case 4: SetPlayerArmour(playerid, armour - 15); // Groin.
					case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
					case 6: SetPlayerArmour(playerid, armour - 5); // Right Arm.
					case 7: SetPlayerArmour(playerid, armour - 5);  // Left Leg.
					case 8: SetPlayerArmour(playerid, armour - 5); // Right Leg.
					case 9: SetPlayerArmour(playerid, armour - 50); // Head.
				}
			}
		}
	}
	if(actmarker[issuerid] >= 1)
        {
                TextDrawShowForPlayer(issuerid, HitMarker);
                timarker = SetTimerEx("HTD", 250, true, "%d", issuerid);
    }
	if (PlayerData[playerid][pFirstAid])
	{
	    SendClientMessage(playerid, COLOR_LIGHTRED, "[WARNING]:{FFFFFF} Your first aid kit is no longer in effect as you took damage.");

        PlayerData[playerid][pFirstAid] = 0;
		KillTimer(PlayerData[playerid][pAidTimer]);
	}
	return 1;
}
Reply
#2

In this part you don't check if "issuerid" is not equal to INVALID_PLAYER_ID:
Код:
if (actmarker[issuerid] >= 1)
{
    TextDrawShowForPlayer(issuerid, HitMarker);
    timarker = SetTimerEx("HTD", 250, true, "%d", issuerid);
}
Moreover instead of having 6 if/else if statements for checking "issuerid != INVALID_PLAYER_ID", have it once at the top and let the rest inside it (except the last part with pFirstAid).
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
In this part you don't check if "issuerid" is not equal to INVALID_PLAYER_ID:
Код:
if (actmarker[issuerid] >= 1)
{
    TextDrawShowForPlayer(issuerid, HitMarker);
    timarker = SetTimerEx("HTD", 250, true, "%d", issuerid);
}
Moreover instead of having 6 if/else if statements for checking "issuerid != INVALID_PLAYER_ID", have it once at the top and let the rest inside it (except the last part with pFirstAid).
So would I just remove all the "issuerid != INVALID_PLAYER_ID" & just put it to
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
	new	Float: health;
    new Float: armour;
	GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
	if(issuerid != INVALID_PLAYER_ID)
	{
		if(weaponid == 24)
		{
			switch(armour)
			{
				case 0:
				{
					switch(bodypart)
					{
						case 3: SetPlayerHealth(playerid, health - 25); // Torso.
						case 4: SetPlayerHealth(playerid, health - 20); // Groin.
						case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
						case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
						case 7: SetPlayerHealth(playerid, health - 10);  // Left Leg.
						case 8: SetPlayerHealth(playerid, health - 10); // Right Leg.
						case 9: SetPlayerHealth(playerid, health - 50); // Head.
					}
				}
				default:
				{
					switch(bodypart)
					{
						case 3: SetPlayerArmour(playerid, armour - 13); // Torso.
						case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
						case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
						case 6: SetPlayerArmour(playerid, armour - 5); // Right Arm.
						case 7: SetPlayerArmour(playerid, armour - 5);  // Left Leg.
						case 8: SetPlayerArmour(playerid, armour - 5); // Right Leg.
						case 9: SetPlayerArmour(playerid, armour - 25); // Head.
					}
				}
			}
		}
		else if(weaponid == 25)
		{
			switch(armour) // Creates a switch that switches through the armour float, and checks the value.
			{
				case 0: // If the value is 0, the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerHealth(playerid, health - 40); // Torso.
						case 4: SetPlayerHealth(playerid, health - 20); // Groin.
						case 5: SetPlayerHealth(playerid, health - 15);  // Left Arm.
						case 6: SetPlayerHealth(playerid, health - 15); // Right Arm.
						case 7: SetPlayerHealth(playerid, health - 15);  // Left Leg.
						case 8: SetPlayerHealth(playerid, health - 15); // Right Leg.
						case 9: SetPlayerHealth(playerid, health - 100); // Head.
					}
				}
				default: // Otherwise the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerArmour(playerid, armour - 20); // Torso.
						case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
						case 5: SetPlayerArmour(playerid, armour - 7);  // Left Arm.
						case 6: SetPlayerArmour(playerid, armour - 7); // Right Arm.
						case 7: SetPlayerArmour(playerid, armour - 7);  // Left Leg.
						case 8: SetPlayerArmour(playerid, armour - 7); // Right Leg.
						case 9: SetPlayerArmour(playerid, armour - 50); // Head.
					}
				}
			}
		}
		else if(weaponid == 30)
		{
			switch(armour) // Creates a switch that switches through the armour float, and checks the value.
			{
				case 0: // If the value is 0, the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerHealth(playerid, health - 35); // Torso.
						case 4: SetPlayerHealth(playerid, health - 35); // Groin.
						case 5: SetPlayerHealth(playerid, health - 20);  // Left Arm.
						case 6: SetPlayerHealth(playerid, health - 20); // Right Arm.
						case 7: SetPlayerHealth(playerid, health - 14);  // Left Leg.
						case 8: SetPlayerHealth(playerid, health - 14); // Right Leg.
						case 9: SetPlayerHealth(playerid, health - 50); // Head.
					}
				}
				default: // Otherwise the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerArmour(playerid, armour - 15); // Torso.
						case 4: SetPlayerArmour(playerid, armour - 15); // Groin.
						case 5: SetPlayerArmour(playerid, armour - 10);  // Left Arm.
						case 6: SetPlayerArmour(playerid, armour - 10); // Right Arm.
						case 7: SetPlayerArmour(playerid, armour - 7);  // Left Leg.
						case 8: SetPlayerArmour(playerid, armour - 7); // Right Leg.
						case 9: SetPlayerArmour(playerid, armour - 50); // Head.
					}
				}
			}
		}
		else if(weaponid == 31)
		{
			switch(armour) // Creates a switch that switches through the armour float, and checks the value.
			{
				case 0: // If the value is 0, the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerHealth(playerid, health - 20); // Torso.
						case 4: SetPlayerHealth(playerid, health - 20); // Groin.
						case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
						case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
						case 7: SetPlayerHealth(playerid, health - 7);  // Left Leg.
						case 8: SetPlayerHealth(playerid, health - 7); // Right Leg.
						case 9: SetPlayerHealth(playerid, health - 100); // Head.
					}
				}
				default: // Otherwise the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerArmour(playerid, armour - 10); // Torso.
						case 4: SetPlayerArmour(playerid, armour - 10); // Groin.
						case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
						case 6: SetPlayerArmour(playerid, armour - 4); // Right Arm.
						case 7: SetPlayerArmour(playerid, armour - 4);  // Left Leg.
						case 8: SetPlayerArmour(playerid, armour - 4); // Right Leg.
						case 9: SetPlayerArmour(playerid, armour - 50); // Head.
					}
				}
			}
		}
		else if(weaponid == 34)
		{
			switch(armour) // Creates a switch that switches through the armour float, and checks the value.
			{
				case 0: // If the value is 0, the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerHealth(playerid, health - 50); // Torso.
						case 4: SetPlayerHealth(playerid, health - 25); // Groin.
						case 5: SetPlayerHealth(playerid, health - 10);  // Left Arm.
						case 6: SetPlayerHealth(playerid, health - 10); // Right Arm.
						case 7: SetPlayerHealth(playerid, health - 10);  // Left Leg.
						case 8: SetPlayerHealth(playerid, health - 10); // Right Leg.
						case 9: SetPlayerHealth(playerid, health - 100); // Head.
					}
				}
				default: // Otherwise the codes underneath will activate.
				{
					switch(bodypart)
					{
						case 3: SetPlayerArmour(playerid, armour - 25); // Torso.
						case 4: SetPlayerArmour(playerid, armour - 15); // Groin.
						case 5: SetPlayerArmour(playerid, armour - 5);  // Left Arm.
						case 6: SetPlayerArmour(playerid, armour - 5); // Right Arm.
						case 7: SetPlayerArmour(playerid, armour - 5);  // Left Leg.
						case 8: SetPlayerArmour(playerid, armour - 5); // Right Leg.
						case 9: SetPlayerArmour(playerid, armour - 50); // Head.
					}
				}
			}
		}
		if(actmarker[issuerid] >= 1)
			{
					TextDrawShowForPlayer(issuerid, HitMarker);
					timarker = SetTimerEx("HTD", 250, true, "%d", issuerid);
		}
	}
	if (PlayerData[playerid][pFirstAid])
	{
	    SendClientMessage(playerid, COLOR_LIGHTRED, "[WARNING]:{FFFFFF} Your first aid kit is no longer in effect as you took damage.");

        PlayerData[playerid][pFirstAid] = 0;
		KillTimer(PlayerData[playerid][pAidTimer]);
	}
	return 1;
}
Reply
#4

You already have a topic on Script help section..
Reply
#5

Quote:
Originally Posted by oSAINTo
Посмотреть сообщение
So would I just remove all the "issuerid != INVALID_PLAYER_ID" & just put it to
Код:
...
Yes, like that to avoid checking the same thing all the time. I'd also use switch for the weaponid as well.
Reply
#6

Here's my error log.
Код:
[09:44:37] [debug] Server crashed while executing roleplay.amx
[09:44:37] [debug] AMX backtrace:
[09:44:37] [debug] #0 native SetTimerEx () [00473860] from samp-server.exe
[09:44:37] [debug] #1 000b0b44 in public OnPlayerTakeDamage (0x00000001, 0x00000000, 0x4238cccd, 0x00000019, 0x00000009) from roleplay.amx
[09:44:37] [debug] Native backtrace:
[09:44:37] [debug] #0 004828d2 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #1 00473919 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #2 004010b6 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #3 642b5f2a in ?? () from E:\Prospect Rolepaly\plugins\crashdetect.DLL
[09:44:37] [debug] #4 642b822e in ?? () from E:\Prospect Rolepaly\plugins\crashdetect.DLL
[09:44:37] [debug] #5 642aff6f in ?? () from E:\Prospect Rolepaly\plugins\crashdetect.DLL
[09:44:37] [debug] #6 642b5f7a in ?? () from E:\Prospect Rolepaly\plugins\crashdetect.DLL
[09:44:37] [debug] #7 0046ed5c in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #8 00493c03 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #9 00498d56 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #10 00498d5b in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #11 00498d78 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #12 67e8046a in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #13 59000043 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #14 247c83c3 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #15 2277e004 in ?? () from E:\Prospect Rolepaly\samp-server.exe
[09:44:37] [debug] #16 042474ff in ?? ()
Reply
#7

pawn Код:
SetTimerEx("HTD", 250, true, "%d", issuerid);
4th parameter is the format. "i" or "d" for integer, "f" for floats "s" for string etc. "issuerid" is an integer so:
pawn Код:
SetTimerEx("HTD", 250, true, "d", issuerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)