Raised This Month: $12 Target: $400
 3% 

Is it same code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lingzhidiyu
Senior Member
Join Date: Mar 2014
Old 09-29-2014 , 07:01   Is it same code?
Reply With Quote #1

same code?

PHP Code:
stock bool:IsClientTeamT(client)
{
    if(
client && client <= MaxClients)
        if(
GetClientTeam(client) == CS_TEAM_T)
            return (
true);

    return (
false);
}

stock bool:IsClientTeamT(client)
{
    if(
client && client <= MaxClients)
    {
        if(
GetClientTeam(client) == CS_TEAM_T)
        {
            return (
true);
        }
    }
    else
    {
        return (
false);
    }

lingzhidiyu is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 09-29-2014 , 07:05   Re: Is it same code?
Reply With Quote #2

Edit: the first is better, use the first, the second have a error
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 09-29-2014 at 08:24.
Franc1sco is offline
Send a message via MSN to Franc1sco
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 09-29-2014 , 08:35   Re: Is it same code?
Reply With Quote #3

PHP Code:
stock bool:IsClientTeamT(client

    if(
client && client <= MaxClients
    { 
        if(
GetClientTeam(client) == CS_TEAM_T
        { 
            return (
true); 
        }
        else
        { 
            
// missing return false here ;-)
        
}
    } 
    else 
    { 
        return (
false); 
    } 

So yeah, the first is better.

EDIT: You also might want to check client validity via IsClientInGame() before GetClientTeam()

Last edited by KissLick; 09-29-2014 at 08:39.
KissLick is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 09-29-2014 , 09:26   Re: Is it same code?
Reply With Quote #4

It's a matter of style, but the first one usually never better.
PHP Code:
stock bool:IsClientTeamT(client) {

    if (
client && client <= MaxClients) {
        if (
IsClientInGame(client)) {
            if (
GetClientTeam(client) == CS_TEAM_T) {
                return 
true;
            }
        }
    }

    return 
false;

xf117 is offline
Send a message via ICQ to xf117
Mitchell
~lick~
Join Date: Mar 2010
Old 09-29-2014 , 13:11   Re: Is it same code?
Reply With Quote #5

Nested if statements

PHP Code:
stock bool:IsClientTeamT(client) {

    if (
client && client <= MaxClients &&
        
IsClientInGame(client) &&
        
GetClientTeam(client) == CS_TEAM_T) {
        return 
true;
    }

    return 
false;

Mitchell is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 09-29-2014 , 13:42   Re: Is it same code?
Reply With Quote #6

Just for more readability (hah)

PHP Code:
stock bool:IsClientTeamT(client) {
    return (
client && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == CS_TEAM_T);

__________________

Last edited by floube; 09-29-2014 at 13:42.
floube 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 01:39.


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