Page 3 of 3

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 3:58 pm
by Archive-Poster
Fakemeta function :

Code: Select all

EngFunc_MoveToOrigin
Description :
Moves an entity a defined distance toward a coordinate.

If the distance between Entity and Destination is less than the required distance, the entity will pass over that point.
Usage :

Code: Select all

engfunc(EngFunc_MoveToOrigin, iEnt, Float:Destination[3], Float:Distance, iMoveType);
Parameters
iEnt = Entity index
Destination[3] = A Coordinate toward which the entity moves
Distance = The distance to move the entity
iMoveType = This is the MOVE_* option used for monsters and players to change the behaviour of the movement

Code: Select all

#define MOVE_NORMAL		0	// normal move in the direction monster is facing
#define MOVE_STRAFE		1	// moves in direction specified, no matter which way monster is facing
#define MOVE_STUCK_DIST		32	// if a monster can't step this far, it is stuck.
#define MOVE_START_TURN_DIST	64	// when this far away from moveGoal, start turning to face next goal
Caveats :
iEnt must be on ground
If there's an object closer than Distance that iEnt could collide then the movement is not done
If there's a ramp, it works like an object and the movement is not done

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:03 pm
by Archive-Poster
Fakemeta function:

Code: Select all

EngFunc_CheckVisibility 
Description:
This function is used to check if an entity is in your PVS.
It can be used on all entities except worldspawn!
Here I will show you how to use is, since this function has a paramater that must be obtained in a special way!

What is PVS?
PVS means potentially visible set, this means that the entities that we have in this list can be seen.
PVS does not hold just the entities that we see!
By knowing this we can get to the conclusion that PVS has the role of limiting data transfer for better internet connection/lower amount of data transfer!

So in small words I want to say something like this:
Entity that is in PVS => Can be seen => Data Transfer about that entity
Entity that it is not in PVS => Can not be seen => No data transfer => Save bandwidth
How does it work?
Well let's say that every room of the map is a cube.
We find ourselves in a room and that also means that we are in the cube of that room.
We can see the entities in the next rooms because the cubes of that room touch with the cube of the room we are in.

How do I use this function?
Well this function has a parameter that must be obtained in a special way. That is the "pset" parameter.
Here is how you obtain that parameter.
Note: The parameter is player only, that means that if you get pset for example for a player that has the id "1". When you use this function on an entity it will check whether that entity is in PVS of the Player id "1".

Example Usage:

Code: Select all

new g_cl_pset[33]

public plugin_init(id)
{
    register_forward(FM_AddToFullPack, "pfw_atfp", 1)
}

public pfw_atfp(es, e, ent, host, flags, player, set)
{
    g_cl_pset[host] = set
    
    return FMRES_IGNORED
}

stock is_ent_in_player_pvs(id, entity)
{
    return engfunc(EngFunc_CheckVisibility, entity, g_cl_pset[id])
}

stock get_pvs_players(id, players[32], num, flags[], team[])
{
    if (!is_user_connected(id))
        return 0    

    get_players(players, num, flags, team)
    
    for (new i=0;i<num;i++)
    {
        if (!is_ent_in_player_pvs(id, players[i]))
        {
            num--;
            
            for (new j=i;j<num;j++)
            {
                players[j] = players[j+1]
            }
            
            i--
        }
    }
    
    return 1
} 

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:04 pm
by Archive-Poster
Fakemeta function :

Code: Select all

EngFunc_PrecacheModel
Description :

Precaches a model or sprite file.

This should be used only when you would need to postpone the precache processus in plugin_init() or plugin_cfg(), otherwise you should use precache_model() native directly in plugin_precache() forward.
It can be useful for example when you want to manage models with cvars and to avoid registering them in plugin_precache() then getting some trouble, you could manage out of this forward.

Usage :

Code: Select all

engfunc( EngFunc_PrecacheModel, "models/MyModel.mdl" );
engfunc( EngFunc_PrecacheModel, "sprites/MySprite.spr" );
It returns the precached model/sprite index if successful, otherwise 0.

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:06 pm
by Archive-Poster
Fakemeta function :

Code: Select all

EngFunc_PrecacheSound
Description :

Precaches a sound, only *.wav file. ( for mp3, see EngFunc_PrecacheGeneric )

