From 191d3bab77261d1e17af60739a191e43b398ac3a Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 21 Oct 2024 20:04:57 +0000 Subject: [PATCH] Add Spawn Unique mutator to prevent spawning at the same spawn point twice in a row --- mutators.cfg | 5 ++++ qcsrc/common/mutators/mutator/_mod.inc | 1 + qcsrc/common/mutators/mutator/_mod.qh | 1 + .../mutators/mutator/spawn_unique/_mod.inc | 4 ++++ .../mutators/mutator/spawn_unique/_mod.qh | 4 ++++ .../mutator/spawn_unique/sv_spawn_unique.qc | 23 +++++++++++++++++++ .../mutator/spawn_unique/sv_spawn_unique.qh | 5 ++++ 7 files changed, 43 insertions(+) create mode 100644 qcsrc/common/mutators/mutator/spawn_unique/_mod.inc create mode 100644 qcsrc/common/mutators/mutator/spawn_unique/_mod.qh create mode 100644 qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qc create mode 100644 qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qh diff --git a/mutators.cfg b/mutators.cfg index 7bf69658d..61e19ccb2 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -551,3 +551,8 @@ set g_pinata_offhand 0 "if enabled, the second weapon will drop as well while du // ========= set g_cloaked 0 "display all players mostly invisible" set g_balance_cloaked_alpha 0.25 "opacity of cloaked players" + +// ============== +// spawn unique +// ============== +set g_spawn_unique 0 "players cannot spawn at the same point twice in a row" diff --git a/qcsrc/common/mutators/mutator/_mod.inc b/qcsrc/common/mutators/mutator/_mod.inc index 924e442f3..d07e3eae5 100644 --- a/qcsrc/common/mutators/mutator/_mod.inc +++ b/qcsrc/common/mutators/mutator/_mod.inc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/_mod.qh b/qcsrc/common/mutators/mutator/_mod.qh index ad45ec8c9..be1ed7f13 100644 --- a/qcsrc/common/mutators/mutator/_mod.qh +++ b/qcsrc/common/mutators/mutator/_mod.qh @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/spawn_unique/_mod.inc b/qcsrc/common/mutators/mutator/spawn_unique/_mod.inc new file mode 100644 index 000000000..7bb6d977d --- /dev/null +++ b/qcsrc/common/mutators/mutator/spawn_unique/_mod.inc @@ -0,0 +1,4 @@ +// genmod.sh autogenerated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/spawn_unique/_mod.qh b/qcsrc/common/mutators/mutator/spawn_unique/_mod.qh new file mode 100644 index 000000000..c19bd6a56 --- /dev/null +++ b/qcsrc/common/mutators/mutator/spawn_unique/_mod.qh @@ -0,0 +1,4 @@ +// genmod.sh autogenerated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qc b/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qc new file mode 100644 index 000000000..2d32c51c9 --- /dev/null +++ b/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qc @@ -0,0 +1,23 @@ +#include "sv_spawn_unique.qh" + +REGISTER_MUTATOR(spawn_unique, expr_evaluate(autocvar_g_spawn_unique)); + +MUTATOR_HOOKFUNCTION(spawn_unique, Spawn_Score) +{ + entity player = M_ARGV(0, entity); + entity spawn_spot = M_ARGV(1, entity); + vector spawn_score = M_ARGV(2, vector); + + if(spawn_spot == player.su_last_point) + spawn_score.x = 0.1; // extremely low priority but still selectable + + M_ARGV(2, vector) = spawn_score; +} + +MUTATOR_HOOKFUNCTION(spawn_unique, PlayerSpawn) +{ + entity player = M_ARGV(0, entity); + entity spawn_spot = M_ARGV(1, entity); + + player.su_last_point = spawn_spot; +} diff --git a/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qh b/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qh new file mode 100644 index 000000000..fd4d5ee8d --- /dev/null +++ b/qcsrc/common/mutators/mutator/spawn_unique/sv_spawn_unique.qh @@ -0,0 +1,5 @@ +#pragma once + +string autocvar_g_spawn_unique; + +.entity su_last_point; -- 2.39.2