From 30c6e5ae708db20563b164caa740a22868356f51 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Thu, 7 Jul 2022 23:22:47 +0200 Subject: [PATCH] Add lifetime for spawned vehicles and turrets, their spawn functionality is completed! --- mutators.cfg | 2 ++ qcsrc/common/mutators/mutator/nades/nades.qc | 6 +++++- qcsrc/common/mutators/mutator/nades/nades.qh | 2 ++ qcsrc/common/turrets/sv_turrets.qc | 13 +++++++++++-- qcsrc/common/turrets/sv_turrets.qh | 1 + qcsrc/common/vehicles/sv_vehicles.qc | 17 +++++++++++++++++ qcsrc/common/vehicles/sv_vehicles.qh | 1 + 7 files changed, 39 insertions(+), 3 deletions(-) diff --git a/mutators.cfg b/mutators.cfg index 07875a6476..0055680074 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -271,6 +271,8 @@ set g_nades_heal_foe -2 "Multiplier of health given to enemies" // Tandem (7) set g_nades_pokenade_monster_lifetime 150 "How long pokenade monster will survive" +set g_nades_pokenade_turret_lifetime 150 "How long pokenade turret will take to be in the world" +set g_nades_pokenade_vehicle_lifetime 150 "How long pokenade vehicle will take to be in the world" set g_nades_pokenade_type "zombie" "Monster, item, vehicle and turret to spawn" set g_nades_tandemnade_type 0 "Tandem nade selection; 0: monster, 1: item, 2: vehicle, 3: turret" set g_nades_tandem_ball_spread 0.5 "Maximum force which the ball will have on explosion" diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 56fae5e121..ea64deb605 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -992,7 +992,9 @@ void nade_tandem_boom(entity this) if(!e) return; // vehicle failed to be spawned - + + if(autocvar_g_nades_pokenade_vehicle_lifetime > 0) + e.vehicle_lifetime = time + autocvar_g_nades_pokenade_vehicle_lifetime; return; } case 3: @@ -1017,6 +1019,8 @@ void nade_tandem_boom(entity this) if(!e) return; // turret failed to be spawned + if(autocvar_g_nades_pokenade_turret_lifetime > 0) + e.turret_lifetime = time + autocvar_g_nades_pokenade_turret_lifetime; return; } default: diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index c3cf84afc9..7b19520583 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -82,6 +82,8 @@ float autocvar_g_nades_dark_radius; string autocvar_g_nades_pokenade_type; int autocvar_g_nades_tandemnade_type; //LegendGuard adds new nade cvar for emerald nade options 01-07-2021 float autocvar_g_nades_pokenade_monster_lifetime; +float autocvar_g_nades_pokenade_turret_lifetime; +float autocvar_g_nades_pokenade_vehicle_lifetime; #endif // use slots 70-100 diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc index 8177f1734f..6b6c89e106 100644 --- a/qcsrc/common/turrets/sv_turrets.qc +++ b/qcsrc/common/turrets/sv_turrets.qc @@ -1030,6 +1030,15 @@ void turret_fire(entity this) void turret_think(entity this) { + if(this.tur_spawned && this.turret_lifetime != 0) + if(time >= this.turret_lifetime) + { + tmp_vehcount--; + + turret_die(this); + return; + } + this.nextthink = time + this.ticrate; MUTATOR_CALLHOOK(TurretThink, this); @@ -1128,7 +1137,7 @@ void turret_think(entity this) // Check if we have a vailid enemy, and try to find one if we dont. // Don't attack against owner - if (turret_select_target(this) == this.realowner) return; + if(turret_select_target(this) == this.realowner) return; // g_turrets_targetscan_maxdelay forces a target re-scan at least this often float do_target_scan = 0; @@ -1152,7 +1161,7 @@ void turret_think(entity this) { this.enemy = turret_select_target(this); // Don't attack against owner - if (this.enemy == this.realowner) return; + if(this.enemy == this.realowner) return; this.target_select_time = time; } diff --git a/qcsrc/common/turrets/sv_turrets.qh b/qcsrc/common/turrets/sv_turrets.qh index 83d971f43c..497c3b8c52 100644 --- a/qcsrc/common/turrets/sv_turrets.qh +++ b/qcsrc/common/turrets/sv_turrets.qh @@ -39,6 +39,7 @@ TR_PROPS_COMMON(X, , ) .float tur_dist_aimpos; // distance to aim location .float tur_dist_impact_to_aimpos; // distance impact<->aim .bool tur_spawned; // spawned turret using spawnturret +.float turret_lifetime; // turret disappears instantly after this delay, set from spawn .float volly_counter; // decrement counter from .shot_volly to 0 .float target_select_time; // last time turret had a valid target .float target_validate_time; // throttle re-validation of current target diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 399eac132b..752391030e 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -978,6 +978,7 @@ void vehicles_enter(entity pl, entity veh) if(veh.owner) return; // got here and didn't enter the gunner, return + if(!teamplay) if(!veh.realowner) if(veh.realowner != pl && autocvar_g_vehicles_steal) @@ -1110,6 +1111,22 @@ void vehicles_enter(entity pl, entity veh) void vehicles_think(entity this) { + if(this.summoned && this.vehicle_lifetime != 0) + if(time >= this.vehicle_lifetime) + { + Send_Effect(EFFECT_TELEPORT, this.origin + '0 0 100', '0 0 0', 1); + + tmp_vehcount--; + + // to avoid weird entity assignments to other stuff like projectiles + delete(this.vehicle_shieldent); + delete(this.vehicle_hudmodel); + delete(this.tur_head); + delete(this.vehicle); + delete(this); + return; + } + this.nextthink = time + autocvar_g_vehicles_thinkrate; if(this.owner) diff --git a/qcsrc/common/vehicles/sv_vehicles.qh b/qcsrc/common/vehicles/sv_vehicles.qh index 708244d5d5..b59550fa7d 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qh +++ b/qcsrc/common/vehicles/sv_vehicles.qh @@ -88,6 +88,7 @@ const int MAX_AXH = 4; .bool no_respawn_option; .bool cannot_respawn; .bool summoned; +.float vehicle_lifetime; // vehicle disappears instantly after this delay, set from spawn // vehicle functions .void(int _spawnflag) vehicle_spawn; /// Vehicles custom fucntion to be efecuted when vehicle (re)spawns -- 2.39.2