AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detecting when shield is hit (not just aiming at it) (https://forums.alliedmods.net/showthread.php?t=95992)

Owyn 06-29-2009 14:50

Detecting when shield is hit (not just aiming at it)
 
i searched the forum and found only ways to detect when user is aiming at the shield but not hitting it with the bullet, i want to make an action only when shield is hit not when you just look at it, maybe someone found a way ?

i tried get_tr2( tr, TR_iHitgroup ) in TraceAttack pre and post but traceattack isn't even called for shield

SchlumPF* 06-29-2009 15:19

Re: Detecting when shield is hit
 
you could rebuild the traceline the engine sends and check yourself whether it hits the shield or not, use FM_EmitSound (bad method) or some better way which hopefully exists ^^

Alka 06-29-2009 15:20

Re: Detecting when shield is hit
 
IIRC the hitgroup of shield is 8.

EDIT:As i knew -> http://forums.alliedmods.net/showpos...57&postcount=5

Owyn 06-29-2009 15:51

Re: Detecting when shield is hit (not just aiming at it)
 
for 8th hitgroup TraceAttack isn't called and traceline hooks aiming not shooting (as far as i know)

SchlumPF*
i haven't done anything like that yet, could you help me little further?

Alka 06-29-2009 17:09

Re: Detecting when shield is hit (not just aiming at it)
 
You can simply modulate TraceLine to detect attack. Just hook CmdStart forward, check Buttons&IN_ATTACK then do a traceline ? There are some other ways too...

SchlumPF* 06-29-2009 17:22

Re: Detecting when shield is hit (not just aiming at it)
 
,Owyn. yet, i wont give you the code but i will tell you how you can find out how to do what you want (learn-effect):
- download the hlsdk
- search in mp5.dll for the function which is called when the weapon is fired and find the function inside which checks for a hit
- the function is located in combat.cpp
- understand its code, try to rebuild it in pawn and add your shieldhit detection

if its really that hard for you (at least try it) i may help you as soon as i got more motivation + time ;D

@Alka
i guess you know my knife-distance plugin and how it detects the attack type (tracehandle value), should be possible here too :) also, there is already a tutorial of VEN about this (Owyn search for it in the code snippets section, might be helpful) which does not check pev_buttons or uses cmdstart in general ^^

Alka 06-29-2009 17:30

Re: Detecting when shield is hit (not just aiming at it)
 
Yea, but my idea is a simple way (: i said
Quote:

Originally Posted by Alka
There are some other ways too...


joaquimandrade 07-01-2009 09:32

Re: Detecting when shield is hit (not just aiming at it)
 
There isn't a clean way to do this since when you hit a shield a traceattack doesn't occur and the shield doesn't even exist as an entity. This is the best way I found:

PHP Code:


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

#define PLUGIN    "New Plugin"
#define AUTHOR    "Unknown"
#define VERSION    "1.0"

const m_iClip 51
const m_iClip_linuxoffset 4

new Weapons[] = 
{
    
CSW_P228,
    
CSW_SCOUT,
    
CSW_XM1014,
    
CSW_C4,
    
CSW_MAC10,
    
CSW_AUG,
    
CSW_ELITE,
    
CSW_FIVESEVEN,
    
CSW_UMP45,
    
CSW_SG550,
    
CSW_GALI,
    
CSW_GALIL,
    
CSW_FAMAS,
    
CSW_USP,
    
CSW_GLOCK18,
    
CSW_AWP,
    
CSW_MP5NAVY,
    
CSW_M249,
    
CSW_M3,
    
CSW_M4A1,
    
CSW_TMP,
    
CSW_G3SG1,
    
CSW_DEAGLE,
    
CSW_SG552,
    
CSW_AK47,
    
CSW_KNIFE,
    
CSW_P90,
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    new 
weaponName[24];
    for(new 
i=0;i<sizeof Weapons;i++)
    {
        
get_weaponname(Weapons[i],weaponName,charsmax(weaponName));
        
RegisterHam(Ham_Weapon_PrimaryAttack,weaponName,"attack")
    }
}

public 
attack(weaponID)
{
    if(
get_pdata_int(weaponID,m_iClip,m_iClip_linuxoffset))
    {
        static 
Float:start[3], Float:dest[3] , Float:viewOffset[3], Float:path[3]
        
        new 
id pev(weaponID,pev_owner)
        
        
pev(id,pev_origin,start);
        
pev(id,pev_view_ofs,viewOffset);
        
xs_vec_add(start,viewOffset,start);

        
pev(id,pev_v_angle,path);
        
engfunc(EngFunc_MakeVectors,path);
        
global_get(glb_v_forward,path);

        
xs_vec_mul_scalar(path,9999.0,dest);
        
xs_vec_add(start,dest,dest);
            
        
engfunc(EngFunc_TraceLine,start,dest,0,id,0);
        
        if(
get_tr2(0,TR_iHitgroup) == 8)
        {
            
client_print(0,print_chat,"Hit Shield")
        }
    }


You have to modify it to handle the knife attack right because, as it is, as long you are aiming at a shield (no matter how far from it) and you use the weapon primary attack, it reports a shield hit. (Or ask Schweinsteiger* to do it for you)

Owyn 07-01-2009 11:25

Re: Detecting when shield is hit (not just aiming at it)
 
you get same result just checking pev button IN_ATTACK in traceline, atm i think hooking shield-hit sound with fakemeta is a nice way

joaquimandrade 07-01-2009 11:42

Re: Detecting when shield is hit (not just aiming at it)
 
Quote:

Originally Posted by .Owyn. (Post 861650)
you get same result just checking pev button IN_ATTACK in traceline, atm i think hooking shield-hit sound with fakemeta is a nice way

You get the same results but is some hundred times more expensive.

And thinking again, no you don't. You can be pressing IN_ATTACK without attacking.


All times are GMT -4. The time now is 12:05.

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