View Single Post
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-12-2019 , 18:08   Re: How to return multiple values and apply conditionals for all possible combination
Reply With Quote #3

A bitvec / bitflag is basically an array of boolean values, so you might as well get the contents of m_upgradeBitVec and check your requirements against it; something like the following (untested):

Code:
// contains bitflag of upgrades (m_upgradeBitVec)
int upgradeBitVec;

// you'd want to translate the cvar to the corresponding bitvec somehow, your choice on implementation
// for the sake of example, I'll fill them in:
int vipUpgradeChoice = L4D2_WEPUPGFLAG_INCENDIARY;
int regUpgradeChoice = L4D2_WEPUPGFLAG_LASER;

// true if the player has either incendiary or explosive upgrades
// I'm not sure what your desired behavior is in that case so you'll have to work that out
bool hasMutuallyExclusiveUpgrade = upgradeBitVec & (L4D2_WEPUPGFLAG_INCENDIARY | L4D2_WEPUPGFLAG_EXPLOSIVE);

if (vipUpgradeChoice != L4D2_WEPUPGFLAG_NONE && bIsVip && !(upgradeBitVec & vipUpgradeChoice)) {
	// they are VIP and they don't have this upgrade, so apply it
	// TODO apply the VIP upgrade here
} else if (regUpgradeChoice != L4D2_WEPUPGFLAG_NONE && !(upgradeBitVec & regUpgradeChoice)) {
	// they aren't VIP or they already had the upgrade
	// TODO apply the regular upgrade here
}
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-12-2019 at 18:11. Reason: code oops
nosoop is offline