Difference between revisions of "FakeMeta Functions Detailed Descriptions"
(Entity Search Functions) |
m (typo on EntitiesInPVS name) |
||
Line 307: | Line 307: | ||
==== Notes ==== | ==== Notes ==== | ||
− | It's not clear the main purpose of this function because you can get similar results with [[# | + | It's not clear the main purpose of this function because you can get similar results with [[#EngFunc_EntitiesInPVS]]. |
− | [[#EngFunc_CheckVisibility]] and [[# | + | [[#EngFunc_CheckVisibility]] and [[#EngFunc_EntitiesInPVS]] are better functions to use. |
Revision as of 23:31, 6 September 2010
Point Functions
EngFunc_PointContents
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!
EngFunc_GetBonePosition
This 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"
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.
get_bone_hitgroup
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 }
find_closest_bone_to_gunshot
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 }
Messaging Functions
EngFunc_MessageBegin
This function is used to generate client messages.
Usage
Syntax:
engfunc(EngFunc_MessageBegin, dest, msg_type, origin[3] = {0, 0, 0}, player = 0)
Example:
static Float:origin[3] // Origin should be a Float pev(id, pev_origin, origin) // Get user origin engfunc(EngFunc_MessageBegin,MSG_BROADCAST,SVC_TEMPENTITY,origin,0) // Create message
With MSG_ONE_UNRELIABLE:
engfunc(EngFunc_MessageBegin,MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,_,id) // Create message
With MSG_ALL:
engfunc(EngFunc_MessageBegin,MSG_ONE_UNRELIABLE,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().
Entity Search Functions
EngFunc_FindEntityInSphere
Find entities within a radius. The function returns the next entity id after the start entity.
If we use
engfunc(EngFunc_FindEntityInSphere, -1, origin, radius)
In the situation described on the picture the function call above will return 1,
engfunc(EngFunc_FindEntityInSphere, 20, origin, radius)
will return 30 and
engfunc(EngFunc_FindEntityInSphere, 100, origin, radius)
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)
EngFunc_EntitiesInPVS
This function checks entities that are in the PVS of an entity. It can't be used on worldspawn.
The function returns the first entity on the PVS and then you can traverse through the results using pev_chain/EV_ENT_chain. A NULL value of pev_chain/EV_ENT_chain indicates the end of the chain.
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 } }
EngFunc_FindEntityByString
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
Usage
iEnt = engfunc(EngFunc_FindEntityByString, iStartEnt, sAttribute, sValue)
Parameters:
- iStartEnt: Start searching on this entity (ex: 0 = worldspawn)
- sAttribute: Name of attribute over which we need to search (ex: classname)
- sValue: Text string that we are searching for (ex: func_breakable)
The function returns the first entity matching the criteria.
EngFunc_FindClientInPVS
Returns the next "player" entity in someone's PVS using a global loop.
Usage
iEnt2 = engfunc(EngFunc_FindClientInPVS, iEnt)
Parameters:
- iEnt Source entity. Seek someone within iEnt's PVS
Unlike #EngFunc_EntitiesInPVS, it does not return a series of chained entities. Instead, 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 several times to find every entity in PVS and can also return the source entity but it can't be called twice inside the same function because it will return the same entity.
Notes
It's not clear the main purpose of this function because you can get similar results with #EngFunc_EntitiesInPVS. #EngFunc_CheckVisibility and #EngFunc_EntitiesInPVS are better functions to use.