AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   client_PreThink for one client only (https://forums.alliedmods.net/showthread.php?t=47151)

irok 11-10-2006 23:43

client_PreThink for one client only
 
How would I use client_PreThink for one client only(admin)?
I want to avoid set_task.
Code:

public client_PreThink(id) {
//CODE
}


Drak 11-11-2006 00:02

Re: client_PreThink for one client only
 
You can check for SteamID or flag rights.

stupok 11-11-2006 01:14

Re: client_PreThink for one client only
 
I wonder if this would work... haven't tested so I'm not sure.

Code:
public client_putinserver(id, level, cid) {     if (!cmd_access(id,level,cid,2))         return PLUGIN_HANDLED             new adminid = id } public client_PreThink(adminid) {     //code... }

Brad 11-11-2006 01:54

Re: client_PreThink for one client only
 
Why do you want to avoid set_task?

Also, what do you mean you only want to use client_PreThink for one client only? It fires for every client and passes in the id of the client it's currently firing for.

XxAvalanchexX 11-11-2006 02:01

Re: client_PreThink for one client only
 
You can't do that, stupok, but it would be good thinking to set whether or not a user's PreThink should be tracked in client_putinserver, so that you don't have to calculate it every time. For example:

Code:
 new prethink[33]; public client_authorized(id) {      prethink[id] = 0;      if(/* check here: steamid, admin flags, etcetera */) prethink[id] = 1; } public client_PreThink(id) {      if(!prethink[id]) return;      // your code here }

organizedKaoS 11-11-2006 13:16

Re: client_PreThink for one client only
 
Quote:

Originally Posted by XxAvalanchexX (Post 402142)
You can't do that, stupok, but it would be good thinking to set whether or not a user's PreThink should be tracked in client_putinserver, so that you don't have to calculate it every time. For example:

Code:
 new prethink[33]; public client_authorized(id) {      prethink[id] = 0;      if(/* check here: steamid, admin flags, etcetera */) prethink[id] = 1; } public client_PreThink(id) {      if(!prethink[id]) return;      // your code here }

Good advice, or you could just use
Code:
public client_PreThink(id) {      if(!is_user_admin(id)) return; }

Pretty much the same as your checking if the player id is admin.

Not sure if one is more efficient than the other but you get the idea.

stupok 11-11-2006 14:29

Re: client_PreThink for one client only
 
I would definitely go with XxAvalanchexX 's method, it doesn't execute the is_user_admin() function every frame, which is completely unnecessary, so it is definitely much faster.

XxAvalanchexX 11-11-2006 21:33

Re: client_PreThink for one client only
 
KaoS, it really depends on exactly what he wants to check. If it's a steamid comparison, it should be done somewhere besides prethink. If it's only to check if user is an admin, then your way would be fine too.

organizedKaoS 11-12-2006 00:53

Re: client_PreThink for one client only
 
Yes I agree avalanche.

Your method is of course just as good.

Just showing every possibility for it.

Though he did say admin in his initial post which is why I gave my input. :up:

[ --<-@ ] Black Rose 11-12-2006 12:26

Re: client_PreThink for one client only
 
Code:
#include <amxmodx> #include <fakemeta> new forward_PreThink new bool:g_prethink[32] public client_authorized(id) {         g_prethink[id] = false;         if ( /* check here: steamid, admin flags, etcetera */ ) {         g_prethink[id] = true;         forward_PreThink = register_forward(FM_PlayerPreThink, "FM_Prethink")     } } public FM_Prethink(id) {     if ( ! g_prethink[id] )         return         // your code here } public client_disconnect(id) {     if ( ! g_prethink[id] )         return         if ( none_left() )         unregister_forward(FM_PlayerPreThink, forward_PreThink, 1) } stock none_left() {         for ( new i = 0 ; i < 32 ; i++ ) {              if ( g_prethink[i] )             return 0     }         return 1 }

I win.


All times are GMT -4. The time now is 06:54.

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