Raised This Month: $12 Target: $400
 3% 

[INFO] Fakemeta & Ham detailed function descriptions and examples


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-26-2009 , 08:03   [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #1

Fakemeta Func Wiki

I think that we all need to contribute to this topic so let's get it started.

FakeMeta Functions
HamSandWich Functions
Contributors
  • Arkshine
  • Starsailor
  • joropito
  • Nomexous
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 09-17-2010 at 07:28. Reason: Type fixes :P
ot_207 is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-26-2009 , 08:18   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #2

Fakemeta function:
PHP Code:
EngFunc_PointContents 
Description:
This function checks an origin and gives us information of its whearabouts.

The constants that this function returns are these:
Code:
#define	CONTENTS_EMPTY                  -1
#define	CONTENTS_SOLID                  -2
#define	CONTENTS_WATER                  -3
#define	CONTENTS_SLIME                  -4
#define	CONTENTS_LAVA                   -5
#define	CONTENTS_SKY                    -6
#define	CONTENTS_ORIGIN                 -7          // Removed at csg time
#define	CONTENTS_CLIP                   -8          // Changed to contents_solid
#define	CONTENTS_CURRENT_0              -9
#define	CONTENTS_CURRENT_90             -10
#define	CONTENTS_CURRENT_180            -11
#define	CONTENTS_CURRENT_270            -12
#define	CONTENTS_CURRENT_UP             -13
#define	CONTENTS_CURRENT_DOWN           -14
#define CONTENTS_TRANSLUCENT            -15
#define	CONTENTS_LADDER                 -16
#define	CONTENT_FLYFIELD                -17
#define	CONTENT_GRAVITY_FLYFIELD        -18
#define	CONTENT_FOG                     -19
Usage:
PHP Code:
static Float:origin[3]
static 
result
result 
engfunc(EngFunc_PointContentsorigin)
// if for example result is CONTENTS_SKY
// then the origin that we see is in the sky we can for example use this to see where a player is aming if he is aiming at sky this will be the result! 
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-15-2009 , 13:33   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #3

Fakemeta function:
PHP Code:
EngFunc_EntitiesInPVS 
Description:
This function checks entities that are in the PVS of an entity.
It can be used on all entities except worldspawn!

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:
Code:
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 doesn't work like EngFunc_FindEntityInSphere so the HL engine has another method of providing the information.
At first this function returns a start entity and after that we can find the next entity using pev_chain/EV_ENT_chain. And so on, untill pev_chain is NULL.

Example Usage:
PHP Code:
public whatisonPVS(id)
{
    static 
nextchain
    
static class[32]
    
    
next engfunc(EngFunc_EntitiesInPVSid)
    while(
next)
    {
        
pev(nextpev_classname, class, charsmax(class))
        
chain pev(nextpev_chain)
        
        
server_print("Found entity in player (%i) PVS: ent(%i) class(%s)"idnext, class)
        
        if(!
chain)
            break
    
        
next chain
    
}

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 09-15-2009 at 13:40.
ot_207 is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 10-13-2009 , 04:24   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #4

HamSandWich function:
PHP Code:
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:
PHP Code:
#define OFFSET_LAST_HIT_GROUP      75
#define EXTRAOFFSET_PL_LINUX        5

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

public 
fw_takedamage(victiminflictorattackerFloat:damagebits)
{
    
// 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(victimOFFSET_LAST_HIT_GROUPEXTRAOFFSET_PL_LINUX)

How to properly execute damage? This is the way to do it!
PHP Code:
#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(victiminflictorattackerdamagehitgroupbits)
{
    
set_pdata_int(victimOFFSET_LAST_HIT_GROUPhitgroupEXTRAOFFSET_PL_LINUX)
    
ExecuteHam(Ham_TakeDamagevictiminflictorattackerdamage*hitgroup_multi[hitgroup], bits)
}

stock Ham_ExecDamageB(victiminflictorattackerdamagehitgroupbits)
{
    
set_pdata_int(victimOFFSET_LAST_HIT_GROUPhitgroupEXTRAOFFSET_PL_LINUX)
    
ExecuteHamB(Ham_TakeDamagevictiminflictorattackerdamage*hitgroup_multi[hitgroup], bits)
}

stock HamRadiusDamage(entFloat:radiusFloat:damagebits)
{
    new 
target = -1Float:origin[3]
    
pev(entpev_originorigin)
    
    while(( 
target find_ent_in_sphere(targetoriginradius) ))
    {
        static 
Float:o[3]
        
pev(targetpev_origino)
        
        
xs_vec_sub(originoo)
        
        
// Recheck if the entity is in radius
        
if (xs_vec_len(o) > radius)
            continue
        
        
Ham_ExecDamageB(targetentpev(entpev_owner), damage * (xs_vec_len(o) / radius), HIT_GENERICbits)
    }

__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 10-16-2009 at 06:14.
ot_207 is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-14-2009 , 22:17   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #5

Thats a good post on Ham_TakeDamage!

I think it is worthwhile to discuss when we should use Ham_TakeDamage and when we should use Ham_TraceAttack.
__________________
stupok is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-26-2009 , 08:26   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #6

( Nice initiative but I think it should be update on the wiki too because more readable. Also for here creating a list for fakemeta and ham would be interesting. )

Last edited by Arkshine; 05-26-2009 at 08:30.
Arkshine is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-26-2009 , 08:35   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #7

Nice ot.
__________________
joaquimandrade is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-26-2009 , 08:39   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #8

Quote:
Originally Posted by arkshine View Post
( Nice initiative but I think it should be update on the wiki too because more readable. Also for here creating a list for fakemeta and ham would be interesting. )
I think that we should update here first and after that do a wiki.
And thanks!

Quote:
Originally Posted by joaquimandrade View Post
Nice ot.
Thanks! If you have functions or constants that are important please post .
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 05-26-2009 , 09:08   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #9

Fakemeta function:
PHP Code:
EngFunc_TraceLine 
Description:
This function traces between 2 origins and gives us information about it.

The constants that we can use in flags:
PHP Code:
#define DONT_IGNORE_MONSTERS            0
#define IGNORE_MONSTERS                 1
#define IGNORE_MISSILE                  2
#define IGNORE_GLASS                    0x100 
These constants can be used together.
Ex: IGNORE_MISSILE | IGNORE_MONSTERS | IGNORE_GLASS - This makes the traceline ignore missiles, monsters (players) and glass.

Here is a drawing that will show you how it works!
PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/1863/traceline1.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendDONT_IGNORE_MONSTERS0tr
[IMG]http://img529.**************/img529/1415/traceline2.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/5815/traceline3.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/326/traceline4.jpg[/IMG]

Functions that come with the TraceLine pack:
PHP Code:
// Description: This creates a trace handle! 
// It is important to use because we don't want our plugins to mess with eachothers info!
new ptr create_tr2() 
PHP Code:
// Description: This creates a trace handle! 
// It is important to use because we don't want our plugins to mess with each others info!
free_tr2(ptr
PHP Code:
// Description: Gets/Sets information from/in the trace_handle
[g|s]et_tr2(trace_handleCONSTANTnumber_if_needed!) 
CONSTANT Expresion has this posible values:
Code:
enum TraceResult
{
	TR_AllSolid,		// int
	TR_StartSolid,		// int
	TR_InOpen,		// int
	TR_InWater,		// int
	TR_flFraction,		// float
	TR_vecEndPos,		// float array[3]
	TR_flPlaneDist,		// float
	TR_vecPlaneNormal,	// float array[3]
	TR_pHit,		// int (edict_t*)
	TR_iHitgroup,		// int
};
The float and array values need the third argument! Example:

PHP Code:
    new allsolid get_tr2(traceTR_AllSolid)
    new 
startsolid get_tr2(traceTR_StartSolid)
    
// TR_StartSolid is a boolean that says whether you were "inside" something 
    // (usually the world) when the trace started (point A)
    // TR_AllSolid tells you if you ever got out of the "inside" or not.
    
    
new inopen get_tr2(traceTR_InOpen)
    
// TR_InOpen means that the start point is in Open
    // That means in the world and not in an ent or something
    
    
new hit get_tr2(traceTR_pHit)
    
// What was hit by the traceline. It will either be a player index,
    // entity index, 0 (part of map), or -1 (didn't hit anything; 
    // doesn't happen with player tracelines).
    
    
new hitgroup get_tr2(traceTR_iHitgroup)
    
// If the traceline hit another player, returns will be HIT_HEAD,
    // HIT_CHEST, HIT_LEFTLEG... etc. If the traceline hit part of the
    // map, this returns HIT_GENERIC.
    
    
new Float:fraction
    get_tr2
(traceTR_flFractionfraction)
    
// Returns a number between 0.0 and 1.0, indicating how far the
    // traceline traveled start to end before it hit something. Depending
    // on what conditions were passed to this traceline forward function,
    // it could either be a wall or another entity.
    
    
new Float:end_origin[3]
    
get_tr2(traceTR_vecEndPosend_origin)
    
// The official end of the traceline. Not necesarily the same as the
    // second argument passed to this traceline forward function.
    
    
new Float:normal[3]
    
get_tr2(traceTR_vecPlaneNormalnormal)
    
// Returns a 1 unit long vector normal to the spot that it hit. Note
    // that "normal" has a special connotation here. It doesn't mean "regular." 
Example Stock:
PHP Code:
stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    
// Create the trace handle! It is best to create it!
    
new ptr create_tr2()
    
    
// The main traceline function!
    // This function ignores GLASS, MISSILE and MONSTERS!
    // Here is an example of how you should combine all the flags!
    
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS IGNORE_MONSTERS IGNORE_MISSILEignore_entptr)
    
    
// We are interested in the fraction parameter
    
new fraction
    get_tr2
(ptrTR_flFractionfraction)
    
    
// Free the trace handle (don't forget to do this!)
    
free_tr2(ptr)
    
    
// If = 1.0 then it didn't hit anything!
    
return (fraction != 1.0)

Extra info:
Valve - arguments of the trace handle
TraceLine Tutorial (Nomexous)
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 09-15-2009 at 16:51.
ot_207 is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 03-19-2013 , 06:36   Re: [INFO] Fakemeta & Ham detailed function descriptions and examples
Reply With Quote #10

Quote:
Originally Posted by ot_207 View Post
Fakemeta function:
PHP Code:
EngFunc_TraceLine 
Description:
This function traces between 2 origins and gives us information about it.

The constants that we can use in flags:
PHP Code:
#define DONT_IGNORE_MONSTERS            0
#define IGNORE_MONSTERS                 1
#define IGNORE_MISSILE                  2
#define IGNORE_GLASS                    0x100 
These constants can be used together.
Ex: IGNORE_MISSILE | IGNORE_MONSTERS | IGNORE_GLASS - This makes the traceline ignore missiles, monsters (players) and glass.

Here is a drawing that will show you how it works!
PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/1863/traceline1.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendDONT_IGNORE_MONSTERS0tr
[IMG]http://img529.**************/img529/1415/traceline2.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/5815/traceline3.jpg[/IMG]

PHP Code:
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS0tr
[IMG]http://img529.**************/img529/326/traceline4.jpg[/IMG]

Functions that come with the TraceLine pack:
PHP Code:
// Description: This creates a trace handle! 
// It is important to use because we don't want our plugins to mess with eachothers info!
new ptr create_tr2() 
PHP Code:
// Description: This creates a trace handle! 
// It is important to use because we don't want our plugins to mess with each others info!
free_tr2(ptr
PHP Code:
// Description: Gets/Sets information from/in the trace_handle
[g|s]et_tr2(trace_handleCONSTANTnumber_if_needed!) 
CONSTANT Expresion has this posible values:
Code:
enum TraceResult
{
	TR_AllSolid,		// int
	TR_StartSolid,		// int
	TR_InOpen,		// int
	TR_InWater,		// int
	TR_flFraction,		// float
	TR_vecEndPos,		// float array[3]
	TR_flPlaneDist,		// float
	TR_vecPlaneNormal,	// float array[3]
	TR_pHit,		// int (edict_t*)
	TR_iHitgroup,		// int
};
The float and array values need the third argument! Example:

PHP Code:
    new allsolid get_tr2(traceTR_AllSolid)
    new 
startsolid get_tr2(traceTR_StartSolid)
    
// TR_StartSolid is a boolean that says whether you were "inside" something 
    // (usually the world) when the trace started (point A)
    // TR_AllSolid tells you if you ever got out of the "inside" or not.
    
    
new inopen get_tr2(traceTR_InOpen)
    
// TR_InOpen means that the start point is in Open
    // That means in the world and not in an ent or something
    
    
new hit get_tr2(traceTR_pHit)
    
// What was hit by the traceline. It will either be a player index,
    // entity index, 0 (part of map), or -1 (didn't hit anything; 
    // doesn't happen with player tracelines).
    
    
new hitgroup get_tr2(traceTR_iHitgroup)
    
// If the traceline hit another player, returns will be HIT_HEAD,
    // HIT_CHEST, HIT_LEFTLEG... etc. If the traceline hit part of the
    // map, this returns HIT_GENERIC.
    
    
new Float:fraction
    get_tr2
(traceTR_flFractionfraction)
    
// Returns a number between 0.0 and 1.0, indicating how far the
    // traceline traveled start to end before it hit something. Depending
    // on what conditions were passed to this traceline forward function,
    // it could either be a wall or another entity.
    
    
new Float:end_origin[3]
    
get_tr2(traceTR_vecEndPosend_origin)
    
// The official end of the traceline. Not necesarily the same as the
    // second argument passed to this traceline forward function.
    
    
new Float:normal[3]
    
get_tr2(traceTR_vecPlaneNormalnormal)
    
// Returns a 1 unit long vector normal to the spot that it hit. Note
    // that "normal" has a special connotation here. It doesn't mean "regular." 
Example Stock:
PHP Code:
stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    
// Create the trace handle! It is best to create it!
    
new ptr create_tr2()
    
    
// The main traceline function!
    // This function ignores GLASS, MISSILE and MONSTERS!
    // Here is an example of how you should combine all the flags!
    
engfunc(EngFunc_TraceLinestartendIGNORE_GLASS IGNORE_MONSTERS IGNORE_MISSILEignore_entptr)
    
    
// We are interested in the fraction parameter
    
new fraction
    get_tr2
(ptrTR_flFractionfraction)
    
    
// Free the trace handle (don't forget to do this!)
    
free_tr2(ptr)
    
    
// If = 1.0 then it didn't hit anything!
    
return (fraction != 1.0)

Extra info:
Valve - arguments of the trace handle
TraceLine Tutorial (Nomexous)
I have Question
What is "GLASS", what does that mean?
Is it some kind of entity like func_wall or it is texture material type?
.Dare Devil. is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:46.


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