Announcement

Collapse
No announcement yet.

Making a new weapon randomly replace an old weapon pickup?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making a new weapon randomly replace an old weapon pickup?

    I've been going over a bunc of QC info and tutorials, but I can't seem to find what I'm looking for.

    I'm putting together a new weapon that I don't wan't to replace any of the old ones. But I want it to have about a 25%-35% chance of replacing the normal double shotgun weapon pick up on maps. That way it can be used in old maps.

    Thanks for any help.

  • #2
    open items.qc :
    Code:
    void() weapon_supershotgun =
    {
    	precache_model ("progs/g_shot.mdl");
    	precache_model ("progs/yourweapon_g_model.mdl");// your custom model
    
    if (random() <= 0.35) // 35%
    	{
            setmodel (self, "progs/yourweapon_g_model.mdl");
            self.classname = "your_weapon"
    	self.weapon = IT_YOURGUN;
    	self.netname = "your_weapon_gun";
    	self.touch = weapon_touch;
    	setsize (self, '-16 -16 0', '16 16 56');
    	StartItem ();
            return;
    	}
            
            setmodel (self, "progs/g_shot.mdl");
    	self.weapon = IT_SUPER_SHOTGUN;
    	self.netname = "Double-barrelled Shotgun";
    	self.touch = weapon_touch;
    	setsize (self, '-16 -16 0', '16 16 56');
    	StartItem ();
    
    
    };
    the invasion has begun! hide your children, grab the guns, and pack sandwiches.

    syluxman2803

    Comment


    • #3
      @nahuel.
      That's really interesting for a coding dummy like myself.

      What would the code look like if you wanted all the weapons to randomly cycle?
      (Leaving out the custom weapon requirement).
      For example, if I did a map and placed ten DB Shotguns but wanted them to spawn randomly as any of the original weapons.

      Also, is this piece of code a direct replacement or an addition in the items.qc?

      Thanks for the insight.
      Username : Atomic Robokid on Steam

      Please check out my Quake made things:

      https://www.indiedb.com/games/run-over
      https://adam-freeman.itch.io/hazard
      https://adam-freeman.itch.io/diver
      https://adam-freeman.itch.io/beyond

      Comment


      • #4
        you need to change all the weapon_ functions to call a newone called "weapon random"

        Code:
        void() weapon_random =
        {
        local float rand;
        rand = random();
        
        
              if (rand < 0.166)
               { 
              precache_model ("progs/g_shot.mdl");        
              setmodel (self, "progs/g_shot.mdl");
        	self.weapon = IT_SUPER_SHOTGUN;
        	self.classname = "weapon_supershotgun";
        	self.netname = "Double-barrelled Shotgun";
               }
              if ( (rand < 0.333) && (rand >= 0.166) )
               {
        	precache_model ("progs/g_nail.mdl");
        	setmodel (self, "progs/g_nail.mdl");
        	self.weapon = IT_NAILGUN;
        	self.classname = "weapon_nailgun";
        	self.netname = "nailgun";
               }
              if ( (rand < 0.5) && (rand >= 0.333) )
               {
        	precache_model ("progs/g_nail2.mdl");
        	setmodel (self, "progs/g_nail2.mdl");
        	self.weapon = IT_SUPER_NAILGUN;
        	self.classname = "weapon_supernailgun";
        	self.netname = "Super Nailgun";
               }
              if ( (rand < 0.666) && (rand >= 0.5) )
               {
        	precache_model ("progs/g_rock.mdl");
        	setmodel (self, "progs/g_rock.mdl");
        	self.weapon = 3;
        	self.classname = "weapon_grenadelauncher";
        	self.netname = "Grenade Launcher";
               }
              if ( (rand < 0.833) && (rand >= 0.666) )
               {
            	precache_model ("progs/g_rock2.mdl");
        	setmodel (self, "progs/g_rock2.mdl");
        	self.weapon = 3;
        	self.classname = "weapon_rocketlauncher";
        	self.netname = "Rocket Launcher";
               }
              if (rand >= 0.8333) 
               {
        	precache_model ("progs/g_light.mdl");
        	setmodel (self, "progs/g_light.mdl");
        	self.weapon = 3;
        	self.classname = "weapon_lightning";
        	self.netname = "Thunderbolt";
               }
        	self.touch = weapon_touch;
        	setsize (self, '-16 -16 0', '16 16 56');
        	StartItem ();
        
        };
        
        void() weapon_supershotgun =
        {
        self.nextthink = time + random() * 0.3; // ugly stuff but wroks more "random"
        self.think = weapon_random;
        };
        
        /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
        */
        
        void() weapon_nailgun =
        {
        	self.think = weapon_random;
        self.nextthink = time + random() * 0.3;
        
        
        };
        
        /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
        */
        
        void() weapon_supernailgun =
        {
        	self.think = weapon_random;
        self.nextthink = time + random() * 0.3;
        
        
        };
        
        /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
        */
        
        void() weapon_grenadelauncher =
        {
        		self.think = weapon_random;
        self.nextthink = time + random() * 0.3;
        
        };
        
        /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
        */
        
        void() weapon_rocketlauncher =
        {
        	self.think = weapon_random;
        self.nextthink = time + random() * 0.3;
        
        };
        
        
        /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
        */
        
        void() weapon_lightning =
        {
        		self.think = weapon_random;
        self.nextthink = time + random() * 0.3;
        
        };
        the invasion has begun! hide your children, grab the guns, and pack sandwiches.

        syluxman2803

        Comment


        • #5
          Wow.



          Really awesome.

          Thanks for that.
          Username : Atomic Robokid on Steam

          Please check out my Quake made things:

          https://www.indiedb.com/games/run-over
          https://adam-freeman.itch.io/hazard
          https://adam-freeman.itch.io/diver
          https://adam-freeman.itch.io/beyond

          Comment


          • #6
            did you know that .flags & FL_ITEM will make the size about 15% wider on each side so it can more easily be picked up?

            Comment


            • #7
              What would the code look like if you wanted all the weapons to randomly cycle?
              Unless you are only calling weapon_random ONCE when the map loads., i dont think you can have those precache functions in there.

              If you want weapons to randomly respawn you need to move the precaches out and set the think to weapon_random in SUB_regen...
              Last edited by R00k; 08-06-2014, 01:43 AM.
              www.quakeone.com/qrack | www.quakeone.com/cax| http://en.twitch.tv/sputnikutah

              Comment


              • #8
                Thanks Nahuel.

                Comment


                • #9
                  Ok, I ran into a hiccup. I finally got around to implementing your code and it did replace the ground model. But it didn't actually give the player the weapon. It still just gave the regular ssg. Did I miss a line somewhere? Is it cause I already have the new weapon defined after the ssg?

                  Comment


                  • #10
                    Can we see the code you put in please? Remember you'll need to define it in weapon_touch function as well if you haven't done so.

                    EDIT: When I say it I mean your new weapon. LOL
                    Last edited by PrimalLove; 08-18-2014, 11:28 PM.

                    Comment


                    • #11
                      This is the code I have:

                      Code:
                      =============
                      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 + 60;
                      	}
                      	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 + 120;
                      	}
                      	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;
                      	}
                      	[COLOR="DarkOrange"]else if (self.classname == "weapon_riotshotgun")
                      	{
                      		if (leave && (other.items & IT_RSHOT) )
                      			return;
                      		hadammo = other.ammo_rockets;			
                      		new = IT_RSHOT;
                      		other.ammo_shells = other.ammo_shells + 10;[/COLOR]
                      	}
                      	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
                      };
                      
                      
                      /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
                      */
                      
                      void() weapon_supershotgun =
                      {
                      	precache_model ("progs/g_shot.mdl");
                      [COLOR="DarkOrange"]	precache_model ("progs/g_rshot.mdl");
                      	
                      if (random() <= 0.30)
                      	{
                      	setmodel (self, "progs/g_rshot.mdl");
                      	self.weapon = IT_RSHOT;
                      	self.netname = "Riot Controller";
                      	self.touch = weapon_touch;
                      	setsize (self, '-16 -16 0', '16 16 56');
                      	StartItem ();
                      	return;
                      	}[/COLOR]
                      	
                      	setmodel (self, "progs/g_shot.mdl");
                      	self.weapon = IT_SUPER_SHOTGUN;
                      	self.netname = "Double-barrelled Shotgun";
                      	self.touch = weapon_touch;
                      	setsize (self, '-16 -16 0', '16 16 56');
                      	StartItem ();
                      };
                      
                      [COLOR="DarkOrange"]/*QUAKED weapon_riotshotgun (0 .5 .8) (-16 -16 0) (16 16 32)
                      */
                      
                      void() weapon_riotshotgun =
                      {
                      	precache_model ("progs/g_rshot.mdl");
                      	setmodel (self, "progs/g_rshot.mdl");
                      	self.weapon = IT_RSHOT;
                      	self.netname = "Riot Controller";
                      	self.touch = weapon_touch;
                      	setsize (self, '-16 -16 0', '16 16 56');
                      	StartItem ();
                      };[/COLOR]
                      I thought that the weapon_touch covered picking up the gun?

                      Comment


                      • #12
                        @Legend

                        Take a closer look at nahuel's example.

                        Code:
                        void() weapon_supershotgun =
                        {
                        	precache_model ("progs/g_shot.mdl");
                        	precache_model ("progs/yourweapon_g_model.mdl");// your custom model
                        
                        if (random() <= 0.35) // 35%
                        	{
                                setmodel (self, "progs/yourweapon_g_model.mdl");
                                self.classname = "your_weapon"
                        	self.weapon = IT_YOURGUN;
                        	self.netname = "your_weapon_gun";
                        	self.touch = weapon_touch;
                        	setsize (self, '-16 -16 0', '16 16 56');
                        	StartItem ();
                                return;
                        	}
                                
                                setmodel (self, "progs/g_shot.mdl");
                        	self.weapon = IT_SUPER_SHOTGUN;
                        	self.netname = "Double-barrelled Shotgun";
                        	self.touch = weapon_touch;
                        	setsize (self, '-16 -16 0', '16 16 56');
                        	StartItem ();
                        
                        
                        };

                        You'll notice this code:

                        Code:
                          self.classname = "your_weapon"
                        You likely didn't add that to your code. The rest of the weapons will not require this. Why? They are already defined by the map with the classname so it doesn't need it. But any new weapons not placed on a map will need the classname included. So for example.

                        Code:
                        void() weapon_supershotgun =
                        {
                        	precache_model ("progs/g_shot.mdl");
                        	precache_model ("progs/g_rshot.mdl");
                        	
                        	if (random() <= 0.75) // 75%
                        	{
                            setmodel (self, "progs/g_rshot.mdl");
                            self.classname = "weapon_riotshotgun"; //THIS IS IT :) 
                        	self.weapon = IT_RSHOT;
                        	self.netname = "Riot Controller";
                        	self.touch = weapon_touch;
                        	setsize (self, '-16 -16 0', '16 16 56');
                        	StartItem ();
                                return;
                        	}
                                
                                setmodel (self, "progs/g_shot.mdl");
                        	self.weapon = IT_SUPER_SHOTGUN;
                        	self.netname = "Double-barrelled Shotgun";
                        	self.touch = weapon_touch;
                        	setsize (self, '-16 -16 0', '16 16 56');
                        	StartItem ();

                        You can see I added the classname to your new weapon. I used 75% as a test so it happened more often. You can change it to whatever you like. But without that classname it will default to the classname in the map which is the double barreled shotgun and not your riotgun. This is happening because you are using the weapon_touch function which identifies using classnames. If you use above code it will work fine. Check syntax and ask questions if you don't know what something is used for. Nahuel did use classname in his example but he assumed you'd understand the significance of defining it. Now you know. I just put this into the code you sent me and compiled. Worked fine.
                        Last edited by PrimalLove; 08-19-2014, 05:17 AM.

                        Comment


                        • #13
                          Bump

                          Comment

                          Working...
                          X