Weapon X2 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: Weapon X2 damage (
/showthread.php?tid=362168)
Weapon X2 damage -
Dan. - 23.07.2012
I made a code, to make damages more realistic:
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
new Float:HP, Float: damage;
GetPlayerHealth(playerid, HP);
damage = floatdiv(HP, amount);
SetPlayerHealth(playerid, damage);
}
return 1;
}
Is the command bugged or I just have to make the damage made lower? Currently if I shoot with a M4, I almost shoot the guy dead. The code is supposed to remove the amount of damage done from the player, and it returns 1 so it removes the amount of damage again. Is it X2 or bugged?
Re: Weapon X2 damage -
Vince - 23.07.2012
Err, I think you just need to subtract
amount once more from the current health, seeing as the old health is the current health plus the amount.
Re: Weapon X2 damage -
Roko_foko - 23.07.2012
I will explain the problem via an example.
What you actually do?
Let's say player at start has HP=100. amount(damage) is 2
1st time:
his health will be 100/2=50
2nd time:
his health will be 50/2=25
3rd time:
his health will be 25/2=12.5
etc.
It will allways take less damage. Cuz of that it will take time untill the player is dead.
Re: Weapon X2 damage -
Dan. - 23.07.2012
I want the damage to be X2 not more. Currently it seems to me that it's taking away more health than X2. The code takes away
"amount" damage. Then I get the players health and subtract
"amount" once again from the health. That should make the damage X2 as I want it to be. But it seems to be higher, 1 bullet with M4 almost kills the guy.
E:// How dumb.. I thought was using floatsub not floatdiv. Little typo there, thanks for helping.
Re: Weapon X2 damage -
leonardo1434 - 23.07.2012
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{
if(issuerid != INVALID_PLAYER_ID)
{
new Float:HP, Float: damage;
GetPlayerHealth(playerid, HP);//lets say it is 100.
damage = floatdiv(HP, amount);
// lets say the damage was 50.
//100/50 = 2 of hp.
SetPlayerHealth(playerid, damage); // so the player gonna have 2 of hp.
}
return 1;
}
an simple example of what you're doing.
pawn Код:
public OnFilterScriptInit()
{
new Float:Number1 = 100.0, Float:Number2 = 50.0;
new Float:Result;
new l[5];
Result = floatdiv(Number1, Number2);
format(l,5,"%0.2f",Result);
printf(l);
}
//it gonna print 2.00 which is 2.