PDA

View Full Version : [INFO] Fakemeta & Ham detailed function descriptions and examples


ot_207
05-26-2009, 08:03
Fakemeta Func Wiki (http://wiki.alliedmods.net/FakeMeta_Functions_Detailed_Descriptions)

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

FakeMeta Functions

Point Functions

EngFunc_PointContents (http://forums.alliedmods.net/showpost.php?p=835011&postcount=2)
EngFunc_GetBonePosition (http://forums.alliedmods.net/showpost.php?p=963674&postcount=103)


Messaging Functions

EngFunc_MessageBegin (http://forums.alliedmods.net/showpost.php?p=835328&postcount=19)


Entity Search Functions

EngFunc_FindEntityInSphere (http://forums.alliedmods.net/showpost.php?p=835040&postcount=7)
EngFunc_EntitiesInPVS (http://forums.alliedmods.net/showpost.php?p=933833&postcount=68)
EngFunc_FindEntityByString (http://forums.alliedmods.net/showpost.php?p=962797&postcount=82)
EngFunc_FindClientInPVS (http://forums.alliedmods.net/showpost.php?p=964380&postcount=104)


Trace Functions

EngFunc_TraceLine (http://forums.alliedmods.net/showpost.php?p=835030&postcount=6)
EngFunc_TraceTexture, DLLFunc_PM_FindTextureType (http://forums.alliedmods.net/showpost.php?p=929952&postcount=51)
EngFunc_TraceModel (http://forums.alliedmods.net/showpost.php?p=962893&postcount=94)
EngFunc_TraceToss (http://forums.alliedmods.net/showpost.php?p=1012481&postcount=138)


Model/Decal/Texture Functions

EngFunc_SetModel (http://forums.alliedmods.net/showpost.php?p=962860&postcount=91)
EngFunc_ModelIndex (http://forums.alliedmods.net/showpost.php?p=962753&postcount=81)
EngFunc_ModelFrames (http://forums.alliedmods.net/showpost.php?p=962845&postcount=89)
EngFunc_DecalIndex (http://forums.alliedmods.net/showpost.php?p=962770&postcount=80)
EngFunc_AnimationAutomove (http://forums.alliedmods.net/showpost.php?p=988936&postcount=115)


Entity/Global Functions

EngFunc_NumberOfEntities (http://forums.alliedmods.net/showpost.php?p=962849&postcount=90)
EngFunc_SetSize (http://forums.alliedmods.net/showpost.php?p=962865&postcount=92)
EngFunc_SetOrigin (http://forums.alliedmods.net/showpost.php?p=962865&postcount=93)
EngFunc_MoveToOrigin (http://forums.alliedmods.net/showpost.php?p=963033&postcount=97)


Visibility Functions

EngFunc_CheckVisibility (http://forums.alliedmods.net/showpost.php?p=963665&postcount=102)


Other Functions

EngFunc_PrecacheModel (http://forums.alliedmods.net/showpost.php?p=835189&postcount=14)
EngFunc_PrecacheSound (http://forums.alliedmods.net/showpost.php?p=835201&postcount=15)
EngFunc_AlertMessage (http://forums.alliedmods.net/showpost.php?p=964853&postcount=106)



HamSandWich Functions

Ham_TraceAttack (http://forums.alliedmods.net/showpost.php?p=913473&postcount=42)
Ham_TakeDamage (http://forums.alliedmods.net/showpost.php?p=960618&postcount=71)


Contributors
Arkshine
Starsailor
joropito
Nomexous

ot_207
05-26-2009, 08:18
Fakemeta function:
EngFunc_PointContents

Description:
This function checks an origin and gives us information of its whearabouts.

The constants that this function returns are these:
#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:
static Float:origin[3]
static result
result = engfunc(EngFunc_PointContents, origin)
// 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!

Arkshine
05-26-2009, 08:26
( 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. )

joaquimandrade
05-26-2009, 08:35
Nice ot.

ot_207
05-26-2009, 08:39
( 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!

Nice ot.

Thanks! If you have functions or constants that are important please post :).

ot_207
05-26-2009, 09:08
Fakemeta function:
EngFunc_TraceLine

Description:
This function traces between 2 origins and gives us information about it.

The constants that we can use in flags:
#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!
engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/1863/traceline1.jpg (http://img529.**************/my.php?image=traceline1.jpg)

engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, 0, tr)
http://img529.**************/img529/1415/traceline2.jpg (http://img529.**************/my.php?image=traceline2.jpg)

engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/5815/traceline3.jpg (http://img529.**************/my.php?image=traceline3.jpg)

engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/326/traceline4.jpg (http://img529.**************/my.php?image=traceline4.jpg)

Functions that come with the TraceLine pack:
// 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()

// 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)

// Description: Gets/Sets information from/in the trace_handle
[g|s]et_tr2(trace_handle, CONSTANT, number_if_needed!)

CONSTANT Expresion has this posible values:

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:

new allsolid = get_tr2(trace, TR_AllSolid)
new startsolid = get_tr2(trace, TR_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(trace, TR_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(trace, TR_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(trace, TR_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(trace, TR_flFraction, fraction)
// 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(trace, TR_vecEndPos, end_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(trace, TR_vecPlaneNormal, normal)
// 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:
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_TraceLine, start, end, IGNORE_GLASS | IGNORE_MONSTERS | IGNORE_MISSILE, ignore_ent, ptr)

// We are interested in the fraction parameter
new fraction
get_tr2(ptr, TR_flFraction, fraction)

// 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 (http://developer.valvesoftware.com/wiki/TraceLines)
TraceLine Tutorial (Nomexous) (http://forums.alliedmods.net/showthread.php?t=66076)

ot_207
05-26-2009, 09:37
Fakemeta function:
EngFunc_FindEntityInSphere

Description:
Find entities within a radius. The function returnes the next entity id after the start entity!

This is a drawing to show how this function works:
http://img265.**************/img265/2395/screenshot053.png (http://img265.**************/my.php?image=screenshot053.png)


If we use
engfunc(EngFunc_FindEntityInSphere, -1, origin, radius)
The function in the situation above will return 1!
engfunc(EngFunc_FindEntityInSphere, 20, origin, radius)
The function in the situation above will return 30!
engfunc(EngFunc_FindEntityInSphere, 100, origin, radius)
The function in the situation above will return 0, meaning that it didn't find an entity with an id grater than 100!


Usage:
engfunc(EngFunc_FindEntityInSphere, ent_to_start, origin, radius)

Dr.G
05-26-2009, 09:53
nice ot. if anyone think a sphere is another word for circle its not -> http://en.wikipedia.org/wiki/File:Sphere_wireframe.svg

ot_207
05-26-2009, 09:57
nice ot. if anyone think a sphere is another word for circle its not -> http://en.wikipedia.org/wiki/File:Sphere_wireframe.svg

Thanks! That was just as an example. If someone would do a 3d design it would be great :mrgreen:.

Dr.G
05-26-2009, 10:46
this is some screenshots from autocad

xPaw
05-26-2009, 12:15
Good job ot, i suggest you add some list at first post

EngFunc_GetBonePosition (http://forums.alliedmods.net/showpost.php?p=835005&postcount=1)
EngFunc_PointContents (http://forums.alliedmods.net/showpost.php?p=835011&postcount=2)
EngFunc_TraceLine (http://forums.alliedmods.net/showpost.php?p=835030&postcount=6)
EngFunc_FindEntityInSphere (http://forums.alliedmods.net/showpost.php?p=835040&postcount=7)

ot_207
05-26-2009, 12:26
this is some screenshots from autocad

Good job but try to make the 3 entities spheres in 3d and give them the same names as I did!

Good job ot, i suggest you add some list at first post

Edit: Added it!

EngFunc_GetBonePosition (http://forums.alliedmods.net/showpost.php?p=835005&postcount=1)
EngFunc_PointContents (http://forums.alliedmods.net/showpost.php?p=835011&postcount=2)
EngFunc_TraceLine (http://forums.alliedmods.net/showpost.php?p=835030&postcount=6)
EngFunc_FindEntityInSphere (http://forums.alliedmods.net/showpost.php?p=835040&postcount=7)

Good idea.
This list I will add in the future!
But you should also try to describe some functions or constants. I can't just do all of them...

Arkshine
05-26-2009, 12:41
Good idea.

I was my suggestion above. I haven spoken chinese probably. :mrgreen:
I will try to describe some functions too.

I can't just do all of them...

I'm sure you can. :p

Arkshine
05-26-2009, 14:17
Fakemeta function :

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() (http://www.amxmodx.org/funcwiki.php?search=plugin_init&go=search) or plugin_cfg() (http://www.amxmodx.org/funcwiki.php?search=plugin_cfg&go=search), otherwise you should use precache_model() (http://www.amxmodx.org/funcwiki.php?go=func&id=15) native directly in plugin_precache() (http://www.amxmodx.org/funcwiki.php?go=func&id=7) 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 :

engfunc( EngFunc_PrecacheModel, "models/MyModel.mdl" );
engfunc( EngFunc_PrecacheModel, "sprites/MySprite.spr" );

It returns the precached model/sprite index if successful, otherwise 0.

Arkshine
05-26-2009, 14:38
Fakemeta function :

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() (http://www.amxmodx.org/funcwiki.php?search=plugin_init&go=search) or plugin_cfg() (http://www.amxmodx.org/funcwiki.php?search=plugin_cfg&go=search), otherwise you should use precache_sound() (http://www.amxmodx.org/funcwiki.php?search=precache_sound&go=search) native directly in plugin_precache() (http://www.amxmodx.org/funcwiki.php?go=func&id=7) 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 :

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

It returns the precached sound index if successful, otherwise 0.

SchlumPF*
05-26-2009, 15:50
better create some kind of wiki where everyone can contribute like wikipedia, would be more handy than a forum thread.
i would appreciate that very much :D

Arkshine
05-26-2009, 15:54
What I've suggested in my first post, but ot_207 prefers to do that to start. Someone can give me a good page name, I'm suck to find a good one and I will create the page right away on the wiki.

SchlumPF*
05-26-2009, 16:03
What I've suggested in my first post, but ot_207 prefers to do that to start. Someone can give me a good page name, I'm suck to find a good one and I will create the page right away on the wiki.
sry didnt read the whole thread, i just came home and checked the forum before showering and saw the thread. i simply read the mainpost and posted my idea :D
anyway, im sry but i cant find such a wikicms or whatever i should call it either :(

Starsailor
05-26-2009, 18:04
Fakemeta Function:

EngFunc_MessageBegin

Description:

This function is used to generate client messages.

Usage:

engfunc(EngFunc_MessageBegin,dest,msg_type,or igin[3]={0,0,0},player=0)


static Float:origin[3] // Origin should be a Float
pev(id, pev_origin, origin) // Get user origin
engfunc(EngFunc_MessageBegin,MSG_BROADCAST,SV C_TEMPENTITY,origin,0) // Create message

//With MSG_ONE_UNRELIABLE
engfunc(EngFunc_MessageBegin,MSG_ONE_UNRELIAB LE,SVC_TEMPENTITY,_,id) // Create message

//With MSG_ALL
engfunc(EngFunc_MessageBegin,MSG_ONE_UNRELIAB LE,SVC_TEMPENTITY,_,id) // Create message
dest can be :


#define MSG_BROADCAST 0 // Unreliable to all, There is not id
#define MSG_ONE 1 // Reliable to one (msg_entity)
#define MSG_ALL 2 // Reliable to all, There is not origin
#define MSG_INIT 3 // Write to the init string
#define MSG_PVS 4 // Ents in PVS of org
#define MSG_PAS 5 // Ents in PAS of org
#define MSG_PVS_R 6 // Reliable to PVS
#define MSG_PAS_R 7 // Reliable to PAS
#define MSG_ONE_UNRELIABLE 8 // Send to one client, but don't put in reliable stream, put in unreliable datagram (could be dropped), There is not origin
#define MSG_SPEC 9 // Sends to all spectator proxies
Before calling another EngFunc_MessageBegin you must call message_end()

Starsailor
05-26-2009, 18:25
List of all functions:

EngFunc_GetBonePosition (http://forums.alliedmods.net/showpost.php?p=835005&postcount=1)
EngFunc_PointContents (http://forums.alliedmods.net/showpost.php?p=835011&postcount=2)
EngFunc_TraceLine (http://forums.alliedmods.net/showpost.php?p=835030&postcount=6)
EngFunc_FindEntityInSphere (http://forums.alliedmods.net/showpost.php?p=835040&postcount=7)
EngFunc_PrecacheModel (http://forums.alliedmods.net/showpost.php?p=835189&postcount=14)
EngFunc_PrecacheSound (http://forums.alliedmods.net/showpost.php?p=835201&postcount=15)
EngFunc_MessageBegin (http://forums.alliedmods.net/showpost.php?p=835328&postcount=19)

Arkshine
05-26-2009, 18:36
Your example is wrong. There is not id nor origin for MSG_ALL/MSG_BROADCAST. You should add an example for all.

Starsailor
05-26-2009, 20:21
oo yes, you are right, i have forgotten that

EDIT: Done

ConnorMcLeod
05-27-2009, 01:34
Your example is wrong. There is not id nor origin for MSG_ALL/MSG_BROADCAST. You should add an example for all.

+ origins have to be floats.

Arkshine
05-27-2009, 01:39
oo yes, you are right, i have forgotten that

EDIT: Done

It's still wrong.


engfunc( EngFunc_MessageBegin, MSG_BROADCAST, SVC_TEMPENTITY );
engfunc( EngFunc_MessageBegin, MSG_ALL, SVC_TEMPENTITY );

engfunc( EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id );
engfunc( EngFunc_MessageBegin, MSG_ONE, SVC_TEMPENTITY, _, id );

engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0 );
engfunc( EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, origin, 0 );

You should also comment more each MSG_*.

SchlumPF*
05-27-2009, 01:44
EngFunc_Message_Beginuses floats, message_begin() doesnt.
if you explain such a function you should add an example when to use EngFunc_Message_Beginand when to use message_begin() because imo is EngFunc_Message_Beginkinda unnecesarry :X
also, you should explain MSG_INIT, PVS and PAS (with a short example ofc). at least because i never was able to find that out xD i mean MSG_ONE and MSG_ALL (+ the unreliable ones of them) are quite common but i guess there are a lot who never used MSG_INIT, MSG_PVS and MSG_PAS.
another thing is the origin, are there a few messages where you need it? i mean most messages need write_coord() to set the origin ^^

Arkshine
05-27-2009, 02:10
EngFunc_MessageBegin is not unnecessary if you work with float and you use MSG_PVS/MSG_PAS. But it's true except that, message_begin() (http://www.amxmodx.org/funcwiki.php?go=func&id=262) should be used.

Btw :

MSG_PVS = Potentially Visible Set = The message will be sent only to player who potentially view the provided origin.
MSG_PAS = Potentially Audible Set = The message will be sent only to player who potentially hear the sound from the provided origin.

It's useful to reduce data sent to a client.

MSG_PVS_R and MSG_PAS_R are not used. I think there is a thread about that.

Exolent[jNr]
05-27-2009, 02:11
This is the most unorganized information tutorial I've ever seen.

Arkshine
05-27-2009, 02:16
That's why it's better to use directly the wiki. :p

By the way, can you find for me a good page name so I can create it on the wiki, Exolent ? :p

xPaw
05-27-2009, 04:08
Fakemeta functions and their descriptions :mrgreen:

hleV
05-27-2009, 04:38
"arkshine's Wiki".

Arkshine
05-27-2009, 04:46
It doesn't help a lot. :mrgreen:

I will try and it can be renamed later anyway.

Arkshine
05-27-2009, 05:03
You are drunk ?

zwfgdlc
05-27-2009, 05:09
haha!sorry,my english is very bad.i misunderstand what you say.

Starsailor
05-27-2009, 12:11
just i'm trying to help :cry::cry::cry::|:|:|

ot_207
05-27-2009, 12:43
just i'm trying to help :cry::cry::cry::|:|:|

It is good that you are trying to help and you should also receive :crab:'s for that but you must help correctly! Look at the way I did the functions :), if you can do the same it will be great, arkshine is lending you a hand :wink:, try to take into account his advices.

SchlumPF*
05-27-2009, 12:47
It is good that you are trying to help and you should also receive Karma for that but you must help correctly! Look at the way I did the functions :), if you can do the same it will be great, arkshine is lending you a hand :wink:, try to take into account his advices.
there is no karma anymore, you need to give :crab:'s now :D

ot_207
05-27-2009, 12:51
there is no karma anymore, you need to give :crab:'s now :D

Right! Fixed that :mrgreen:!
Ja! Ich habe das repariert :mrgreen:!

Edit: Wo hat diese geniale idee, um Krabs stattdessen Karma geben?
Who had the idea of giving crabs instead of karma?

Edit2: SnoW the thread is already spammed enough so one post in plus won't make a dif :P.

SnoW
05-27-2009, 13:27
Who had the idea of giving crabs instead of karma?
You are making spam to your own thread. It was never instead. Guys gave crabs much before the karma system was nuked.

SchlumPF*
05-27-2009, 15:21
Edit: Wo hat diese geniale idee, um Krabs stattdessen Karma geben?
Who had the idea of giving crabs instead of karma?

Wo = where, who = wer
-> Wer hatte diese geniale Idee (there is no "genial" in your english sentence), Krabben statt Karma zu geben. (falscher Nebensatz).

i love ppl speaking german who learned it barely :D the sentences are most often wrong but you can understand nearly each sentece... this is much harder if someone _tries_ to speak english xD

:crab::crab::crab: to you ot_2007 <3

ot:
as you can see a thread is a really bad assembly of this idea which is really nice. some kind of wikipedia including a thread here at amxx where ppl can complain about erros and give you -:crab:'s!!!

ot_207
08-25-2009, 09:41
Let's create a wiki with this. These functions will be useful.

SnoW
08-25-2009, 12:03
Oi but you need a name on that. The thread's name is too long i guess.

ot_207
08-26-2009, 09:44
HamSandWich function:
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:
#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:

#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
}

fysiks
08-26-2009, 18:51
- direction - this parameter has a very important roll, it is the tangent of the line that the bullet goes

I don't understand this. Is it the direction vector from the attacker to the victim?

ot_207
08-26-2009, 18:54
I don't understand this. Is it the direction vector from the attacker to the victim?

Let me explain in vectors.
We have the endposition of the bullet.
ENDPOS
We have the gun tube from where the bullet was fired.
STARTPOS
Direction is xs_vec_normalize(ENDPOS-STARTPOS), it shows the angles.

fysiks
08-26-2009, 19:04
Ok that's what I thought. Tangent is not a good word to use there in this case. The tangent of the bullet's path is constantly changing throughout it's parabolic path (I don't know if they consider gravity for bullets in these games :|).

ot_207
08-26-2009, 19:07
Ok that's what I thought. Tangent is not a good word to use there in this case. The tangent of the bullet's path is constantly changing throughout it's parabolic path (I don't know if they consider gravity for bullets in these games :|).

Gravity does not influence bullets. So Tangent is the best term (I think) to describe it.
If you have a better suggestion please let me know :).

fysiks
08-27-2009, 00:12
Gravity does not influence bullets. So Tangent is the best term (I think) to describe it.
If you have a better suggestion please let me know :).

"[Unit] vector in the direction of the bullets path."

[unit] only if it's normalized.

The tangent of a straight line is the line itself. When I first read it I was thinking perpendicular for some reason which would mean it was a plane lol :).

ConnorMcLeod
08-27-2009, 00:39
It's called normal vector i guess.

Emp`
09-03-2009, 12:23
NOTE The terms "perpendicular," "orthogonal," and "normal" all mean essentially the same thing - meeting at right angles. However, it is common to say that two vectors are orthogonal, two lines or planes are perpendicular, and a vector is normal to a given line or plane.

fysiks
09-03-2009, 17:12
Normalize => convert to vector of length 1 (aka unit vector).

!=

normal vector (Emp explains above)

ot_207
09-11-2009, 14:18
FakeMeta functions:
EngFunc_TraceTexture, DLLFunc_PM_FindTextureType

Description:
The TraceTexture function detects the texture of an entity from a direction
The FindTextureType function allows to get the type of the material of the texture.

Parameters:
engfunc(EngFunc_TraceTexture, ent, Float:start[3], Float:end[3], texture_name, len)
- ent is the entity that we want to get the texture
- start is the point from where the trace starts
- end is the point where the trace ends
- texture_name - here we save the texture name
- len - the texture_name string length
@Return
Nothing!

dllfunc(DLLFunc_PM_FindTextureType, texture_name)
- texture_name is the name of the texture that we have gotten with TraceTexture
@Return
It returns the material of the texture.


Constants:
The first function does not have any constants but if the name of the texture begins with '{' the texture is semi-transparent!

The letter constants are returned by the second function. "DLLFunc_PM_FindTextureType"

/*
C : concrete
D : dirt
G : grate
M : metal
N : snow
P : computer
S : slosh
T : tile
V : ventilation
W : wood
Y : glass
*/


new const material_array[] =
{
'C', 'D', 'G', 'M', 'N', 'P', 'S', 'T', 'V', 'W', 'Y'
}


Usage:
new texture_name[64], texture_type
engfunc(EngFunc_TraceTexture, 0, start, end, texture_name, charsmax(texture_name))
texture_type = dllfunc(DLLFunc_PM_FindTextureType, texture_name)

Notes:
- Improper use of these functions may crash the server!!!
- To avoid crashing the server use the TraceTexture:
-on any entities (even worldspawn) except players
-use this function only when there is at least one player connected
-the distance between the two points must be big! [> 2000.0]

Arkshine
09-11-2009, 14:41
You forget to say that the material returned is depending the materials.txt file. ( client ) So it's very limited. ( You forget N for Snow )

ot_207
09-11-2009, 14:42
You forget to say that the material returned is depending the materials.txt file. ( client ) So it's very limited.

It depends on the server config.

Arkshine
09-11-2009, 15:02
What do you mean ?

ot_207
09-11-2009, 15:33
What do you mean ?

I mean that every map has its own set of textures and every texture has its own material. And it is not client dependent.

SnoW
09-11-2009, 15:34
( You forget N for Snow )
Did someone call me?

ot_207
09-11-2009, 15:36
Did someone call me?

Added you to the constants :mrgreen:

ConnorMcLeod
09-11-2009, 15:38
And it is not client dependent.

Yes it is, unfortunately.

Arkshine
09-11-2009, 15:41
I mean that every map has its own set of textures and every texture has its own material. And it is not client dependent.

You're wrong. Most of maps use common textures from valve wad. But the material is listed in materials.txt (client file ) corresponding the texture. Only the default textures are listed there. ( it's possible that some maps when you install it on your pc modify the file to add its textures, but it rarely happens ). If you play a map which use custom textures not listed in this file, the default material will be 'Concrete'.

ot_207
09-11-2009, 15:42
Yes it is, unfortunately.

How can this be?
It traces the map that you have on your server not the client map.

You're wrong. Most of maps use common textures from valve wad. But the material is listed in materials.txt corresponding the texture. Only the default textures are listed there. If you play a map which use custom textures not listed in this file, the default material will be Concrete.

It is dependent on that but not on client!

Arkshine
09-11-2009, 15:51
I don't understand what you mean. The file is on the CLIENT and material is defined corresponding the texture in this file ONLY. DLLFunc_PM_FindTextureType called on client. Meaning if you use an unknow texture not listed, the material will bon concrete by default.

ot_207
09-11-2009, 15:55
I don't understand what you mean. The file is on the CLIENT and material is defined corresponding the texture in this file ONLY. DLLFunc_PM_FindTextureType called on client. Meaning if you use an unknow texture not listed, the material will bon concrete by default.

Than why does the function not have dllfunc(DLLFunc_PM_FindTextureType, texture_name, player_id) ??????

Arkshine
09-11-2009, 16:00
What. Why are you talking about player id ? lol I think, when the game is loading, it reads the file and loading in memory.


void PM_InitTextureTypes()
{
char buffer[512];
int i, j;
byte *pMemFile;
int fileSize, filePos;
static qboolean bTextureTypeInit = false;

if ( bTextureTypeInit )
return;

memset(&(grgszTextureName[0][0]), 0, CTEXTURESMAX * CBTEXTURENAMEMAX);
memset(grgchTextureType, 0, CTEXTURESMAX);

gcTextures = 0;
memset(buffer, 0, 512);

fileSize = pmove->COM_FileSize( "sound/materials.txt" );
pMemFile = pmove->COM_LoadFile( "sound/materials.txt", 5, NULL );
if ( !pMemFile )
return;

filePos = 0;
// for each line in the file...
while ( pmove->memfgets( pMemFile, fileSize, &filePos, buffer, 511 ) != NULL && (gcTextures < CTEXTURESMAX) )
{
// skip whitespace
i = 0;
while(buffer[i] && isspace(buffer[i]))
i++;

if (!buffer[i])
continue;

// skip comment lines
if (buffer[i] == '/' || !isalpha(buffer[i]))
continue;

// get texture type
grgchTextureType[gcTextures] = toupper(buffer[i++]);

// skip whitespace
while(buffer[i] && isspace(buffer[i]))
i++;

if (!buffer[i])
continue;

// get sentence name
j = i;
while (buffer[j] && !isspace(buffer[j]))
j++;

if (!buffer[j])
continue;

// null-terminate name and save in sentences array
j = min (j, CBTEXTURENAMEMAX-1+i);
buffer[j] = 0;
strcpy(&(grgszTextureName[gcTextures++][0]), &(buffer[i]));
}

// Must use engine to free since we are in a .dll
pmove->COM_FreeFile ( pMemFile );

PM_SortTextures();

bTextureTypeInit = true;
}



char PM_FindTextureType( char *name )
{
int left, right, pivot;
int val;

assert( pm_shared_initialized );

left = 0;
right = gcTextures - 1;

while ( left <= right )
{
pivot = ( left + right ) / 2;

val = strnicmp( name, grgszTextureName[ pivot ], CBTEXTURENAMEMAX-1 );
if ( val == 0 )
{
return grgchTextureType[ pivot ];
}
else if ( val > 0 )
{
left = pivot + 1;
}
else if ( val < 0 )
{
right = pivot - 1;
}
}

return CHAR_TEX_CONCRETE;
}


PM_FindTextureType is a client-side function.

ot_207
09-11-2009, 16:04
Then why doesn't it have the player_id in the arguments?
So that the server will now what material to look at.

Arkshine
09-11-2009, 16:11
Player has nothing to do here. Textures/materials stuff is done by the client, not server. ( like you can see the file is read when you load the game ). DLLFunc_PM_FindTextureType calls just PM_FindTextureType function on the client. I don't know how to explain properly sorry. lol. For sure sounds are played by player. If you modify the materials.txt file on your pc, removing all the textures, it will play always the concrete sound only for you. What you you need to understand is the material is found by checking the texture name in this file.

ot_207
09-11-2009, 16:15
Player has nothing to do here. Textures/materials stuff is done by the client, not server. ( like you can see the file is read when you load the game ). DLLFunc_PM_FindTextureType calls just PM_FindTextureType function on the client. I don't know how to explain properly sorry. lol. For sure sounds are played by player. If you modify the materials.txt file on your pc, removing all the textures, it will play always the concrete sound only for you. What you you need to understand is the material is found by checking the texture name in this file.

I understand that each material is what affects the client but normally the return values should only depend on the server map and server materials.txt and only that! In this situation you are right that the sounds are client side!

Arkshine
09-11-2009, 16:22
only depend on the server map and server materials.txt

It does already that !! Depending the texture used for the map and the texture listed by default in materials.txt you will get the right material or the default one.

[Edit] Ahhh "server". Sorry. Well there is probably a good reason for that.

ot_207
09-15-2009, 13:33
Fakemeta function:
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:
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:
public whatisonPVS(id)
{
static next, chain
static class[32]

next = engfunc(EngFunc_EntitiesInPVS, id)
while(next)
{
pev(next, pev_classname, class, charsmax(class))
chain = pev(next, pev_chain)

server_print("Found entity in player (%i) PVS: ent(%i) class(%s)", id, next, class)

if(!chain)
break

next = chain
}
}

Arkshine
09-15-2009, 13:37
Please indent the code properly. :twisted:

ot_207
09-15-2009, 13:41
Please indent the code properly. :twisted:

Done :P

ot_207
10-13-2009, 04:24
HamSandWich function:
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:

#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!

#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)
}
}

stupok
10-14-2009, 22:17
Thats a good post on Ham_TakeDamage! :up:

I think it is worthwhile to discuss when we should use Ham_TakeDamage and when we should use Ham_TraceAttack.

SnoW
10-15-2009, 07:20
Also to mention that knife damage also equals DMG_BULLET | DMG_NEVERGIB, so if you wanted to catch that you would have to check player's weapon like with other guns.

joropito
10-15-2009, 09:33
Ot, if you have time, it would be nice yo have a full tutorial of TraceModel and TraceHull because they are two of the most powerfull functions I guess.

ot_207
10-15-2009, 09:45
Also to mention that knife damage also equals DMG_BULLET | DMG_NEVERGIB, so if you wanted to catch that you would have to check player's weapon like with other guns.

Fixed.

Ot, if you have time, it would be nice yo have a full tutorial of TraceModel and TraceHull because they are two of the most powerfull functions I guess.

I will do them in the future. This topic will slowly be complete.
The only thing that bothers me is that no one besides me still is active in this topic.
No one is interested in helping others, but everybody is good at observing someone else's mistake...

Arkshine
10-15-2009, 10:05
It requires some time to well-written a complete description. :)

ot_207
10-15-2009, 10:07
It requires some time to well-written a complete description. :)

That may be true, but if you try to make them they will be done in maximum one hour, and it only takes that long when you truly have a big description.

Arkshine
10-15-2009, 10:12
I'm going to try to make the easy ones. :mrgreen:

ot_207
10-15-2009, 10:14
I'm going to try to make the easy ones. :mrgreen:

Ok :P

Arkshine
10-15-2009, 10:44
Fakemeta function :

EngFunc_ModelIndex


Description :

Returns an unique index of the model name provided.
It's actually the same number that precache_model() (http://www.amxmodx.org/funcwiki.php?search=precache_model&go=search) returns.

A model index is used for example in some TE_* messages. ( TE_LIGHTNING, TE_GLOWSPRITE, etc.. See message_const.inc (http://svn.tcwonline.org/viewvc.cgi/trunk/plugins/include/message_const.inc?view=markup&root=amxmodx) file ).
The model index of an entity is stored in pev_modelindex.
Usage :

ModelIndex = engfunc( EngFunc_ModelIndex, "models/MyModel.mdl" );

Arkshine
10-15-2009, 10:58
Fakemeta function :

EngFunc_DecalIndex


Description :

Returns an unique index of the decal name provided.

A decal index is used for example in some TE_* messages. ( TE_PLAYERDECAL, TE_DECAL, etc.. See message_const.inc (http://svn.tcwonline.org/viewvc.cgi/trunk/plugins/include/message_const.inc?view=markup&root=amxmodx) file ).
All the available decals are stored in the decals.wad file. ( Located at your mod root )
As side-note a plugin Decals/Models Lister (http://forums.alliedmods.net/showthread.php?p=247677) is available to see a list of decals/models index/name. ( Only CS and HL )
Usage :

DecalIndex = engfunc( EngFunc_DecalIndex, "{bigshot1" );

joropito
10-15-2009, 11:52
Fakemeta function :
EngFunc_FindEntityByString


Description :

Returns the first entity found that matches the search criteria.

You can use any of string type attributes of entities:

classname Type of entity
globalname This is the name of the global variable that can be used to control the state of the entity
model The model of the entity
target Entity that this entity is handling
targetname The name given to this entity that another entity searches for to handle it
netname Player or NPC name
message Seems to be used mainly to store sound (string). It happens to store others things, depending the need of the entity
noise Noise variables do different things for different ents.
noise1 This is the move sound for doors.
noise2 This is the stop sound for doors.
noise3 This is for blocking game_player_equip and player_weaponstrip

source: http://xpaw.ru/pev_research.php


Usage :

iEnt = engfunc( EngFunc_FindEntityByString, iStartEnt, sAttribute, sText );


Parameters
iStartEnt = Start search on this entity (ex: 0 = worldspawn)
sAttribute = Name of attribute over which we need to search (ex: classname)
sText = Text string that we are searching for (ex: func_breakable)

Return
iEnt = Index of the first entity that matches the search

xPaw
10-15-2009, 11:58
source: http://xpaw.ru/pev_research.php
:mrgreen:

joropito
10-15-2009, 12:02
:mrgreen:

Ok, this too http://www.ghwchronic.com/pev_research.php

:P

ot_207
10-15-2009, 12:16
Updated Ham_TraceAttack (http://forums.alliedmods.net/showpost.php?p=913473&postcount=42)!

Will add all your posts to the first post.
Good job and keep up the good posts. :wink:

Edit: Added them :mrgreen:

Arkshine
10-15-2009, 12:24
"message" seems to be used mainly to store sound (string). It happens to store others things, depending the need of the entiy.

joropito
10-15-2009, 12:29
"message" seems to be used mainly to store sound (string). It happens to store others things, depending the need of the entiy.

Thanks, updated.

I'm at home with a great flu so I will write tutorial for some other functions.

ot_207
10-15-2009, 12:37
Thanks, updated.

I'm at home with a great flu so I will write tutorial for some other functions.

Ow. Hope you get well soon! :up:
And hoping to see some more functions from you :wink:.

Edit:
Thats a good post on Ham_TakeDamage! :up:

I think it is worthwhile to discuss when we should use Ham_TakeDamage and when we should use Ham_TraceAttack.

Thanks!
Will add to the description on observation about the moment when it is best to use them!

Arkshine
10-15-2009, 12:48
Fakemeta function :

EngFunc_ModelFrames


Description :

Returns the frames number of a model.
Usage :

ModelFrames = engfunc( EngFunc_ModelFrames, ModelIndex );
ModelIndex = The model index. Value you can get from precache_model() (http://www.amxmodx.org/funcwiki.php?search=precache_model&go=search) or EngFunc_ModelIndex (http://forums.alliedmods.net/showpost.php?p=962753&postcount=81).

joropito
10-15-2009, 12:52
Fakemeta function :
EngFunc_NumberOfEntities

Description :
Returns the number of entities in the world.

Usage :
ents = engfunc(EngFunc_NumberOfEntities);

Engine Replacement :
http://www.amxmodx.org/funcwiki.php?go=func&id=356
ents = entity_count();

joropito
10-15-2009, 12:58
Fakemeta function :
EngFunc_SetModel

Description :
Properly sets a new model on an entity.

Usage :
engfunc(EngFunc_SetModel, iEnt, sModel);

Parameters
iEnt = Entity index
sModel = Model file name to set on entity (ex: "models/player/vip/vip.mdl")


Engine Replacement :
http://www.amxmodx.org/funcwiki.php?go=func&id=354
entity_set_model( entity, Model[] );

joropito
10-15-2009, 13:03
Fakemeta function :
EngFunc_SetSize

Description :
Sets the bounds of an entity.

Usage :
engfunc(EngFunc_SetSize, iEnt, Float:fMins[3], Float:fMaxs[3]);

Parameters
iEnt = Entity index
fMins[3] = Mins boundings values (x,y,z)
fMaxs[3] = Maxs boundings values (x,y,z)


Engine Replacement :
http://www.amxmodx.org/funcwiki.php?go=func&id=328
entity_set_size( index, Float:mins[3], Float:maxs[3] );

joropito
10-15-2009, 13:07
Fakemeta function :
EngFunc_SetOrigin

Description :
Properly sets a new origin on an entity.

Usage :
engfunc(EngFunc_SetOrigin, iEnt, Float:Origin[3]);
Parameters
iEnt = Entity index
Origin[3] = New origin for the entity (x,y,z)


Engine Replacement :
http://www.amxmodx.org/funcwiki.php?go=func&id=353
entity_set_origin( index, Float:NewOrigin[3] );

ot_207
10-15-2009, 13:23
Fakemeta function:
EngFunc_TraceModel

Description:
This function traces between 2 origins a model and gives us properties about it.
It acts just like a TraceLine but it ignores all the entities except the one we want to hit!

The constants that we can use in hull:
#define HULL_POINT 0 // This means that we are moving a point from the start to the end
#define HULL_HUMAN 1 // That means that we move a cube of a player from start to end
#define HULL_LARGE 2 // That means that we move a bigger cube that one of the player from start to end (used in HL for big monsters!)
#define HULL_HEAD 3 // This means that we move from start to end the hull of a ducked player

Usage:
// start - start origin
// end - end origin
// hull - the hull that is moved check above to see them
// ent_to_hit - the entity that you want to hit (this is a must!)
// ptr - the trace handle pointer, acts the same as the one in trace line!
engfunc(EngFunc_TraceModel, const Float:start[3], const Float:end[3], hull, ent_to_hit, ptr)

Extra info:
Do not use this unless you are familliar with TraceLine!
TraceModel usage simple example. (http://forums.alliedmods.net/showthread.php?p=850698)
EngFunc_TraceLine Explanation (http://forums.alliedmods.net/showpost.php?p=835030&postcount=6)

joropito
10-15-2009, 13:54
EngFunc_TraceModel


Does this function hits only to bones of the entity? or it can hit to model area or to bounding box?

Alka
10-15-2009, 14:20
bounding box

joropito
10-15-2009, 15:10
Fakemeta function :
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 :
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

#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

Exolent[jNr]
10-15-2009, 15:21
About MOVETYPE there's no clew of what it does this option within the function.
Almost every option gives the same result, but if you use MOVETYPE_NONE, you could get random movements.

...

(tested with players only)

That may be why. Test with an entity you created.

Arkshine
10-15-2009, 15:27
Movetype are that :


#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


It's used mainly for monster but should work on player.

joropito
10-15-2009, 15:52
It's used mainly for monster but should work on player.

Yeah!
Updated.

When I was using MOVE_NORMAL, I saw random movements but with this information it makes sense.

Thanks

ot_207
10-16-2009, 06:16
Good job!
Keep em coming.
Added all of them to the main post and added a little extra info on Ham_TakeDamage.
So please recheck if interested.

ot_207
10-16-2009, 08:09
Fakemeta function:
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:
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
}

ot_207
10-16-2009, 08:24
Fakemeta function:
EngFunc_GetBonePosition

Description:
The function allows to get the bone positions of an entity. This is best used on getting specific player origin points.

These are the bones that a player has.

Bone 1 Name: "Bip01"

Bone 2 Name: "Bip01 Pelvis"

Bone 3 Name: "Bip01 Spine"

Bone 4 Name: "Bip01 Spine1"

Bone 5 Name: "Bip01 Spine2"

Bone 6 Name: "Bip01 Spine3"

Bone 7 Name: "Bip01 Neck"

Bone 8 Name: "Bip01 Head"

Bone 9 Name: "Bone01"

Bone 10 Name: "Bip01 L Clavicle"

Bone 11 Name: "Bip01 L UpperArm"

Bone 12 Name: "Bip01 L Forearm"

Bone 13 Name: "Bip01 L Hand"

Bone 14 Name: "Bip01 L Finger0"

Bone 15 Name: "Bip01 L Finger01"

Bone 16 Name: "Bip01 L Finger1"

Bone 17 Name: "Bip01 L Finger11"

Bone 18 Name: "-- L knuckle"

Bone 19 Name: "-- L Forearm twist"

Bone 20 Name: "-- L wrist"

Bone 21 Name: "-- L Elbow"

Bone 22 Name: "-- L bicep twist"

Bone 23 Name: "-- L shoulder outside"

Bone 24 Name: "-- L Shoulder inside"

Bone 25 Name: "Bip01 R Clavicle"

Bone 26 Name: "Bip01 R UpperArm"

Bone 27 Name: "Bip01 R Forearm"

Bone 28 Name: "Bip01 R Hand"

Bone 29 Name: "Bip01 R Finger0"

Bone 30 Name: "Bip01 R Finger01"

Bone 31 Name: "Bip01 R Finger1"

Bone 32 Name: "Bip01 R Finger11"

Bone 33 Name: "-- R knuckle"

Bone 34 Name: "-- R wrist"

Bone 35 Name: "-- R forearm twist"

Bone 36 Name: "-- R Elbow"

Bone 37 Name: "-- R bicep twist"

Bone 38 Name: "-- R Shoulder inside"

Bone 39 Name: "-- R shoulder outside"

Bone 40 Name: "-- Neck smooth"

Bone 41 Name: "-- R Butt"

Bone 42 Name: "-- L butt"

Bone 43 Name: "Bip01 L Thigh"

Bone 44 Name: "Bip01 L Calf"

Bone 45 Name: "Bip01 L Foot"

Bone 46 Name: "Bip01 L Toe0"

Bone 47 Name: "-- L ankle"

Bone 48 Name: "-- L Knee"

Bone 49 Name: "Bip01 R Thigh"

Bone 50 Name: "Bip01 R Calf"

Bone 51 Name: "Bip01 R Foot"

Bone 52 Name: "Bip01 R Toe0"

Bone 53 Name: "-- R Ankle"

Bone 54 Name: "-- R Knee"

Bone 55 Name: "Bomb"

This image shows the locations of the bones, they are marked through blue points. The red point is the player origin.

http://img507.**************/img507/7762/playerskeleton.jpg (http://img507.**************/my.php?image=playerskeleton.jpg)


Usage:
// ENTITY is the player entity id
// BONE_NUMBER you have to choose from the list above
// bone_origin[3] is the vector where we save the bone origin
// bone_angles[3] the vector that holds the angles of the bone.
engfunc(EngFunc_GetBonePosition, ENTITY, BONE_NUMBER, Float:bone_origin[3], Float:bone_angles[3])

Useful Stocks:
These stocks are made for CS/CZ you need to port them to other mods.

This gets the hitgroup of the bone.

#define BONE_HIT_HEAD 8
#define BONE_HIT_CHEST 6
#define BONE_HIT_STOMACH 4
#define BONE_HIT_LEFTARM 24
#define BONE_HIT_RIGHTARM 39
#define BONE_HIT_LEFTLEG 48
#define BONE_HIT_RIGHTLEG 54
#define HEAD_NECK 40
#define BONE_L_BUTT 41
#define BONE_R_BUTT 42

stock get_bone_hitgroup(number)
{
switch (number)
{
case HEAD_NECK:
{
return HIT_HEAD
}
case BONE_L_BUTT:
{
return HIT_LEFTLEG
}
case BONE_R_BUTT:
{
return HIT_RIGHTLEG
}
}

if (1 <= number <= BONE_HIT_STOMACH)
return HIT_STOMACH

if (BONE_HIT_STOMACH < number <= BONE_HIT_CHEST)
return HIT_CHEST

if (BONE_HIT_CHEST < number <= BONE_HIT_HEAD)
return HIT_HEAD

if (BONE_HIT_HEAD < number <= BONE_HIT_LEFTARM)
return HIT_LEFTARM

if (BONE_HIT_LEFTARM < number <= BONE_HIT_RIGHTARM)
return HIT_RIGHTARM

if (BONE_HIT_RIGHTARM < number <= BONE_HIT_LEFTLEG)
return HIT_LEFTLEG

if (BONE_HIT_LEFTLEG < number <= BONE_HIT_RIGHTLEG)
return HIT_RIGHTLEG

return HIT_GENERIC
}

This gets the closest bone to the gunshot [Use this in FM_TraceLine and Ham_TraceAttack

#define DISTANCE_CLEAR_HIT 2.0

stock find_closest_bone_to_gunshot(victim, Float:endtrace[3])
{
new Float:angles[3], Float:origin[3], Float:dist = 9999999.99, Float:curorigin[3], bone_nr
for (new i=1;i<=54;i++)
{
// Get the bone position
engfunc(EngFunc_GetBonePosition, victim, i, curorigin, angles)
// Calculate the distance vector
xs_vec_sub(curorigin, endtrace, angles)

// If this is smaller than the last small distance remember the value!
if (xs_vec_len(angles) <= dist)
{
origin = curorigin
dist = xs_vec_len(angles)
bone_nr = i
}

// If distance is smaller than CLEARHIT! Break (We accept the last value!)
if (dist <= DISTANCE_CLEAR_HIT)
{
break
}
}

// Return the bone
return bone_nr
}

joropito
10-16-2009, 20:19
Fakemeta function :
EngFunc_FindClientInPVS

Description :
Return the next "player" entity in someone PVS using a global loop.

Usage :
iEnt2 = engfunc(EngFunc_FindClientInPVS, iEnt);

Parameters
iEnt = Source entity. Seek someone within of iEnt PVS

Unlike EngFunc_EntitiesInPVS (http://forums.alliedmods.net/showpost.php?p=933833&postcount=68), it does not return a series of chained entities.

It works like a global loop of entities.
No matter which source entity you use, this function maintains the last index used and returns the next entity in source entity PVS.

This function must be called severals times to find every entity in PVS and also can return the source entity but it can't be called twice inside the same function because it will return the same entity.


Notes :
It seems you can call this function once between some forward (maybe UpdateClientData, Think, AddToFullPack or some other).

It's not clear the main purpose of this function because you can get similar results with FindEntitiesInPVS.
CheckVisibility and FindEntitiesInPVS are better functions to use.

ot_207
10-17-2009, 06:29
I suggest doing an example of that function.
Since it is harder to use than EngFunc_FindEntityByString or FindEntityInSphere

Starsailor
10-17-2009, 11:54
Fakemeta function :
EngFunc_AlertMessage

Description :
Prints an alert message.

Usage:
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.

joropito
10-17-2009, 13:29
I suggest doing an example of that function.
Since it is harder to use than EngFunc_FindEntityByString or FindEntityInSphere

Yes, too complicated to use this function and I can't find a good use of this (why not use EntitiesInPVS instead of this?).

It seems you can call this function once between some forward (maybe UpdateClientData, Think, AddToFullPack).
I'm thinking this based on my tests and what Arkshine said in other post.

If you call this function 1000 times inside a loop, it always returns the same entity.

In fakemeta there's a FM_FindClientInPVS but if you try to forward that call, it's not even called (tried to run, jump, shoot, kill, plant bomb and wait the explosion, drop guns, throw nades, etc).

ot_207
10-17-2009, 14:27
Yes, too complicated to use this function and I can't find a good use of this (why not use EntitiesInPVS instead of this?).

It seems you can call this function once between some forward (maybe UpdateClientData, Think, AddToFullPack).
I'm thinking this based on my tests and what Arkshine said in other post.

If you call this function 1000 times inside a loop, it always returns the same entity.

In fakemeta there's a FM_FindClientInPVS but if you try to forward that call, it's not even called (tried to run, jump, shoot, kill, plant bomb and wait the explosion, drop guns, throw nades, etc).

Ok, then at least add a note that says this function has problems.
CheckVisibility and FindEntsInPVS are better to use.

joropito
10-17-2009, 15:18
Ok, then at least add a note that says this function has problems.
CheckVisibility and FindEntsInPVS are better to use.

Updated.
I think it doesn't have problems. I think it's as is :)

Arkshine
10-17-2009, 16:58
Yeah I remember it's just a pain how works this function. If you refer at a post -somewhere- there is a delay between each update, and it matches with the frequency of the "entity-without-classname" ( This entity is created right after max_clients ; if there is entities created in plugin_precache(), this entity will be created after that ). This entity is updated between .25 to 0.3s. It could be used there but it's more easy and efficient to use FindEntsInPVS.

xPaw
10-17-2009, 17:28
Yeah I remember it's just a pain how works this function. If you refer at a post -somewhere- there is a delay between each update, and it matches with the frequency of the "entity-without-classname" ( This entity is created right after max_clients ; if there is entities created in plugin_precache(), this entity will be created after that ). This entity is updated between .25 to 0.3s. It could be used there but it's more easy and efficient to use FindEntsInPVS.

Always wanted to know what that entity does, any info about it ? :)

Arkshine
10-17-2009, 17:36
It seems to update the hud and others things. Try to delete it, you will see.

joropito
10-17-2009, 18:30
It seems to update the hud and others things. Try to delete it, you will see.

I've deleted and everything in game worked fine (hud too) but if I try to connect again, I get SVC_BAD...lol

ot_207
10-18-2009, 06:49
I've deleted and everything in game worked fine (hud too) but if I try to connect again, I get SVC_BAD...lol

Those entities are the ones that ocupy a slot for a player.

When a player connects the entity "without_classname" gets the "player" classname. That is why I think that you received the SVC_BAD error. The player entity could not be correctly created.

joropito
11-13-2009, 10:25
Fakemeta function :
EngFunc_AnimationAutomove

Description :
Plays the selected animation on entity

Usage :
entity_set_float(iEnt, EV_FL_framerate, fFrameRate);
entity_set_int(iEnt, EV_INT_sequence, iSequence);
engfunc(EngFunc_AnimationAutomove, iEnt, fTime);

Parameters
fFrameRate = Frame rate of desired animation.
iSequence = Sequence to play.
iEnt = Source entity.
fTime = It seems to not affect the animation. Maybe for internal use.

First you have to select the sequence and the desired frame rate. Then you can start the animation.
It will run in an endless loop.

It seems to work only on non-player entities

ot_207
11-21-2009, 06:52
Nice, I haven't used that function yet. Added it to the first post ;).

#8 SickneSS
11-22-2009, 16:21
Thanks ot!

solano
12-02-2009, 06:15
new Zombie = create_entity( "monster_zombie" );
set_pev( Zombie, pev_origin, Origin );
//set_pev(Zombie,pev_enemy,id)
DispatchSpawn( Zombie );
drop_to_floor( Zombie );

new Float:TestOrigin[3];

TestOrigin[0]=156.871551;
TestOrigin[1]=892.470581;
TestOrigin[2]=-1864.542480;

engfunc(EngFunc_MoveToOrigin,Zombie,TestOrigi n,10.0,MOVE_STRAFE)
but the zombie doesnt move it just sits there :|

joropito
12-02-2009, 06:26
You need to set MOVETYPE_ and SOLID_ in entity.

Are you sure that TestOrigin is a valid target?

solano
12-02-2009, 06:27
pev( TargetIndex, pev_origin, Origin );
pev( TargetIndex , pev_v_angle, Angles );



angle_vector( Angles, ANGLEVECTOR_FORWARD, Forward );
xs_vec_mul_scalar( Forward, 150.0, Forward );
xs_vec_add( Origin, Forward, Origin );

this is how i got the origin

joropito
12-02-2009, 06:35
I've only tested with non-monsters entities but try this on that entity


set_pev(ent, pev_solid, SOLID_BBOX)
set_pev(ent, pev_movetype, MOVETYPE_TOSS)
set_pev(ent, pev_maxspeed, 9999.0)


I don't know if BBOX it's right for that entity.

solano
12-02-2009, 06:40
new Target[ 32 ];
read_argv( 1, Target, charsmax( Target ) );
new TargetIndex = cmd_target( id, Target, CMDTARGET_ALLOW_SELF | CMDTARGET_ONLY_ALIVE );

if ( !TargetIndex )
{
return PLUGIN_HANDLED;
}

new Float:Angles [ 3 ];
new Float:Origin [ 3 ];
new Float:Forward[ 3 ];


pev( TargetIndex, pev_origin, Origin );
pev( TargetIndex , pev_v_angle, Angles );

angle_vector( Angles, ANGLEVECTOR_FORWARD, Forward );
xs_vec_mul_scalar( Forward, 150.0, Forward );
xs_vec_add( Origin, Forward, Origin );

new Zombie = create_entity( "monster_zombie" );
set_pev( Zombie, pev_origin, Origin );
entity_set_int(Zombie,EV_INT_movetype,MOVETYP E_STEP);
entity_set_int(Zombie,EV_INT_solid,SOLID_BBOX )
//set_pev(Zombie,pev_enemy,id)
DispatchSpawn( Zombie );
drop_to_floor( Zombie );

new Float:TestOrigin[3];

TestOrigin[0]=156.871551;
TestOrigin[1]=892.470581;
TestOrigin[2]=-1864.542480;

engfunc(EngFunc_MoveToOrigin,Zombie,TestOrigi n,100.0,MOVE_STRAFE)

this is the code i use and it doesnt work

solano
12-02-2009, 06:43
btw is this the right function for the thing i want to do?
i want to make the monster "walk" to a specific location
walk is in "" because while walking if he sees a player he should start attacking him

joropito
12-02-2009, 11:26
btw is this the right function for the thing i want to do?
i want to make the monster "walk" to a specific location
walk is in "" because while walking if he sees a player he should start attacking him

I've tried with func_breakable entities and it walks fine and only tested with MOVETYPE_TOSS.
Try with that kind of entity, movetype and setup the model you want.

Arkshine
12-02-2009, 12:54
I don't think it will work with (real) monsters from HL1 because such monsters have predefined paths. I've tried and zombies are warp directly. Don't know how to force to generate paths. A way could be to create a dummy entity at the origin you want, then forcing the zombie to see it as enemy ( pev_enemy ) ; it may works.

joropito
12-02-2009, 13:04
For bots, EngFunc_RunPlayerMove
For non-intelligent entities, EngFunc_MoveToOrigin
For monsters, EngFunc_WalkMove

Not tested but...

EngFunc_WalkMove(edict_t *ent, float yaw, float dist, int iMode)


Where:

- You get yaw using EngFunc_VecToYaw to convert vector to yaw (it returns a float value)
- The distance to walk is dist
- iMode

#define WALKMOVE_NORMAL 0 // Normal walkmove
#define WALKMOVE_WORLDONLY 1 // Doesn't hit ANY entities, no matter what the solid type
#define WALKMOVE_CHECKONLY 2 // Move, but don't touch triggers


Give a try and tell us.

Arkshine
12-02-2009, 13:17
Yeah, totally forget about this one. I'm blind because I'm reviewing the SinglePlayer HLSDK too.

Anyway, i've tested and the same result, zombie is warped instead of walking. Probably because there is not path available at this time.

joropito
12-02-2009, 13:25
Yeah, totally forget about this one. I'm blind because I'm reviewing the SinglePlayer HLSDK too.

Anyway, i've tested and the same result, zombie is warped instead of walking. Probably because there is not path available at this time.

Take a look into hlsdk-2.3-p3/singleplayer/dlls/monsters.cpp

int CBaseMonster :: CheckLocalMove


It says something about making WALK_MOVE for every step


// this loop takes single steps to the goal.
for ( flStep = 0 ; flStep < flDist ; flStep += LOCAL_STEP_SIZE )
...
...
...
if ( !WALK_MOVE( ENT(pev), flYaw, stepSize, WALKMOVE_CHECKONLY ) )
...


EDIT:

Remember to set MOVETYPE_WALK on the monster!!!!

Arkshine
12-02-2009, 13:37
The same. Stepping by 16 units doesn't help. Well this function is just to test the origin step by step.

Remember to set MOVETYPE_WALK on the monster!!!!

Not sure if I should do because zombie spawns already with a specific configuration. I don't see any reference of such move type for monsters. MOVETYPE_WALK would be only for player.


void CZombie :: Spawn()
{
Precache( );

SET_MODEL(ENT(pev), "models/zombie.mdl");
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );

pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_GREEN;
pev->health = gSkillData.zombieHealth;
pev->view_ofs = VEC_VIEW;// position of the eyes relative to monster's origin.
m_flFieldOfView = 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
m_afCapability = bits_CAP_DOORS_GROUP;

MonsterInit();
}


Edit: I was right, it crashes the server saying that's a bad movetype.

joropito
12-02-2009, 13:44
I can't test right now (I'm at work).
I'm sure you have read my edit about movetype_walk

You can also take a look at hlsdk-2.3-p3/singleplayer/dlls/roach.cpp in CRoach::Move called from MonsterThink

As I see, the properties of the roach are

- SOLID_SLIDEBOX
- MOVETYPE_STEP

Arkshine
12-02-2009, 13:50
Yes I've read and already answered. See my edit. :)

Edit : About the roach, it seems that the roach runs by being 'warped' very often ( Think function ) only few units each time.

Edit2: This function seems interesting :


BOOL CBaseMonster::MoveToLocation( Activity movementAct, float waitTime, const Vector &goal )
{
m_movementActivity = movementAct;
m_moveWaitTime = waitTime;

m_movementGoal = MOVEGOAL_LOCATION;
m_vecMoveGoal = goal;
return FRefreshRoute();
}

ConnorMcLeod
12-06-2009, 10:52
You are wrong, player can be alive in pre spawn, haven't read rest of post.

solano
12-06-2009, 10:57
Originally Posted by hleV https://forums.alliedmods.net/images/buttons/viewpost.gif (https://forums.alliedmods.net/showthread.php?p=805471#post805471)
PHP Code:
RegisterHam(Ham_Spawn, "player", "PlayerPreSpawn", 0); // Pre, player is dead
RegisterHam(Ham_Spawn, "player", "PlayerPostSpawn", 1); // Post, player is alive

fixed my post

ConnorMcLeod
12-06-2009, 12:16
This is still wrong, i suggest you delete your post.

Exolent[jNr]
12-06-2009, 15:15
Also, you need to check is_user_alive in post hook.

fysiks
12-06-2009, 15:45
Description:
Forward:This function is called when an player is spawned

This is not technically true either. It only works for player spawn when the second argument is "player".

solano
12-06-2009, 16:44
see thats why im telling you it should be added

joropito
12-10-2009, 15:08
Fakemeta function :
EngFunc_TraceToss

Description :
Trace the point where some entity movement will finish.
If for some reason the entity movement must be blocked for other entity (or worldspawn), TraceToss will detect that situation taking in account the original entity bounding boxes.

Usage :

engfunc(EngFunc_TraceToss, ent, skipent, tr);

Parameters
ent = The entity which movement we want to trace
skipent = The entity to skip in trace
tr = trace result

Example:

If you open the attached image, you can see a player jumping and 2 points.

Start Point: Is the origin of the player when TraceToss was called
End Point: Is the point returned in TR result

So the player is making a parabola from START to END.
The green line is only for testing purposes and show from where to where the trace is.
This was tested with gravity = 400.

ConnorMcLeod
12-10-2009, 16:10
Amazing function !!

joropito
12-10-2009, 16:18
I didn't found any example so I have to test by myself and yes, it's a very interesting function.

joaquimandrade
12-10-2009, 16:25
Thanks for taking your time teaching us that function

Exolent[jNr]
12-10-2009, 16:34
I actually could find a use out of it :P

joaquimandrade
12-10-2009, 16:41
;1012587']I actually could find a use out of it :P

You are not alone. :twisted:

Arkshine
12-10-2009, 16:43
I didn't found any example so I have to test by myself and yes, it's a very interesting function.

As code example, you can show a sprite where a grenade will fall. It reminds me the game "Worms".

joropito
12-10-2009, 16:45
You are not alone. :twisted:

But the function exists!!!

Maybe to make some prediction.

Starsailor
12-10-2009, 20:35
i tested this function with this code


#include <amxmodx>
#include <fakemeta>
#include <csx>

public grenade_throw(id,ent,wid)
{
static tr, Float:End[3]

engfunc(EngFunc_TraceToss,ent,0,tr)
get_tr2(tr,TR_vecEndPos,End)

client_print(0,print_chat,"%f %f %f",End[0],End[1],End[2])
}



Result:


Grenade Throw: X= 446.208038 Y= 2446.914794 Z= -69.998535
My Origin: X= 448.000000 Y= 2464.000000 Z= -91.9687


Only my origin changes a few units.

this is right?

joaquimandrade
12-10-2009, 21:44
But the function exists!!!

Maybe to make some prediction.

I think you got me wrong. I meant that the function is useful. And thanks again for explaining it :wink:

Arkshine
12-11-2009, 05:48
i tested this function with this code


#include <amxmodx>
#include <fakemeta>
#include <csx>

public grenade_throw(id,ent,wid)
{
static tr, Float:End[3]

engfunc(EngFunc_TraceToss,ent,0,tr)
get_tr2(tr,TR_vecEndPos,End)

client_print(0,print_chat,"%f %f %f",End[0],End[1],End[2])
}



Result:


Grenade Throw: X= 446.208038 Y= 2446.914794 Z= -69.998535
My Origin: X= 448.000000 Y= 2464.000000 Z= -91.9687


Only my origin changes a few units.

this is right?

Pass the player's id, not 0.

01101101
12-11-2009, 06:14
Pass the player's id, not 0.

The result will be the same whether you show it to all players or just him o.o

This function seems really nice for tracing a line from the nade start point to the end point (before it actually falls). The bad thing is that the only way of doing a curve is with many lines lol (I think, maybe there is a message for a curve but I've never seen it)

Arkshine
12-11-2009, 06:28
The result will be the same whether you show it to all players or just him

What are you talking about...

01101101
12-11-2009, 06:38
What are you talking about...

public grenade_throw(id,ent,wid)
{
static tr, Float:End[3]

engfunc(EngFunc_TraceToss,ent,0,tr)
get_tr2(tr,TR_vecEndPos,End)
//We have the result of the entity

client_print(0,print_chat,"%f %f %f",End[0],End[1],End[2]) // You print that result to all players (the result does not depend on the client)
}

Arkshine
12-11-2009, 06:40
You miss the point that this param has nothing to do with "to show to all players or just him".

skipent = The entity to skip in trace

joropito
12-11-2009, 08:11
i tested this function with this code

Only my origin changes a few units.

this is right?

Try to execute this function when you're jumping.

The bad thing is that the only way of doing a curve is with many lines lol (I think, maybe there is a message for a curve but I've never seen it)

If you need to draw the parabola, you must do it at think and not with this functions.

I've tested this function in this way:

- Long jump
- Execute this function as fast as possbile to draw a line.
- I get a lot of lines from every point in the parabola to the same end

Arkshine
12-11-2009, 08:19
Try to execute this function when you're jumping.

Why do you say that ? I mean the skipent exists to avoid this problem to ignore the entity where the trace starts. It's the same as TraceLine if you start a trace from your origin it will collide on you.

joropito
12-11-2009, 09:20
Why do you say that ? I mean the skipent exists to avoid this problem to ignore the entity where the trace starts. It's the same as TraceLine if you start a trace from your origin it will collide on you.

The function works when you're moving off-ground.

If you're standing up on worldspawn, you'll get the same origin as the start point.

If you're jumping, you'll get the point where you will touch again worldspawn.

One funny thing.
If you jump and you're going to touch sky (or ceiling) this trace will be that point and not where you will be back at floor.

So, this function returns the point where you will be stopped (at the fly) by something.

Arkshine
12-11-2009, 09:31
If you're standing up on worldspawn, you'll get the same origin as the start point.

Just tested again, it works fine for me whatever I'm moving, jumping or not.

01101101
12-11-2009, 10:07
If you need to draw the parabola, you must do it at think and not with this functions.


Yes, but with think it draws the line while it moves in the air.
With this function you could draw the parabola before it is actually thrown.
This wouldn't be hard since unlikely source random nades motion, cs is like static, the end position will be always the same, the curve ratio, and many other factors.

Starsailor
12-11-2009, 12:34
Try to execute this function when you're jumping.


Yes, Now It is working for me

Tested With this code


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

static BeamSprite

public plugin_init()
{
RegisterHam(Ham_Player_Jump,"player","jump")
}

public plugin_precache()
{
BeamSprite = precache_model("sprites/zbeam1.spr");
}

public jump(id)
{
static tr,Float:End[3],Float:Origin[3]

pev(id,pev_origin,Origin)
engfunc(EngFunc_TraceToss,id,IGNORE_MONSTERS, tr)
get_tr2(tr,TR_vecEndPos,End)

message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMPOINTS)
engfunc(EngFunc_WriteCoord, Origin[0])
engfunc(EngFunc_WriteCoord, Origin[1])
engfunc(EngFunc_WriteCoord, Origin[2])
engfunc(EngFunc_WriteCoord, End[0])
engfunc(EngFunc_WriteCoord, End[1])
engfunc(EngFunc_WriteCoord, End[2])
write_short(BeamSprite)
write_byte(1)
write_byte(5)
write_byte(60)
write_byte(20)
write_byte(0)
write_byte(255)
write_byte(0)
write_byte(0)
write_byte(200)
write_byte(200)
message_end()

}


Result:

http://fotocopiasyapuntes.webs.com/TraceToss.JPG

01101101
12-11-2009, 13:00
Yes, Now It is working for me

Tested With this code



Why was the jump function called 7 times?

joropito
12-11-2009, 13:08
Why was the jump function called 7 times?

maybe he was holding the key :P

Starsailor, which map is it?

Arkshine
12-11-2009, 13:18
Starsailor, which map is it?

dm_drawmp_v2 or gg_

Starsailor
12-11-2009, 13:51
maybe he was holding the key :P

Starsailor, which map is it?

Yes, i was holding the key.

The map is dm_drawnmp

AlexALX
09-06-2010, 17:59
possibly do to get end by invisible objects? (SOLID_NOT or SOLID_TRIGGER) such as the substitution function EngFunc_TraceLine

ot_207
09-06-2010, 18:03
possibly do to get end by invisible objects? (SOLID_NOT or SOLID_TRIGGER) such as the substitution function EngFunc_TraceLine

What do you want to do exactly?

AlexALX
09-06-2010, 18:30
What do you want to do exactly?determine whether the player in a trigger and the player SOLID_NOT (like touch, touch do not work with SOLID_NOT).

ot_207
09-06-2010, 18:40
determine whether the player in a trigger and the player SOLID_NOT (like touch, touch do not work with SOLID_NOT).

Well, you can make the entity think and add an entity_range check to it. That is a way IMO.

AlexALX
09-06-2010, 19:16
Well, you can make the entity think and add an entity_range check to it. That is a way IMO.I do not know id ent in plugin (must determine how it is - This is my problem).

Seta00
09-07-2010, 11:23
http://wiki.alliedmods.net/FakeMeta_Functions_Detailed_Descriptions

Please do not mess with the page. Contribute only if you know what are you doing.

Arkshine
09-07-2010, 11:36
Thanks, Seta00. :)

AlexALX
09-08-2010, 17:15
http://wiki.alliedmods.net/FakeMeta_Functions_Detailed_Descriptions

Please do not mess with the page. Contribute only if you know what are you doing. None of these functions makes it impossible to check a player to be SOLID_NOT in the trigger or not. EngFunc_FindEntityInSphere find entity with absmin absmax and not suitable for the purpose of determining in entite (if few Brashes as one entity). EngFunc_TraceLine and etc do not detect triggers (and solid_not).

AlexALX
09-08-2010, 17:24
int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask )
{
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
CBaseEntity *pEntity;
int count;

count = 0;

if ( !pEdict )
return count;

for ( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
{
if ( pEdict->free ) // Not in use
continue;

if ( flagMask && !(pEdict->v.flags & flagMask) ) // Does it meet the criteria?
continue;

if ( mins.x > pEdict->v.absmax.x ||
mins.y > pEdict->v.absmax.y ||
mins.z > pEdict->v.absmax.z ||
maxs.x < pEdict->v.absmin.x ||
maxs.y < pEdict->v.absmin.y ||
maxs.z < pEdict->v.absmin.z )
continue;

pEntity = CBaseEntity::Instance(pEdict);
if ( !pEntity )
continue;

pList[ count ] = pEntity;
count++;

if ( count >= listMax )
return count;
}

return count;
}What is this?

Arkshine
09-08-2010, 17:35
It searches entities in a box.


int UTIL_EntitiesInBox( CBaseEntity **pList, int listMax, const Vector &mins, const Vector &maxs, int flagMask )
{
edict_t *pEdict = g_engfuncs.pfnPEntityOfEntIndex( 1 );
CBaseEntity *pEntity;
int count;

count = 0;

if ( !pEdict )
return count;

for ( int i = 1; i < gpGlobals->maxEntities; i++, pEdict++ )
{
if ( pEdict->free ) // Not in use
continue;

if ( flagMask && !(pEdict->v.flags & flagMask) ) // Does it meet the criteria?
continue;

if ( mins.x > pEdict->v.absmax.x ||
mins.y > pEdict->v.absmax.y ||
mins.z > pEdict->v.absmax.z ||
maxs.x < pEdict->v.absmin.x ||
maxs.y < pEdict->v.absmin.y ||
maxs.z < pEdict->v.absmin.z )
continue;

pEntity = CBaseEntity::Instance(pEdict);
if ( !pEntity )
continue;

pList[ count ] = pEntity;
count++;

if ( count >= listMax )
return count;
}

return count;
}

AlexALX
09-08-2010, 18:02
I was pretty strange that there's no this function in amxmodx, but here, too, checking through absmun absmax and not suitable to me.

Arkshine
09-08-2010, 18:41
None of these functions makes it impossible to check a player to be SOLID_NOT in the trigger or not. EngFunc_FindEntityInSphere find entity with absmin absmax and not suitable for the purpose of determining in entite (if few Brashes as one entity). EngFunc_TraceLine and etc do not detect triggers (and solid_not).

It doesn't matter if your entity has the SOLID_NOT flag, EngFunc_FindEntityInSphere whill find your entity and doesn't work like you said. Did you tried at least the function ??!

AlexALX
09-09-2010, 10:28
It doesn't matter if your entity has the SOLID_NOT flag, EngFunc_FindEntityInSphere whill find your entity and doesn't work like you said. Did you tried at least the function ??!EngFunc_FindEntityInSphere find method - pev_absmin pev_absmax, and when 2 brash add to one entity - have bug... see test map for my plugin [DeathRun] Triggers & Entites Fix v1.1.1 [UPDATE 09/09/10] (http://forums.alliedmods.net/showthread.php?t=137576)

abdul-rehman
09-09-2010, 10:54
This thread should be made as a sticky becoz of its importance :)

meTaLiCroSS
09-09-2010, 19:23
@ot_207

http://forums.alliedmods.net/showthread.php?p=913473#post913473

ExecuteHamB(Ham_TraceAttack, attacker, hit, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)

That wont be...

ExecuteHamB(Ham_TraceAttack, hit, attacker, damage, direction, ptr, DMG_NEVERGIB | DMG_BULLET)

?

joropito
09-09-2010, 22:39
You're right Metalicross

meTaLiCroSS
09-09-2010, 23:47
You're right Metalicross

:crab:

ot_207
09-16-2010, 20:04
http://wiki.alliedmods.net/FakeMeta_Functions_Detailed_Descriptions

Please do not mess with the page. Contribute only if you know what are you doing.

I like it. Thanks a lot!!!

:crab:

Crabs for you too. Fixed and thanks!

wrecked_
02-22-2011, 02:09
I can't even describe how much this thread has helped me in the past few months. Newer people really should know about this.

Bump for justice.

ConnorMcLeod
02-22-2011, 02:16
"Sticked"

ot_207
02-22-2011, 03:30
I can't even describe how much this thread has helped me in the past few months. Newer people really should know about this.

Bump for justice.

Oh, it is nice to see that people still have interest in this topic.
Will add some more functions in the funcwiki and here after my access to it will be fixed.

"Sticked"

Thank you!

SpeeDeeR
12-05-2011, 12:22
Do one for TraceHull.

CVarsMaster
04-29-2012, 12:04
What's the difference between InOpen and StartSolid values from traceline function? I mean, StartSolid detects if starts on a solid object (brush) and InOpen detects if starts on a entity?

Aooka
06-22-2012, 14:00
Awesome !
Very good Job ! It's very usefull !! Thanks a lot

CryWolf
12-04-2012, 07:31
Thank you all for creating this tread, it really helped me alot to understand much better of how to use!

.Dare Devil.
03-19-2013, 06:36
Fakemeta function:
EngFunc_TraceLine

Description:
This function traces between 2 origins and gives us information about it.

The constants that we can use in flags:
#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!
engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/1863/traceline1.jpg (http://img529.**************/my.php?image=traceline1.jpg)

engfunc(EngFunc_TraceLine, start, end, DONT_IGNORE_MONSTERS, 0, tr)
http://img529.**************/img529/1415/traceline2.jpg (http://img529.**************/my.php?image=traceline2.jpg)

engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/5815/traceline3.jpg (http://img529.**************/my.php?image=traceline3.jpg)

engfunc(EngFunc_TraceLine, start, end, IGNORE_GLASS, 0, tr)
http://img529.**************/img529/326/traceline4.jpg (http://img529.**************/my.php?image=traceline4.jpg)

Functions that come with the TraceLine pack:
// 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()

// 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)

// Description: Gets/Sets information from/in the trace_handle
[g|s]et_tr2(trace_handle, CONSTANT, number_if_needed!)

CONSTANT Expresion has this posible values:

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:

new allsolid = get_tr2(trace, TR_AllSolid)
new startsolid = get_tr2(trace, TR_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(trace, TR_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(trace, TR_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(trace, TR_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(trace, TR_flFraction, fraction)
// 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(trace, TR_vecEndPos, end_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(trace, TR_vecPlaneNormal, normal)
// 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:
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_TraceLine, start, end, IGNORE_GLASS | IGNORE_MONSTERS | IGNORE_MISSILE, ignore_ent, ptr)

// We are interested in the fraction parameter
new fraction
get_tr2(ptr, TR_flFraction, fraction)

// 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 (http://developer.valvesoftware.com/wiki/TraceLines)
TraceLine Tutorial (Nomexous) (http://forums.alliedmods.net/showthread.php?t=66076)
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?

Arkshine
03-19-2013, 07:33
Like the one in cs_assault, T side, you see ? But It's most likely related to any entity with some render.

HamletEagle
06-27-2014, 13:18
Here (https://forums.alliedmods.net/showpost.php?p=913473&postcount=42)

Register_Ham(Ham_TraceAttack, "func_breakable", "fw_traceatt_break")
---->
RegisterHam(Ham_TraceAttack, "func_breakable", "fw_traceatt_break")

Just a small typo,but....

meTaLiCroSS
07-26-2014, 19:40
Fakemeta function:
EngFunc_CanSkipPlayer

Description: Returns 1 or 0 depending of client's cl_lw cvar value (if cl_lw different from 0, returns 1). This functions is used by the mod for checking if player has weapon prediction enabled. Mod uses CanSkipPlayer on weapons, directly on SendWeaponAnim function.

If client haves cl_lw cvar enabled, it means that haves weapon prediction enabled = no need to send weapons animations.
Usage:

if(engfunc(EngFunc_CanSkipPlayer(index))
{
// client has weapon prediction enabled
}
else
{
// client has weapon prediction disabled, server will sent him everything from his weapons.
}Parameters:index = client's index (must be a player)

Not really an important snippet, but it will be useful for someone. May this function be unknown for a lot of scripters.

meTaLiCroSS
07-26-2014, 19:49
Fakemeta function:
EngFunc_Time

Description: Returns time in seconds (float) since the game started. Rather the same as tickcount(). It seems to not be used by the mod (it's useless anyway).
Usage:

new Float:flElapsedTime = Float:engfunc(EngFunc_Time)
server_print("%.2f seconds passed since the server started", flElapsedTime)
new Float:flStartTime = Float:engfunc(EngFunc_Time)
MyVeryBigFunction()
AnotherHugeFunction()
SpamArkshineSteamChat()
server_print("Execution time: %f", Float:engfunc(EngFunc_Time) - flStartTime)Parameters:no params for this function

Another not really important function, but as many others, it's unknown for many scripters.

HamletEagle
09-08-2014, 10:44
@meTaLiCroSS, from what I see EngFunc_Time acts like get_gametime. AFAIK the value returned by get_gametime is increased only in next frame. In your last example, if the execution of the 3 private functions happen in the same frame, it will print 0. Is this right ?

meTaLiCroSS
09-12-2014, 20:00
@meTaLiCroSS, from what I see EngFunc_Time acts like get_gametime. AFAIK the value returned by get_gametime is increased only in next frame. In your last example, if the execution of the 3 private functions happen in the same frame, it will print 0. Is this right ?

I posted it because I researched the engine and found it usage, it has nothing to do with get_gametime(). Time will always return a difference of time (substracting 2 values from get_systime() as example)