Raised This Month: $ Target: $400
 0% 

[TF2] Player-Following Annotations Snippet


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-30-2013 , 16:34   Re: [TF2] Player-Following Annotations Snippet
Reply With Quote #1

Quote:
Originally Posted by Mitchell View Post
Just making sure, ill have to test this at a later moment but say if i want to show it to only one player i would just make the bitstring: "2^(clientindex)" correct?
For bitfields, why not just use (left) bitshifting? That's what it exists for.

The only catch is that I'm not sure if it counts from 0 or not.

So, here's both versions... try both and see if they work.
PHP Code:
new bitfield 0;

// Iterating through all clients to build a visibility bitfield of all alive players
for (new client 1client <= MaxClientsi++)
{
    if (
IsClientInGame(client) && IsPlayerAlive(client))
    {
         
// 1-based
        
bitfield |= (<< client);
        
// 0-based
        //bitfield |= (1 << (client - 1));
    
}
}

// or for a single client

new bitfield = (<< client); 
(I'm assuming 1-based is correct based on glancing at the gravestone plugin's BuildBitString)

Edit: For those of you who don't know what bitshifting does, I'll give a quick example.

Pretend this is a series of 8 bits: 0b00000000 (0b is used to denote it's binary... it's a GCC thing)
Like a standard decimal, the lowest number is the one at the far right. What (1 << client) does is tell it to take the number 1 and move it to the left client bits. So:

Code:
(1 << 0) = 0b00000001
(1 << 1) = 0b00000010
(1 << 2) = 0b00000100
and there are 32-bits to a cell in Pawn.

It's a cheap way of storing a bunch of bools as a single value.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-30-2013 at 16:52.
Powerlord 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 18:27.


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