Forum

Adding New Weapons

Need help with a tutorial found on InsideQC.com? Post here.

Moderator: InsideQC Admins

Adding New Weapons

Postby EMR » Sat Nov 13, 2010 7:34 pm

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]
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Postby silverjoel » Sat Nov 13, 2010 8:00 pm

They have to be powers of 2. Well, if you want it to work right.
silverjoel
 
Posts: 51
Joined: Thu Sep 30, 2010 6:46 am

Postby EMR » Sat Nov 13, 2010 8:15 pm

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)...
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Postby Downsider » Sat Nov 13, 2010 8:24 pm

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.
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby mankrip » Sat Nov 13, 2010 9:25 pm

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.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
User avatar
mankrip
 
Posts: 914
Joined: Fri Jul 04, 2008 3:02 am

Postby EMR » Sun Nov 14, 2010 8:11 pm

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)
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Postby Downsider » Sun Nov 14, 2010 8:47 pm

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:
User avatar
Downsider
 
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Postby EMR » Sun Nov 14, 2010 9:53 pm

I'm sorry. Having looked into it more, yeah, you can't mess with the hud with normal QC.
EMR
 
Posts: 13
Joined: Mon Oct 11, 2010 8:08 pm

Postby something » Tue Nov 16, 2010 5:48 am

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.
something
 
Posts: 27
Joined: Tue Apr 20, 2010 2:02 pm
Location: Melbourne,Au


Return to Tutorial Help

Who is online

Users browsing this forum: No registered users and 1 guest