AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How efficient is this? (https://forums.alliedmods.net/showthread.php?t=106399)

Drak 10-14-2009 17:40

How efficient is this?
 
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?

Jon 10-14-2009 18:02

Re: How efficient is this?
 
Can't you use entity_range()? Tasks are bad, but 3 seconds I don't know.

Drak 10-14-2009 22:19

Re: How efficient is this?
 
Quote:

Originally Posted by Jon (Post 962116)
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?

ConnorMcLeod 10-15-2009 01:02

Re: How efficient is this?
 
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.

01010111 10-15-2009 01:13

Re: How efficient is this?
 
Indeed.

And by the way, Hamsandwich is the way to go :)

ConnorMcLeod 10-15-2009 01:17

Re: How efficient is this?
 
register_think from engine is the way, no need of ham here.

Drak 10-15-2009 12:34

Re: How efficient is this?
 
Quote:

Originally Posted by ConnorMcLeod (Post 962454)
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.

vitorrd 10-15-2009 14:20

Re: How efficient is this?
 
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?

Exolent[jNr] 10-15-2009 14:47

Re: How efficient is this?
 
Quote:

Originally Posted by Drak (Post 962832)
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.

Drak 10-15-2009 17:16

Re: How efficient is this?
 
Quote:

Originally Posted by Exolent[jNr] (Post 963012)
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     } }


All times are GMT -4. The time now is 22:37.

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