Files
wnsrc/gamemodes/base/entities/entities/gmod_player_start.lua
lifestorm 94063e4369 Upload
2024-08-04 22:55:00 +03:00

92 lines
2.1 KiB
Lua

--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
-- This is just a simple point entity.
-- We only use it to represent the position and angle of a spawn point
-- So we don't have to do anything here because the baseclass will
-- take care of the basics
-- This file only exists so that the entity is created
ENT.Type = "point"
function ENT:Initialize()
if ( self.RedTeam or self.GreenTeam or self.YellowTeam or self.BlueTeam ) then
-- If any of these are set to true then
-- make sure that any that aren't setup are
-- set to false.
self.BlueTeam = self.BlueTeam or false
self.GreenTeam = self.GreenTeam or false
self.YellowTeam = self.YellowTeam or false
self.RedTeam = self.RedTeam or false
else
-- If none are set then make it so that they all
-- are set to true since any team can spawn here.
-- This will also happen if we don't have the "spawnflags"
-- keyvalue setup.
self.BlueTeam = true
self.GreenTeam = true
self.YellowTeam = true
self.RedTeam = true
end
end
function ENT:KeyValue( key, value )
if ( key == "spawnflags" ) then
local sf = tonumber( value )
for i = 15, 0, -1 do
local bit = math.pow( 2, i )
-- Quick bit if bitwise math to figure out if the spawnflags
-- represent red/blue/green or yellow.
-- We have to use booleans since the TEAM_ identifiers
-- aren't setup at this point.
-- (this would be easier if we had bitwise operators in Lua)
if ( ( sf - bit ) >= 0 ) then
if ( bit == 8 ) then self.RedTeam = true
elseif ( bit == 4 ) then self.GreenTeam = true
elseif ( bit == 2 ) then self.YellowTeam = true
elseif ( bit == 1 ) then self.BlueTeam = true
end
sf = sf - bit
else
if ( bit == 8 ) then self.RedTeam = false
elseif ( bit == 4 ) then self.GreenTeam = false
elseif ( bit == 2 ) then self.YellowTeam = false
elseif ( bit == 1 ) then self.BlueTeam = false
end
end
end
end
end