Give player a certain amount of damage? - 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: Give player a certain amount of damage? (
/showthread.php?tid=416674)
Give player a certain amount of damage? -
Dubya - 17.02.2013
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) {
if(issuerid != INVALID_PLAYER_ID) {
if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0) {
new Float:damage;
damage = amount * 0.5;
OnPlayerTakeDamage(playerid, INVALID_PLAYER_ID, damage, weaponid);
}
}
return 1;
}
So I'm trying to make the player take 1.5x more damage, and this doesn't work. Is there a certain thing to make a player take damage?
Re: Give player a certain amount of damage? -
[MG]Dimi - 17.02.2013
Quote:
Originally Posted by Dubya
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) { if(issuerid != INVALID_PLAYER_ID) { if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0) { new Float:damage; damage = amount * 0.5; OnPlayerTakeDamage(playerid, INVALID_PLAYER_ID, damage, weaponid); } } return 1; }
So I'm trying to make the player take 1.5x more damage, and this doesn't work. Is there a certain thing to make a player take damage?
|
You don't have to call callback. You have to reduce his health by half of damage already taken.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0)
{
new Float:damage,Float:HP;
damage = amount/2;
GetPlayerHealth(playerid,HP);
SetPlayerHealth(playerid,(HP-damage));
}
}
return 1;
}
Re: Give player a certain amount of damage? -
Dubya - 17.02.2013
But what if they have armour?
Re: Give player a certain amount of damage? -
[MG]Dimi - 17.02.2013
There. It's good.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0)
{
new Float:damage,Float:HP[2];
damage = amount/2;
GetPlayerHealth(playerid,HP[0]);
GetPlayerArmour(playerid,HP[1]);
if(HP[1] <= 0.0) SetPlayerHealth(playerid,(HP-damage)); //if he doesn't have armour
else if(HP[1] < damage) //if he has armour but it's not larger than damage we should deduct
{
SetPlayerArmour(playerid,0.0);
SetPlayerHealth(playerid,HP[0]-(damage-HP[1]));
}
else SetPlayerArmour(playerid,HP[1]-damage); //and if his armour is high enough to take from it.
}
}
return 1;
}
Re: Give player a certain amount of damage? -
Dubya - 17.02.2013
Quote:
Originally Posted by [MG]Dimi
There. It's good.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) { if(issuerid != INVALID_PLAYER_ID) { if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0) { new Float:damage,Float:HP[2]; damage = amount/2; GetPlayerHealth(playerid,HP[0]); GetPlayerArmour(playerid,HP[1]); if(HP[1] <= 0.0) SetPlayerHealth(playerid,(HP-damage)); //if he doesn't have armour else if(HP[1] < damage) //if he has armour but it's not larger than damage we should deduct { SetPlayerArmour(playerid,0.0); SetPlayerHealth(playerid,HP[0]-(damage-HP[1])); } else SetPlayerArmour(playerid,HP[1]-damage); //and if his armour is high enough to take from it. } } return 1; }
|
While you were making that I made this:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) {
if(issuerid != INVALID_PLAYER_ID) {
if(PlayerInfo[issuerid][pPerks_ExtraDamage] > 0) {
new Float:damage,Float:HP,Float:A,Float:T;
damage = amount / 2;
T = damage;
GetPlayerHealth(playerid,HP);
GetPlayerArmour(playerid, A);
if(A > 0) { // If the player has armour
if(damage > A) { // if damage is more than armor
T = damage - A; // amount of health that will be take.
SetPlayerArmour(playerid, 0); // getting rid of armour
SetPlayerHealth(playerid, (HP - T));
} else { SetPlayerArmour(playerid, (A - damage)); }
return 1;
}
SetPlayerHealth(playerid,(HP-damage));
}
}
return 1;
}
Not sure if mine will work though.