Adding New Weapons
Adding New Weapons
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]
-
- Posts: 52
- Joined: Thu Sep 30, 2010 6:46 am
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)...
(Oh, and you might want to warn people about that tutorial if it does not actually work)...
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.
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 , 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.
[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;
This screws mostly the weapon items and direct weapon selection (impulses 1 to , 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.
Let us know when you find it. We've been looking for years.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)
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.
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.