Raised This Month: $ Target: $400
 0% 

Is user aiming at an entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-27-2008 , 16:23   Is user aiming at an entity
Reply With Quote #1

How do I find out if a player is aiming at an entity?

I have these two functions, but not sure if this would be an efficient way:
Code:
if(fm_get_user_aiming_ent(id, "func_breakable") == ent) {     // player is aiming at ent } // .... fm_get_user_aiming_ent(index, const sClassName[]) {     new Float:vOrigin[3];     fm_get_aim_origin(index, vOrigin);         new ent, sTempClass[32], iLen = sizeof(sTempClass) - 1;     do     {         pev(ent, pev_classname, sTempClass, iLen);         if(equali(sClassName, sTempClass) && fm_is_ent_visible(index, ent))         {             return ent;         }     }     while((ent = engfunc(EngFunc_FindEntityInSphere, index, vOrigin, 10.0)))         return 0; } // fakemeta_util.inc stock fm_get_aim_origin(index, Float:origin[3]) {     new Float:start[3], Float:view_ofs[3]     pev(index, pev_origin, start)     pev(index, pev_view_ofs, view_ofs)     xs_vec_add(start, view_ofs, start)     new Float:dest[3]     pev(index, pev_v_angle, dest)     engfunc(EngFunc_MakeVectors, dest)     global_get(glb_v_forward, dest)     xs_vec_mul_scalar(dest, 9999.0, dest)     xs_vec_add(start, dest, dest)     engfunc(EngFunc_TraceLine, start, dest, 0, index, 0)     get_tr2(0, TR_vecEndPos, origin)     return 1 } // fakemeta_util.inc stock bool:fm_is_ent_visible(index, entity, ignoremonsters = 0) {     new Float:start[3], Float:dest[3]     pev(index, pev_origin, start)     pev(index, pev_view_ofs, dest)     xs_vec_add(start, dest, start)     pev(entity, pev_origin, dest)     engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0)     new Float:fraction     get_tr2(0, TR_flFraction, fraction)     if (fraction == 1.0 || get_tr2(0, TR_pHit) == entity)         return true     return false }

1. I'm not sure if this would work properly
2. I'm not sure if this is the best way to do this
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 03-27-2008 , 16:47   Re: Is user aiming at an entity
Reply With Quote #2

cant you do something like this with traceline?
Code:
stock bool:fm_get_user_aiming_ent(index, const szClassName[]) {     new Float:origin1[3];     new Float:origin2[3];         pev(index, pev_origin, origin1);     fm_get_aim_origin(index, origin2);     new trace = 0;     engfunc(EngFunc_TraceLine, origin1, origin2, DONT_IGNORE_MONSTERS, 0, trace);             new hit = get_tr2(trace, TR_pHit);     if(hit)     {         new classname[32];         pev(hit, pev_classname, classname);         if(equali(classname, szClassName))             return true;     }     return false; }
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-27-2008 , 16:54   Re: Is user aiming at an entity
Reply With Quote #3

thanks, didnt think of tracelines, cause ive never used them lol
will this work if entity's pev_solid is SOLID_NOT?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 03-27-2008 , 16:56   Re: Is user aiming at an entity
Reply With Quote #4

No...entity must be solid...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-27-2008 , 17:02   Re: Is user aiming at an entity
Reply With Quote #5

thanks alka + rolnaaba

since topic is already made and no since in making new one:
does menu_addblank() take place of a number, or is it just a space?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 03-27-2008 , 17:11   Re: Is user aiming at an entity
Reply With Quote #6

depends...if you set the slot num to 0 ->
Code:
menu_addblank(*iMenu, 0);
then no, but you can put any number, e.g if you put 2 then will take 2 numbers...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Reply



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

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

Forum Jump


All times are GMT -4. The time now is 17:23.


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