Raised This Month: $ Target: $400
 0% 

Best way, global or Ent?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 11-13-2017 , 19:57   Best way, global or Ent?
Reply With Quote #1

What is the best way to valid or not player:

1#

Quote:
Originally Posted by iGENIUS View Post
I personally find storing if the player is valid or not on a global variable more plausible, mainly because there'll be no need of call any native. It's currently using a hardcoded value (which is the entity limit allowed by source engine) because you may need to do a check on an entity higher than MAXPLAYERS, which is controlled by sourcemod.

PHP Code:
#include <sourcemod>

new bool:IsClientInGame[4096];

public 
OnClientPutInServer(client)
    
IsClientInGame[client] = true;

public 
OnClientDisconnect_Post(client)
    
IsClientInGame[client] = false
2#

PHP Code:
public int IsValidClient(int client){
    if(!(
<= client <= MaxClients) || !IsClientInGame(client)){return false;}
    return 
true;

Thanks.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM
rodrigo286 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-13-2017 , 20:05   Re: Best way, global or Ent?
Reply With Quote #2

2#
__________________
8guawong is offline
rodrigo286
Veteran Member
Join Date: Sep 2010
Location: Brazil, São Paulo
Old 11-13-2017 , 20:43   Re: Best way, global or Ent?
Reply With Quote #3

I made this now:

PHP Code:
public int ClientBeValidated(int clientbool alive){
    if(!
alive)
        if(!(
<= client <= MaxClients) || !IsClientInGame(client))
        {return 
false;}
    if(
alive)
        if(!(
<= client <= MaxClients) || !IsClientInGame(client
        || 
IsClientObserver(client) || !IsPlayerAlive(client))
        {return 
false;}

    return 
true;

Regards.
__________________
My Plugins | VIEW HERE | I accept private requests, send me a PM.
Buy respawn | Uber Recall | Grenade drop | Damage Supperssor
Meet the Medic | Disguise Expert | Crazy Jet

CZSBrasil TEAM

Last edited by rodrigo286; 11-13-2017 at 21:13.
rodrigo286 is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 11-13-2017 , 21:12   Re: Best way, global or Ent?
Reply With Quote #4

Quote:
Originally Posted by rodrigo286 View Post
I made this now:

PHP Code:
public int ClientBeValidated(int clientbool alive){
    if(!
alive)
        if(!(
<= client <= MaxClients) || !IsClientInGame(client)){return false;}
        return 
true;
    if(
alive)
        if(!(
<= client <= MaxClients) || !IsClientInGame(client
        || 
IsClientObserver(client) || !IsPlayerAlive(client))
        {return 
false;}else{return true;}

Regards.
Try this: https://github.com/Hexer10/VipMenu-B...stocks.inc#L32
PHP Code:
stock bool IsValidClient(int clientbool AllowBots falsebool AllowDead true)
{
    if (!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !AllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!AllowDead && !IsPlayerAlive(client)))
    {
        return 
false;
    }
    return 
true;


Last edited by brunoronning; 11-13-2017 at 21:16.
brunoronning is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-14-2017 , 00:09   Re: Best way, global or Ent?
Reply With Quote #5

#KillIsValidClientStock
Mitchell is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 11-14-2017 , 00:13   Re: Best way, global or Ent?
Reply With Quote #6

whats wrong with it
hmmmmm is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 11-14-2017 , 08:46   Re: Best way, global or Ent?
Reply With Quote #7

Quote:
Originally Posted by hmmmmm View Post
whats wrong with it
In most cases to check if a client is valid all you're really going to need is the IsClientInGame function. Usually you won't need to check if they are a bot nor do you need to check if the client index lies within range 1 to MaxClients. I think the only time I ever check if its within the range is during some forwards that can pass entities other than clients through the parameters like with many the SDKHooks hooks or tracerays. I think its just better to use the functions that suit your needs on a case by case basis instead of this one that checks everything. Although the way sourcemod compiler handles if statements is pretty smart to avoid unnecessary checks I still stand by what I said
__________________
blaacky is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-14-2017 , 09:38   Re: Best way, global or Ent?
Reply With Quote #8

Quote:
Originally Posted by blaacky View Post
In most cases to check if a client is valid all you're really going to need is the IsClientInGame function. Usually you won't need to check if they are a bot nor do you need to check if the client index lies within range 1 to MaxClients. I think the only time I ever check if its within the range is during some forwards that can pass entities other than clients through the parameters like with many the SDKHooks hooks or tracerays. I think its just better to use the functions that suit your needs on a case by case basis instead of this one that checks everything. Although the way sourcemod compiler handles if statements is pretty smart to avoid unnecessary checks I still stand by what I said
Correct. There are many cases where I've seen people check to see if they are ingame and is within the range of 1 to Max clients within the OnClientPutInServer forward, i've even seen that check within a loop of the client indices. I'm just a believer that you shouldn't need to add in checks for what has already been checked before, this just adds a bit more clutter to your code.
Mitchell 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 22:35.


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