Armor goes up to 250 when it's ment to become 0. - 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: Armor goes up to 250 when it's ment to become 0. (
/showthread.php?tid=664772)
Armor goes up to 250 when it's ment to become 0. -
Stefhan - 10.03.2019
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.
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;
}
Re: Armor goes up to 250 when it's ment to become 0. -
Stefhan - 10.03.2019
Issue solved thanks to a guy on the sa-mp discord. If anyone else has this issue, put this at the top of the code:
PHP Code:
my_SetPlayerArmour(playerid, Float:amount)
{
if(amount < 0.0)
{
amount = 0.0;
}
return SetPlayerArmour(playerid, amount);
}
#if defined _ALS_SetPlayerArmour
#undef SetPlayerArmour
#else
#define _ALS_SetPlayerArmour
#endif
#define SetPlayerArmour my_SetPlayerArmour