Gaming Zone > Unreal Tournament 2004

Manta Run Assists

<< < (8/8)

Unaben:
Cool, here are my suggested changes:

--- Code: ---//============================================================================
// $Id: Mia_FlagrunInfo.uc by Jrubzjeknf
//============================================================================
class Mia_FlagrunInfo extends ReplicationInfo;

//============================================================================
// Variables
//============================================================================
var TeamInfo EnemyTeamInfo;
var float EnemyTeamScore;

var float TimeCarryingFlag;
var float FlagTakenTime;
var int ScoreMethod;
var int MaxScore;
var int MaxAdren;

var PlayerReplicationInfo LastHolderPRI;

struct VehicleDriverPoints
{
var Controller Driver;
var float TimeDriven;
};

var array<VehicleDriverPoints> VehicleDriverPointsArray;


//============================================================================
// PostBeginPlay
//
// Initiates flag monitoring.
//============================================================================
function PostBeginPlay()
{
Super.PostBeginPlay();

SetTimer(1, true);
}


//============================================================================
// Timer
//
// Checks if the flag carrier is sitting on a Vehicle. Every second he's sitting
// on one, the Vehicle driver gets an assist second. This will be used for
// giving the Vehicle driver points and adrenaline for the Vehicle run.
//============================================================================
function Timer()
{
local pawn Driver;
local Controller C;

if(Owner !=  None)
{
if(Owner.IsInState('Held'))
{
if(CTFFlag(Owner).Holder != None) {
LastHolderPRI = PlayerReplicationInfo(CTFFlag(Owner).Holder);
}
}

if(FlagTakenTime != CTFFlag(Owner).TakenTime) //the flag has just been taken, check it the flag has been captured between seconds.
{
CheckCapture();
FlagTakenTime = CTFFlag(Owner).TakenTime;
}

if(!Owner.IsInState('Home')) //The flag is being carried or has been dropped.
{
TimeCarryingFlag += 1;

if(CTFFlag(Owner).Holder != None &&
CTFFlag(Owner).Holder.Base != None &&
Vehicle(CTFFlag(Owner).Holder.Base) != None &&
Vehicle(CTFFlag(Owner).Holder.Base).Driver != None) //The flag carrier is sitting on an occupied Vehicle.
{

Driver = Vehicle(CTFFlag(Owner).Holder.Base).Driver;

if(Driver.GetTeamNum() == CTFFlag(Owner).Holder.GetTeamNum() && Driver != CTFFlag(Owner).Holder){ //The Vehicle driver is friendly (and not self!).
if (Driver.DrivenVehicle != None && Driver.DrivenVehicle.Controller != None){
C = Driver.DrivenVehicle.Controller;
}
else{
C = Driver.Controller;
}
UpdateTimeDrivenFor(C); //Give the driver seconds.
}
}
}
else if(TimeCarryingFlag != 0) //The flag is home, but has been carried. Check if the flag has been captured.
CheckCapture();
}
}


//============================================================================
// CheckCapture
//
// Check is the flag has been captured.
//============================================================================
function CheckCapture()
{
local int i;
local float RelativeTimeDriven;
local float Points;
local float Adren;

if(EnemyTeamScore != EnemyTeamInfo.Score)
{
EnemyTeamScore = EnemyTeamInfo.Score;

for(i=0; i<VehicleDriverPointsArray.Length; i++)
if(VehicleDriverPointsArray[i].Driver != None)
{
if(LastHolderPRI == None ||
LastHolderPRI.PlayerID != VehicleDriverPointsArray[i].Driver.PlayerReplicationInfo.PlayerID)
{
if (ScoreMethod == 1){
RelativeTimeDriven = VehicleDriverPointsArray[i].TimeDriven/TimeCarryingFlag;
Points = RelativeTimeDriven*MaxScore;
Adren = RelativeTimeDriven*MaxAdren;
}
else{
Points = min(VehicleDriverPointsArray[i].TimeDriven, MaxScore);
Adren = min(VehicleDriverPointsArray[i].TimeDriven*2, MaxAdren);
}

if(PlayerController(VehicleDriverPointsArray[i].Driver) != None)
PlayerController(VehicleDriverPointsArray[i].Driver).ClientMessage("Flag Run Assist! Points:"@string(int(Points * 100) / 100)$", Adrenaline:"@string(int(Adren * 100) / 100));

VehicleDriverPointsArray[i].Driver.PlayerReplicationInfo.Score += Points; //Flag carrier gets MaxScore points on flawless cap.
VehicleDriverPointsArray[i].Driver.Adrenaline += Adren; //Flag carriers get MaxAdren adrenaline.
}
}
}

TimeCarryingFlag = 0;
LastHolderPRI = None;
VehicleDriverPointsArray.Length = 0;
}


//============================================================================
// UpdateTimeDrivenFor: give current driver seconds.
// GetIndexOf: gets array index of current driver.
// AddToArray: add current driver to array.
//============================================================================
function UpdateTimeDrivenFor(Controller Driver)
{
local int i;

i = GetIndexOf(Driver);

if(i != -1)
VehicleDriverPointsArray[i].TimeDriven += 1;
else
AddToArray(Driver);
}

function int GetIndexOf(Controller C)
{
local int i;

for(i=0; i<VehicleDriverPointsArray.Length; i++)
if(VehicleDriverPointsArray[i].Driver == C)
return i;

return -1;
}

function AddToArray(Controller C)
{
local int i;

i = VehicleDriverPointsArray.Length;

VehicleDriverPointsArray.Length = i + 1; //VehicleDriverPointsArray.Length++; would make it crash 0_o
VehicleDriverPointsArray[i].Driver = C;
VehicleDriverPointsArray[i].TimeDriven = 1;
}

defaultproperties
{
}


--- End code ---



--- Quote from: Piglet on March 18, 2024, 14:23 ---The code is here...on the second post of this thread....

--- End quote ---

Piglet:
Thank you.

Yes. That makes perfect sense.

One small correction:


--- Code: ---LastHolderPRI = CTFFlag(Owner).Holder.PlayerReplicationInfo;
--- End code ---

The Holder is the pawn that's holding the flag. We need its PRI.

Navigation

[0] Message Index

[*] Previous page

Go to full version