AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Displaying bullet damage with HamSandwich (https://forums.alliedmods.net/showthread.php?t=83612)

hleV 01-12-2009 08:58

Displaying bullet damage with HamSandwich
 
Hi. I got some problems with damage display using HamSandwich.
Code:
#include <amxmodx> #include <hamsandwich>   new g_iHudSyncObj;   public plugin_init() {         RegisterHam(Ham_TakeDamage, "player", "hTakeDamage", 1);           g_iHudSyncObj = CreateHudSyncObj(); }   public hTakeDamagePost(iVictim, iInflictor, iAttacker, Float:fDmg) {         if (!is_user_connected(iVictim) || !is_user_connected(iAttacker))                 return;           if (iVictim != iAttacker && get_user_team(iVictim) != get_user_team(iAttacker))         {                 set_hudmessage(200, 200, 200, -1.0, 0.46, 0, 6.0, 2.0, 0.1, 0.1, -1);                 ShowSyncHudMsg(iAttacker, g_iHudSyncObj, "%i^n", floatround(fDmg));         } }
Sometimes it shows more or less damage than the victim loses. Like you hit for 16, but victim lost only 8. Or you hit for 96, but victim (which had 100 HP) died.

For example use Glock's Burst-Fire mode and shoot to other player's head. It will show 96 while the other player is dead.

Anyone can suggest how to fix this?

xPaw 01-12-2009 09:13

Re: Displaying bullet damage with HamSandwich
 
try to take a look into amxx super

anakin_cstrike 01-12-2009 09:17

Re: Displaying bullet damage with HamSandwich
 
Quote:

For example use Glock's Burst-Fire mode and shoot to other player's head. It will show 96 while the other player is dead.
I thinks the bullet don't fire at the same time, and the last bullet makes that 96 dmg.

Anyway, i tried the same thing 2 weeks ago, and i maked the floatround before set_hudmessage, creating a variable.

PHP Code:

new dmg floatround(fDmg); 


hleV 01-12-2009 09:39

Re: Displaying bullet damage with HamSandwich
 
It's clear with Glock. But still sometimes shows 10 more or less damage than the player lost.

Going to use 'Damage' event until someone will find out how to fix it.

EDIT: Also the floatround is a bit tricky in this case because it displays number which has +-1 difference from the real taken damage. I mean if I do 1.1 damage, floatround will make it 1, but the victim get 2 dmg, because it's more than 1. Any ideas how to solve it?

anakin_cstrike 01-12-2009 10:58

Re: Displaying bullet damage with HamSandwich
 
Well, i think it will always make 2dmg if it was 1.1 or other values between 1.1 and 1.9 . If you set the player's health at 1.x it will automatically change to 2 (hl)

hleV 01-12-2009 11:34

Re: Displaying bullet damage with HamSandwich
 
Yes. But if the fFloat = 1.1, floatround(fFloat) = 1. So if I do 20.1 damage, player will lose 21 HP but it will print that he lost 20.

ConnorMcLeod 01-12-2009 11:49

Re: Displaying bullet damage with HamSandwich
 
Damage (arg4) is not the damage that the player will actually take.
It depends on DMG_TYPE, wepon, distance, armor...
To retrieve real damage, register the forward as post (as you did), and check pev_dmg_take player value.

hleV 01-12-2009 13:50

Re: Displaying bullet damage with HamSandwich
 
Thanks. Another question.
Code:
#include <amxmodx> #include <fakemeta> #include <hamsandwich>   new g_bCritHit[33];   public plugin_init() {         RegisterHam(Ham_TakeDamage, "player", "hTakeDamagePre");         RegisterHam(Ham_TakeDamage, "player", "hTakeDamagePost", 1); }   public hTakeDamagePre(iVictim, iInflictor, iAttacker, Float:fDmg) {         new iRandom = random_num(0, 100);           if (iRandom < 15) // 15% of success         {                 g_bCritHit[iAttacker] = true;                 new fMultiplier = random_float(1.5, 2.5);                   SetHamParamFloat(4, fDmg * fMultiplier);         } }   public hTakeDamagePost(iVictim, iInflictor, iAttacker, Float:fDmg) {         if (g_bCritHit[iAttacker])         {                 pev(iVictim, pev_dmg_take, fDmg);                   client_print(iAttacker, print_chat, "You've made a critical hit with %d damage", floatround(fDmg));                   g_bCritHit[iAttacker] = false;         } }

(example code, skipped connected/alive checks)

I want to print not only the total damage, but also the starting damage (which was multiplied) and multiplier. All in the same message.

Like this: You've made a critical hit: normal dmg: 10, dmg multiplier: 2, total dmg: 20

Of course I could do this with some global variables, but isn't there another way?

ConnorMcLeod 01-12-2009 14:06

Re: Displaying bullet damage with HamSandwich
 
I don't know if final damage (pev_dmg_take) is proportional to initial damage, but if it is, this should work :
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

new Float:g_fCritHit[33];

public 
plugin_init()
{
    
RegisterHam(Ham_TakeDamage"player""hTakeDamagePre");
    
RegisterHam(Ham_TakeDamage"player""hTakeDamagePost"1);
}

public 
hTakeDamagePre(iVictimiInflictoriAttackerFloat:fDmg)
{
    if(
random_num(099) < 15// 15% of success
    
{
        
g_fCritHit[iAttacker] = random_float(1.52.5);
        
SetHamParamFloat(4fDmg g_fCritHit[iAttacker]);
    }
}

public 
hTakeDamagePost(iVictimiInflictoriAttackerFloat:fDmg)
{
    static 
Float:fMult
    
if( ( fMult g_fCritHit[iAttacker] ) )
    {
        
pev(iVictimpev_dmg_takefDmg);  
        
client_print(iAttackerprint_chat,
            
"You've made a critical hit: normal dmg: %d, dmg multiplier: %.1f, total dmg: %d",
            
floatround(fDmg*fMult), fMultfloatround(fDmg))
        
g_fCritHit[iAttacker] = 0.0;
    }



hleV 01-13-2009 09:36

Re: Displaying bullet damage with HamSandwich
 
It works. Just one edit:
Code:
floatround(fDmg*fMult)
>
Code:
floatround(fDmg / fMult)
Thanks a lot. ^^


All times are GMT -4. The time now is 01:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.