Forum

detecting the players current weapons and removing them?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

detecting the players current weapons and removing them?

Postby ceriux » Thu Mar 22, 2012 9:14 pm

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?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: detecting the players current weapons and removing them?

Postby andrewj » Fri Mar 23, 2012 12:53 am

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

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

where 'wep' is IT_SHOTGUN etc...
andrewj
 
Posts: 133
Joined: Mon Aug 30, 2010 3:29 pm
Location: Australia

Re: detecting the players current weapons and removing them?

Postby ceriux » Fri Mar 23, 2012 4:03 am

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?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: detecting the players current weapons and removing them?

Postby DukeInstinct » Fri Mar 23, 2012 9:58 am

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
User avatar
DukeInstinct
 
Posts: 20
Joined: Sat Jul 10, 2010 11:20 pm
Location: DukeLand

Re: detecting the players current weapons and removing them?

Postby r00k » Fri Mar 23, 2012 5:20 pm

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.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest