Announcement

Collapse
No announcement yet.

Weapons given to killer

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

    Weapons given to killer

    I am making a game type where I want a pawn that kills another pawn to "inherit" their weapon inventory. So, if I kill another player, I get ALL their weapons. Here is the code I have for this, but it doesn't seem to work:

    Code:
    // Give victims weapons to killer
        for(Inv = Victim.Inventory; Inv != None; Inv = Inv.Inventory)
        {
            if(Weapon(Inv)!= None) 
            {
                Inv.GiveTo(Killer);
            }
        }
    Can anyone tell me what I'm doing wrong here? No weapons are being given to the Killer pawn.

    #2
    I am a total noo, but maybe too many teminates???

    Comment


      #3
      I'm not sure where inventory is destroyed in the chain of someone dying, but you may be trying to look through the victim's inventory too late.

      Comment


        #4
        I am extending the xDeathMatch in this class. Here is the full code I'm using for the kill process:

        Code:
        // Some killing action going on...
        function Killed(Controller Killer, Controller Killed, Pawn KilledPawn, class<DamageType> damageType)
        {
            processKill(Killer.Pawn, Killed.Pawn);
            super.Killed(Killer, Killed, KilledPawn, damageType);
        }
        
        
        // Process a kill 
        function processKill(Pawn Killer, Pawn Victim)
        {
            local Inventory Inv;
        
            // Boost killers properties on kill
            Killer.Health = 199;
            Killer.AddShieldStrength(250);
        
            // Give victims weapons to killer
            for(Inv = Victim.Inventory; Inv != None; Inv = Inv.Inventory)
            {
                if(Weapon(Inv)!= None)
                {
                    Log("----- Relinquishing weapon to: " $ Killer.PlayerReplicationInfo.PlayerName $ "...");
                    if(Inv != None) Inv.GiveTo(Killer);
                }
            }
        
            // Max out ammo on killers weapons
            for(Inv = Killer.Inventory; Inv != None; Inv = Inv.Inventory)
            {
                if(Weapon(Inv)!= None) Weapon(Inv).MaxOutAmmo();
            }
        }
        Shouldn't the victims inventory still be intact at this stage?

        Comment


          #5
          Code:
          function processKill(Pawn Killer, Pawn Victim)
          {
              local Inventory Inv, newWeapon;
          
              // Boost killers properties on kill
              Killer.Health = 199;
              Killer.AddShieldStrength(250);
          
              // Give victims weapons to killer
              for(Inv = Victim.Inventory; Inv != None; Inv = Inv.Inventory)
              {
                  if(Weapon(Inv)!= None)
                  {
                      newWeapon = Spawn(Inv.Class);
                      if (newWeapon != None) {
                            Log("----- Relinquishing weapon "$ Weapon(Inv) $" to: "$ Killer.PlayerReplicationInfo.PlayerName $ "...");
                            newWeapon.GiveTo(Killer);
                            newWeapon.MaxOutAmmo();
          
                      }
                  }
              }
          
              // Max out ammo on killers weapons
              //for(Inv = Killer.Inventory; Inv != None; Inv = Inv.Inventory)
              //{
              //        if (Inv!=None)
              //              if(Weapon(Inv)!= None) Weapon(Inv).MaxOutAmmo();
              //}
          }
          Inventory items once owned by a pawn can only be destroyed,, so you need to spawn a new inventory of the same.


          You could modify this for better gameplay, say like check to see if the killer has the weapon first then take the ammo amount and add it to the killers weapon, instead of maxing out ammo, unless that's what you want.

          Comment


            #6
            Thanks for the tip. It is mostly working now, however, it doesn't work for the gun they are holding at the time of death. I believe this is because the weapons gets thrown/dropped when they die. Is there anyway to disable this to make this work for that gun too?

            Comment


              #7
              Victim.Weapon? Contains the current weapon of the pawn. Perhaps it still exists there.

              Comment


                #8
                I'm still not able to get the victim's current weapon. Could this be happening because the weapon is thrown upon death? How do I disable this?

                Comment


                  #9
                  Sorry, my first post was flawed:
                  Code:
                  function bool PreventDeath(Pawn Killed, Controller Killer, class<DamageType> damageType, vector HitLocation){
                  	local bool PD;
                  	PD=Super.PreventDeath(Killed,Killer,damageType,HitLocation);
                  	if (!PD) processKill(Killer.Pawn,Killed);
                  	return PD;
                  }
                  
                  function processKill(Pawn Killer, Pawn Victim)
                  {
                      local Inventory Inv, newWeapon;
                  
                      // Boost killers properties on kill
                      Killer.Health = 199;
                      Killer.AddShieldStrength(250);
                  
                      // Give victims weapons to killer
                      for(Inv = Victim.Inventory; Inv != None; Inv = Inv.Inventory)
                      {
                          if(Weapon(Inv)!= None)
                          {
                              newWeapon = Spawn(Inv.Class);
                              if (newWeapon != None) {
                                    Log("----- Relinquishing weapon "$ Weapon(Inv) $" to: "$ Killer.PlayerReplicationInfo.PlayerName $ "...");
                                    newWeapon.GiveTo(Killer);
                                    if ( Weapon(newWeapon)!=None ) Weapon(newWeapon).MaxOutAmmo();
                                    //Weapon(Inv).Destroy();
                  
                              }
                          }
                      }
                  }
                  Tested an working.

                  Comment


                    #10
                    Thanks. That worked perfectly. Why does this need to be called from the PreventDeath() method rather than the Killed() method to work? I'll still relatively new to unrealscript, so I'm trying to learn as much as I can.

                    Comment


                      #11
                      You going to release this puupy or what?

                      Comment


                        #12
                        Originally posted by bigbogus
                        Thanks. That worked perfectly. Why does this need to be called from the PreventDeath() method rather than the Killed() method to work? I'll still relatively new to unrealscript, so I'm trying to learn as much as I can.
                        PreventDeath() is called before the victim is killed (so he still holds his weapon), Killed() is called when he's killed (so his weapon has already been tossed).

                        Comment


                          #13
                          Is there an easy way to turn off the weapon tossing in the code? I've been looking through source code, but I can't seem to find this setting anywhere.

                          Comment


                            #14
                            I turned off weapon tossing like this in my mutator class, works fine for me.

                            Code:
                            function PreBeginPlay()
                            {
                               Super.PreBeginPlay();
                            
                               Level.Game.bAllowWeaponThrowing = FALSE;
                            }
                            That stops people from tossing their weapons but they still drop their current weapon when they die.

                            Comment


                              #15
                              I'm tring to prevent them from dropping their current weapon when they die. Is there a setting for that?

                              Comment

                              Working...
                              X