I want to achieve a few things:
1. Given a new instance of a weapon that has been spawned, give it to a pawn. I have tried
Code: Select all
Weapon.GiveTo(Pawn P)
2. Given a pawn, and a weapon class, remove it from the given Pawn, and select a new weapon.
I currently do this:
Code: Select all
Pawn.DeleteInventory(wep);//but this also only takes an instance, currently I find an instance using Pawn.FindInventoryType(wep.Class) and pass to this
Pawn.SwitchToBestWeapon();
Code: Select all
//I used help from: https://beyondunrealwiki.github.io/pages/how-ut-weapons-work-switchi.html
local Weapon existing;
Pawn.DeleteInventory(wep);//but this also only takes an instance
Pawn.SwitchToBestWeapon();
//below copied from Pawn.ChangedWeapon with minor changes inspired from PlayerPawn.SwitchWeapon, and DeathMatchPlus.GiveWeapon
if((p == None) || (wep == None)){
return;
}
existing = Weapon(p.FindInventoryType(wep.Class));
if(existing == None){
wep.GiveTo(p);
}
p.PendingWeapon = wep;
//if we are switching to the currently equipped weapon, then cancel the switch
if(p.PendingWeapon == p.Weapon){
p.PendingWeapon = None;
}
//if we cancelled the switch, or we are switching to nothing, then just return
if(p.PendingWeapon == None){
return;
}
//we know past this point that we arent switching to the same weapon as we have selected
if(p.Weapon != None){
p.Weapon.PutDown();
p.Weapon.SetDefaultDisplayProperties();
}
p.PlayWeaponSwitch(p.PendingWeapon);
if((p.PendingWeapon != None) && (p.PendingWeapon.Mass > 20) && (p.carriedDecoration != None)){
p.DropDecoration();
}
p.Weapon = p.PendingWeapon;
p.Inventory.ChangedWeapon(); // tell inventory that weapon changed (in case any effect was being applied)
p.Weapon.RaiseUp(p.Weapon);
if ((p.Level.Game != None) && (p.Level.Game.Difficulty > 1)){
p.MakeNoise(0.1 * p.Level.Game.Difficulty);
}
p.PendingWeapon = None;
What's the best way? My ultimate goal is to "swap" weapons of 2 given pawns, and any that have a "none" weapon, will equip the best weapon they can (eg:
Code: Select all
Pawn.SwitchToBestWeapon()
Ideas?