Raised This Month: $ Target: $400
 0% 

Is Player Controlling a Bot?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 09-24-2013 , 20:31   Re: Is Player Controlling a Bot?
Reply With Quote #10

Quote:
Originally Posted by asherkin View Post
Aha, I thought spcomp might have ignored that little bit of sanity. Oh well, hand rolling what a C++ compiler would generate is the way.

PHP Code:
bool:IsPlayerControllingBot(client
{
    static 
bool:hasChecked false;
    static 
bool:isAvailable false;
    if (!
hasChecked) {
        
isAvailable FindSendPropOffs("CBasePlayer""m_bIsControllingBot") != -1;
        
hasChecked true;
    }

    return 
isAvailable && GetEntProp(clientProp_Send"m_bIsControllingBot") == 1;

Haha, I didn't think to use two statics. Much better. But yea, in this case, I pretty much use const for every parameter I expect to be constant which I think is a valid model. Obviously more useful in larger functions, but it stops third-party clients changing a variable when they didn't intend to, and I have to assume the client could alter any part of the code e.g. take the following useless example:

PHP Code:
PrintToServer("%d"client == 1); 
If the client accidentally wrote:

PHP Code:
PrintToServer("%d"client 1); 
Then no error would be shown, unless the const qualifier had been used. I use it almost instinctively these days.
__________________

Last edited by 11530; 09-24-2013 at 20:32.
11530 is offline
 



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 18:34.


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