10.03.2019, 15:54
I'm trying to make a custom damage system following this guide https://sampforum.blast.hk/showthread.php?tid=558839, but there is an issue.
For health, it works fine. But in the case of armour, it just goes back up to 250 if it doesn't end perfectly on 0.
How do I solve this issue? Code below.
For health, it works fine. But in the case of armour, it just goes back up to 250 if it doesn't end perfectly on 0.
How do I solve this issue? Code below.
PHP Code:
#define BODY_PART_TORSO 3
#define BODY_PART_GROIN 4
#define BODY_PART_LEFT_ARM 5
#define BODY_PART_RIGHT_ARM 6
#define BODY_PART_LEFT_LEG 7
#define BODY_PART_RIGHT_LEG 8
#define BODY_PART_HEAD 9
public OnPlayerConnect(playerid)
{
SetPlayerTeam(playerid, 0);
return 1;
}
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
new Float: health,Float: armour;
GetPlayerHealth(playerid, health);
GetPlayerArmour(playerid, armour);
switch(weaponid) // Starts the switch, and switches through the variable "weaponid". (declared in callback)
{
case 34: // Sniper Rifle weapon ID
{
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) // Under case 0.
{
case 3: SetPlayerHealth(playerid, health - 70); // Torso.
case 4: SetPlayerHealth(playerid, health - 40); // 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) // Under case 0.
{
case 3: SetPlayerArmour(playerid, armour - 35); // Torso.
case 4: SetPlayerArmour(playerid, armour - 20); // 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.
}
}
}
}
}
return 1;
}