Replace Weapons

Discussions about Coding and Scripting
Post Reply
ASLY

Replace Weapons

Post by ASLY »

So, I want to make my first mutator which replaces the weapons in the map and when I pick up I have 999 ammo
I have a weapon package what I want to replace with the weapons (UT2K4 Weapons)
I try it alone, maybe I can do it but when I taked a look for the scripts only thats what I found

WORMReplacer:

Code: Select all

class WormMutator expands WormyReplacer;

var bool bInitialised;
var int loopA, loopB, loopC;


var string myammostring;
var name myitemname;



function ModifyPlayer(Pawn Other)
{
	local inventory Inv, newInv;
	local Weapon weap;

	GetTheCrapINeed();

	for ( inv=Other.inventory; inv!=None; inv=inv.inventory )
	{
		if (inv.isA('weapon')) weap = Weapon(inv);

		if (weap.isA('enforcer')) weap.destroy();
		if (weap.isA('impacthammer')) weap.destroy();
	}

	GiveWeapon(Other, WeaponString[0]);
	GiveWeapon(Other, WeaponString[1]);

	If (class'WormOtherConfig'.Default.bLastManStanding)
	{
		for (LoopA=2; LoopA<10; LoopA++)	GiveWeapon(Other, WeaponString[LoopA]);

		NewInv = Spawn(class'Armor2');
		if( NewInv != None )
		{
			NewInv.bHeldItem = true;
			NewInv.RespawnTime = 0.0;
			NewInv.GiveTo(Other);
		}

		for ( inv=Other.inventory; inv!=None; inv=inv.inventory )
		{
			weap = Weapon(inv);

			if ( (weap != None) && (weap.AmmoType != None) )
				weap.AmmoType.AmmoAmount = weap.AmmoType.MaxAmmo;

		}
	
	}



	Super.ModifyPlayer(Other);

	if ( NextMutator != None )
		NextMutator.ModifyPlayer(Other);
}

function PreBeginPlay()
{
	if ( bInitialised )
		return;

	GetTheCrapINeed();

	//wormDefaultWeap1 = class<weapon>(DynamicLoadObject(weaponstring[0], class'class'));
	defaultweapon = NONE;  //make default weapon nothing for now.


	bInitialised = TRUE;
}

function GetTheCrapINeed()
{

	for (LoopA=0; LoopA<11; LoopA++) 
	{
		WeaponString[LoopA] = class'WormWeapConfig'.Default.WeaponString[LoopA];
		WeaponName[LoopA] = GetTheName(weaponstring[LoopA]);

		AmmoString[LoopA] = GetTheAmmo(WeaponString[LoopA]);
		AmmoName[LoopA] = GetTheName(AmmoString[LoopA]);
	}

	If (class'WormAmmoConfig'.Default.bManualAmmoOverride)
	{
		for (LoopA=0; LoopA<11; LoopA++) 
		{
			AmmoString[LoopA] = class'WormAmmoConfig'.Default.AmmoString[LoopA];
			AmmoName[LoopA] = GetTheName(AmmoString[LoopA]);
		}
	}
	
	bAmmo1 = class'WormAmmoConfig'.Default.bIncludeAmmo1; 
	bAmmo2 = class'WormAmmoConfig'.Default.bIncludeAmmo2; 
	bAmmo3 = class'WormAmmoConfig'.Default.bIncludeAmmo3; 
	bAmmo4 = class'WormAmmoConfig'.Default.bIncludeAmmo4; 
	bAmmo5 = class'WormAmmoConfig'.Default.bIncludeAmmo5; 
	bAmmo6 = class'WormAmmoConfig'.Default.bIncludeAmmo6; 
	bAmmo7 = class'WormAmmoConfig'.Default.bIncludeAmmo7; 
	bAmmo8 = class'WormAmmoConfig'.Default.bIncludeAmmo8; 
	bAmmo9 = class'WormAmmoConfig'.Default.bIncludeAmmo9; 

	for (LoopA=0; LoopA<9; LoopA++)
	{
		PickupString[LoopA] = class'WormPickupConfig'.Default.PickupString[LoopA];
		PickupName[LoopA] = GetTheName(PickupString[LoopA]);
	}

}

function string GetTheAmmo( string myweaponstring )
{
	local class<weapon> myweaponclass;

	myweaponclass = class<weapon>(DynamicLoadObject(myweaponstring, class'class'));

	//Specific Support for the strangelove 2, so it spawns fuel cores rather than invisible rockets.
	if(myweaponstring ~= "slv2.konglauncher") return("slv2.fuelcore");

	myammostring = string(myweaponclass.default.ammoname);
	return(myammostring);
}

function name GetTheName( string myitemstring )
{
	local class<inventory> myitemclass;

	myitemclass = class<inventory>(DynamicLoadObject(myitemstring, class'class'));
	myitemname = myitemclass.name;

	return(myitemname);
}


