Raised This Month: $ Target: $400
 0% 

Displaying bullet damage with HamSandwich


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 01-12-2009 , 13:50   Re: Displaying bullet damage with HamSandwich
Reply With Quote #1

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?
__________________

Last edited by hleV; 01-12-2009 at 13:53.
hleV is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-12-2009 , 14:06   Re: Displaying bullet damage with HamSandwich
Reply With Quote #2

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;
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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