Custom Damage help
#1

Crash detect error:


Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
	new	Float: health;
    new Float: armour;
	GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armour);
	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;
}
I've got no clue on what's wrong.
Reply
#2

https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
issuerid - The ID of the player that caused the damage. INVALID_PLAYER_ID if self-inflicted.
Check if(issuerid != INVALID_PLAYER_ID) before you use it in variables.
Reply
#3

So... Should I just add if(issuerid != INVALID_PLAYER_ID) to the top of OnPlayerTakeDamage?
Reply
#4

Whenever I see 65535 I don't even have to look at the code anymore because the root cause is always the same: not checking whether killerid/issuerid is actually connected before using it as an array index. If the player damages or kills himself through natural causes such as fall damage, fire or drowning there is no killerid/issuerid. This is represented with INVALID_PLAYER_ID (65535).
Reply
#5

Can someone tell me how to implement this fix into the script? I'm still new to PAWN scripting and just wondering.
Reply
#6

would I wrap the code like this?
Код:
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
#7

To be precise.
http://forum.sa-mp.com/showthread.ph...87#post3753187
Reply
#8

Bump.
Reply
#9

Add the brackets for issuerid check statement
Reply
#10

Did it and it still crashed my server whenever someone gets shot with armor.
Код:
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


Forum Jump:


Users browsing this thread: 1 Guest(s)