Raised This Month: $ Target: $400
 0% 

Finding Entities in a Sphere?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-31-2007 , 23:41   Re: Finding Entities in a Sphere?
Reply With Quote #1

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 02-01-2007 , 00:04   Re: Finding Entities in a Sphere?
Reply With Quote #2

Quote:
Originally Posted by XxAvalanchexX View Post
*Stuff*
Thanks ava! Works fine now. Also for the credit i gave you, was from this:
http://forums.alliedmods.net/showpos...10&postcount=6
Drak is offline
Send a message via MSN to Drak
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 00:35.


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