one gun

Discuss programming in the QuakeC language.
Post Reply
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

one gun

Post by franqutrass »

hello I wanted to ask how can I make in "quake 1" can only carry a weapon (apart from axe and the first shotgun).
I want that code because I already got a code to power the gun vote,
good I want is to be like "Counter Strike" in which only one can carry a weapon other than your knife and your gun.

thanks
hello
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

I suppose you could remove the other guns on the pickup of a new gun, if you want to do it the quick and dirty way:

I'm no QuakeC genius but here goes my attempt:

You have weapon_touch which is the function which is triggered when a weapon item is picked up:

Code: Select all

/*
=============
weapon_touch
=============
*/
float() W_BestWeapon;

void() weapon_touch =
{
   local   float   hadammo, best, new, old;
   local   entity   stemp;
   local   float   leave;

   if (!(other.flags & FL_CLIENT))
      return;

// if the player was using his best weapon, change up to the new one if better      
   stemp = self;
   self = other;
   best = W_BestWeapon();
   self = stemp;

   if (deathmatch == 2 || coop)
      leave = 1;
   else
      leave = 0;
   
   if (self.classname == "weapon_nailgun")
   {
      if (leave && (other.items & IT_NAILGUN) )
         return;
      hadammo = other.ammo_nails;         
      new = IT_NAILGUN;
      other.ammo_nails = other.ammo_nails + 30;
   }
   else if (self.classname == "weapon_supernailgun")
   {
      if (leave && (other.items & IT_SUPER_NAILGUN) )
         return;
      hadammo = other.ammo_rockets;         
      new = IT_SUPER_NAILGUN;
      other.ammo_nails = other.ammo_nails + 30;
   }
   else if (self.classname == "weapon_supershotgun")
   {
      if (leave && (other.items & IT_SUPER_SHOTGUN) )
         return;
      hadammo = other.ammo_rockets;         
      new = IT_SUPER_SHOTGUN;
      other.ammo_shells = other.ammo_shells + 5;
   }
   else if (self.classname == "weapon_rocketlauncher")
   {
      if (leave && (other.items & IT_ROCKET_LAUNCHER) )
         return;
      hadammo = other.ammo_rockets;         
      new = IT_ROCKET_LAUNCHER;
      other.ammo_rockets = other.ammo_rockets + 5;
   }
   else if (self.classname == "weapon_grenadelauncher")
   {
      if (leave && (other.items & IT_GRENADE_LAUNCHER) )
         return;
      hadammo = other.ammo_rockets;         
      new = IT_GRENADE_LAUNCHER;
      other.ammo_rockets = other.ammo_rockets + 5;
   }
   else if (self.classname == "weapon_lightning")
   {
      if (leave && (other.items & IT_LIGHTNING) )
         return;
      hadammo = other.ammo_rockets;         
      new = IT_LIGHTNING;
      other.ammo_cells = other.ammo_cells + 15;
   }
   else
      objerror ("weapon_touch: unknown classname");

   sprint (other, "You got the ");
   sprint (other, self.netname);
   sprint (other, "\n");
// weapon touch sound
   sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
   stuffcmd (other, "bf\n");

   bound_other_ammo ();

// change to the weapon
   old = other.items;
   other.items = other.items | new;
   
   stemp = self;
   self = other;

   if (!deathmatch)
      self.weapon = new;
   else
      Deathmatch_Weapon (old, new);

   W_SetCurrentAmmo();

   self = stemp;

   if (leave)
      return;

// remove it in single player, or setup for respawning in deathmatch
   self.model = string_null;
   self.solid = SOLID_NOT;
   if (deathmatch == 1)
      self.nextthink = time + 30;
   self.think = SUB_regen;
   
   activator = other;
   SUB_UseTargets();            // fire all targets / killtargets
};
So in the weapon touch function, make it only give you axe plus the new weapon by making the following modification:
// change to the weapon
// old = other.items; // Baker: comment this line out, they are losing old weapons
// other.items = other.items | new; // Baker: Nope, lose this too
other.items = IT_AXE | IT_SHOTGUN | new; // Baker: you get the axe/shotgun plus what you picked up, losing other weapons
stemp = self;
self = other;

if (!deathmatch) // Baker: comment me out
self.weapon = new;
else // Baker: comment me out
Deathmatch_Weapon (old, new); // Baker: comment me out

W_SetCurrentAmmo();
Should work in theory. I'm not Mr. QuakeC.
Last edited by Baker on Sat Jan 23, 2010 5:30 am, edited 3 times in total.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

if you have a buy menu, just comment out the pickup code, or delete everything in the function and put return;
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

This can be done. I did something much more complex in Conquest (player has 5 slots that can hold any weapon), but you're looking for something much simpler.

Basically, you want to make it so that if the player picks up a weapon, it removes all other weapons from his inventory other than the shotgun & axe. Perhaps it drops the removed weapon on the ground. Using an impulse/alias (bound to mouse2) to swap weapons would be a good idea (instead of doing it on touch only).

In the weapon selection and fire methods, impulse 3 and weapon #3 should check which weapon the player has besides the shotgun/nailgun. It would be handy to store this in a .float, such as .float weapon3;.

Anyway, I have a mod that is much simpler than Conquest, but that does something similar to what you want. It's still the system of being able to store any weapon in any weapon slot, but it should give you a good base to work with. The mod is called Monster Swarm, and I haven't worked on it in some time and never released it.

Basically, monsters spawn randomly throughout the map similar to UT's Invasion mode. The player can run around collecting guns and gunning down the monsters, and he chooses which 5 weapons he carries. Holding down the shift key while looking at a weapon and pressing a weapon number will swap weapons.

So I could swap my shotgun for a super nailgun by looking at the super nailgun, holding shift, and pressing #2. I should probably move the key binding to the mouse2 button or something, since shift is a little awkward. ;)

If someone can point me to a decent upload site that won't fill my poor compy with innumerable worms & viruses, I'd be happy to upload it for your benefit. I'm not sure if it will be useful to you (you only want the 3rd weapon to be switchable), but it may help.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post by Baker »

Wazat wrote:If someone can point me to a decent upload site that won't fill my poor compy with innumerable worms & viruses, I'd be happy to upload it for your benefit. I'm not sure if it will be useful to you (you only want the 3rd weapon to be switchable), but it may help.

www.quaketastic.com password = ilovetheshubhub
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
lth
Posts: 144
Joined: Thu Nov 11, 2004 1:15 pm

Post by lth »

The tidy way to do it, IMO, would be to add a .entity field onto the player called "weapon_item", and store a reference to the currently-held weapon in that. That's how both THE HORROR and MechInf (part-finished) work. I've put the source to MechInf here:
http://www.random-productions.co.uk/quake/mechinf.zip for the curious.
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

Post by franqutrass »

thanks :o :o
hello
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

The mod is uploaded:

Download Monster Swarm

Hopefully this is handy to someone. I lost track of it some time ago and I really should pick it up again.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

Post by franqutrass »

oh is a good mod and have bugs
hello
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

Post by franqutrass »

but a good mod
hello
franqutrass
Posts: 69
Joined: Wed Dec 30, 2009 6:29 pm
Location: peru
Contact:

Post by franqutrass »

but I'll take the Baker
hello
Post Reply