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