This should be used only when you would need to postpone the precache processus in plugin_init() or plugin_cfg(), otherwise you should use precache_sound() native directly in plugin_precache() forward.
It can be useful for example when you want to manage sounds with cvars and to avoid registering them in plugin_precache() then getting some trouble, you could manage out of this forward.

Usage :

Code: Select all

engfunc( EngFunc_PrecacheSound, "sound/MySound.wav" );

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:06 pm
by Archive-Poster
Fakemeta function :

Code: Select all

EngFunc_AlertMessage
Description :
Prints an alert message.

Usage:

Code: Select all

engfunc(EngFunc_AlertMessage, AlertType, const Message)

AlertType can be:
at_notice -
at_console - same as at_notice, but forces a ConPrintf, not a message box, prints output to server console, but only if 'developer' is 1.
at_aiconsole - same as at_console, but only shown if 'developer' is 2.
at_warning -
at_error -
at_logged - prints output to server logs and console.

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:08 pm
by Archive-Poster
HamSandWich function:

Code: Select all

Ham_TraceAttack


Description:
Forward: This function is called when an entity is shot by another player (weapon, not grenade.)
Function: This function simulates a weapon attack on an entity.
You should use this function when you want to simulate an attack by a weapon from a player (like a gunshot!)

Parameters:
(ent, attacker, float:damage, Float:direction[3], trace, bits)
- ent is the entity that has been shot
- attacker is the entity that shoot the victim
- damage - this is the damage done by the shot but it does not have the hitgroup multiplication done (that is done before TakeDamage Call)
- direction - this parameter has a very important roll, it is a normalized vector that shows the direction of the bullets path
- trace - the trace handle that offers lots of useful information
- bits - the damage bits

Forward usage:

Code: Select all

#define SHOT_DISTANCE_POSSIBLE 2048.0

// plugin_init()
Register_Ham(Ham_TraceAttack, "func_breakable", "fw_traceatt_break")

public fw_traceatt_break(ent, attacker, float:damage, Float:direction[3], trace, bits)
{
    new Float:start[3], end[3], fraction, multi
    get_tr2(trace, TR_vecEndPos, end)
    get_tr2(trace, TR_flFraction, fraction)
    
    multi = fraction * SHOT_DISTANCE_POSSIBLE
    
    xs_vec_mul_scalar(direction, multi, start)
    
    // This is how to correctly get the start origin!
    xs_vec_add(start, end, start)
    
} 
Function true usage:

Code: Select all

#define SHOT_DISTANCE_POSSIBLE 2048.0

public Ham_Shoot(attacker, damage, bits, bool:can_penetrate)
{
    new Float:angles[3], Float:start[3], Float:end[3], Float:direction[3], Float:fakeend[3]
    
    // Turn the angles in a true vector
    pev(attacker, pev_angles, angles)
    angle_vector(angles, ANGLEVECTOR_FORWARD, direction)
    
    // We make this as a normal shot!
    xs_vec_mul_scalar(direction, SHOT_DISTANCE_POSSIBLE, fakeend)
    
    // Start origin
    pev(attacker, pev_origin, start)
    pev(attacker, pev_view_ofs, end)
    xs_vec_add(end, start, start)
    
    // Obtain the end shot origin
    xs_vec_add(start, fakeend, end)
    
    // From now this is how these variables will be used
    // origin - start place (will remain constant!)
    // end - end place (will remain constant!)
    // angles - no use
    // fakeend - dynamic start origin
    // direction - will be used in the forwards (will remain constant!)
    
    new ptr = create_tr2()
    
    // Trace to the first entity
    engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, attacker, ptr)
    
    new Float:fraction, hit = get_tr2(ptr, TR_pHit)
    get_tr2(ptr, TR_flFraction, fraction)
    
    // Update the fake start origin
    get_tr2(ptr, TR_vecEndPos, fakeend)
    
    // This means that we hited sky!
    if (fraction != 1.0 && engfunc(EngFunc_PointContents, fakeend) == CONTENTS_SKY && hit == -1)
    {
        // Prepare the trace handle
        set_tr2(ptr, TR_pHit, 0)
        
        // Bullet trace!
        ExecuteHamB(Ham_TraceAttack, 0, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
        
        free_tr2(ptr)
        return -1
    }
    
    if (hit == -1)
    {
        hit = 0
        set_tr2(ptr, TR_pHit, hit)
    }
    
    ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
    
    if (!can_penetrate)
    {
        free_tr2(ptr)
        return 1
    }
    
    // Trace to the next entity
    engfunc(EngFunc_TraceLine, fakeend, end, DONT_IGNORE_MONSTERS, hit, ptr)
    
    hit = get_tr2(ptr, TR_pHit)
    get_tr2(ptr, TR_flFraction, fraction)
    
    // Update the fake start origin
    get_tr2(ptr, TR_vecEndPos, fakeend)
    
    if (hit == -1)
    {
        hit = 0
        set_tr2(ptr, TR_pHit, hit)
    }
    
    set_tr2(ptr, TR_flFraction, get_distance_f(start, fakeend) / SHOT_DISTANCE_POSSIBLE)
    
    ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)
    
        
    free_tr2(ptr)
    return 1
} 

