I'm creating a gamemode, and I need a function that checks the distance between a player from team 5 and player from team 1.
If the distance is more than 256, freeze the player on team 5, otherwise unfreeze.
I've been struggling to get this working, any help would be appreciated.
ok, tried a bit and i couldn't get it to work, here's my code:
function HostageFreeze( ply )
local hostage = team.GetPlayers(5)
local ct = team.GetPlayers(1)
if hostage:GetPos():Distance(ct:GetPos()) > 256 then
hostage:Freeze(true)
else
hostage:Freeze(false)
end
end
timer.Create("HostageFreezing", 0.1, 0, HostageFreeze)
I'm assuming that you always have one hostage and want to freeze him if none of the players on the other team are in range.
function FreezeHostage(hostage)
if not IsValid(hostage) then return end
local hostage_pos = hostage:GetPos()
local ct_players = team.GetPlayers(1)
for _, ct_player in pairs(ct_players) do
if not IsValid(ct_player) then continue end
local ct_player_pos = ct_player_pos:GetPos()
if hostage_pos:Distance(ct_player_pos) < 256 then hostage:Freeze(true) return end
end
hostage:Freeze(false)
end
I have one or more hostages at a time.
also, a new problem has showed up, player spawns are all wrong ( cts spawn wherever they want, terrorists spawn outside the map).
here's my cl_init.lua, init.lua and shared.lua code: [Lua] Gamemode
Sorry, you need to Log In to post a reply to this thread.