Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cfg/tf2ware_ultimate/specialrounds.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hale
hunger_update
inclinity_problem
low_gravity
magnetic_field
math_only
merasmus
mirrored_world
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ hale
hunger_update
inclinity_problem
low_gravity
magnetic_field
math_only
merasmus
mirrored_world
Expand Down
60 changes: 60 additions & 0 deletions scripts/vscripts/tf2ware_ultimate/specialrounds/magnetic_field.nut
Original file line number Diff line number Diff line change
@@ -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)
}
}
}