Raised This Month: $32 Target: $400
 8% 

Global player entity settings and bitwise operations


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 12-30-2015 , 02:04   Global player entity settings and bitwise operations
Reply With Quote #1

I have quite a bit of plugins managing different things with players - are they admins, donators, are they in the Steam group, are they in Friendly mode, have they joined via the favourites tab (and a bunch of my map-specific booleans), etc.

If I want to check for a certain player property in a different plugin, for example, if they have joined via the favourites tab, I'd have to create an .inc file for that specific plugin which is a lot of work for something that small. Checking the first three is a breeze since I can just check their flags, but there's only so many custom ones out there.

TL;DR Here -> Which brings me to my question: Is there an official way of setting certain properties of an (player) entity just for the sole reason of something else reading from it?

I was thinking of using some "unused" property of a player entity such as m_hOwnerEntity or m_flNextAttack or [TF2] m_nCurrency (while not in MvM). But I think simply setting the name of the player entity to a flags number would be the best solution.

Another question: I have not been playing around with bitwise operations before, so please correct me if any of this is wrong:

PHP Code:
#define FLAG_NONE            0
#define FLAG_FRIENDLY        1
#define FLAG_JOINEDBYFAV    2
#define FLAG_BONUSSTAGE        4
#define FLAG_ARENASTAGE        8
#define FLAG_DUELCONTESTANT    16

new iPlayerFlags[MAXPLAYERS+1] = {0, ...};


OnArenaEnter(client){

    
iPlayerFlags[client] |= FLAG_ARENASTAGE;

}

OnArenaExit(client){

    
iPlayerFlags[client] |= ~FLAG_ARENASTAGE;

}

bool:IsClientInBonusStage(client){

    if(
iPlayerFlags[client] & FLAG_BONUSSTAGE)
        return 
true;
    
    return 
false;


Thanks for reading and any help; and a happy New Year to all!

Last edited by Phil25; 12-30-2015 at 02:06.
Phil25 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 12-30-2015 , 02:22   Re: Global player entity settings and bitwise operations
Reply With Quote #2

Quote:
Originally Posted by Phil25 View Post
But I think simply setting the name of the player entity to a flags number would be the best solution.
Maps use targetnames as the main method of saving information about players AFAIK, and plugins sometimes use them for workarounds

Quote:
Originally Posted by Phil25 View Post
TL;DR Here -> Which brings me to my question: Is there an official way of setting certain properties of an (player) entity just for the sole reason of something else reading from it?
I don't think lazy hacks really have official implementations by nature

Quote:
Originally Posted by Phil25 View Post
PHP Code:
iPlayerFlags[client] |= ~FLAG_ARENASTAGE
You want iPlayerFlags[client] &= ~FLAG_ARENASTAGE; if you're trying to remove the flag
Miu is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 12-30-2015 , 03:17   Re: Global player entity settings and bitwise operations
Reply With Quote #3

Thanks for the help. I am aware that some maps and plugins may use this but not in my case. I just want the best and simple solution for my small problem and such workaround seems like the best option. This is all for closed environment which is only a single server with a single map.
Phil25 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-30-2015 , 08:22   Re: Global player entity settings and bitwise operations
Reply With Quote #4

Tying the data to the entity property, especially for player-specific data, seems unnecessary in addition to potentially bringing breakage.

If you're referencing the player entity by index anyway, you're only introducing extra inefficiency by doing a native call to retrieve the data, rather than indexing an array local to the plugin like in your example above.

Your bitwise operations look fine.
psychonic is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 12-30-2015 , 09:12   Re: Global player entity settings and bitwise operations
Reply With Quote #5

Quote:
Originally Posted by psychonic View Post
If you're referencing the player entity by index anyway, you're only introducing extra inefficiency by doing a native call to retrieve the data, rather than indexing an array local to the plugin like in your example above.
I guess the best solution would be to have a seperate plugin managing all that and having every other include that plugin. That would also bring some extra functionality such as forwards.
Phil25 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-30-2015 , 09:28   Re: Global player entity settings and bitwise operations
Reply With Quote #6

Quote:
Originally Posted by Phil25 View Post
I guess the best solution would be to have a seperate plugin managing all that and having every other include that plugin. That would also bring some extra functionality such as forwards.
I completely missed the part about wanting to share the information with other plugins. That makes perfect sense as to why you'd consider using an entity property now.

You could indeed just has a plugin that manages the state, and then provide natives and forwards from that. It gives you much more flexibility in the future as well, should you need to store more values than a single bitfield, in addition to avoiding the other pitfalls with stomping on the game's own fields.

Last edited by psychonic; 12-30-2015 at 09:29.
psychonic is offline
Reply


Thread Tools
Display Modes

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 11:43.


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