Re: [INFO] Fakemeta & Ham detailed function descriptions and examples

Posted: Wed Oct 14, 2026 4:09 pm
by Archive-Poster
HamSandWich function:

Code: Select all

Ham_TakeDamage 
Description:
This function gives us info about the moment a player takes damage, when we use it as a forward. The return of the forward is a boolean, if it is set to 1 then the damage will be done if set to 0 then it will not be done!
It also can be used to give damage.
Here I will present how to correctly use this function!
You should use this function when you want to simulate an attack by a entity!

Usage:

Code: Select all

#define OFFSET_LAST_HIT_GROUP      75
#define EXTRAOFFSET_PL_LINUX        5

// plugin_init()
RegisterHam(Ham_TakeDamage, "player", "fw_takedamage")

public fw_takedamage(victim, inflictor, attacker, Float:damage, bits)
{
    // Victim is the entity that has been taken damage
    // Inflictor is the entity that directly gived damage
    // Attacker is the owner of the inflictor
    // If Attacker == Inflictor that means that the damage was inflicted by a player (such as gun shot/knife stab)
    // Damage the damage
    // Bits the type of damage represented in Bitsums
    
    // For grenade damage (In CS) the bits is equal to (1<<24)
    // Basically for hooking the he grenade damage is to put this condition
    // if (bits & (1<<24))
    
    // For bullet/knife damage (In CS) the bits are equal to (DMG_BULLET | DMG_NEVERGIB)
    // Basically for hooking the shot damage is to put this condition
    // if (bits & (DMG_BULLET | DMG_NEVERGIB))

    // Now the most subtile element is that we can get the last hitgroup where the damage was dealt

    new hitgroup = get_pdata_int(victim, OFFSET_LAST_HIT_GROUP, EXTRAOFFSET_PL_LINUX)
} 
How to properly execute damage? This is the way to do it!

Code: Select all

#define OFFSET_LAST_HIT_GROUP      75
#define EXTRAOFFSET_PL_LINUX        5

new const Float:hitgroup_multi[] =
{
    1.0,  // HIT_GENERIC
    4.0,  // HIT_HEAD
    1.0,  // HIT_CHEST
    1.25, // HIT_STOMACH
    1.0,  // HIT_LEFTARM
    1.0,  // HIT_RIGHTARM
    0.75, // HIT_LEFTLEG
    0.75  // HIT_RIGHTLEG
    0.0   // HIT_SHIELD
}

stock Ham_ExecDamage(victim, inflictor, attacker, damage, hitgroup, bits)
{
    set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX)
    ExecuteHam(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits)
}

stock Ham_ExecDamageB(victim, inflictor, attacker, damage, hitgroup, bits)
{
    set_pdata_int(victim, OFFSET_LAST_HIT_GROUP, hitgroup, EXTRAOFFSET_PL_LINUX)
    ExecuteHamB(Ham_TakeDamage, victim, inflictor, attacker, damage*hitgroup_multi[hitgroup], bits)
}

stock HamRadiusDamage(ent, Float:radius, Float:damage, bits)
{
    new target = -1, Float:origin[3]
    pev(ent, pev_origin, origin)
    
    while(( target = find_ent_in_sphere(target, origin, radius) ))
    {
        static Float:o[3]
        pev(target, pev_origin, o)
        
        xs_vec_sub(origin, o, o)
        
        // Recheck if the entity is in radius
        if (xs_vec_len(o) > radius)
            continue
        
        Ham_ExecDamageB(target, ent, pev(ent, pev_owner), damage * (xs_vec_len(o) / radius), HIT_GENERIC, bits)
    }
}