Wikis / Unreal Wiki / Legacy:Vehicle Weapon Changer Gun

sample Submitted by {DDG}Vaptor vehicle weapon changer gun

Note: this works and its from what im working on

</span><div class="hidden">//=============================================================================
// new allows to change the vehicle weapons
//=============================================================================
class mechGun extends xwoeweapone;
 
//Returns a sentinel belonging to the player, or a sentinel belonging to the same team if !bOnlyOwn, or any Sentinel if bAny.
var bot BodgedBot;
var int NextCheckTime, UpgradeCheckTime;
var vector MarkerLocations[5];
var int currentdefmode;
var bool bAllowUpgrades, bAllowTeamUpgrades,bdeploycars;
var array< class<onsWeapon> > driverUpgradeClasses;
var array< class<onsWeaponPawn> > PassengerUpgradeClasses;
var array<string> Descriptions;
var() xEmitter  chargeEmitter;
var Mutsentaddon myMut;
var name upgradebone;
var float upgraderange, repammo, nextgain;
var class<onsvehicle> upgradeVehicle;
var onsvehicle oldvehicle;
var() array< class<onsvehicle> > configvehiclelist;
var onsvehicle myVehicle;
//==============dynamic list for geting all weapons loaded on server======
var array< class<onsweapon> > vehadded;
var config array< class<onsweapon> > ConfigweaponList;
var array< class<onsweaponpawn> > weaponpawnList;
var array< class<onsweaponpawn> > ConfigweaponpawnList;
	Struct AmmoDivider
	{
	var() int FHP;
	var() int FSPd;
	Var() int fmass;
	};
Var Ammodivider mydiv;
 
replication
{
    reliable if (bNetOwner && bNetDirty && Role == ROLE_Authority)
	mydiv;
 
	reliable if(Role == ROLE_Authority)
		oldvehicle,AddToUpgradeList,bAllowUpgrades,bAllowTeamUpgrades,vehadded,configvehiclelist,bdeploycars;
 
	unreliable if(Role == ROLE_Authority)
		MarkerLocations,repammo,nextgain;
 
	reliable if(Role < ROLE_Authority)
		killscan, DoUpgrade, driverUpgradeClasses, myVehicle, Checkupgrades,deploycar;
 
}
 
simulated function PreBeginPlay()
{
        SetTimer(1.0,true);
 
	Super.PreBeginPlay();
 
	NextCheckTime = Level.TimeSeconds + 1;
	UpgradeCheckTime = NextCheckTime;
}
function PostBeginPlay()
{
local int ic;
 
	Super.PostBeginPlay();
 
	if (myMut == None)
	{
	mymut=class'mutSentaddon'.static.GetsentMutator(Level.Game);
	}
 
	if (myMut != None)
	{
		if(mymut.vehAdded.length > vehadded.length)
		{
        		if(vehadded.length < mymut.vehAdded.length)
         		{ // reinforce data from client side
        		 vehadded.insert(0,mymut.vehadded.length);
        			}
				for(ic = 0; ic < mymut.vehAdded.Length; ic++)
				{
            		vehadded[ic]=mymut.Vehadded[ic];
            		}
 
        	}
        	else
        	{
        	log("mutator preset parts");
        	}
 
		if(mymut.bdeploycars || bdeploycars)
		{
			bdeploycars=true;
 
			if(configvehiclelist.length < mymut.configvehiclelist.length)
         	{ // reinforce data from client side
        		 configvehiclelist.insert(0,mymut.configvehiclelist.length);
 
				for(ic = 0; ic < mymut.configvehiclelist.Length; ic++)
				{
            			configvehiclelist[ic]=mymut.configvehiclelist[ic];
 
				}
 
			}
 
		}
	}
	else
	{
    log("vehicle gun error no parts");
	}
 
	if((Role < ROLE_Authority) && (vehAdded.length > 0))
		LoadUpgrades();
 
}
 
