PDA

View Full Version : Replacing one weapon with another on keypress


Zer0Zer0
24th Jun 2004, 04:37 PM
Hey there all, I'm trying to replace the weapon from which this function is from with another weapon, I can't seem to get it to work, when i press my exec key the weapon just dissappears any ideas.

I've tried loads of different combinations of code.

What i'm essentially trying to do is replace the Firemodes but all attempts at doing this directly have failed. So I've decided to replace the weapon with a subclass which has a different firemode.

And yes i've read the multi ammo weapons thing on the wiki over and over.

Anyway any help at all would be great thx!


exec function UpgradeWeapon()
{
//On Keypress performs an upgrade of the weapon
//this one upgrades the secondaryfire of the rifle to
//a minigun standard fire.
local Pawn P;
local Inventory Inv;
//set the owner
P = Pawn(Owner);
//Check adrenaline allows upgrade
if (P.Controller.Adrenaline == 100) {
log("Weapon Upgradable");
// dont let them upgrade if they are firing
if (FireMode[0].bIsFiring || FireMode[1].bIsFiring)
return;
//Stops stuff firing when upgrading
if (Pawn(Owner) != none && Pawn(Owner).Controller != none)
{
Pawn(Owner).Controller.bFire = 0;
Pawn(Owner).Controller.bAltFire = 0;
}
//Find this class
Inv = P.FindInventoryType(class'MutWeaponsUpgrades.WPAssaultRifle');
if (Inv != class'MutWeaponsUpgrades.WPAssaultRifle')
{
log("Broken");
}
else
{
//Check
log("Using Minigun Fire Upgrade");
Inv = Spawn(Class'MutWeaponsUpgrades.UpgradeOne',self);
Inv.GiveTo(P);
//Destroy the weapon
self.Destroy();
}
log("Used Minigun Fire Upgrade");
}
else
{
log("Not Enough Adrenaline");
}
}

Zer0Zer0
24th Jun 2004, 06:45 PM
Inv = P.FindInventoryType(class'MutWeaponsUpgrades.WPAssaultRifle');
if (Inv != class'MutWeaponsUpgrades.WPAssaultRifle')
{
log("Broken");
}


OK I know that this is the problem, the Inv variable is not being set to my weapon class and therefore none of the replacing code is actually being run (or will run).

I can't see any other way to get hold of the weapon and swap it with another one...

This method is like attempt nine hundred and ninety nine!

Anyone?

MKhaos7
24th Jun 2004, 07:47 PM
Ok, first of all you comparation is wrong

if (Inv != class'MutWeaponsUpgrades.WPAssaultRifle')


this will always be false
what you are looking is for this:

if (!Inv.isA('MutWeaponsUpgrades.WPAssaultRifle'))


try this and see if it works

Zer0Zer0
25th Jun 2004, 04:14 AM
if ( Inv.isA('WPAssaultRifle'))
{
//Check
log("AR770-U Using Minigun Fire Upgrade");
//Destroy the weapon
Inv = Spawn(Class'MutWeaponsUpgrades.UpgradeOne',self);
Inv.GiveTo(P);
self.Destroy();
log("AR770-U Used Minigun Fire Upgrade");
}
else
{
log("Broken");
}


Ok heres the new if which recognises the weapon thanks Kaos however now the rifle just disappears, like i've spawned with no weapons.

I know this is due to self.Destroy(); but when i remove that, nothing happens at all, as in the rifle just remains the same.

Is my spawn statement correct or am I missing something?

MKhaos7
25th Jun 2004, 06:37 AM
First of all which class are you expanding from?
Another weapon, that when upgraded will be replaced by the WPAsaault?
If thats so i think you should have the own pawn inventory... like P.Inventory.AddToInventory(ThUpgrade) (dunno if the AddToInventory command exists).
And after that use the same idea to remove youself (the weapon) from the inventory.
After that you have to tell the player to switch to the new weapon you give to him.

Welll... thats all theory, i never worked with inventory :)

Zer0Zer0
25th Jun 2004, 08:00 PM
I'm replacing from a new weapon called WPAssault Rifle, a sub class of Upgradeable (Weapon abstract class). I'm trying to replace it with a subclass of the WPAssaultRifle. So that it is essentially the same weapon but with different firemodes.

I'll give your idea a go tho.

Thanks.