Raised This Month: $ Target: $400
 0% 

How efficient is this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 10-14-2009 , 17:40   How efficient is this?
Reply With Quote #1

Code:
public Forward_PreThink(id) {     if(!is_user_alive(id))         return FMRES_IGNORED         static EntList[1]     if(find_sphere_class(id,g_aMissionClass,100.0,EntList,1))         RunNPC(id,EntList[0]);         if(!(pev(id,pev_button) & IN_USE && !(pev(id,pev_oldbuttons) & IN_USE)))         return FMRES_IGNORED         new Index,Body     get_user_aiming(id,Index,Body,100);         if(!Index)         return FMRES_IGNORED         static Classname[33]     pev(Index,pev_classname,Classname,32);         if(!equal(Classname,g_aMissionClass))         return }
I'm calling "find_sphere_class" - obviously alot. Which is my question. Is that bad? I only use to check when a player comes close to a NPC. It runs that function. I would use a task (with about 1-3 task time) but I figured I can just throw it into the prethink. So which is better, a task looping every 3 seconds. Or using it in prethink?
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Jon
Veteran Member
Join Date: Dec 2007
Old 10-14-2009 , 18:02   Re: How efficient is this?
Reply With Quote #2

Can't you use entity_range()? Tasks are bad, but 3 seconds I don't know.
Jon is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 10-14-2009 , 22:19   Re: How efficient is this?
Reply With Quote #3

Quote:
Originally Posted by Jon View Post
Can't you use entity_range()? Tasks are bad, but 3 seconds I don't know.
Don't think so. Since you need to pass the entity. Which is why i'm looking for it with "find_sphere_class"\

EDIT:
I thought of something else. Since the "NPC" is a custom entity. I make it's nextthink at 1 second. And use "register_think" or fakemeta forward it. How about that?
__________________
Oh yeah

Last edited by Drak; 10-14-2009 at 22:28.
Drak is offline
Send a message via MSN to Drak
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-15-2009 , 01:02   Re: How efficient is this?
Reply With Quote #4

You could try to create an aiment entity, with the npc as owner, this ent with a large radius, and hook the touch between players and entity.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
01010111
BANNED
Join Date: Oct 2009
Old 10-15-2009 , 01:13   Re: How efficient is this?
Reply With Quote #5

Indeed.

And by the way, Hamsandwich is the way to go
01010111 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-15-2009 , 01:17   Re: How efficient is this?
Reply With Quote #6

register_think from engine is the way, no need of ham here.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 10-15-2009 , 12:34   Re: How efficient is this?
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
You could try to create an aiment entity, with the npc as owner, this ent with a large radius, and hook the touch between players and entity.
Large radius? Set the size of the entity really large? And then register a touch?
That seems good.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
vitorrd
Senior Member
Join Date: Jul 2009
Old 10-15-2009 , 14:20   Re: How efficient is this?
Reply With Quote #8

His point is you should let the engine take care of those calculations for yuo. As you may have figured, PreThink is called VERY often and therefore shouldn't be used on slow calls.

@ 01010111: It seems you find it amusing to talk about what you don't know, isn't it?
vitorrd is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-15-2009 , 14:47   Re: How efficient is this?
Reply With Quote #9

Quote:
Originally Posted by Drak View Post
Large radius? Set the size of the entity really large? And then register a touch?
That seems good.
The problem with that is you still have to check the distance because the radius creates a circle but the bounding box is a square.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 10-15-2009 , 17:16   Re: How efficient is this?
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
The problem with that is you still have to check the distance because the radius creates a circle but the bounding box is a square.
Yeah.. Having issues with that. I just stuck with it's think now.
Code:
public Forward_NPCThink(const Ent) {     set_pev(Ent,pev_nextthink,halflife_time() + 1.0);         static EntList[33],npcName[33]         new Num = find_sphere_class(Ent,"player",100.0,EntList,32)     if(!Num)         return         new id,CurArray = GetNPCArray(Ent);         // Loop through all the found players     for(new Count;Count < Num;Count++)     {         id = EntList[Count]                 // We are currently doing a mission         // or they already said something to us         if(g_UserNPC[id][SAID_SOMETHING] || g_UserNPC[id][QUEST])             continue                 new plName[33]         get_user_name(id,plName,32);                 array_get_string(array_get_int(g_aMission,CurArray),0,npcName,32);         client_print(id,print_chat,"[NPC: %s] Hey %s!",npcName,plName);                 g_UserNPC[id][SAID_SOMETHING] = 1     } }
__________________
Oh yeah
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 22:37.


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