AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding Entities in a Sphere? (https://forums.alliedmods.net/showthread.php?t=50675)

Drak 01-31-2007 22:07

Finding Entities in a Sphere?
 
I'm trying to find all the vaildentites in my area, code:
Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #include <engine> #include <fakemeta_util> #define PLUGIN "Sphere Test" #define VERSION "1.0" #define AUTHOR "Blll" //Should this be global? new validents[3][256] = {     "monster_zombie",     "monster_scientist",     "monster_barney" } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("amx_sphere","sphere") } public sphere(id) {     new origin[3],ent,total,classname[32]     get_user_origin(id,origin)     while((ent = engfunc(EngFunc_FindEntityInSphere,ent,origin,10.0)) != 0 ) {         entity_get_string(ent,EV_SZ_classname,classname,31); //How do i get Classname in FakeMeta?         for(new i=0;i<sizeof(validents);i++) { //Thanks for XxAvalanchexX for this             if(equali(validents[i],classname)) {                 ent = total                 //fm_set_rendering(ent,kRenderFxGlowShell,200,130,42,kRenderNormal,16) Render the ents                 console_print(id,"[DEBUG] Ents found: %d",total)                 break;             }         }     }     return PLUGIN_HANDLED }
The number doesn't return correctly, (Sphere Count) it's usually wrong. I tryed lowering the sphere radius and it still doesn't work correctly. It will keep returning a large, or a null number. When the rendering code in un-commented, it renders all the ents within "validents", but not in radius range.

jim_yang 01-31-2007 22:40

Re: Finding Entities in a Sphere?
 
ent = total // you assign zero to ent
pev(ent, pev_classname, classname, 31)
if you have just 3 strings, then you don't need loop. this is slow.
why not just use fakemeta_util only.

Drak 01-31-2007 23:06

Re: Finding Entities in a Sphere?
 
Quote:

Originally Posted by jim_yang (Post 434122)
ent = total // you assign zero to ent
pev(ent, pev_classname, classname, 31)
if you have just 3 strings, then you don't need loop. this is slow.
why not just use fakemeta_util only.

I try'ed it without a loop and still nothing, and I left fakemeta include in-there on accident.
Code:
public sphere(id) {     new origin[3],classname[32]     get_user_origin(id,origin)     new ent = engfunc(EngFunc_FindEntityInSphere,ent,origin,100.0)     pev(ent, pev_classname, classname, 31)     for(new i=0;i<sizeof(validents);i++) { //Thanks for XxAvalanchexX for this         if(equali(validents[i],classname)) {             fm_set_rendering(ent,kRenderFxGlowShell,200,130,42,kRenderNormal,16) //Render the ents         }     }     console_print(id,"[DEBUG] Ents found: %d",ent)     return PLUGIN_HANDLED }
Changed it to this, but still returning 0 or a odd amount of ents. It also wont render the selected ones again.

Also, i checked what the classname was returning, I either got 'player' or 'bodyque' when i was near a npc.

lunarwolfx 01-31-2007 23:39

Re: Finding Entities in a Sphere?
 
I'm not too sure, but I think the origin is supposed to be a float, and add the while loop back, I'm pretty sure that part was correct.

jim_yang 01-31-2007 23:40

Re: Finding Entities in a Sphere?
 
so your npc's classname is not monster_*, you should set their classname to monster_* when your create them
Code:
public sphere(id) {         new Float:origin[3], ent, classname[32]         pev(id, pev_origin, origin)         while((ent = fm_find_ent_in_sphere(ent, origin, 100.0)))         {                 pev(ent, pev_classname, classname, 31)                 if(equali(classname, "monster_zombie") || equali(classname, "monster_scientist") || equali(classname, "monster_barney"))                 {                         fm_set_rendering(ent,kRenderFxGlowShell,200,130,42,kRenderNormal,16)                         console_print(id,"[DEBUG] Ents found: %d", ent)                 }         }         return PLUGIN_HANDLED }

XxAvalanchexX 01-31-2007 23:41

Re: Finding Entities in a Sphere?
 
Uh-oh, my name's in that code, this can't be good... Anyway, the first code should always be telling you 0, since you never assign "total" a value. This is what I would do:

Code:
#include <amxmodx> #include <amxmisc> #include <fakemeta> #include <engine> #define PLUGIN "Sphere Test" #define VERSION "1.0" #define AUTHOR "Blll" //Should this be global? new validents[3][256] = {     "monster_zombie",     "monster_scientist",     "monster_barney" } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_concmd("amx_sphere","sphere") } public sphere(id) {     new Float:origin[3],ent,total,i,classname[32]     pev(id,pev_origin,origin)     while((ent = engfunc(EngFunc_FindEntityInSphere,ent,origin,10.0)) != 0 ) {         entity_get_string(ent,EV_SZ_classname,classname,31); //How do i get Classname in FakeMeta?         for(i=0;i<sizeof(validents);i++) { //Thanks for XxAvalanchexX for this             if(equali(validents[i],classname)) {                 total++                 //fm_set_rendering(ent,kRenderFxGlowShell,200,130,42,kRenderNormal,16) Render the ents                 break;             }         }     }     console_print(id,"[DEBUG] Ents found: %d",total)     return PLUGIN_HANDLED }

Changes (from first code): I get "origin" as a float, as it should be. I'm surprised that the other code didn't crash or something (Fakemeta is usually very picky). I create "i" outside of any loops, as you only need to create it one time. I add to "total" instead of assigning it the value of the last entity index found. Then I display "total" outside of the loops, since it only needs to be shown once.

Drak 02-01-2007 00:04

Re: Finding Entities in a Sphere?
 
Quote:

Originally Posted by XxAvalanchexX (Post 434139)
*Stuff*

Thanks ava! Works fine now. Also for the credit i gave you, was from this:
http://forums.alliedmods.net/showpos...10&postcount=6


All times are GMT -4. The time now is 00:35.

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