Raised This Month: $ Target: $400
 0% 

Store IsClientInGame as g_ingame ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
D.Moder
I uploaded 2 great gameplay plugins here
Join Date: Sep 2009
Location: Sin city
Old 03-01-2015 , 17:16   Store IsClientInGame as g_ingame ?
Reply With Quote #1

I'm trying to make my mod a bit lighter by using variables instead of natives

I need to make sure they are very accurate.

PHP Code:

// turn these

IsClientInGame(client)
IsPlayerAlive(client)
GetClientTeam(client)

// to

g_ingame[]
g_isalive[]
g_team[] 
__________________
Creator of COD-Life (Half COD, Half Life)
https://forums.alliedmods.net/showthread.php?t=261162
twitter: @D_Moder_61216
D.Moder is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 03-01-2015 , 22:22   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #2

...Why?

How is doing this lighter on the mod?

PHP Code:
new bool:g_ingame[MAXPLAYERS 1];
new 
bool:g_isalive[MAXPLAYERS 1];
new 
g_team[MAXPLAYERS 1];

for (new 
1<= MaxClientsi++) {
    if (!
IsClientInGame(i))
        continue;
    
g_ingame[i] = IsClientInGame(i);
    
g_isalive[i] = IsPlayerAlive(i);
    
g_team[i] = GetClientTeam(i);

Darkness_ is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-02-2015 , 11:01   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #3

To add to what Darkness_ said....
  • IsClientInGame is likely just a check if an entity exists
  • IsPlayerAlive is likely just a netprop check
  • GetClientTeam is likely just fetching the value of a netprop.

None of these are operations are that expensive.

(Note: These say likely because I'd have to look through the SDK to verify it and I haven't)
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-02-2015 , 11:19   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #4

IsPlayerAlive: https://mxr.alliedmods.net/sourcemod...nager.cpp#2507 - netprop check

The others, I'm too lazy to check exact links, but powerlord is correct... very cheap calls
__________________
View my Plugins | Donate
TnTSCS is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 03-02-2015 , 11:23   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #5

But mainly, you would have to cache these values on every event, that might change them (a lot of space to miss something) and it would make your code less readable.

Just use functions, this is not something you should try to optimize.
KissLick is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-02-2015 , 11:54   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #6

If you wanted to bunch up all three of those checks into one, here's a very simplified way:

PHP Code:
public MyFunction(client)
{
    if (
PlayerInGameAliveOnTeam(client2))
    {
        
// Act on player
    
}
    else
    {
        
// Player either isn't in game, not on team specified, or not alive
    
}
}

bool:PlayerInGameAliveOnTeam(clientteam)
{
    if (
IsClientInGame(client) && GetClientTeam(client) == team)
    {
        return 
IsPlayerAlive(client);
    }
    
    return 
false;

__________________
View my Plugins | Donate

Last edited by TnTSCS; 03-02-2015 at 11:55.
TnTSCS is offline
D.Moder
I uploaded 2 great gameplay plugins here
Join Date: Sep 2009
Location: Sin city
Old 03-02-2015 , 17:10   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #7

Quote:
Originally Posted by TnTSCS View Post
If you wanted to bunch up all three of those checks into one, here's a very simplified way:
that's not what I meant, I'm going to use each of those vars in different areas of code, but now as most of you guys say, those functions aren't that expensive, so I think I'll just use the natives then.
__________________
Creator of COD-Life (Half COD, Half Life)
https://forums.alliedmods.net/showthread.php?t=261162
twitter: @D_Moder_61216
D.Moder is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-02-2015 , 19:05   Re: Store IsClientInGame as g_ingame ?
Reply With Quote #8

IsClientInGame: https://github.com/alliedmodders/sou...ayers.cpp#L456
GetClientTeam: https://github.com/alliedmodders/sou...ayers.cpp#L768
__________________

Last edited by WildCard65; 03-02-2015 at 19:06.
WildCard65 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 05:32.


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