AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hook hit with a knife (https://forums.alliedmods.net/showthread.php?t=144060)

DarkGL 11-28-2010 10:52

Hook hit with a knife
 
Hi I wanted to hook when player hit ent with a knife so I spawn ent:
Code:

public spawn(){
        new Float:origin[3]
        if(SsGetOrigin(origin))
        {
                new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
                if(ent){
                        engfunc(EngFunc_SetModel, ent, "models/present1.mdl")
                        engfunc(EngFunc_SetOrigin, ent, origin)
                        set_pev(ent, pev_classname, "prezent");
                        set_pev(ent,pev_takedamage,DAMAGE_YES)
                        set_pev(ent,pev_health,999999.0)
                        set_pev(ent,pev_max_health,999999.0)
                        set_pev(ent,pev_solid,SOLID_BBOX)
                        engfunc(EngFunc_SetSize,ent,Float:{-15.0,-15.0,-2.0},Float:{15.0,15.0,15.0})
                        set_pev(ent,pev_movetype,MOVETYPE_TOSS)
                        set_pev(ent,pev_gravity,1.0)
                        RegisterHamFromEntity(Ham_TakeDamage, ent, "fwTakeDamage", 1)
                }
        }
}

and it's work
a hook of takedamage
Code:

public fwTakeDamage(this, idinflictor, idattacker, Float:damage, damagebits){
        if((damagebits&(1<<2)) && is_user_alive(idattacker)){
                punkty[idattacker]++;
                remove_entity(this);
                return HAM_SUPERCEDE;
        }
        else
        {
                return HAM_SUPERCEDE;
        }
        return HAM_SUPERCEDE;
}

but first if is never true why ?

ConnorMcLeod 11-28-2010 11:41

Re: Hook hit with a knife
 
Replace 1<<2 with defined name so we can read your code without having to open hldsk_const.inc to understand it.
Also, explain better what you are trying to do.

DarkGL 11-28-2010 11:52

Re: Hook hit with a knife
 
#define DMG_SLASH (1<<2) // Cut, clawed, stabbed

I want to add one point player who hit ent created by me ( punkty[idattacker]++;) and remove this ent if he shot ent I do nothing

when I changed condition to
Code:

if(get_user_weapon(idattacker, _, _)==CSW_KNIFE && is_user_alive(idattacker)){
                punkty[idattacker]++;
                remove_entity(this);
                return HAM_SUPERCEDE;
        }

when I hit ent with knife server off :P

ConnorMcLeod 11-28-2010 11:58

Re: Hook hit with a knife
 
Knife generates dmgbit == (DMG_BULLET|DMG_NEVERGIB)

You can see there how to detect knife damage on a player : http://forums.alliedmods.net/showpos...9&postcount=52

So, make sure attacker is a player, attacker and inflictor are equal, attacker weapon is knife


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

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