function Checkupgrades()
{
local int ic;
 
if (myMut == None)
{
mymut=class'mutSentaddon'.static.GetsentMutator(Level.Game);
}
 
	if (myMut != None)
	{
	 if(mymut.vehAdded.length > vehadded.length)
	 {
        	 if(vehadded.length < mymut.vehAdded.length)
         	 { // reinforce data from client side
          	 vehadded.insert(0,mymut.vehadded.length);
        	 }
		for(ic = 0; ic < mymut.vehAdded.Length; ic++)
		{
        	vehadded[ic]=mymut.Vehadded[ic];
        	}
	 }
	if(mymut.bdeploycars || bdeploycars)
	{
	bdeploycars=true;
	}
			if(configvehiclelist.length < mymut.configvehiclelist.length)
         		{ // reinforce data from client side
        		 configvehiclelist.insert(0,mymut.configvehiclelist.length);
 
				for(ic = 0; ic < mymut.configvehiclelist.Length; ic++)
				{
            			configvehiclelist[ic]=mymut.configvehiclelist[ic];
				}
			}
 
	else
	{
   	log("vehicle gun error no parts");
	}
 
 }
}
function GiveTo(Pawn Other, optional Pickup Pickup)
{
	Super.GiveTo(Other, Pickup);
 
	if(Role == ROLE_Authority && Instigator != None && Instigator.Controller.IsA('Bot'))
	{
		NextCheckTime = Level.TimeSeconds + 5; //Never deploy right away.
		BodgedBot = Bot(Instigator.Controller);
	}
}
simulated function onsvehicle SentinelInRange(float Range, bool bOnlyOwn, optional bool bAny)
{
	local Vector HitLocation, HitNormal;
	local Actor A;
	local Vector X, Y, Z;
 
	local bool bSameTeam;
 
	GetViewAxes(X, Y, Z);
	foreach TraceActors(class'Actor', A, HitLocation, HitNormal, Instigator.Location + X * Range, Instigator.Location)
	{
		if(A == None)
			continue;
 
		if(A.bWorldGeometry)
			return None;
 
		if(A.IsA('onsvehicle'))
		{
			return onsvehicle(A);
		}
	}
 
	return None;
}
 
