Page 1 of 1

detecting the players current weapons and removing them?

Posted: Thu Mar 22, 2012 9:14 pm
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?

Re: detecting the players current weapons and removing them?

Posted: Fri Mar 23, 2012 12:53 am
by andrewj
Check:
if (self.items & wep)
{
// do something
}

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

where 'wep' is IT_SHOTGUN etc...

Re: detecting the players current weapons and removing them?

Posted: Fri Mar 23, 2012 4:03 am
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?

Re: detecting the players current weapons and removing them?

Posted: Fri Mar 23, 2012 9:58 am
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.

Re: detecting the players current weapons and removing them?

Posted: Fri Mar 23, 2012 5:20 pm
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.