Page 1 of 1

Adding New Weapons

Posted: Sat Nov 13, 2010 7:34 pm
by EMR
In tutorial 60, (http://www.inside3d.com/showtutorial.php?id=60), it claims that weapon IDs don't need to be powers of two. It seems like one would not do that kind of thing if they didn't need to, so is this... true?[/code][/i]

Posted: Sat Nov 13, 2010 8:00 pm
by silverjoel
They have to be powers of 2. Well, if you want it to work right.

Posted: Sat Nov 13, 2010 8:15 pm
by EMR
Is there a workaround so that we can have an arbitrary number of weapons? My plan was to test all of the weapon functions I could make before re-writing the weapon switching code. The end goal was to implement a weapon switching/shooting system more like BattleField or Halo, where you swap weapons rather than hauling a whole arsenal around.

(Oh, and you might want to warn people about that tutorial if it does not actually work)...

Posted: Sat Nov 13, 2010 8:24 pm
by Downsider
If you want a Halo-type system, and there's only two weapon slots, then you can just define two weapon slots as fields with integers for ID's, instead of bitflags for the entire inventory.

Posted: Sat Nov 13, 2010 9:25 pm
by mankrip
Powers of two (also known as bitflags) are only needed for the HUD to know which weapon icons to display, iirc.

[edit]Actually, this is only the case is you use a separated float to indicate each wepon.

Code: Select all

float	IT_AXE					= 4096;
float	IT_SHOTGUN				= 1;
float	IT_SUPER_SHOTGUN		= 2;
float	IT_NAILGUN				= 4;
float	IT_SUPER_NAILGUN		= 8;
float	IT_GRENADE_LAUNCHER		= 16;
float	IT_ROCKET_LAUNCHER		= 32;
float	IT_LIGHTNING			= 64;
float	IT_EXTRA_WEAPON			= 128;
If you create a new weapon and define it as IT_BROOMSTICK = 3, getting it will be the same thing as getting the super shotgun, because the player already starts with the regular shotgun, and IT_SHOTGUN | IT_SUPER_SHOTGUN == 3, which means that every check for self.items & IT_SUPER_SHOTGUN will always return as true as every check for self.items & IT_BROOMSTICK.

This screws mostly the weapon items and direct weapon selection (impulses 1 to 8), but doesn't affect the cycling of weapons (impulses 10 and 12).

[edit 2] And yes, the third step in that tutorial is wrong and completely unnecessary, because self.items & IT_SNIPER is the same as self.items & (IT_SHOTGUN | IT_GRENADE_LAUNCHER), which means that every time you get the grenade launcher you will also get the sniper rifle anyway. Adding that third step will have the side effect of also making you receive the grenade launcher every time you receive the sniper rifle.

To add new weapons, the best way is to continue increasing the bitflags, using values like 256, 512, 1024, 2048 and 8192 (skipping 4096, which is used for IT_AXE) for new weapons. There's a practical limit for the number of bitflags that can be stored though, and iirc it's 8192 or 16384.

Posted: Sun Nov 14, 2010 8:11 pm
by EMR
Oh, so I suppose it would be more convenient to just dike out the small hud ammo display altogether-(and possibly replace it with a slot-based ammo display). Where in the QC source is that, by the way?

(Edit - I spelled dike wrong)

Posted: Sun Nov 14, 2010 8:47 pm
by Downsider
EMR wrote:Oh, so I suppose it would be more convenient to just dike out the small hud ammo display altogether-(and possibly replace it with a slot-based ammo display). Where in the QC source is that, by the way?

(Edit - I spelled dike wrong)
Let us know when you find it. We've been looking for years. :cry:

Posted: Sun Nov 14, 2010 9:53 pm
by EMR
I'm sorry. Having looked into it more, yeah, you can't mess with the hud with normal QC.

Posted: Tue Nov 16, 2010 5:48 am
by something
you just have as downsider said.
i have new fields that hold the slots current value. and made a function to drop the currently engadged weapon slot. which spawns a item which you can then again pickup.

on my implementation each slot by default uses 'hands' which can pickup and move items, if you pick it up it changes slot*_current to the weapon/item you pickup. then you can use it. or throw it away.

it works out what the weapon on the ground is by its field of item_item, which then determines what it does. item_item 'dartgun' would be put into slot*current when picked up. and when you drop it.. an entity is created with item_item = slot*current.