simulated function bool HasAmmo()
{
	return true;
}
//Make bots really want this.
//Bots should never try to wield the weapon.
function float GetAIRating()
{
	return 0;
}
// by vaptor we destroy the old car and eject the peeps so they don't die
// then we register a new old vehicle with the server
//Simulated Function RegisterOwner(Onsvehicle newvehicle)
//{
//}
//================ ok this is the hard part =========== works 100%
simulated function setupdriverweapon(onsvehicle upgradervehicle, class<onsweapon> newWeapon ,int i)
{
local name xb; // bone
local bool bkilled;
 
bkilled=false;
 
	if(upgradervehicle.Weapons[i] == none && !bkilled)
	{
	Instigator.ReceiveLocalizedMessage(class'HELMessage', 8);
	return; // prevents it from applying to non existant slots
	}
	if(upgradervehicle.Weapons[i] != none && !bkilled)
	{
	upgradervehicle.Weapons[i].destroy();
	bkilled=true;
	}
	// means there was a weapon that we destroyed
	if(bkilled)
	{
	XB=upgradervehicle.Default.DriverWeapons[i].WeaponBone;
            // Spawn the new Weapon
            upgradervehicle.Weapons[i] = upgradervehicle.spawn(newweapon, upgradervehicle,, upgradervehicle.Location, rot(0,0,0));
            upgradervehicle.AttachToBone(upgradervehicle.Weapons[i], XB);
        if (!upgradervehicle.Weapons[i].bAimable)
                upgradervehicle.Weapons[i].CurrentAim = rot(0,32768,0);
        }
 
    	if (upgradervehicle.ActiveWeapon < upgradervehicle.Weapons.length)
    	{
            upgradervehicle.PitchUpLimit = upgradervehicle.Weapons[upgradervehicle.ActiveWeapon].PitchUpLimit;
            upgradervehicle.PitchDownLimit = upgradervehicle.Weapons[upgradervehicle.ActiveWeapon].PitchDownLimit;
    	}
	upgradervehicle.Weapons[i].team=Instigator.getTeamnum();
	upgradervehicle.SetTeamNum(Instigator.getTeamnum());
	upgradervehicle.TeamChanged();
}
//============== ok driver weapon setup is ready now this part gets messy ========
simulated function setuppasweapon(onsvehicle upgradervehicle, class<onsweapon> newpaswep, int i)
{
local bool bkilled;
 
bkilled=false;
 
	if(upgradervehicle.WeaponPawns[i] == none && !bkilled)
	{
	Instigator.ReceiveLocalizedMessage(class'HELMessage', 8);
	return; // prevents it from applying to non existant slots
	}
	if(upgradervehicle.WeaponPawns[i].gun != none && !bkilled)
	{
	upgradervehicle.WeaponPawns[i].gun.destroy();
	bkilled=true;
	}
        // Spawn the Passenger Weapons
            // Spawn WeaponPawn
	if(bkilled)
	{
            upgradervehicle.WeaponPawns[i].gun = upgradervehicle.WeaponPawns[i].spawn(newpaswep,upgradervehicle.WeaponPawns[i],,upgradervehicle.WeaponPawns[i].Location);
            upgradervehicle.WeaponPawns[i].AttachToVehicle(upgradervehicle,upgradervehicle.PassengerWeapons[i].WeaponBone);
            upgradervehicle.WeaponPawns[i].ObjectiveGetOutDist = upgradervehicle.ObjectiveGetOutDist;
	}
	upgradervehicle.WeaponPawns[i].gun.team=Instigator.getTeamnum();
	upgradervehicle.SetTeamNum(Instigator.getTeamnum());
	upgradervehicle.TeamChanged();
}
//Change ammo icon do indicate which type of Sentinel may be spawned.
simulated event WeaponTick(float dt)
{
	local int ViewPitch;
	local class<Ammunition> A;
 
	ViewPitch = Instigator.GetViewRotation().Pitch;
 
	if(level.timeseconds > nextgain)
	{
	if(repammo < 4)
		RepAmmo+=1;
 
	nextGain=level.timeseconds+2;
	}
 
	A = GetAmmoClass(0);
 
	if(A != None)
	{
		if(ViewPitch > 1124 && ViewPitch < 31744)
		{
			A.Default.IconMaterial=Finalblend'ammoslothel';
			A.Default.IconCoords.X1 = 32;
			A.Default.IconCoords.Y1 = 32;
			A.Default.IconCoords.X2 = 96;
			A.Default.IconCoords.Y2 = 96;
		}
                else
		{
			A.Default.IconMaterial=FinalBlend'ammoslotsentNO';
			A.Default.IconCoords.X1 = 0;
			A.Default.IconCoords.y1 = 0;
			A.Default.IconCoords.x2 = 64;
			A.Default.IconCoords.y2 = 64;
		}
	}
 
}
simulated function PostnetBeginPlay()
{
	Super.PostBeginPlay();
 
	if(Role == ROLE_Authority)
		LoadUpgrades();
}
simulated Function Loadupgrades()
{
local int ic;
          if(vehadded.length > driverUpgradeClasses.length)
         { // reinforce data from client side
         driverUpgradeClasses.insert(0,vehadded.length);
			for(ic = 0; ic < vehAdded.Length; ic++)
			{
            		AddToUpgradeList(ic,vehadded[ic]);
            		}
        }
}
simulated function DoUpgrade( int i, optional class<onsweapon> driveUpgrade, optional class<onsweapon> pasUpgrade)
{
local onsvehicle SentinelToUpgrade;
	if(!bAllowUpgrades)
	{
		warn("Tried to add an upgrade but they are disabled.");
		return;
	}
	if(DriveUpgrade == None && pasupgrade == none)
	{
		warn("Tried to add an upgrade that doesn't exist.");
		return;
	}
	SentinelToUpgrade = SentinelInRange(class'mechFire'.Default.UpgradeRange, true);
	if(SentinelToUpgrade == None)
	{
		Instigator.ReceiveLocalizedMessage(class'HELMessage', 9);
		return;
	}
	if(AmmoAmount(0) < 20)
	{
		Instigator.ReceiveLocalizedMessage(class'HELMessage', 8);
		return;
	}
	if(driveupgrade == class'onslinkableweapon' || pasupgrade == class'onslinkableweapon' )
	{
	return;
	}
 
	if(driveupgrade != none)
	{
		if(AmmoAmount(0) > 20)
		{
		setupdriverweapon(SentinelToUpgrade,driveUpgrade,I);
		ConsumeAmmo(0,20);
		}
	}
	else
	{
	    if(AmmoAmount(0) > 20)
		{
		setuppasweapon(SentinelToUpgrade,pasUpgrade,I);
		ConsumeAmmo(0,20);
		}
	}
}
function Tick(float DeltaTime)
{
	local name BotState, BotOrders;
 
	if(Level.TimeSeconds >= UpgradeCheckTime)
	{
		UpgradeCheckTime = Level.TimeSeconds + 1;
		mechFire(FireMode[0]).DoStuffe();
	}
	if(BodgedBot == None || Level.Game.bGameEnded)
		return;
	if(Level.TimeSeconds >= NextCheckTime && VSize(Instigator.Velocity) < 1)
	{
	NextCheckTime = Level.TimeSeconds + 1;
	}
}
simulated Function DeployCar(class<onsvehicle> Type, int RequiredAmmo )
{
local int AmmoConsume;
local int zx;
local Vector X, Y, Z;
local Vector DeployLocation;
 
if ( !Level.Game.bAllowVehicles)
{
Level.Game.bAllowVehicles=true; 
}
 
GetViewAxes(X, Y, Z);
if(requiredammo > 200)
{
requiredammo=150;
}
if(killscan(type.default.CollisionRadius) && AmmoAmount(0) >= RequiredAmmo)
{
 
 IF(oldVehicle != none)
 {
	if(oldvehicle.Driver != none)
	{
	oldVehicle.EjectDriver();
 
		if(oldvehicle.weaponpawns.length > 0)
		{
			for (zx = 0; zx < oldvehicle.WeaponPawns.length; zx++)
			{
			oldvehicle.WeaponPawns[zx].EjectDriver();
			oldvehicle.WeaponPawns[zx].Died(None, class'DamageType', oldvehicle.Location);
			}
		oldvehicle.WeaponPawns.length = 0;
		}
 
	oldvehicle.Died(None, class'DamageType', oldvehicle.Location);
	oldVehicle=none;
	}
 
 }
 
 if(oldvehicle == none)//seems to work but won't spawn
 {
 DeployLocation = Instigator.Location + (X * (20.0 + type.default.CollisionRadius)) + (z * type.default.collisionheight);
 OldVehicle= Spawn(type,,, DeployLocation, rot(0, -16384, 0));
 ConsumeAmmo(0,RequiredAmmo);
 }
}
}
 
