I love the smell of UnrealEd crashing in the morning. – tarquin
Legacy:VitalOverdose/TimedVehiclePropertyChanger
Overview[edit]
This is a generic script that can be used to change properties of a vehicle for a set amount of time before returning it back to its original state.There are 100's of properties that could be changed on a vehicle to simulate many different special fx during gameplay.
Example MOD's[edit]
Heres a few examples of some of the things that could be done using this template script as a guide.
- Setting fire to a vehicle.
- Temp slowing a vehicle down after its driver through a patch of water.
- Forcing someone to drive in a straight line for a set amount of time.
- Increase the driver eject force on a vehicle for a while.
- Stretching a vehicle. If this is used with forcing a straight line you could simulate a jump to hyperspace.
- Temp shrinking of a vehicle.
- Reduce the Weight of a vehicle to allow for longer jumps.
Its been designed to handle multiple vehicles at the same time.For the sake of an example (and so i could test the script) the template script is designed to changed the 'Drawscale' prpotery of a vehicle.
Method[edit]
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 (or whatever property you choose to change) is set back to its original value and then it gets removed from the list (Dynamic Array) of vehicles being tracked.
Using the script[edit]
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/released from the TimedVehiclePropertyChanger's control. When build a script of this type its best leave adding the 'Cosmetic' SpecialFx to last.
The script[edit]
//====================================================================================== // 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 set by the mapper in Unrealed. // 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; // - How often that the vehicle list will be processed (in seconds) // Note :you dont want this number to low or it will slow down gameplay. var () float TimerFrequency; // Using a struct allows you to group together a bunch of user defined variables and give them a single name. // This struct defines a custom variable type that acts as a record for the vehicles under our control. // inside it are the 2 essential variables :VehicleBeingTracked and TrackingTime. // // OriginalFloatProperty: is used to store the original drawscale of the vehicle under our control // Note: 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. // Extra : You could also add extra variables of any type here if you want to change more of the vehicles property's than just the Drawscale alone. 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 refers to the drawscale }; //This is a 'Dynamic Array' (an array of no fixed size) of our new custom variable type TrackingVehiclesDetails defined in the 'struct' above. var array < TrackingVehiclesDetails > TrackingVehiclesList; //Extra: 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 CheckExistingTrackingVehiclesList() to see if we are already 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 AddVehicleReferenceToList(). function Touch(Actor Other) { local vehicle ValidVehicleActor; ValidVehicleActor = Vehicle(Other); if ((ValidVehicleActor != none) && (CheckExistingTrackingVehiclessList(ValidVehicleActor) < 0)) AddVehicleReferenceToList (ValidVehicleActor); Super.Touch(Other); } //:Custom function : CheckExistingTrackingVehiclessList() // This function checks though all the references of any vehicles we are currently tracking 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 length (size) of the array. if (TrackingVehiclesList[inc].VehicleBeingTracked == VehicleReference) // Checks the vehicle reference one from list return inc; // -If they match it returns the value stored in the Counter (inc) return -1; // -If no match is found '-1' will be returned by default. } // AddVehicleReferenceToList() :Custom function : // This function receives a valid vehicle reference and adds it to the list of vehicles we are already 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 duration 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 entered a vehicle reference then SetTimer(TimerFrequency,false); // we need to set the Timer() function going. Otherwise its controlled from the end of the Timer() by default } // Timer() : Generic function : Overwriting : added Simulated // Here the timer uses the counter (inc) from a forloop to reference 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. // // The TimerFrequency value is then subtracted from its current Tracking time. // // The new current Tracking time is then checked to see if its < 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 that value 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 using this function and return the new value to the //point the function was called from once the vehicle record has been destroyed automatically. function RemoveVehicleFromList( Out Int VehiclesPositionInList ) { //log ("-------------RemoveVehicleFromList was passed :"$VehiclesPositionInList); // ReleasedVehicleSpecialFX(VehiclesPositionInList); // optional special FX for when the vehicle is removed from list (Dynamic Array). TrackingVehiclesList.remove(VehiclesPositionInList,1); VehiclesPositionInList--; } //Custom function : added Simulated //Here the passed reference to the vehicles position(index) in the TrackingVehiclesList array is used to return the // original property value to the Vehicle. 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 // Note :This is an optional (Cosmetic)function that you could use for any special FX (emitters,sound etc) to want to fire // when the a valid vehicle reference gets entered into the 'TrackingVehiclesList'(Dynamic Array). // Important:If you do use this example code you will HAVE to add matching 'global' variables // to the very start of the script (ReleasedVehicleEmitterClass and ReleasedVehicleSoundClass). // Extra :In this example the spawned emitter is HardAttach'ed it to the vehicle using the 'Setbase()' function. //simulated function CapturedVehicleSpecialFX(int IndexOfPositionVehicleRecord) //{ // 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 property's are returned to their 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) //{ // Example of some Special FX Code : // 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 }