Raised This Month: $32 Target: $400
 8% 

Solved code validity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-03-2019 , 13:20   code validity
Reply With Quote #1

i recently wrote a goombastomp plugin, its a plugin which if a player fell on another player's head with a high fall velocity, player that got jumped on will be killed (die's,goombastomp), wondering if is there another better method can be achieve.

PHP Code:
/* Plugin generated by AMXX-Studio */

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

#define PLUGIN "goomba stomp"
#define VERSION "1.0"
#define AUTHOR "Natsheh"

new g_cvar1g_cvar2g_cvar3;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_cvar1 register_cvar("goombastomp_min_fallspeed""500");
    
g_cvar2 register_cvar("goombastomp_damage""50");
    
g_cvar3 register_cvar("goombastomp_silent_dmg""0");
    
    
RegisterHam(Ham_Touch"player""fw_player_touch_pre");
}

public 
fw_player_touch_pre(idother)
{
    if(
is_user_alive(id))
    {
        if(
is_user_alive(other))
        {
            if(
pev(otherpev_groundentity) == id)
            {
                static 
Float:fVelocity[3], Float:fMinFallSpeed;
                
pev(otherpev_velocityfVelocity)
                if(
fVelocity[2] <= (fMinFallSpeed=-get_pcvar_float(g_cvar1)))
                {
                    static 
Float:fHealthFloat:fDamage;
                    
pev(idpev_healthfHealth);
                    
                    
fDamage = (fVelocity[2]/floatmax(floatabs(fMinFallSpeed), 0.1)) * -get_pcvar_float(g_cvar2);
                    if(
fDamage >= fHealth)
                        
ExecuteHamB(Ham_Killedidother2);
                    else
                    {
                        if(
get_pcvar_num(g_cvar3))
                            
set_pev(idpev_health, (fHealth-fDamage));
                        else 
ExecuteHamB(Ham_TakeDamageidotherotherfDamageDMG_BLAST);
                    }
                    
                    
fVelocity[2] = 0.0;
                    
set_pev(otherpev_velocityfVelocity);
                    
set_pev(otherpev_flFallVelocity0.0);
                    
set_pev(otherpev_flags, (pev(otherpev_flags)&~FL_ONGROUND));
                }
            }
        }
    }

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-04-2019 at 11:49.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-03-2019 , 18:16   Re: code validity
Reply With Quote #2

You don't need the "touch" event. Since the damage should be dealt only with a high velocity, such velocity will probably be enough to cause default fall damage from the game. Thus, you can simply hook the "damage" event and check the player below you. I wrote such a plugin a while ago. Guess there's no point in keeping it private anymore:

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <fun>
#include <hamsandwich>

#define PLUGIN_VERSION "1.1"
#define STOMP_SOUND "iplay/stomp.wav"
#define FLAG_VIP ADMIN_RESERVATION

new g_pFriendlyFire,
    
g_pFrags,
    
g_pNormalBonus,
    
g_pVipBonus

public plugin_init()
{
    
register_plugin("Goomba Stomp"PLUGIN_VERSION"OciXCrom")
    
RegisterHam(Ham_TakeDamage"player""OnTakeDamagePre"0)
    
g_pFriendlyFire get_cvar_pointer("mp_friendlyfire")
    
g_pFrags register_cvar("goomba_frags""2")
    
g_pNormalBonus register_cvar("goomba_normal_bonus""30.0")
    
g_pVipBonus register_cvar("goomba_vip_bonus""15.0")
}

public 
plugin_precache()
    
precache_sound(STOMP_SOUND)

public 
OnTakeDamagePre(iVictimiInflictoriAttackerFloat:fDamageiBits)
{
    if(
iBits DMG_FALL)
    {
        new 
iEnt pev(iVictimpev_groundentity)
        
        if(!
is_ent_breakable(iEnt))
            return 
HAM_IGNORED
            
        fDamage 
+= get_pcvar_float(g_pNormalBonus)
            
        if(
get_user_flags(iVictim) & FLAG_VIP)
            
fDamage += get_pcvar_float(g_pVipBonus)
            
        
ExecuteHamB(Ham_TakeDamageiEnt0iVictimfDamageDMG_FALL)
        
        if(
is_user_connected(iEnt))
        {
            if(
get_pcvar_num(g_pFriendlyFire) || get_user_team(iVictim) != get_user_team(iEnt))
                
GoombaStomp(iVictimiEntfDamage)
        }
        
        return 
HAM_SUPERCEDE
    
}
    
    return 
HAM_IGNORED
}

GoombaStomp(idiEntFloat:fDamage)
{
    new 
szName[2][32]
    
get_user_name(idszName[0], charsmax(szName[]))
    
get_user_name(iEntszName[1], charsmax(szName[]))
        
    if(
is_user_alive(iEnt))
    {
        
client_print(idprint_center"You dealt %.0f damage to %s. He has %i HP left!"fDamageszName[1], pev(iEntpev_health))
        
client_print(iEntprint_center"%s fell on top of you dealing %.0f damage!"szName[0], fDamage)
    }
    else
    {
        
set_user_frags(idget_user_frags(id) + get_pcvar_num(g_pFrags))
        
cs_set_user_deaths(idcs_get_user_deaths(id))
        
client_print(0print_center"%s Goomba Stomped %s with %.0f damage!"szName[0], szName[1], fDamage)
        
emit_sound(idCHAN_AUTOSTOMP_SOUND1.0ATTN_NORM0PITCH_NORM)
    }
}

bool:is_ent_breakable(iEnt)
{
    if(
iEnt)
    {        
        new 
szName[32]
        
entity_get_string(iEntEV_SZ_classnameszNamecharsmax(szName))
    
        if(
equal(szName"hostage_entity"))
            return 
false
    
        
if((entity_get_float(iEntEV_FL_health) > 0.0) && (entity_get_float(iEntEV_FL_takedamage) > 0.0) && !(entity_get_int(iEntEV_INT_spawnflags) & SF_BREAK_TRIGGER_ONLY))
            return 
true
    
}
    
    return 
false

__________________

Last edited by OciXCrom; 05-03-2019 at 18:17.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-04-2019 , 04:28   Re: code validity
Reply With Quote #3

PHP Code:
  set_pev(otherpev_flFallVelocity0.0);
                    
set_pev(otherpev_flags, (pev(otherpev_flags)&~FL_ONGROUND)); 
The weird part is this managed to block the fall damage.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-04-2019 , 05:05   Re: code validity
Reply With Quote #4

Why do you think it's weird? flFallVelocity is used to determine if fall damage should be applied and you set it to 0.
__________________
HamletEagle is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-04-2019 , 05:47   Re: code validity
Reply With Quote #5

I'm just not familiar when the fall damage is happening after or before the touch nor fall velocity behaviour, i am more certain about it happening after the touch, I have some doubts.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-04-2019 at 05:49.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-04-2019 , 09:46   Re: code validity
Reply With Quote #6

Like I said, you don't need to check any touches. You can check if the damage is fall damage in the damage event and easily locate the player you fell on.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-04-2019 , 09:50   Re: code validity
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
when the fall damage is happening after or before the touch nor fall velocity behaviour, i am more certain about it happening after the touch, I have some doubts.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 05-04-2019 , 10:07   Re: code validity
Reply With Quote #8

Why does that matter if you don't need to use it? If you're curious, you can simply hook both events and print a message when they happen to see which message will get printed first.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-04-2019 , 11:49   Re: code validity
Reply With Quote #9

Because I didn't find any explanation on pev_flFallvelocity and this entity variable don't make sense anyway it's solved.

And it's doesn't matter if I don't use it an explanation will be helpful for future planning.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-05-2019 at 14:52.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-04-2019 , 19:35   Re: code validity
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
I'll stick into my method since its more efficient.
Touch is called every frame and for each player.
__________________

Last edited by Black Rose; 05-04-2019 at 19:35.
Black Rose 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 17:13.


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