simulated function NewDrawWeaponInfo(Canvas Canvas, float YPos)
{
	local PlayerController PC;
 
	PC = PlayerController(Instigator.Controller);
 
	if(PC == None)
		return;
 
	HudBase(PC.myHUD).TargetMaterial = finalblend'Targetcores';
 
	HudBase(PC.myHUD).TargetMaterial = HudBase(PC.myHUD).Default.TargetMaterial;
}
//=============================================================================
// Utility functions:
//=============================================================================
//Upgrades are replicated to clients here.
simulated function AddToUpgradeList(int i, class<onsweapon> NextDriverClass)
{
	if(nextDriverClass != none)
		driverUpgradeClasses[i] = NextDriverClass< SEMI > // found a way to make it only need this data!
}
static function int GetCost(class<onsvehicle> vehiclewanted,int total)
{
local int totalother;
local float divspd;
 
// use percentage logic crud this may be too much math
if(vehiclewanted != none)
{
totalother=vehiclewanted.default.GroundSpeed + vehiclewanted.default.airSpeed + vehiclewanted.default.mass + vehiclewanted.default.health;
}
divspd=total/200; // use to subtract from other values
//log(total);
return(totalother/divspd);
}
simulated function BringUp(optional Weapon PrevWeapon)
{
    Super.BringUp(PrevWeapon);
}
simulated function bool PutDown()
{
    if ( Super.PutDown() )
    {
		GotoState('');
		return true;
	}
	return false;
}
 
