AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get origin of player's hitboxes (https://forums.alliedmods.net/showthread.php?t=95582)

Day 06-25-2009 03:48

Get origin of player's hitboxes
 
How to get origin of each hitbox of a player?

I can get the origin of player's vector using entity_get_vector(ent, EV_VEC_origin, entOrigin) function. Is there any way to get the origin of player's legs/hands for example?

Any suggestions are wellcome.
Thks in advance.

Arkshine 06-25-2009 04:10

Re: Get origin of player's hitboxes
 
You can use EngFunc_GetBonePosition ( see fakemeta_cons.inc ) and to know the bone number just do "Dump Model Info" with Half-Life Model Viewer.

Day 06-25-2009 04:41

Re: Get origin of player's hitboxes
 
Thank you, will try and revert.

Day 06-25-2009 07:05

Re: Get origin of player's hitboxes
 
Tyvm, i works well, but is there any other way to do it? This func is a bit CPU consuming...

Arkshine 06-25-2009 07:27

Re: Get origin of player's hitboxes
 
How is a bit CPU consuming ? It should be retrieve information already loaded into memory.

Day 06-25-2009 07:47

Re: Get origin of player's hitboxes
 
Well maybe it's other func using my CPU...

How to write trace_line(-1, userOrigin, entOrigin, hitOrigin) function using FakeMeta instead of Engine? and will it give me any advantage?

Arkshine 06-25-2009 08:09

Re: Get origin of player's hitboxes
 
Here the code source for TraceLine ( engine ) :

Code:
static cell AMX_NATIVE_CALL trace_line(AMX *amx, cell *params) {     int iEnt = params[1];     cell *cStart = MF_GetAmxAddr(amx, params[2]);     cell *cEnd = MF_GetAmxAddr(amx, params[3]);     REAL fStartX = amx_ctof(cStart[0]);     REAL fStartY = amx_ctof(cStart[1]);     REAL fStartZ = amx_ctof(cStart[2]);     REAL fEndX = amx_ctof(cEnd[0]);     REAL fEndY = amx_ctof(cEnd[1]);     REAL fEndZ = amx_ctof(cEnd[2]);     cell *vRet = MF_GetAmxAddr(amx, params[4]);     Vector vStart = Vector(fStartX, fStartY, fStartZ);     Vector vEnd = Vector(fEndX, fEndY, fEndZ);     TraceResult tr;     if (iEnt == -1)         TRACE_LINE(vStart, vEnd, ignore_monsters, NULL, &tr);     else         TRACE_LINE(vStart, vEnd, dont_ignore_monsters, INDEXENT2(iEnt), &tr);     edict_t *pHit = tr.pHit;     vRet[0] = amx_ftoc(tr.vecEndPos.x);     vRet[1] = amx_ftoc(tr.vecEndPos.y);     vRet[2] = amx_ftoc(tr.vecEndPos.z);     if (FNullEnt(pHit))         return 0;     return ENTINDEX(pHit); }

Quote:

Hit = trace_line(-1, userOrigin, entOrigin, hitOrigin)
When -1, it means IgnoreEnt will be null. This native returns the entity index if it hits something (TR_pHit ) and it passes by reference the hit origin. ( TR_vecEndPos ).

In fakemeta it would be : engfunc( EngFunc_TraceLine, vStart, vEnd, IGNORE_MONSTERS, 0, tr);

But it doesn't return TR_pHit nor TR_vecEndPos, you have to do using get_tr2().

If you use an index for IgnoreEnt, in fakemeta it would be : engfunc( EngFunc_TraceLine, vStart, vEnd, DONT_IGNORE_MONSTERS, iEnt, tr);


Depending what you need, you have to use engine or fakemeta. For example if you want to use IGNORE_MONSTERS with a valid IgnoreEnt, you can't. If you don't need the end pos and hit, use fakemeta. If you want to use IGNORE_GLASS you can't etc. The engine version is more specific. The fakemeta version you have an access to all the params of TRACE_LINE() function. ( engine use TRACE_LINE() too ). EngFunc_TraceLine is a direct link to the HL1 engine function TRACE_LINE(), there are no addition like in the engine function. That's why you can do more things with EngFunc_TraceLine. If you reproduce the engine function to fakemeta, it will be more efficient to use engine. Not sure if I explain well. :p

Day 06-25-2009 08:18

Re: Get origin of player's hitboxes
 
Wow, thks for such detailed explanation! But how do you think which way will take less CPU engine (trace_line) or fakemata(engfunc+get_tr2)?

Arkshine 06-25-2009 08:25

Re: Get origin of player's hitboxes
 
The less natives calls you have ( amxx plugin -> module ) = the less cpu consuming it will be.

eg: You want to retrieve the hit and the hit origin.

Using engine :

Code:
new Float:Start[3]; new Float:End[3]; new Float:EndPos[3]; new Hit; [...] Hit = trace_line( -1, Start, End, EndPos );

Using fakemeta :

Code:
new Float:Start[3]; new Float:End[3]; new Float:EndPos[3]; new Hit; [...] engfunc( EngFunc_TraceLine, Start, End, DONT_IGNORE_MONSTERS, Ent, 0 ); Hit = get_tr2( 0, TR_pHit ); get_tr2( 0, TR_vecEndPos, EndPos );

Engine, you need one call, Fakemeta 3.
It's possible to see the difference using the profiler by sawce. But here the difference would not be really significant.

Arkshine 06-25-2009 08:42

Re: Get origin of player's hitboxes
 
Just profiled :

Code:

type |          name | calls | time / min / max
-------------------------------------------------------------------
  f | TraceEngine  | 10000 | 0.038086 / 0.000003 / 0.002073
  f | TraceFakemeta | 10000 | 0.082984 / 0.000006 / 0.005594
0 natives, 0 public callbacks, 2 function calls were not executed.

Like you see engine is ~x2 faster than fakemeta doing the same job.


All times are GMT -4. The time now is 15:29.

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