detecting the players current weapons and removing them?

Discuss programming in the QuakeC language.
Post Reply
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

detecting the players current weapons and removing them?

Post by ceriux »

how can i detect what weapons the player has ? that way i can remove them. basically iv built a buy menu and i need to check which weapon the player has and when he purchases the new weapon remove it.

would i do something like make a .float and store owep? and if owep = it_wep self.items = self.items && self.items - owep? or something?
andrewj
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Re: detecting the players current weapons and removing them?

Post by andrewj »

Check:
if (self.items & wep)
{
// do something
}

Remove:
self.items = self.items - (self.items & wep)

where 'wep' is IT_SHOTGUN etc...
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: detecting the players current weapons and removing them?

Post by ceriux »

andrewj wrote:Check:
if (self.items & wep)
{
// do something
}

Remove:
self.items = self.items - (self.items & wep)

where 'wep' is IT_SHOTGUN etc...

right, but how would i be able to keep track of which weapon? say you start with the shotgun, but you buy a... nailgun owep gets turned to 3 since shotgun would be 1. i have to keep track of the players weapon that way when they buy a new weapon the remove code i call knows which to remove. so basically if owep == this remove this weapon. i could call owep , mywep so if mywep == 1 and i purchase a nailgun since mywep is 1 it would know to call the code to remove the shotgun that way when the player is given the nailgun he doesnt have both and the wrong weapon isnt removed, i would just change mywep to the number of the current held weapon. would this work?
DukeInstinct
Posts: 20
Joined: Sat Jul 10, 2010 11:20 pm
Location: DukeLand
Contact:

Re: detecting the players current weapons and removing them?

Post by DukeInstinct »

self.items should already be keeping track of the weapons the player possesses.

Couldn't you just set self.items to the flag of the new weapon and force the player to select the new one? Like so:

self.items = IT_SHOTGUN;

As long as you're not using self.items for things other than weapons, that should work. Otherwise, you could subtract just the weapon flags off and then add the new one.

if (self.items & IT_SHOTGUN)
self.items = self.items - IT_SHOTGUN;

and just repeat for all the other possible flags.
Image
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: detecting the players current weapons and removing them?

Post by r00k »

You could have it so that they can sell the shotgun back to the "store" for half price.

Code: Select all

self.items = self.items - (self.items & IT_SHOTGUN);//the IT_SHOTGUN can be replaced with a variable of the sold item
self.weapon = 0; //this is for the hud
self.currentammo = 0;//hud
self.weaponmodel = "";//dont draw the viewmodel
self.weaponframe = 0;//reset animation
Look at the weapon touch function to get an example of how to equip the player when they buy an item.
Post Reply