function bool killscan(int radu) // new code for telefragchecking by vaptor
{
local vector checklocation,scy;
local Vector X, Y, Z, HitLocation, HitNormal;
local actor victimizedactor;
 
	GetViewAxes(X, Y, Z);
 
	checkLocation = Instigator.Location + X * 100;
	scy.x=radu;
	scy.y=radu;
	scy.z=16;
	Victimizedactor = Trace(HitLocation, HitNormal, checkLocation, Instigator.Location , true, scy);
 
	 // set it false first
 
	if(victimizedActor != none)
	{
	 if(victimizedActor.isa('Pawn'))
	 {
		if(pawn(victimizedActor) != none)
		{
			if(pawn(victimizedActor).Controller.SameTeamAs(Instigator.Controller) ) // confirmed! stop them now!
			{
				return false;
			}
			else
			{
				return true;
			}
		}
		else
		{
			return true;
		}
 
	 }
 
	}
	return true;
}
defaultproperties
{
     bAllowUpgrades=True
     upgraderange=1200.000000
     FireModeClass(0)=Class'sentsv12.mechFire'
     FireModeClass(1)=Class'sentsv12.mechlaunchFire'
     IdleAnim="Idle"
     SelectAnim="Select"
     SelectSound=Sound'WeaponSounds.Misc.shieldgun_change'
     SelectForce="ShieldGun_change"
     AIRating=1.500000
     CurrentRating=1.500000
     Description="NEW weapon technology useing thinking machines to provide general support for soldiers"
     EffectOffset=(X=70.000000,Y=10.000000)
     SmallViewOffset=(X=23.000000,Y=6.000000,Z=-6.000000)
     CenteredOffsetY=-5.000000
     CenteredRoll=5000
     CenteredYaw=-300
     CustomCrosshair=31
     CustomCrossHairColor=(G=0,R=0)
     CustomCrossHairTextureName="AS_FX_TX.Icons.OBJ_Destroy_Tex"
     InventoryGroup=8
     GroupOffset=158
     PlayerViewOffset=(X=11.000000)
     BobDamping=1.575000
     AttachmentClass=Class'sentsv12.mechAttach'
     IconMaterial=FinalBlend'AS_FX_TX.Icons.OBJ_HellBender_FB'
     IconCoords=(X2=64,Y2=64)
     ItemName="VehicleMechanic"
     Mesh=SkeletalMesh'Weapons.BallLauncher_1st'
     DrawScale=0.400000
     Skins(0)=Combiner'sentsv12.Beams.ANGLETRAILxx'
     Skins(1)=FinalBlend'sentsv12.Beams.casedvortex'
     Skins(2)=Shader'sentsv12.Beams.coilshader'
}

Category:Legacy Custom Class (UT2004)

Category:Legacy To Do what is this? the parent class doesn't show up on wiki. Delete it?

Page Categories

Page Information

2022-11-18T16:02:34.024386Z 2007-11-19T22:46:52Z Sweavo * https://wiki.beyondunreal.com/Legacy:Vehicle Weapon Changer Gun Attribution-NonCommercial-ShareAlike 3.0