Jump to content

Home

a noob questions :)


alexx860

Recommended Posts

  • 2 weeks later...

The ^ operator is Exclusive OR (XOR) - with the following truth table:

 

A B R

 

0 0 0

0 1 1

1 0 1

1 1 0

 

This code:

 

if( ent->client->ps.stats[sTAT_HOLDABLE_ITEM] & HI_JETPACK )

{

ent->client->ps.stats[sTAT_HOLDABLE_ITEM] ^= HI_JETPACK ;

}

 

...would toggle the HI_JETPACK bit to off, if it was on. So actually, even though it's a bit OTT (Razor's code is the more correct and easier way!), this code should actually succeed in turning off that bit.

 

I think the problem may lie in when you are running this code - I don't think you've specified this anywhere. Also, you probably need to clear the EF_JETPACK flag at the same time...

 

i.e.

 

ent->client->ps.stats[sTAT_HOLDABLE_ITEM] &= ~HI_JETPACK;

ent->client->ps.eFlags &= ~EF_JETPACK;

Link to comment
Share on other sites

If you wanna use the same command to give the jetpack as take it away then XORing is the way to go:

 

if( !strcmp(cmd, "givejetpack"))
{
ent->client->ps.stats[sTAT_HOLDABLE_ITEM] ^= HI_JETPACK;
ent->client->ps.eFlags ^= EF_JETPACK;
}

 

That command will give them a jetpack if they don't have one, and take it away if they do. The only problem is if the HI_JETPACK and EF_JETPACK bits get out of sync with each other. =]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...