Skip to content

Conversation

@justgo97
Copy link

@justgo97 justgo97 commented Mar 5, 2023

This will allow distinguishing different trace types easily, For example an efficient method to make bullets penetrate through teammates would be:

#include <amxmodx>
#include <fakemeta>
#include <reapi>

// Custom flags that we can retrieve in pfnShouldCollide
// Starting from BIT(16) to reserve space for more flags for Engine
#define FTRACE_BULLET				(1<<16)
#define FTRACE_FLASH				(1<<17)

public plugin_init() {
    register_plugin("Bullets penetrate teammates", "0.0.1", "JustGo")

    register_forward(FM_ShouldCollide, "FMHook_ShouldCollide")
    register_forward(FM_AddToFullPack, "FMHook_AddToFullPack_Post", 1)
}

public FMHook_ShouldCollide(entTouched, entOther) {
    if(!is_user_alive(entTouched) || !is_user_alive(entOther)) return FMRES_IGNORED

    if((global_get(glb_trace_flags) & FTRACE_BULLET) && isSameTeam(entTouched, entOther)) {
        forward_return(FMV_CELL, 0)
        return FMRES_SUPERCEDE
    }

    return FMRES_IGNORED
}

public FMHook_AddToFullPack_Post(es_handle,e,ent,host,hostflags,player,pSet)
{
    if(!player) return FMRES_IGNORED;

    if(!is_user_alive(host) || !is_user_alive(ent)) return FMRES_IGNORED

    if(isSameTeam(host, ent))
    {
        set_es(es_handle, ES_RenderMode, kRenderTransAlpha)
        set_es(es_handle, ES_RenderAmt, 100 );
    }
    return FMRES_IGNORED;
}

stock isSameTeam(id1, id2) {
    return (get_member(id1, m_iTeam) == get_member(id2, m_iTeam))
}

Also now it would be possible to create an entity that is both shootable and can be trespassed:

public FMHook_ShouldCollide(entTouched, entOther) {

    ...
    
    if(!isCustomEntity(entTouched)) return FMRES_IGNORED

    if(!(global_get(glb_trace_flags) & FTRACE_BULLET)) {
        forward_return(FMV_CELL, 0)
        return FMRES_SUPERCEDE
    }

    return FMRES_IGNORED
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants