-
Notifications
You must be signed in to change notification settings - Fork 0
Vehicle functions
These are the ZScript functions shared by all vehicles and turrets.
- TurretClass: The class of the turret to spawn, must be based on KAI_BaseTurret
- None, for a pointer to the spawned turret, just check the Turret pointer.
This function handles the basic tasks for spawning a vehicle turret, like setting its' allegiance, passing the vehicles spawn flags to the turret, etc. Useful if you have custom turret spawning logic in SpawnVehicleTurret(), such as a vehicle that can have different turrets through a user variable.
- AttachTo: The actor to attach the lights to, normally a vehicle.
- Offsets: The Vector3 offsets relative to AttachTo's origin at which the light should spawn.
- Flags:
- VHSF_BACKLIGHT: The spawned headlight is a backlight.
- LightColor: The color of the headlight, because this uses dynamic light actors, this is a Vector3 that stores the R, G, and B colors of the the light, respectively, can be any value between 0 and 255. Is white by default (255, 255, 255).
- Intensity: How strong the headlight is, default is 256.
- SpotlightAngles: A Vectpr2 that stores the inner (X) and outer (Y) angles of the headlight.
- Returns a KAI_Headlight pointer to the spawned light. For storing to the headlights array.
Spawn a vehicle headlight, vehicle headlights are spotlight actors. Normally called in the SpawnHeadlights() virtual to spawn and store the vehicle's headlights when it spawns.
This is how the function is used by one of the vehicles from the Military Vehicles Pack.
Override Void SpawnHeadlights ()
{
Headlights.Push(SpawnVehicleHeadlight(Self,(128,28,8),intensity:384));
Headlights.Push(SpawnVehicleHeadlight(Self,(128,-28,8),intensity:384));
Headlights.Push(SpawnVehicleHeadlight(Self,(128,28,8),VHSF_BACKLIGHT,(255,0,0),32,(40,80)));
Headlights.Push(SpawnVehicleHeadlight(Self,(128,-28,8),VHSF_BACKLIGHT,(255,0,0),32,(40,80)));
}
This function must be called before the actor moves, but after the position to move to has been decided, to push any obstacles out of the way. Refer to how it's used in KAI_MoveTowards() as an example.
As of 13/7/2023, vehicles can only push obstacles away that are not touching each other. This means that a vehicle can push a trashcan away, but not two of them next to each other for example. So far I haven't been able to get obstacles to push each other as well without the game freezing, and nobody has helped. So it'll stay this way for the foreseeable future.
- Source: The actor who is pushing the obstacles away, this is normally the vehicle itself.
- MovePos: The XY position to check for pushable obstacles to push away at.
- MaxPushRadius: The maximum radius a blocking obstacle can have before the vehicle can no longer push it, normally this value is the vehicles' MaxPushRadius.
- MaxPushHeight: Ditto
- Pushovers: A pointer to an actor array can be passed to this parameter, to have pointers to all the actors that will be pushed out of the way stored.
Pushes all pushable obstacles that are intersecting the the callers' hitbox at NextPos away. This must be called before the vehicle actually moves.
- Other: The actor to retreat from.
- Distance: How far back to pick a position away from the Other actor.
- CheckDistance: How far ahead of the vehicle to check for obstacles, so the vehicle can try to avoid them. A value of 0 disables obstacle avoidance.
- Slices: How many angles around the caller to check for obstacles (360 degrees / slices). A value of 0 here also disables obstacles avoidance.
- DetourFactor, AngleLimit, ChaseFlags, Flags: These parameters work the same as in KAI_MoveTowards().
- Not a return, but this does set the NPCs' NextMovePos.
Makes the vehicle retreat from Other, unlike KAI_MoveAway(), this function picks the furthest Distance away from the other actor, instead of a random spot that is the furthest. Even more unlike KAI_MoveAway(), this function will attempt to make the vehicle avoid hitting any obstacles that are CheckDistance ahead of the vehicle.
- None
Handles the vehicles' SearchTime property. Used by KAI_LandVehicleChase() and can also be called independently on turrets if you want them to be able to stop chasing their target and switch to a new one.
- MaxDist: The distance to check if the vehicles' friendplayer is within. Default is 384 map units.
- None
Checks if the player the vehicle is following is within MaxDist, if they are then the function turns +DONTFOLLOWPLAYERS on, otherwise it turns it off. This is used by KAI_LandVehicleChase() to try and prevent friendly vehicles from dogpiling the player and blocking their way.
- Flags: The flags to use for the retarget. These are mostly flags for not running specific retarget conditions.
- RVHF_NOTARGETCHANGE: Don't actually change the callers' target to the hull of the turret they are targeting, only return if the retarget SHOULD occur.
- RVHF_NOTRANSFERDAMAGECHECK: Don't retarget if the turret has +TRANSFERDAMAGE, and the hull its' attached to is bigger than the turret itself.
- RVHF_NOWEAKHULLCHECK: Don't retarget if the vehicle the turret is attached to is weaker than the turret itself.
- Returns true if the callers' target is a vehicle turret, and targeting the vehicle the turret is attached to would be more advantageous instead.
Checks if the callers' target is a vehicle turret, and changes it if it would be more advantageous to target the vehicle itself, this function checks for several conditions to determine if it would be better/easier to target the vehicle rather than its' turret:
- If the turret has +TRANSFERDAMAGE, and is overall smaller than the vehicle it's on. Then it would make more sense to target the bigger hull, since both actors share the same health pool.
- If the turret does not have +TRANSFERDAMAGE, but the vehicle it's attached to is weaker than 80% of the turrets' current health. Meaning that it should be easier and quicker to destroy the vehicle itself than its' turret, which it can probably function without anyway.
- RadiusMultiplier: The amount to multiply the crushing radius of the vehicle by. Default is 1.0, which only crushes corpses the vehicle is touching.
- None
Handles crushing any non-flying corpses the vehicle is touching. Useful for making vehicles that can crush corpses they drive or walk over. Like tanks. Must be called every time the vehicle moves ideally, to crush the corpses after every move.
These functions handle the vehicles' headlight system.
Turn the vehicle's headlights on if they aren't already, and increases its light level by 64, along with the light level of any turret attached on it.
Turns the headlights off and sets the vehicles and turrets' light levels back to 0.
Removes all the vehicles' headlights. Called when vehicles die or are erased from existence.
- Home
- Features
- Classes
- Functions
- Guides