Raised This Month: $ Target: $400
 0% 

What's the best way to detect entity type?


Post New Thread Reply   
 
Thread Tools Display Modes
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 12-22-2006 , 07:27   Re: What's the best way to detect entity type?
Reply With Quote #11

=) i always complicate things

i'll try to look into amx/x source code to decide can i use it in my case

thanx
Simon Logic is offline
Send a message via Skype™ to Simon Logic
The Specialist
BANNED
Join Date: Nov 2006
Old 12-22-2006 , 07:28   Re: What's the best way to detect entity type?
Reply With Quote #12

NP
The Specialist is offline
Send a message via AIM to The Specialist
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 12-22-2006 , 10:46   Re: What's the best way to detect entity type?
Reply With Quote #13

Wow, great! That's what i needed. Via private data:
Code:
return *((int *)pWeapon->pvPrivateData + OFFSET_WEAPONTYPE);
Simon Logic is offline
Send a message via Skype™ to Simon Logic
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 12-25-2006 , 06:38   Re: What's the best way to detect entity type?
Reply With Quote #14

My joy was premature.

Can someone test attached script? I always get cs_get_weapon_id() = 0. What's wrong?

PS. How to test this: just throw a weapon and look into console.
Attached Files
File Type: sma Get Plugin or Get Source (test_cs_get_weapon_id.sma - 588 views - 692 Bytes)

Last edited by Simon Logic; 12-25-2006 at 07:02.
Simon Logic is offline
Send a message via Skype™ to Simon Logic
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 12-25-2006 , 08:08   Re: What's the best way to detect entity type?
Reply With Quote #15

Code:
stock bool:isWeapon(ent_id) {     static pStr     static sBuffer[11] // sizeof("weaponbox") + 1         pev(ent_id, pev_classname, pStr, sBuffer, sizeof(sBuffer)-1)         return bool:equal(sBuffer, "weaponbox") }

Wtf are you doing here :S

Code:
stock bool:isWeapon(ent_id) {     static sBuffer[11] // sizeof("weaponbox") + 1         pev(ent_id, pev_classname, sBuffer, sizeof(sBuffer)-1)         return bool:equal(sBuffer, "weaponbox") }
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 12-25-2006 , 10:00   Re: What's the best way to detect entity type?
Reply With Quote #16

Then wtf is that?!

Code:
/* Returns entvar data from an entity   Use the pev_* enum to specify which form of data you want returned.  *  * If retrieving strings, you may optionally get a pointer into the global string table. Depending on  * your situation, there are two ways to do this.  * 1: This simply gets the pointer.  *    new ptr = pev(entid, pev_classname)  * 2: The pointer will be stored in ptr AND the actual string is retrieved.  *    new ptr, classname[32]  *    pev(entid, pev_classname, ptr, classname, 31)  */ native pev(_index,_value,{Float,Sql,Result,_}:...);

Anyway it works ok. Did you check the result value for cs_get_weapon_id() ?
Simon Logic is offline
Send a message via Skype™ to Simon Logic
P34nut
AMX Mod X Beta Tester
Join Date: Feb 2006
Location: Netherlands
Old 12-25-2006 , 10:05   Re: What's the best way to detect entity type?
Reply With Quote #17

Quote:
Originally Posted by Simon Logic View Post
Did you check the result value for cs_get_weapon_id() ?
no didnt test it
__________________
All you need to change the world is one good lie and a river of blood
P34nut is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 12-26-2006 , 13:42   Re: What's the best way to detect entity type?
Reply With Quote #18

It works fine it because of your usage. You can't use it on the weaponbox entity. You have to use it on the weapon itself. So you need to search for the actually weapon entity index.

Code:
#include <amxmodx> #include <fakemeta> #include <cstrike> new g_hTouch = 0 public plugin_init() {     g_hTouch = register_forward(FM_Touch, "onTouch") } public plugin_end() {     if(g_hTouch) {         unregister_forward(FM_Touch, g_hTouch)         g_hTouch = 0     } } public onTouch(eid, pid) {     if(!eid) return FMRES_IGNORED     if(isWeapon(eid))     {         new ent = FindEntityByOwner(eid)         if(ent)         {             server_print("[AMXX] cs_get_weapon_id(%d) = %d", eid, cs_get_weapon_id(ent))         }     }     return FMRES_IGNORED } stock FindEntityByOwner(owner) {     new i;     for(i = get_maxplayers() + 1; i < global_get(glb_maxEntities); i++)     {         if(pev(i, pev_owner) == owner)         {             break;         }     }     return i; } stock bool:isWeapon(ent_id) {     static pStr     static sBuffer[11] // sizeof("weaponbox") + 1     pev(ent_id, pev_classname, pStr, sBuffer, sizeof(sBuffer)-1)     server_print("%s", sBuffer);     return bool:equal(sBuffer, "weaponbox") }
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 12-26-2006 , 17:43   Re: What's the best way to detect entity type?
Reply With Quote #19

Quote:
Originally Posted by Simon Logic
Can someone test attached script? I always get cs_get_weapon_id() = 0. What's wrong?
If You are tesing this stuff with csdm weapons (created for itemmode)- don't forget they are not created with the classname "weaponbox" but they are created with classnames "csdmw_xxx" - the exact names You can see in the table g_EntClass[][] of csdm_itemmode plugin.
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.
KWo is offline
Simon Logic
Senior Member
Join Date: Nov 2006
Location: RF
Old 12-27-2006 , 05:34   Re: What's the best way to detect entity type?
Reply With Quote #20

KWo, it's ok. I understand this. I tested it on THROWN weapon. Also i deactivated all plugins for sure on testing.

teame06, thank you very much!

Looks like this method can be very CPU intensive to scan through global_get(glb_maxEntities) instead of scanning an array with models, but reliable.

I think it's much faster to use engfunc(EngFunc_FindEntityByString, -1, "owner", strWeaponBoxID). I'll rewrite a script and test it.

But does weaponbox entity own only ONE entity always?
Simon Logic is offline
Send a message via Skype™ to Simon Logic
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 19:34.


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