From ac2524997ab83fd6b538127201eb7ccb06377896 Mon Sep 17 00:00:00 2001 From: Kimmy <127680179+KimmyTF2@users.noreply.github.com> Date: Sun, 19 Apr 2026 23:56:13 +0200 Subject: [PATCH] New Special Round | Magnetic Field Forces nearby players to move towards each other. Pull strength and distance between players can be tweaked if needed. This needs testing with other players to see how they react to the pull force and if something breaks, and I'm sure something will break. --- cfg/tf2ware_ultimate/specialrounds.cfg | 1 + .../default/specialrounds.nut | 1 + .../specialrounds/magnetic_field.nut | 60 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 scripts/vscripts/tf2ware_ultimate/specialrounds/magnetic_field.nut diff --git a/cfg/tf2ware_ultimate/specialrounds.cfg b/cfg/tf2ware_ultimate/specialrounds.cfg index a6ee2286..df6ecea3 100644 --- a/cfg/tf2ware_ultimate/specialrounds.cfg +++ b/cfg/tf2ware_ultimate/specialrounds.cfg @@ -14,6 +14,7 @@ hale hunger_update inclinity_problem low_gravity +magnetic_field math_only merasmus mirrored_world diff --git a/scripts/vscripts/tf2ware_ultimate/default/specialrounds.nut b/scripts/vscripts/tf2ware_ultimate/default/specialrounds.nut index fe7b3cc9..ac622f69 100644 --- a/scripts/vscripts/tf2ware_ultimate/default/specialrounds.nut +++ b/scripts/vscripts/tf2ware_ultimate/default/specialrounds.nut @@ -16,6 +16,7 @@ hale hunger_update inclinity_problem low_gravity +magnetic_field math_only merasmus mirrored_world diff --git a/scripts/vscripts/tf2ware_ultimate/specialrounds/magnetic_field.nut b/scripts/vscripts/tf2ware_ultimate/specialrounds/magnetic_field.nut new file mode 100644 index 00000000..f0d5b9a0 --- /dev/null +++ b/scripts/vscripts/tf2ware_ultimate/specialrounds/magnetic_field.nut @@ -0,0 +1,60 @@ +special_round <- Ware_SpecialRoundData +({ + name = "Magnetic Field" + author = "Kimmy" + description = "Nearby players are being pulled towards each other." + min_players = 2 + category = "" + convars = + { + tf_avoidteammates_pushaway = 0 + } +}) + +function OnUpdate() +{ + local dt = FrameTime() + local players = Ware_GetAlivePlayers() + + local maxDist = 250.0 // pull distance between players + local strength = 1000.0 // pull strength + + foreach (player in players) + { + if (!player.IsValid()) + continue + + local origin = player.GetOrigin() + local avgDir = Vector(0, 0, 0) + local totalWeight = 0.0 + + foreach (other in players) + { + if (other == player || !other.IsValid()) + continue + + local offset = other.GetOrigin() - origin + local dist = offset.Length() + + if (dist > maxDist || dist <= 5.0) + continue + + offset.z = 0 + offset.Norm() + + local weight = pow(1.0 - (dist / maxDist), 1.2) // pull strength based on distance to a player + + avgDir += offset * weight + totalWeight += weight + } + + if (totalWeight > 0.0) + { + local invWeight = 1.0 / totalWeight + avgDir *= invWeight + avgDir.Norm() + + player.ApplyAbsVelocityImpulse(avgDir * strength * dt) + } + } +} \ No newline at end of file