Raised This Month: $ Target: $400
 0% 

client_PreThink for one client only


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
irok
New Member
Join Date: Nov 2006
Old 11-10-2006 , 23:43   client_PreThink for one client only
Reply With Quote #1

How would I use client_PreThink for one client only(admin)?
I want to avoid set_task.
Code:
public client_PreThink(id) {
//CODE
}
irok is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 11-11-2006 , 00:02   Re: client_PreThink for one client only
Reply With Quote #2

You can check for SteamID or flag rights.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
stupok
Veteran Member
Join Date: Feb 2006
Old 11-11-2006 , 01:14   Re: client_PreThink for one client only
Reply With Quote #3

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... }
stupok is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 11-11-2006 , 01:54   Re: client_PreThink for one client only
Reply With Quote #4

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.
__________________
Brad is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 11-11-2006 , 02:01   Re: client_PreThink for one client only
Reply With Quote #5

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 }
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
organizedKaoS
Senior Member
Join Date: Feb 2006
Old 11-11-2006 , 13:16   Re: client_PreThink for one client only
Reply With Quote #6

Quote:
Originally Posted by XxAvalanchexX View Post
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.
organizedKaoS is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 11-11-2006 , 14:29   Re: client_PreThink for one client only
Reply With Quote #7

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.
stupok is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 11-11-2006 , 21:33   Re: client_PreThink for one client only
Reply With Quote #8

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
organizedKaoS
Senior Member
Join Date: Feb 2006
Old 11-12-2006 , 00:53   Re: client_PreThink for one client only
Reply With Quote #9

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.
organizedKaoS is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 11-12-2006 , 12:26   Re: client_PreThink for one client only
Reply With Quote #10

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.

Last edited by [ --<-@ ] Black Rose; 11-12-2006 at 15:55.
[ --<-@ ] Black Rose is offline
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 17:55.


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