function GiveWeapon(Pawn PlayerPawn, string aClassName )
{
	local class<Weapon> WeaponClass;
	local Weapon NewWeapon;

	WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));

	if( PlayerPawn.FindInventoryType(WeaponClass) != None )
		return;
	newWeapon = Spawn(WeaponClass);
	if( newWeapon != None )
	{

	//	If (newWeapon.AmmoName != NONE)
	//	{
			newWeapon.RespawnTime = 0.0;
			newWeapon.GiveTo(PlayerPawn);
			newWeapon.bHeldItem = true;
			newWeapon.GiveAmmo(PlayerPawn);
			newWeapon.SetSwitchPriority(PlayerPawn);
			newWeapon.WeaponSet(PlayerPawn);
			newWeapon.AmbientGlow = 0;
			if ( PlayerPawn.IsA('PlayerPawn') )
				newWeapon.SetHand(PlayerPawn(PlayerPawn).Handedness);
			else
				newWeapon.GotoState('Idle');
			PlayerPawn.Weapon.GotoState('DownWeapon');
			PlayerPawn.PendingWeapon = None;
			PlayerPawn.Weapon = newWeapon;
	/*	}
		Else
		{
			newWeapon.Instigator = PlayerPawn;
			newWeapon.BecomeItem();
			PlayerPawn.AddInventory(newWeapon);
			newWeapon.GiveAmmo(PlayerPawn);
			newWeapon.SetSwitchPriority(PlayerPawn);
			newWeapon.WeaponSet(PlayerPawn);
		}
	*/
	}
}
Im trying to search the line where I can replace to myweapons

999 Ammo:

Code: Select all

class UnlimitedAmmo expands Mutator;

var bool Initialized;

var(UnlimitedAmmo) globalconfig bool RedeemerUnlimited;

event PreBeginPlay()
{
	Super.PreBeginPlay();

	if (Initialized)
		return;
	Initialized = true;

	Spawn(class'UnlimitedAmmoSpawnNotify', self);
	SetTimer(Level.TimeDilation, true);
}


function Timer()
{
	// Top it up every second

	local Ammo A;
	ForEach AllActors(class'Ammo', A)
	{
		if (!RedeemerUnlimited && A.IsA('WarheadAmmo'))
			continue;
		A.AmmoAmount = 999;
		A.MaxAmmo = 999;
	}
}
It's possible to combined this to script?
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Replace Weapons

Post by Feralidragon »

Put:

Code: Select all

var(UnlimitedAmmo) globalconfig bool RedeemerUnlimited;
After:

Code: Select all

var bool bInitialised;
var int loopA, loopB, loopC;


var string myammostring;
var name myitemname;
Put:

Code: Select all

   SetTimer(Level.TimeDilation, true);
After the bInitialised = TRUE; line in:

Code: Select all

function PreBeginPlay()
{
   if ( bInitialised )
      return;

   GetTheCrapINeed();

   //wormDefaultWeap1 = class<weapon>(DynamicLoadObject(weaponstring[0], class'class'));
   defaultweapon = NONE;  //make default weapon nothing for now.


   bInitialised = TRUE;
}
Lastly put:

Code: Select all

function Timer()
{
   // Top it up every second

   local Ammo A;
   ForEach AllActors(class'Ammo', A)
   {
      if (!RedeemerUnlimited && A.IsA('WarheadAmmo'))
         continue;
      A.AmmoAmount = 999;
      A.MaxAmmo = 999;
   }
}
anywhere in the WORM code, it doesn't matter much where (it could be at the end).

The whole thing is a bit messy, but should work.
ASLY

Re: Replace Weapons

Post by ASLY »

Thanks for help Ferali but wait!
This is the pack what I want to use: http://www.2shared.com/file/_uU35M8T/Uweaponway2k4.html
So I think it's not that script what I mean :oops:
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Replace Weapons

Post by MrLoathsome »

Not sure if this is exactly what you are looking for, but I have been using this for several years on my DM/CTF server to replace a few of the default
UT weapons with some custom ones.

It replaces the PulseRifle with a Cherrybomb gun, replaces reg shockrifles with the zoom-instagib shock, and sniper rifles with the zark assault sniper gun.

You could easily change the class names I have hardcoded in there for those, to whatever weapons you wanted to use.
This does not make any changes to the default ammo amounts for the weapons, but I think you could add that right after
the "ReplaceWith" lines.

This thing is about as simple as a mutator can get. I named it FF.F just to keep the class name short, and was pretty sure that would not
conflict with anything. (Runs server side only, so no need for redirect or inclusion in server packages section etc. )

Here is the complete source, ready to tweak and compile:

Code: Select all

class F expands Mutator;

function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
{
	bSuperRelevant = 0;

	if ( Other.IsA('Weapon') )
	{
		if (Other.IsA('PulseGun') && !Other.IsA('CherryBomb'))
		{
			ReplaceWith(Other, "CherryBomb.CherryBomb");
			return False;
		}
		if (Other.IsA('ShockRifle') && !Other.IsA('ZoomShockRifle'))
		{
			ReplaceWith(Other, "ZoomShockRifle.ZoomShockRifle");
			return False;
		}
		if (Other.IsA('SniperRifle') && !Other.IsA('AssaultRifle'))
		{
			ReplaceWith(Other, "ZarkAssaultRifle.AssaultRifle");
			return False;
		}
	}
	return True;
}

defaultproperties
{
}
blarg
Post Reply