AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ham Damage (Knife) (https://forums.alliedmods.net/showthread.php?t=318685)

mentalproblems 09-14-2019 15:18

Ham Damage (Knife)
 
Greetings.

I have a level system which gives xp to "killer" for every kill...
Example if Knife Kill = +5xp if HS knife kill = +7xp.

But I need a plugin that will multiply the knife damage and not affect the Level system, because some plugins I tried... won't give xp after knife kill.

I think RegisterHam(Ham_TakeDamage, ....) should be the solution, but I do not know how to create such thing by myself.
register_event works but, doesnt give XP after knife kill.

Anyone who can help?
Thank you.

thEsp 09-14-2019 19:14

Re: Ham Damage (Knife)
 
Code:
    /**      * Description:     Usually called whenever an entity takes any kind of damage.      *                  Inflictor is the entity that caused the damage (such as a gun).      *                  Attacker is the entity that tirggered the damage (such as the gun's owner).      * Forward params:  function(this, idinflictor, idattacker, Float:damage, damagebits);      * Return type:     Integer.      * Execute params:  ExecuteHam(Ham_TakeDamage, this, idinflictor, idattacker, Float:damage, damagebits);      */     Ham_TakeDamage
Register "Ham_TakeDamage" (pre), check if third parameter (attacker) is carrying a knife and change fourth parameter (SetHamParamFloat) if should.

OciXCrom 09-15-2019 06:47

Re: Ham Damage (Knife)
 
There's no reason for the other plugin not to work unless you're stopping the event in your plugin.
Both "register_event" and "RegisterHam" should work if you do it properly. I suggest the latter.

mentalproblems 09-15-2019 07:06

Re: Ham Damage (Knife)
 
Okay, but what should I correct here then so it should work?
Or how should I convert this to RegisterHam?

Here's the source of knife damage.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>

new g_iDamage

public plugin_init() {
    
    
register_plugin("Knife Damage""2.0""alKapone")
    
register_event("Damage""event_damage""be")
    
    
g_iDamage register_cvar("rgc_knife_damage""2")
}

public 
event_damage(id) {
    
    new 
victim id;
    if(!
is_user_connected(victim)) return PLUGIN_CONTINUE
    
new dmg_take read_data(2);
    new 
dmgtype read_data(3);
    new 
Float:multiplier get_pcvar_float(g_iDamage);
    new 
Float:damage dmg_take multiplier;
    new 
health get_user_health(victim);
    
    new 
iWeapIDattacker_id get_user_attacker(victimiWeapID);
    
    if(!
is_user_connected(attacker_id) || !is_user_alive(victim)) {
        return 
PLUGIN_HANDLED
    
}
    
    if(
iWeapID == CSW_KNIFE) {
        
        if(
floatround(damage) >= health) {
            if(
victim == attacker_id) {
                return 
PLUGIN_CONTINUE
            
}
            else {
                
log_kill(attacker_idvictim"knife"0);
            }
            
            return 
PLUGIN_CONTINUE
        
}
        else {
            if(
victim == attacker_id) return PLUGIN_CONTINUE
            
            fakedamage
(victim"weapon_knife"damagedmgtype);
        }
    }
    return 
PLUGIN_CONTINUE
}

stock log_kill(killervictimweapon[],headshot) {
    
user_silentkill(victim);
    
    
message_begin(MSG_ALLget_user_msgid("DeathMsg"), {0,0,0}, 0);
    
write_byte(killer);
    
write_byte(victim);
    
write_byte(headshot);
    
write_string(weapon);
    
message_end();
    
    new 
kfrags get_user_frags(killer);
    
set_user_frags(killerkfrags++);
    new 
vfrags get_user_frags(victim);
    
set_user_frags(victimvfrags++);
    
    return  
PLUGIN_CONTINUE



OciXCrom 09-15-2019 07:26

Re: Ham Damage (Knife)
 
PHP Code:

if(!is_user_connected(attacker_id) || !is_user_alive(victim)) {
        return 
PLUGIN_HANDLED
    


Using "return PLUGIN_HANDLED" in a event will block that event so it won't be captured by any following plugins. Use "PLUGIN_CONTINUE".

Your code is unnecessarily complicated. With "Ham_TakeDamage" you can do the same thing with 20x times less code.

mentalproblems 09-16-2019 13:59

Re: Ham Damage (Knife)
 
Well it doesn't even work now, does anyone have any idea of another knife damage multiplier which fills my criteria too?

thEsp 09-16-2019 14:12

Re: Ham Damage (Knife)
 
Please consider reading what I said above and tell us what you've tried so far...

mentalproblems 09-17-2019 07:57

Re: Ham Damage (Knife)
 
Well as much as I could possibly understand, I somehow managed to reach this point.
But not sure if this is fully correct. And I would also like to make this work only for RIGHT CLICK Stab.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

new g_pCvarDamage

public plugin_init() {
    
register_plugin("Knife Damage Multiplier""1.0""Nevermind")
    
    
RegisterHam(Ham_TakeDamage"player""Fw_TakeDamage_Post"1)
    
    
g_pCvarDamage register_cvar("knife_damage_multiplier""2")
}

public 
Fw_TakeDamage_Post(iVictimiInflictoriAttackerFloat:fDamagebitsDamageType)
{
    if (!
is_user_alive(iVictim) || !is_user_alive(iAttacker))
        return 
PLUGIN_CONTINUE
    
    
if (get_user_weapon(iAttacker) == CSW_KNIFE)
    {
        
SetHamParamFloat(4fDamage get_pcvar_float(g_pCvarDamage)) // not sure if this line is correct
        
return PLUGIN_CONTINUE
    
}
    
    return 
PLUGIN_CONTINUE



OciXCrom 09-17-2019 08:17

Re: Ham Damage (Knife)
 
You're registering the event as POST. This means the event has already passed so you can't possibly modify anything. The last argument in "RegisterHam" needs to be 0 if you want to change things (PRE).

Also, in ham you use HAM_IGNORED, HAM_HANDLED, HAM_SUPERCEDE, not PLUGIN_*.

mentalproblems 09-17-2019 08:29

Re: Ham Damage (Knife)
 
Ok thank you.

I'm not sure which one is correct IGNORED or SUPERCEDE
but I put supercede.

Is this okay now?

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>

new g_pCvarDamage

public plugin_init() {
    
register_plugin("Knife Damage Multiplier""1.0""Nevermind")
    
    
RegisterHam(Ham_TakeDamage"player""Fw_TakeDamage_Post"0)
    
    
g_pCvarDamage register_cvar("rgc_knife_damage""2")
}

public 
Fw_TakeDamage_Post(iVictimiInflictoriAttackerFloat:fDamage// , bitsDamageType
{
    if (!
is_user_alive(iVictim) || !is_user_alive(iAttacker))
        return 
HAM_SUPERCEDE
    
    
if (get_user_weapon(iAttacker) == CSW_KNIFE)
    {
        
SetHamParamFloat(4fDamage get_pcvar_float(g_pCvarDamage)) // not sure if this line is correct
        
return HAM_SUPERCEDE
    
}
    
    return 
HAM_SUPERCEDE




All times are GMT -4. The time now is 11:43.

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