Turret
Turret
The turret is an advanced stationary sentry. It's designed to be linked with one or more security cameras, automatically attacking the closest target that is visible to a security camera. Not to be confused with the Camgoyle, which is a security camera that can also attack enemies. The following features are offered by the turret:
- Fires explosive, high-velocity projectiles at the closest enemy detected by linked security cameras. Enable "seeAIs" on the security camera and update the "team" spawnarg if you'd like it to fire at AIs.
- Predicts its target's position based on its movement.
- Can be destroyed with fire arrows/mines by default, producing fx like sparks and breaking into pieces. Alternatively, it can be switched on/off via a simple trigger i.e. from a button.
- Comes with a separate rotating platform and recoiling barrel.
- Similarly to the security camera, both the turret and its projectiles are highly customizable.
- Offers script control to fire at specific entities or positions using the "attack" and "attackPosition" events.
- Its view can be sent to a camera screen.
- There is also a script-based flamethrower version as an unofficial download here.
Entities and Prefabs
The official thread can be found here: https://forums.thedarkmod.com/index.php?/topic/22307-212-turrets/ Turret entities can be found in AI/Machines/Turret and inherit from atdm:turret_base. Prefabs can be found in AI/Machines. The projectiles can be found in Internal/Weapons/Projectiles.
Spawnargs
Movement Spawnargs
- "rotation_speed_vertical" - Vertical turning speed in degrees per second.
- "rotation_speed_horizontal" - Horizontal turning speed in degrees per second.
- "max_incline_up" - How many degrees the turret can rotate upwards from its starting orientation.
- "max_incline_down" - How many degrees the turret can rotate downwards from its starting orientation.
Note: horizontal rotation can't be restricted at present.
Attack Spawnargs
- "accuracy" - Add a random number of degrees up to this value whenever the turret fires a shot. 0 is perfect accuracy.
- "attack_delay" - Time in seconds before the turret can make its first attack after establishing a lock on the enemy.
- "attack_delay_rand" - Additional random delay up to this amount for attack_delay.
- "attack_interval" - Time in seconds between each attack of the turret while the turret still has a lock on the enemy.
- "attack_interval_rand" - Additional random delay up to this amount for attack_interval.
- "fire_range_max" - Max distance at which the turret can attack targets.
- "fire_range_min" - Min distance at which the turret can attack targets.
- "fire_tolerance" - Max difference in degrees between the enemy's position and the turret's current orientation. 0 means the turret has to point perfectly at the enemy to attack.
- "predict_motion" - Whether the turret will predict the enemy's motion when firing projectiles.
- "friendly_fire" - The turret will attack its target even if a friendly actor is in the line of fire.
Projectile Spawnargs
These spawnargs affect the projectile launched by the turret:
- "def_projectile" - Projectile to be fired. At time of writing, a guided and (experimental) bouncing version of the projectile are also available: atdm:turret01_projectile_guided and atdm:turret01_projectile_bounce.
- "projectile_offset" - Offset the projectile launch position from the model origin. This should be roughly where the barrel's muzzle is.
- "projectile_speed" - Speed at which projectiles are launched. The corresponding value in the projectile def is not used.
- "projectile_trace_radius" - Radius of the bounding box that's used to determine whether the projectile hits something.
Barrel Spawnargs
The basic model comes with a separate barrel which recoils whenever a shot is fired.
- "model_barrel" - Model of a separate barrel entity. Set to '-' if you don't want to spawn a barrel.
- "broken_barrel" - Switch the barrel to this model when the turret is destroyed.
- "barrel_offset" - Offset the barrel origin from the turret's origin.
- "recoil" - Translation by the barrel when recoiling. Set to '0 0 0' to disable.
- "recoil_time1" - Time taken for the barrel to travel to the recoil position.
- "recoil_time2" - Time taken for the barrel to return from the recoil position.
- "broken_hide_barrel" - Hide the attached barrel entity if the turret is destroyed.
Color Spawnargs
- "color_idle" - Color when all connected security cameras are idle.
- "color_suspicious" - Color when at least one connected security camera is in a suspicious state.
- "color_alerted" - Color when at least one connected security camera is in an alerted state.
- "color_passive" - Color when not connected to any operational security cameras.
Turret Damage Spawnargs
These spawnargs govern the player's ability to do damage to the turret:
- "health" - Entity's health. Set to 0 for invulnerability.
- "damage_threshold" - Hits have to do at least this much damage for the turret be damaged. Avoids taking small amounts of splash damage from relatively distant projectile impacts. Set to 0 to disable.
- "damage_flinderize" - Attacks dealing at least this amount of damage can turn the turret into fragments upon or after destruction. Set to 0 to disable.
- "damage_blackjack" - Damage taken from blackjack attacks. Default damage: 0
- "damage_mult_sword" - Damage multiplier for sword attacks. Default damage: 42
- "damage_mult_arrow" - Damage multiplier for broadheads and rope arrows. Default damage: 35
- "damage_mult_firearrow_direct" - Damage multiplier for fire arrow and mine direct hits. Fire arrows and mines deal either direct damage or splash damage. Default damage: 400
- "damage_mult_firearrow_splash" - Damage multiplier for fire arrow and mine splash damage. Fire arrows and mines deal either direct damage or splash damage. Default maximal damage: 30
- "damage_mult_moveable" - Damage multiplier for all moveables. Significant mass and velocity are needed to do significant damage. Default maximal damage: mass divided by 5
- "damage_mult_other" - Damage multiplier for anything else. You can create individual damage_ spawnargs by naming the damage def, i.e. 'damage_mult_atdm:damage_rock' '1.0', or the inflicting entity, i.e. 'damage_atdm:attachment_melee_shortsword' '1.0'
- "fx_damage" - fx played when the turret is damaged while power is on.
- "fx_damage_nopower" - fx played when the turret is damaged while power is off.
Turret Destruction Spawnargs
These spawnargs govern what happens when the turret is destroyed:
- "snd_death" - Sound made when the turret is destroyed while power is on.
- "snd_death_nopower" - Sound made when the turret is destroyed while power is off.
- "fx_destroyed" - fx played when the turret is destroyed while power is on.
- "fx_destroyed_nopower" - fx played when the turret is destroyed while power is off.
- "broken" - switch to this model when the turret is broken.
- "broken_flinderized" - switch to this model when the turret is broken and flinderized (fragmented). Set the flinderize threshold with 'damage_flinderize'. If no model is set here, will use 'broken' instead.
- "skin_broken" - switch to this skin when the turret is broken.
- "skin_broken_flinderized" - switch to this skin when the turret is broken and flinderized (fragmented). Set the flinderize threshold with 'damage_flinderize'. If no skin is set here, will use 'skin_broken' instead.
- "def_flinderN" - EntityDef of a flinder entity, replace N with 1, 2, 3 etc.
- "flinder_offsetN" - Offset of the flinder spawn position relative to the turret's origin, taking the turret's rotation into account.
- "findler_countN" - Number of flinders of this type to spawn.
Sparks Spawnargs
These spawnargs control the sparks effect that plays periodically after the turret has been destroyed and if it's still powered.
- "sparks" - 1 = When the turret is destroyed, spawn a post-destruction particle func_emitter and play snd_sparks.
- "snd_sparks" - Sound emitted when the turret emits sparks after it was destroyed.
- "sparks_offset" - Offset the sparks particle emitter from the model origin.
- "sparks_particle" - Particle that is spawned upon destruction.
- "sparks_delay" - Delay the initial appearance of the particle emitter after the turret is destroyed.
- "sparks_power_dependent" - Only show the particle if power to the turret is switched on.
- "sparks_interval" - Minimum time between each trigger of the particle emitter + snd_sparks.
- "sparks_interval_rand" - Additional random factor added to the time between each trigger of the particle + snd_sparks.
Sound Spawnargs
- "snd_stationary" - Sound made while idle.
- "snd_fire" - Sound made when a projectile is fired.
- "snd_sparks" - Sound emitted when the turret emits sparks after it was destroyed.
- "snd_death" - Sound made when the turret is destroyed while power is on.
- "snd_death_nopower" - Sound made when the turret is destroyed while power is off.
AI Spawnargs
These spawnargs affect how the turret and AIs interact with each other:
- "notice_destroyed" - AIs will react if they see this turret has been destroyed.
- "AIUse" - Allows AIs to react to this turret when they see that it has been destroyed.
- "rout_enemies" - Enemies attacked by the turret will flee. 1 = always flee, 2 = flee if not fighting an enemy. Note: may not work perfectly.
- "rout_radius" - Enemies within this distance of the attacked enemy will also flee. See settings in rout_enemies.
Misc Spawnargs
- "start_off" - Whether the turret starts powered on or off.
- "cameraFovX" - Display screens showing the turret's view will have this field of view in X.
- "cameraFovY" - Display screens showing the turret's view will have this field of view in Y.
Damaging the Turret
Damage and destruction of the turret are highly customizable and work similarly to the Security Camera. See the corresponding section there.
Scripting
Script Events
The turret supports the following script events:
- getTurretState - Returns the turret's state. 0 = passive: no active security cameras connected. 1 = unalerted, 2 = suspicious, 3 = fully alerted, 4 = power off, 5 = destroyed.
- attack(entity enemy, float ignoreCollisions) - Direct the turret to manually attack the specified entity. Use disableManualAttack() to disable. enemy: enemy to attack. ignoreCollisions: whether to ignore obstacles in the way to the enemy when planning to attack
- attackPosition(vector targetPos, float ignoreCollisions) - Direct the turret to manually attack a position. targetPos: position to attack. ignoreCollisions: whether to ignore obstacles in the way to the target position when planning to attack. Recommended true for this event.
- disableManualAttack() - Stop attacking the manually specified enemy or position and return to automatic target acquisition mode.
- activate() and trigger() - Toggle the turret's power.
- getHealth() and setHealth(float newHealth) - As per the name. Setting health to 0 or lower will destroy the turret, which is irreversible. Using setHealth can turn an invincible turret vulnerable.
Scriptobjects
The turret's scriptobject is only needed for cosmetic elements specific to the default turret (recoiling barrel, attack FX and a rotating platform).
Upon Destruction
You may call a script when the turret is destroyed via the spawnarg "break_up_script". This script should be able to receive the name of the destroyed turret as input, i.e.:
void turret_destroyed ( entity turret )