Legacy:VitalOverdose/TimedVehiclePropertyChanger
Overview
This is a generic script that can be used to change properties of a vehicle for a set amount of time.Its been designed to handle multiple vehicles.You can use this template script to change almost any vehicle property you want, but for the sake of an example (and so i could test the script) ive written it to change a vehicles drawscale property.
Method
If a valid vehicle comes in contact with this actor it;-
- Checks to see if this vehicle is currently being tracked
- if not a valid reference to the vehicle is stored in a record along with the original drawscale + tracking time.
- Sets the new drawscale on the vehicle
- Uses the timer function keep track of the vehicles.
- When the vehicle has been under our control for the amount of time stated by the mapper it has its drawscale set back original value and removes it from the list of vehicles being tracked.
Using the script
There are two optional functions at the end of the script that would allow you to spawn an emitter or play sounds etc when a vehicle is captured or when its released from our control.
The script
<uscript> //====================================================================================== // Generic TimedVehiclePropertyChanger by Vitaloverdose oct 2007 // http://www.vitaloverdose.com // This is a skeleton script that can be use to change the properties on a vehicle // for a set amount of time. // As an example this script has been written to change a vehicles Drawscale property //====================================================================================== class TimedVehiclePropertyChanger extends Triggers placeable;
var () float PropertyChangeTime;
// im using this for the vehicles drawscale as an example just so the script can be compiled and checked // for errors. But you can use this to store any float value from the vehicle for any property // you want to change while the vehicle under our control. var () float AFloatProperty;
// this is the frequency that the vehicle list will be processed (in seconds) // you dont want this number to low or it will slow down gameplay. var () float TimerFrequency;
// this struct defines a custom variable type that acts as a record for the vehicles under our control // inside it is the 2 essential variables :VehicleBeingTracked and TrackingTime. // // OriginalFloatProperty: is used to store the original drawscale of the vehicle under our control // this is optional and could be changed to store the original property value of anything you // are going to change while the vehicle is under our control. // Also you could add extra variables of any type here if you want to change more of the vehicles propertys struct TrackingVehiclesDetails { var Vehicle VehicleBeingTracked; // the valid reference to this vehicle var float TrackingTime; // the timer counter for this vehicle var float OriginalFloatProperty; // for the example this referes to the drawscale };
//This is a dynamic array of our new custom variable type TrackingVehiclesDetails; var array < TrackingVehiclesDetails > TrackingVehiclesList;
//Note: if you are going to use the SpecialFX example code detailed in the last 2 functions of this script //then you will need to add the declaration of these variables here; // var () Class< Emitter > ReleasedVehicleEmitterClass; // Var () Class< sound > ReleasedVehicleSoundClass; // var () Class< Emitter > ReleasedVehicleEmitterClass; // Var () Class< sound > ReleasedVehicleSoundClass;
//Generic function : Overwriting
// First a quick check that its a vehicle so we can then typecast the reference and send it to the
// function CheckExistingTrackingVehiclessList() to see if we are allready tracking this vehicle
// if the value returned is not over -1 we know the vehicle is not being tracked and we can then
// pass the valid vehicle reference to the function
function Touch(Actor Other)
{
local vehicle ValidVehicleActor;
ValidVehicleActor = Vehicle(Other);
if ((ValidVehicleActor != none) && (CheckExistingTrackingVehiclessList(ValidVehicleActor) < 0))
AddVehicleReferenceToList (ValidVehicleActor);
super.Touch(Other); }
//:Custom function : CheckExistingTrackingVehiclessList() // checks though all the references of any vehicles in the TrackingVehiclesList array // if a match is found the index number for its position in the array is returned // if no match if found a flag of -1 gets returned by default function int CheckExistingTrackingVehiclessList(vehicle VehicleReference) { local int inc; // temp counter for the forloop //log ("-------------CheckExistingTrackingVehiclessList was passed :"$VehicleReference); for (inc = 0; inc < TrackingVehiclesList.length; inc ++) // loop based on size(length) of array
if (TrackingVehiclesList[inc].VehicleBeingTracked == VehicleReference) // checks the vehicle reference one from list return inc; // if they match it returns the value 'inc'
return -1; // if no match is found -1 will be returned by default. }
// AddVehicleReferenceToList() :Custom function : // takes a valid vehicle reference and adds it to the list of vehicle we are allready tracking function AddVehicleReferenceToList(vehicle AValidVehicleReferenceToAdd) { //log ("------------AddVehicleReferenceToList was passed :"$AValidVehicleReferenceToAdd); TrackingVehiclesList.insert(0,1); // a place is made for the new vehicle in the array
TrackingVehiclesList[0].VehicleBeingTracked = AValidVehicleReferenceToAdd; // a valid reference to the vehicle is stored TrackingVehiclesList[0].TrackingTime = PropertyChangeTime; // The timer for the property change TrackingVehiclesList[0].OriginalFloatProperty = AValidVehicleReferenceToAdd.DrawScale; // Example of a property to change :drawscale
AValidVehicleReferenceToAdd.SetDrawScale(AFloatProperty);
if (TrackingVehiclesList.length == 1) // if the TrackingVehiclesList was empty before we enetered a vehicle reference then
SetTimer(TimerFrequency,false); // we need to set the timer going. Otherwise its controlled from the end of the timer()
} // function.
// Timer() : generic function : overwriting : added simulated // Here the timer uses the counter (inc) from a forloop to refernce the stored details of any vehicle in the array // // first it checks to see if the vehicle is still in play . // - if it is in play its actor reference is retrieved along with its current Tracking time. // // whatever the TimerFrequency value is then gets subtracted from its current Tracking time. // // The new current Tracking time is then check to see if its bellow 0 // - if it is < 0 the index number of it position in the TrackingVehiclesList array is then passed to the // fuction ReturnVehiclesOriginalProperties(). The index is then passed to RemoveVehicleFromList() which // subtracts 1 from the value and then returns it when the record for the vehicle has been deleted // simulated function Timer() { local int inc; local Vehicle VehicleFromList; local float TimeLeftUntilPropertiesAreReturned; //log ("-------------Timer()"); for ( inc = 0 ; inc < TrackingVehiclesList.length; inc++ )
{ if ((TrackingVehiclesList[inc].VehicleBeingTracked != none) || (TrackingVehiclesList[inc].VehicleBeingTracked.bvehicleDestroyed == false)) { VehicleFromList = TrackingVehiclesList[inc].VehicleBeingTracked; //log ("-------------Checking vehicle from list"$VehicleFromList); TimeLeftUntilPropertiesAreReturned = TrackingVehiclesList[inc].TrackingTime; TrackingVehiclesList[inc].TrackingTime = TimeLeftUntilPropertiesAreReturned - TimerFrequency;
if (TrackingVehiclesList[inc].TrackingTime < 0 ) { ReturnVehiclesOriginalProperties(inc); RemoveVehicleFromList(inc); } } else RemoveVehicleFromList(inc); }
if ( TrackingVehiclesList.length > 0 )
SetTimer(TimerFrequency,false);
//log ("-------------Timer ended.TrackingVehiclesList.length = "$TrackingVehiclesList.length ); super.timer(); }
//custom function : added 'out' so we can alter the index value and return the new value to the //point the function was called from once the vehicle record has been destroyed function RemoveVehicleFromList( out int VehiclesPositionInList ) { //log ("-------------RemoveVehicleFromList was passed :"$VehiclesPositionInList); // ReleasedVehicleSpecialFX(VehiclesPositionInList); // optional special FX when the vehicle is removed from list TrackingVehiclesList.remove(VehiclesPositionInList,1); VehiclesPositionInList--; }
//custom function : added simulated // here the passed reference to the vehicles position in the TrackingVehiclesList is used to return its // original property values simulated function ReturnVehiclesOriginalProperties(int VehiclesPositionInList) { local float RetrievedOriginalProperty; local Vehicle TargetVehicle;
TargetVehicle = TrackingVehiclesList[VehiclesPositionInList].VehicleBeingTracked; RetrievedOriginalProperty = TrackingVehiclesList[VehiclesPositionInList].OriginalFloatProperty; TargetVehicle.SetDrawScale(RetrievedOriginalProperty); }
//custom function : added simulated // This is an optional function that you can use for any special FX (emitters,sound etc) to want to fire // when the a valid vehicle reference is entered into the 'TrackingVehiclesList'. // if you do use this example code you will have to add matching global variables to the very start of the script // for ReleasedVehicleEmitterClass and ReleasedVehicleSoundClass; // In this exaple i spawn an emiter and hardattach it to the vehicle, but you dont need to have the 'setbase' bit // if you just want to spawn a static emitter actor. // Example: // var () Class< Emitter > CapturedVehicleEmitterClass; // Var () Class< sound > CapturedVehicleSoundClass; simulated function CapturedVehicleSpecialFX(int IndexOfPositionVehicleRecord) { // Example: // // local Emitter SpawnedEmitter; // local vehicle TargetVehicle; // // TargetVehicle = TrackingVehiclesList[IndexOfPositionVehicleRecord].VehicleBeingTracked; // TargetVehicleLocation = TargetVehicle.location; // // if (CapturedVehicleEmitterClass != none) // { // SpawnedEmitter = spawn(CapturedVehicleEmitterClass,self,,TargetVehicleLocation); // if (SpawnedEmitter != None) // SpawnedEmitter.setbase(TargetVehicle) // } //if (CapturedVehicleSoundClass != none) // playsound(CapturedVehicleSoundClass); // }
//custom function : added simulated // This is an optional function that you can use for any special FX (emitters,sound etc) to want to fire // when the a valid vehicles propertys that were changed are returned to the original values. // Note // if you do use this example code you will have to add matching global variables to the very start of the script // for ReleasedVehicleEmitterClass and ReleasedVehicleSoundClass; // simulated function ReleasedVehicleSpecialFX(vehicle TargetVehicle) { // // FX Code Example: // local Emitter SpawnedEmitter; // if (ReleasedVehicleEmitterClass != none) // SpawnedEmitter = spawn(ReleasedVehicleEmitterClass); // //if (ReleasedVehicleSoundClass != none) // playsound(ReleasedVehicleSoundClass); // }
defaultproperties {
PropertyChangeTime=5.000000 AFloatProperty=2.000000 TimerFrequency=1.000000 CollisionRadius=150.000000 CollisionHeight=150.000000
} </uscript>