
Rama
PS: tutorial was at his request

//you could add this code to your existing custom playercontroller class Class UpgradeablePlayerClass extends PlayerController; //Make a struct for easy copy-pasting of upgrade data //With this setup, to copy all upgrade data from one //player to another you can just do: //player1.weaponStats = player2.weaponStats; //this is the struct for 1 weapon type //add additional variables even if //only 1 weapon uses them //since with this setup all weapons //will look for this one type of struct. struct weaponUpgradeData { var class weaponClass; var float damageMultiplier; var float weaponSpeed; var float weaponAccel; var float projLifeSpan; var vector drawscale; //other upgrade stats //you can even change what projectile //the weapon uses as it gets upgraded! var class projectileClass; //default upgrade stats structdefaultproperties { damageMultiplier = 1 drawscale = (x=1,y=1,z=1); projLifeSpan = 10 //seconds } }; //supposing 7 different weapon types available to player var weaponUpgradeData weaponStats[7]; //only use static array, dynamic arrays will not work in multiplayer games Simulated Event PostBeginPlay() { super.PostBeginPlayer(); //set the weapon classes and their //starting projectile classes //weapon 1 starting upgrades weaponStats[0].weaponClass = 'YourFirstweaponClass'; weaponStats[0].projectileClass = 'FirstweaponProjectileClass'; weaponStats[0].weaponSpeed = 3000; weaponStats[0].weaponAccel = 30; //weapon 2 starting upgrades weaponStats[1].weaponClass = 'YourSecondweaponClass'; weaponStats[1].projectileClass = 'SecondweaponProjectileClass'; weaponStats[1].weaponSpeed = 1000; weaponStats[1].weaponAccel = 300; //etc... }
class upgradeableProjBase extends UTProjectile dependson(UpgradeablePlayerClass); //custom initialization func function joyInit(vector Direction, weaponUpgradeData weaponData ) { //set speed and acceleration //per instance of projectile speed = weaponData.weaponSpeed; accelrate = weaponData.weaponAccel; //~~~ Damage ~~~ //here's how you adjust the damage //as weapon gets upgraded //In the character class who is using this //projectile, you store this multiplier permanently //as a character statistic Damage *= weaponData.damageMultiplier; //~~~ Life Span of Projectile ~~~ //you can customize how long //projectile stays alive //per instance / upgraded weapon LifeSpan = weaponData.projLifeSpan; //~~~ Asymetric draw scale ~~~ //can make weapon proj look different //per player //so as weapon gets upgraded it's projectile //could get bigger or longer for example SetDrawScale3D(weaponData.drawscale); //~~~ Emitter Parameter Changes ~~~ //if your particle effect has parameters //you could set them here as well //to change color or other aspects of the particle system //~~~ UTProjectile.uc Init ~~~ Init(Direction); }
class upgradeableWeapon extends UTWeapon dependson(UpgradeablePlayerClass); //global variable to store the upgrade data var weaponUpgradeData weaponData; //copied out of engine/weapon.uc //editing this code to allow each player //who picks up an instance of a weapon //to modify that weapon based on the player's upgrade weapon data /************ * State Active * A Weapon this is being held by a pawn should be in the active state. In this state, * a weapon should loop any number of idle animations, as well as check the PendingFire flags * to see if a shot has been fired. *********/ simulated state Active { /** Initialize the weapon as being active and ready to go. */ simulated event BeginState(Name PreviousStateName) { local int i; local weaponUpgradeData oneSetofStats; //set the global weaponData var when //a player picks up this weapon if(UpgradeablePlayerClass(Instigator.Controller) != none) { for(i=0; i < ArrayCount( UpgradeablePlayerClass(Instigator.Controller).weaponStats), i++) { oneSetofStats = UpgradeablePlayerClass(Instigator.Controller).weaponStats[i]; if(oneSetofStats.weaponClass == Self.class){ weaponData = oneSetofStats; break; } } //end for } //end if // Cache a reference to the AI controller if (Role == ROLE_Authority) { CacheAIController(); } // Check to see if we need to go down if( bWeaponPutDown ) { `LogInv("Weapon put down requested during transition, put it down now"); PutDownWeapon(); } else if ( !HasAnyAmmo() ) { WeaponEmpty(); } else { // if either of the fire modes are pending, perform them for( i=0; i<GetPendingFireLength(); i++ ) { if( PendingFire(i) ) { BeginFire(i); break; } } } } /** Override BeginFire so that it will enter the firing state right away. */ simulated function BeginFire(byte FireModeNum) { if( !bDeleteMe && Instigator != None ) { Global.BeginFire(FireModeNum); // in the active state, fire right away if we have the ammunition if( PendingFire(FireModeNum) && HasAmmo(FireModeNum) ) { SendToFiringState(FireModeNum); } } } /** * ReadyToFire() called by NPC firing weapon. * bFinished should only be true if called from the Finished() function */ simulated function bool ReadyToFire(bool bFinished) { return true; } /** Activate() ignored since already active */ simulated function Activate() { } /** * Put the weapon down */ simulated function bool TryPutDown() { PutDownWeapon(); return TRUE; } } //copied out of utgame/utweapon.uc //add the custom initialization function //to the weapon firing function simulated function Projectile ProjectileFire() { local vector RealStartLoc; local Projectile SpawnedProjectile; // tell remote clients that we fired, to trigger effects IncrementFlashCount(); if( Role == ROLE_Authority ) { // this is the location where the projectile is spawned. RealStartLoc = GetPhysicalFireStartLoc(); // Spawn projectile using weapon upgrade data //projectile class if(Instigator.Controller.isa('UpgradeablePlayerClass')){ SpawnedProjectile = Spawn(weaponData.projectileClass,,, RealStartLoc); } else { GetProjectileClass(); } //if the user of weapon has weaponUpgradeData if(Instigator.Controller.isa('UpgradeablePlayerClass')){ if( SpawnedProjectile != None && !SpawnedProjectile.bDeleteMe ) { //use upgrade data via custom initialization function upgradeableProjBase(SpawnedProjectile).joyInit( Vector(GetAdjustedAim( RealStartLoc )), weaponData ); } } //standard code else { if( SpawnedProjectile != None && !SpawnedProjectile.bDeleteMe ) { SpawnedProjectile.Init( Vector(GetAdjustedAim( RealStartLoc )); } } // Return it up the line return SpawnedProjectile; } return None; }
//in the weapon class extending UTWeapon //global variable to store the upgrade data var weaponUpgradeData weaponData; //set the global weaponData var when //a player picks up this weapon simulated state Active { /** Initialize the weapon as being active and ready to go. */ simulated event BeginState(Name PreviousStateName) { local int i; local weaponUpgradeData oneSetofStats; if(UpgradeablePlayerClass(Instigator.Controller) != none) { for(i=0; i < ArrayCount( UpgradeablePlayerClass(Instigator.Controller).weaponStats), i++) { oneSetofStats = UpgradeablePlayerClass(Instigator.Controller).weaponStats[i]; if(oneSetofStats.weaponClass == Self.class){ weaponData = oneSetofStats; break; } } //end for } //end if //partial code snippet only
Leave a comment: