Raised This Month: $ Target: $400
 0% 

help with bit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zXCaptainXz
Member
Join Date: May 2017
Old 04-12-2022 , 17:07   Re: help with bit
Reply With Quote #1

Without getting into too much detail on how it works, you can compare the int "loaded" to a boolean array of size 32. So say you want to check if a player is connected, you can do it like this, note that the bool method is in comments

Code:
new Connected //new bool:Connected[33]

#define get_bit(%2,%1) (%1 & (1<<(%2&31)))
#define set_bit(%2,%1) (%1 |= (1<<(%2&31)))
#define rem_bit(%2,%1) (%1 &= ~(1 <<(%2&31)))

public client_connect(id)
{
	set_bit(id, Connected) // Connected[id] = true;
}

public client_disconnect(id)
{
	rem_bit(id, Connected) // Connected[id] = false;
}

public IsClientConnected(id)
{
	if(get_bit(id, Connected)) //if(Connected[id])
	{
		//Player is connected
	}
	else
	{
		//Player is not connected
	}
}
zXCaptainXz 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 21:20.


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