
-- Rambo_6
----------------------------------------------------------------------------------
-- THE STALKER 1.0 LUA CODE (yes, i know it is messy :P )
----------------------------------------------------------------------------------
-- PLEASE DON'T TAKE THESE CODES WITHOUT ASKING PERMISSION!  )
----------------------------------------------------------------------------------
-- This entire script defines the default game rules.
----------------------------------------------------------------------------------
-- ...HOW TO MAKE A MAP FOR THE STALKER:

-- MAKE SPAWN AREAS FOR EACH TEAM (Blue is I.R.I.S, red is The Stalker)

-- USE THE gmod_player_start ENTITIES

-- PLACE A gmod_gamesetup ENTITY ANYWHERE IN THE MAP

-- MAKE SURE IT IS SET TO RUN: "TheStalker/init.lua"

-- BE SURE THE MAP HAS LOTS OF DARK AREAS, AND SOME LIGHT AREAS TOO!

-- FEEL FREE TO MAKE SOME HIDING SPOTS (LEDGES, ETC ) FOR STALKER TO HIDE ON!
----------------------------------------------------------------------------------
-- Patched by JetBoom
-- Thank you Jetty! :D

----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
-- PLEASE DO NOT EDIT BELOW THIS LINE, UNLESS YOU KNOW WHAT YOU'RE DOING.
----------------------------------------------------------------------------------
-- RagDoll pickup/eating system + Stalker use pickup by JetBoom

PHYSMULTI = 5.2
PHYSMULTI=PHYSMULTI*TICKRATE
_OpenScript("gamemodes/TheStalker/admin.lua")

fIntermissionEnd = _CurTime() + IntermissionTime
bEndGame = false
RoundsDone = 0
------------------------------------------------------------------
StalkerHolding = 0
function gamerulesThink()
	local userid = 0
	for i=1, _MaxPlayers() do
		if _player.GetFlashlight(i) then
			if _PlayerInfo(i, "team") == TEAM_BLUE and players[i].bSecond == 5 then
				players[i].bPickup = true
			else
				_PlayerSetFlashlight(i, false)
			end
		end
		if _PlayerInfo(i, "team") == TEAM_RED then userid = i end
	end
	if StalkerHolding > 0 then
		if not _EntExists(StalkerHolding) or userid <= 0 then
			StalkerHolding = 0
			return
		end
		if not _PlayerIsKeyDown(userid, IN_USE) or not IsInRadius(StalkerHolding, userid, 143) then
			StalkerHolding = 0
			return
		end
		local endpos = vecAdd(_PlayerGetShootPos(userid), vecMul(_PlayerGetShootAng(userid), vector3(40,40,40)))
		local entvec = vecNormalize(vecSub(endpos, _EntGetPos(StalkerHolding)))
		_phys.ApplyForceCenter(StalkerHolding, vecMul(entvec, vector3(_phys.GetMass(StalkerHolding)*PHYSMULTI, _phys.GetMass(StalkerHolding)*PHYSMULTI, _phys.GetMass(StalkerHolding)*PHYSMULTI*3.0)))
		_EntitySetPhysicsAttacker(StalkerHolding, userid)
	end
	if fIntermissionEnd < _CurTime() then
		if bEndGame then
			_StartNextLevel()
		else
			StartNextRound()
		end
	end
end

function CheckCorpseExplode(x, y, z)
	local ents = _EntitiesFindInSphere(vector3(x, y, z), 125)
	for k,i in ents do
		if IsPlayer(i) then
			if not Gibbed[i] then
				if IsPlayerOnline(i) and not _PlayerInfo(i, "alive") then
					Gib(i)
				end
			end
		end
	end
end

function IsInRadius(a, b, dist)
	return math.abs(vecLength(vecSub(_EntGetPos(a),_EntGetPos(b)))) <= dist
end

function PickDefaultSpawnTeam(userid)
	if _TeamNumPlayers(TEAM_RED) < 1 then
		_PlayerChangeTeam(userid, TEAM_RED)
	elseif _TeamNumPlayers(TEAM_BLUE) < 2 then
		_PlayerChangeTeam(userid, TEAM_BLUE)
		_GModText_Start("HudHintTextLarge")
		_GModText_SetPos(0.32, 0.76)
		_GModText_SetTime(30, 0.3, 0.3)
		_GModText_SetText("Press a number from 1 - 4 to continue.")
		_GModText_SetColor(250, 250, 250, 190)
		_GModText_Send(userid, 166)
	else
		_PlayerChangeTeam(userid, TEAM_SPECTATOR)
	end
	return true
end

function eventPlayerActive(name,userid,steamid)
	_EntSetKeyValue(userid, "rendermode", "1")
end

function StartNextRound()
	if not called then
		called = true
		local reps = 0
		while reps < 100 and _TeamNumPlayers(TEAM_BLUE) < 9 do
			reps = reps + 1
			local m = math.random(1, _MaxPlayers())
			if IsPlayerOnline(m) then
				if _PlayerInfo(m, "team") == TEAM_SPECTATOR then
					_PlayerChangeTeam(m, TEAM_BLUE)
				end
			end
		end
		for i=1, _MaxPlayers() do
			_PlayerRespawn(i)
			_PlayerGod(i, false)
		end
		_PrintMessageAll(3, "Picking a random bunch of people (8) to play IRIS side.")
		_PrintMessageAll(2, "Picking a random bunch of people (8) to play IRIS side.")
		_Msg("Round begins...\n")
	end
end

function StartIntermission()
	NDB.GlobalSave()
	called = false
	fIntermissionEnd = _CurTime() + IntermissionTime + 10
	RoundsDone = RoundsDone + 1
	if RoundsDone == MaxRounds then
		for i=1, _MaxPlayers() do
			_PlayerShowScoreboard(i)
			_PlayerLockInPlace(i, true)
			bEndGame = true
		end	
	end
end

function gamerulesStartMap ()
	bEndGame = false
	RoundsDone = 0
	chosen = false
	_GameSetTargetIDRules( TRGTID_TEAMONLY )
	_TeamSetName( TEAM_BLUE, "I.R.I.S." )
	_TeamSetName( TEAM_SPECTATOR, "KiA" )
	_TeamSetName( TEAM_GREEN, "MiA" )
	_TeamSetName( TEAM_YELLOW, "MiA" )
	_TeamSetName( TEAM_RED, "Stalker" )

	_Msg("\n")
	_Msg("- The Stalker\n")
	_Msg("- by Rambo_6 + JetBoom\n\n")

	for i=1, _MaxPlayers() do
		_PlayerLockInPlace( i, false )
	end
end

function PlayerSpawnChooseModel(playerid)
	if _PlayerInfo(playerid, "team") == TEAM_RED then
		_PlayerSetModel(playerid,"models/player/stalker.mdl")
	else
		_PlayerSetModel(playerid,"models/player/police.mdl")
	end
end

players={}
for i = 1,_MaxPlayers() do
 	table.insert(players,i,i)
	players[i] = {bPickup,bSecond,bSSecond}
	players[i].bPickup = _CurTime()
	players[i].bSecond = 1
	players[i].bSSecond = 1
	players[i].Spectating = 1
	players[i].SpecSpam = 0
end
    
function PlayerMaxSpeedTimer(userid, speed)
	AddTimer(0.1, 1, _PlayerSetMaxSpeed, userid, speed)
end

TeamLimit = true
function GiveDefaultItems(playerid)
 	if _PlayerInfo(playerid, "team") == TEAM_BLUE then
		if players[playerid].bSecond == 1 then 
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_P228.lua" )
		elseif players[playerid].bSecond == 2 then
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_SOCOM.lua" )
		elseif players[playerid].bSecond == 3 then
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_deagle.lua" )
		elseif players[playerid].bSecond == 4 then
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_Medikit.lua" )
		elseif players[playerid].bSecond == 5 then
			players[playerid].bPickup = true
		end
    elseif _PlayerInfo(playerid, "team") == TEAM_RED then
    	_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_stalker.lua" )
		if players[playerid].bSSecond == 1 then 
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_fragnade.lua" )
		elseif players[playerid].bSSecond == 2 then
			_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_Smokenade.lua" )
		end
   	end
end
	
function CheckTeamStat(userid)
	if _PlayerInfo(userid, "team") == TEAM_BLUE then
		if _TeamNumPlayers(TEAM_RED) < 1 then
			_PlayerChangeTeam(userid, TEAM_RED)
		end
	elseif _PlayerInfo(userid, "team") == TEAM_RED then
		if _TeamNumPlayers(TEAM_RED) > 1 then
			_PlayerChangeTeam(userid, TEAM_BLUE)
		end
	end
end

TorsoModels = {}
TorsoModels[1] = "models/Zombie/Classic_torso.mdl"
TorsoModels[2] = "models/Humans/Charple03.mdl"
_EntPrecacheModel("models/Zombie/Classic_torso.mdl")
_EntPrecacheModel("models/Humans/Charple03.mdl")

LegModels = {}
LegModels[1] = "models/Zombie/Classic_legs.mdl"
LegModels[2] = "models/Gibs/Fast_Zombie_Legs.mdl"
_EntPrecacheModel("models/Zombie/Classic_legs.mdl")
_EntPrecacheModel("models/Gibs/Fast_Zombie_Legs.mdl")

GibModels = {}
GibModels[1]="models/Gibs/Antlion_gib_medium_1.mdl"
GibModels[2]="models/Gibs/Antlion_gib_small_1.mdl"
GibModels[3]="models/Gibs/Antlion_gib_medium_2.mdl"
GibModels[4]="models/Gibs/Antlion_gib_medium_3.mdl"
GibModels[5]="models/Gibs/Antlion_gib_small_1.mdl"
GibModels[6]="models/Gibs/Antlion_gib_small_2.mdl"

_EntPrecacheModel("models/Gibs/Antlion_gib_medium_1.mdl")
_EntPrecacheModel("models/Gibs/Antlion_gib_small_1.mdl")
_EntPrecacheModel("models/Gibs/Antlion_gib_medium_2.mdl")
_EntPrecacheModel("models/Gibs/Antlion_gib_medium_3.mdl")
_EntPrecacheModel("models/Gibs/Antlion_gib_small_1.mdl")
_EntPrecacheModel("models/Gibs/Antlion_gib_small_2.mdl")
_EntPrecacheModel("models/gibs/HGIBS.mdl")
_EntPrecacheModel("models/gibs/HGIBS_rib.mdl")
_EntPrecacheModel("models/gibs/HGIBS_rib.mdl")
_EntPrecacheModel("models/gibs/HGIBS_rib.mdl")
_EntPrecacheModel("models/gibs/HGIBS_scapula.mdl")
_EntPrecacheModel("models/gibs/HGIBS_spine.mdl")

Gibbed = {}
for i=1, _MaxPlayers() do
	Gibbed[i] = false
end

function Gib(killed)
	if Gibbed[killed] then return end
	Gibbed[killed] = true
	_TraceLine(_EntGetPos(killed), vector3(0,0,-1), 100, killed)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
	end
	local velocity = vecLength(_EntGetVelocity(killed)) + 30
	Gibbed[killed] = true
	local ent = _EntCreate("env_shooter")
	if ent > 0 then
		_EntSetPos(ent, _EntGetPos(killed))
		_EntSetKeyValue(ent, "m_iGibs", "1")
		_EntSetKeyValue(ent, "m_flVelocity", velocity)
		_EntSetKeyValue(ent, "shootmodel", LegModels[math.random(1,2)])
		_EntSetKeyValue(ent, "m_flVariance", "5.0")
		_EntSetKeyValue(ent, "simulation", "2")
		_EntSpawn(ent)
		_EntFire(ent, "shoot", "", 0)
		_EntFire(ent, "kill", "", 1)
	end
	local ent = _EntCreate("env_shooter")
	if ent > 0 then
		_EntSetPos(ent, _EntGetPos(killed))
		_EntSetKeyValue(ent, "m_iGibs", "1")
		_EntSetKeyValue(ent, "m_flVelocity", velocity)
		_EntSetKeyValue(ent, "shootmodel", TorsoModels[math.random(1,2)])
		_EntSetKeyValue(ent, "m_flVariance", "5.0")
		_EntSetKeyValue(ent, "simulation", "2")
		_EntSpawn(ent)
		_EntFire(ent, "shoot", "", 0)
		_EntFire(ent, "kill", "", 1)
	end
	_EffectInit()
	_EffectSetOrigin(_EntGetPos(killed))
	_EffectSetScale(8)
	_EffectSetFlags(9)
	_EffectDispatch("bloodspray")
	_EffectDispatch("bloodspray")
	_EffectDispatch("bloodspray")
	local gibstospawn = {}
	for i=1, 3 do
		 gibstospawn[table.getn(gibstospawn)+1] = GibModels[math.random(1, table.getn(GibModels))]
	end
	for i in gibstospawn do
		local gib = _EntCreate("prop_physics")
		if gib > 0 then
			_EntSetModel(gib, gibstospawn[i])
			_EntSetKeyValue(gib, "spawnflags", "4")
			_EntSetPos(gib, vecAdd(_EntGetPos(killed), vector3(math.random(-10,10),math.random(-10,10),math.random(10,30))))
			_EntSetAngAngle(gib, vector3(math.random(0,359), math.random(0,359), math.random(0,359)))
			_EntSetKeyValue(gib, "physdamagescale", "1500")
			_EntSetName(gib, "gibs")
			_EntSpawn(gib)
			_EntFire(gib, "AddOutput", "onhealthchanged GibHitWall,RunScript,,0,3", 0)
			_phys.ApplyForceCenter(gib, vecAdd(vecMul(_EntGetVelocity(killed), 12), vector3(math.random(-2000, 2000), math.random(-2000, 2000), math.random(0, 2000))))
			_phys.ApplyTorqueCenter(gib, vector3(math.random(-10500, 10500), math.random(-10500, 10500), math.random(-3000, 13000)))
			_EntFire(gib, "kill", "", 7.5)
			local trail = _EntCreate("env_smoketrail")
			if trail > 0 then
				_EntSetPos(trail, _EntGetPos(gib))
				_EntSetKeyValue(trail, "spawnrate", "22")
				_EntSetKeyValue(trail, "lifetime", "1.2")
				_EntSetKeyValue(trail, "startcolor", "255 0 0")
				_EntSetKeyValue(trail, "endcolor", "255 0 0")
				_EntSetKeyValue(trail, "minspeed", "0")
				_EntSetKeyValue(trail, "maxspeed", "0")
				_EntSetKeyValue(trail, "startsize", "6")
				_EntSetKeyValue(trail, "endsize", "9")
				_EntSetKeyValue(trail, "spawnradius", "2")
				_EntSetKeyValue(trail, "firesprite", "sprites/redglow3.spr")
				_EntSetKeyValue(trail, "smokesprite", "sprites/redglow3.spr")
				_EntSpawn(trail)
				_EntSetParent(trail, gib)
				_EntFire(trail, "kill", "", 4.0)
			end
		end
	end
	_EntEmitSoundEx(killed, "physics/flesh/flesh_bloody_break.wav", 1.0, 0.75)
	AddTimer(0.1, 1, _PlayerSilentKill, killed, 1.5, true)
end

function GibHitWall(hit, gib)
	_TraceLine(_EntGetPos(gib), vector3(0,0,-1), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(0,0,1))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_TraceLine(_EntGetPos(gib), vector3(0,0,1), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(0,0,-1))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_TraceLine(_EntGetPos(gib), vector3(1,0,0), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(-1,0,0))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_TraceLine(_EntGetPos(gib), vector3(-1,0,0), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(1,0,0))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_TraceLine(_EntGetPos(gib), vector3(0,1,0), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(0,-1,0))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_TraceLine(_EntGetPos(gib), vector3(0,-1,0), 32, gib)
	if _TraceHit() then
		_MakeDecal(math.random(46,51))
		_EffectInit()
		 _EffectSetOrigin(_EntGetPos(gib))
		 _EffectSetNormal(vector3(0,1,0))
		 _EffectSetScale(7)
		 _EffectSetFlags(9)
		_EffectDispatch("bloodspray")
		_EffectDispatch("bloodspray")
	end
	_EntEmitSound(gib, "physics/flesh/flesh_bloody_impact_hard1.wav")
end
MakeFunction("GibHitWall")

function onTakeDamage(ent, inflictor, attacker, damage)
	if _EntGetType(ent) == "player" then
		if _PlayerInfo(ent, "team") == TEAM_RED then
			if attacker == 0 and damage == 10 then
				_PlayerSetHealth(ent, _PlayerInfo(ent,"health")+10)
			elseif damage >= _PlayerInfo(ent, "health")+25 then
				Gib(ent)
			end
		elseif damage >= _PlayerInfo(ent, "health")+25 then
			if IsPlayer(attacker) then
				if _PlayerInfo(attacker, "team") ~= _PlayerInfo(ent, "team") or ent == attacker then
					Gib(ent)
				end
			else
				Gib(ent)
			end
		end
	end
end

function eventPlayerSpawn(userid)
	Gibbed[userid] = false
	players[userid].bPickup = _CurTime()
	_player.ShouldDropWeapon(userid, false)
	AddTimer(0.1, 1, _PlayerEnableSprint, userid, false)
	CheckTeamStat(userid)
	players[userid].bPickup = false
	_EntFire(userid, "alpha", "255", 0)
	if _PlayerInfo(userid, "team") == TEAM_BLUE then
		_PlayerFreeze(userid, true)
		_PlayerSetMaxSpeed(userid, HumanSpeed)
		MakeMenu(userid)
		_PlayerSetDrawWorldModel(userid, true)
	elseif _PlayerInfo(userid, "team") == TEAM_RED then
		_PlayerSetDrawWorldModel(userid, false)
		_PlayerSetMaxSpeed(userid, 240)
		_PlayerSetHealth(userid, StalkerHp)
		_EntSetKeyValue(userid, "rendermode", "1")
		_EntFire(userid, "Alpha", "10", 0)
	else
		_GModText_Hide(userid, 2, 0.4, 0)
		_GModText_Hide(userid, 3, 0.4, 0)
		_GModText_Hide(userid, 4, 0.4, 0)
		_GModText_Hide(userid, 166, 0.4, 0)
		_PlayerFreeze(userid, false)
	end
	if TeamLimit then
		if _PlayerInfo(userid, "team") ~= TEAM_BLUE and _PlayerInfo(userid, "team") ~= TEAM_RED and _PlayerInfo(userid, "team") ~= TEAM_SPECTATOR then
			_PlayerChangeTeam(userid, TEAM_BLUE)
		end
	end
end

	
jumptime = _CurTime()
function eventKeyPressed(userid, key)
	if key == IN_SPEED then
		_PlayerEnableSprint(userid, false)
		if _PlayerInfo(userid,"team") == TEAM_RED then
			if jumptime <= _CurTime() then
				_PlayerSetMaxSpeed(userid, StalkerSpeed)
				_TraceSetMask(MASK_ALL)
				_TraceLine( _PlayerGetShootPos( userid ), vector3(0,0,-90), 72, userid )
				if _TraceHit() then
					_EntEmitSound(userid,"npc/stalker/stalker_footstep_right"..math.random(1,2)..".wav")
					local jumpvec1 = vecAdd(_EntGetVelocity(userid), vecMul( _PlayerGetShootAng(userid), vector3(400, 400, 450)))
					local jumpvec2 =  vecAdd(jumpvec1,vector3(0,0,500))
					_EntSetVelocity(userid,jumpvec2)
					jumptime = _CurTime() + 1.5
				end
			end
		end
   elseif _PlayerInfo(userid,"team") == TEAM_SPECTATOR then
		if key == IN_ATTACK then
			if _CurTime() < players[userid].SpecSpam then return end
			PlayerLookTrace(userid, 9999)
			for _, i in _EntitiesFindInSphere(_TraceEndPos(), 128) do
				if IsPlayerOnline(i) and _PlayerInfo(i, "team") ~= TEAM_SPECTATOR and _PlayerInfo(i, "team") ~= TEAM_RED and players[userid].Spectating ~= i then
					_PlayerSpectatorStart(userid, OBS_MODE_CHASE)
					_PlayerSetChaseCamDistance(userid, 64)
					_PlayerSpectatorTarget(userid, i)
					players[userid].Spectating = i
					players[userid].SpecSpam = _CurTime() + 2
					_PrintMessage(userid, 4, "Now spectating: ".._PlayerInfo(i, "name"))
					return
				end
			end
		elseif key == IN_ATTACK2 then
			if _CurTime() < players[userid].SpecSpam then return end
			players[userid].SpecSpam = _CurTime() + 2
			_PlayerSpectatorStart(userid, OBS_MODE_ROAMING)
			_PrintMessage(userid, 4, "Free Camera")
		end
   end
end

function eventPlayerUseEntity(userid, entity)
	if _PlayerInfo(userid,"team") == TEAM_RED then
		if _EntGetName(entity) == "gibs" then
			if not IsInRadius(userid, entity, 120) then return true end
			local maxhealth = 125
			local health = _PlayerInfo(userid, "health")
			if health < maxhealth then
				_PlayerSetHealth(userid, health+(math.ceil(maxhealth*0.1)))
				if _PlayerInfo(userid, "health") > maxhealth then
					_PlayerSetHealth(userid, maxhealth)
				end
				_EntEmitSound(entity, "physics/body/body_medium_break"..math.random(2, 4)..".wav")
				_EntFire(entity, "kill", "", 0.01)
				return true
			end
		elseif _phys.GetMass(entity) <= 175 and _EntGetType(entity) == "prop_physics" then
			StalkerHolding = entity
			_EntitySetPhysicsAttacker(entity, userid)
			return true
		end
	end
	return false
end

function eventPlayerDisconnect(name, userid, address, steamid, reason)
	if _PlayerInfo(userid, "team") == TEAM_RED then
		StartNextRound()
	end
end

function eventPlayerKilled(killed, attacker, weapon)
	_PlayerAddDeath(killed, 1)
	if killed == attacker then
		_PlayerChangeTeam(killed, TEAM_SPECTATOR)
		if _TeamNumPlayers(TEAM_BLUE) <= 0 then
			StartIntermission()
			_PrintMessageAll(3, "The Stalker won the round!")
			_PlayerAddScore(killed, -1)
		elseif _TeamNumPlayers(TEAM_RED) == 0 then
			StartIntermission()
			_PrintMessageAll(3, "I.R.I.S won the round!")
			local stk = killed
			for i=1, _MaxPlayers() do
				if IsPlayerOnline(i) and killed ~= i then
					stk = i
				end
			end
			pname = _PlayerInfo(stk, "name")
			_PrintMessageAll(3, pname.." is now The Stalker...")
			_PlayerChangeTeam(stk, TEAM_RED)
			for i=1, _MaxPlayers() do
				_PlayerGod(i, true)
			end
		end
	elseif _PlayerInfo(killed,"team") == TEAM_RED then
		StartIntermission()
		_PrintMessageAll(3, "I.R.I.S won the round!")
		pname = _PlayerInfo(attacker, "name")
		_PrintMessageAll(3, pname.." is now The Stalker...")
		_PlayerChangeTeam(killed, TEAM_BLUE)
		_PlayerChangeTeam(attacker, TEAM_RED)
		_PlayerAddScore(attacker, 2)
		if IsPlayer(attacker) then
			NDB.AddMoney(attacker, 250)
		end
		for i = 1,  _MaxPlayers() do
			_PlayerGod(i, true)
		end
	elseif _PlayerInfo(killed,"team") == TEAM_BLUE and _PlayerInfo(attacker,"team") ~= TEAM_RED then
		_PlayerChangeTeam(killed, TEAM_SPECTATOR)
	elseif _PlayerInfo(killed,"team") == TEAM_BLUE and _PlayerInfo(attacker,"team") == TEAM_RED then
		_PlayerChangeTeam(killed, TEAM_SPECTATOR)
		if _TeamNumPlayers(TEAM_BLUE) <= 0 then
			StartIntermission()
			_PrintMessageAll(3, "The Stalker won $250!")
			_PlayerAddScore(attacker, 2)
			NDB.AddMoney(attacker, 250)
		end
	else
		if _PlayerInfo(killed,"team") == TEAM_RED and (attacker <= 0 or attacker > _MaxPlayers()) then
			for i=1, _MaxPlayers() do
				if _PlayerInfo(i, "team") == TEAM_BLUE then attacker = i end
			end
			StartIntermission()
			_PrintMessageAll(3, "I.R.I.S won the round!")
			pname = _PlayerInfo(attacker, "name")
			_PrintMessageAll(3, pname.." is now The Stalker...")
			NDB.AddMoney(attacker, 250)
			_PlayerChangeTeam(killed, TEAM_BLUE)
			_PlayerChangeTeam(attacker, TEAM_RED)
			for i = 1,  _MaxPlayers() do
				_PlayerGod(i, true)
			end
		end
	end
end

function MakeMenu(UID)
	_GModText_Start("BudgetLabel")
	 _GModText_SetPos(0.09, 0.03)
	 _GModText_SetTime(9999, 0.4, 0.4)
	 _GModText_SetText("The Stalker")
	 _GModText_SetColor(176, 0, 0, 250)
	_GModText_Send(UID, 2)

	_GModText_Start("BudgetLabel")
	 _GModText_SetPos(0.09, 0.06)
	 _GModText_SetTime(9999, 0.4, 0.4)
	 _GModText_SetText("By Rambo_6 and JetBoom\n\nPress F1 for help.")
	 _GModText_SetColor(250, 250, 240, 240)
	_GModText_Send(UID, 3)

	_GModText_Start("BudgetLabel")
	 _GModText_SetPos(0.09, 0.18)
	 _GModText_SetTime(99999, 1, 0.4)
	 --_GModText_SetText("1)Sig 552\n2)SPAS-12\n3)FN-P90\n4)FA MAS-C\n")
	 _GModText_SetText("1)Sig 552\n2)FN-P90\n3)FA MAS-C\n")
	 _GModText_SetColor(250, 250, 190, 255)
	 _GModText_Send(UID, 4)
	_PlayerOption(UID, "PlayerChoose", 99999)
end

-- Opening menu, now pick a gun!
function PlayerChoose(playerid, num, seconds)
_GModText_Hide(playerid, 2, 0.4, 0)
_GModText_Hide(playerid, 3, 0.4, 0)
_GModText_Hide(playerid, 4, 0.4, 0)
_GModText_Hide(playerid, 166, 0.4, 0)
_PlayerFreeze(playerid, false)
if _PlayerInfo(playerid, "team") == TEAM_SPECTATOR then return end

  if num == 1 then
	if not Sig552 then
		_PlaySoundPlayer( playerid, "common/bugreporter_failed.wav" )
	else
		_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_sg552.lua" )
		_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )
	end
 --[[ elseif num == 2 then
	if not Spas12 then
		_PlaySoundPlayer( playerid, "common/bugreporter_failed.wav" )
	else
		_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_Spas12.lua" )
		_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )
	end
	]]
  elseif num == 2 then
	if not P90 then
		_PlaySoundPlayer( playerid, "common/bugreporter_failed.wav" )
	else
		_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_p90.lua" )
		_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )
	end
   elseif num == 3 then
	if not Famas then
		_PlaySoundPlayer( playerid, "common/bugreporter_failed.wav" )
	else
		_PlayerGiveSWEP( playerid, "weapons/stalker/weapon_famas.lua" )
		_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )
	end
   end  
end

function PlayerHelpMenu(UID)
	_GModText_Start("Default")
	_GModText_SetPos(0.06, 0.13)
	_GModText_SetTime(13, 0.6, 0.5)
	_GModText_SetText("[RULES]\n\n-The objective is to kill the invisible Stalker!\n-If you die, you spectate until the round ends.\nRounds per map: "..MaxRounds..".\n")
	_GModText_SetColor(225, 225, 225, 222)
	_GModText_Send(UID,85)
	
	_GModText_Start("Default")
	_GModText_SetPos(0.06, 0.26)
	_GModText_SetTime(14, 0.6, 0.5)
	_GModText_SetText("[I.R.I.S. CONTROLS]\n\n-F3 is used for for choosing a secondary weapon.\n-Press F2 for a list of team chat sounds.\n")
	_GModText_SetColor(225, 225, 225, 222)
	_GModText_Send(UID,86)

	_GModText_Start("Default")
	_GModText_SetPos(0.06, 0.38)
	_GModText_SetTime(15, 0.6, 0.5)
	_GModText_SetText("[STALKER CONTROLS]\n\n-Stalkers can press the SPRINT key to do a big leap!\n-Stalkers can also climb stuff by right clicking.\n-Press F4 to choose your Stalker secondary weapon.")
	_GModText_SetColor(225, 225, 225, 222)
	_GModText_Send(UID,87)
end

function cc_limits(playerid,args)
	_PlaySoundPlayer( playerid, "HL1/fvox/boop.wav" )	
	_GModText_Start("Default")
	_GModText_SetPos(0.06, 0.65)
	_GModText_SetTime(16, 0.6, 0.5)
	_GModText_SetText("Time Limit: "..TimeLimit.." ~~~~~ Round Limit:"..MaxRounds)
	_GModText_SetColor(200, 1, 2, 190)
	_GModText_Send(UID,92)
end
CONCOMMAND ("limits", cc_limits)

function onShowHelp(userid)
	PlayerHelpMenu(userid)
end
	
	
function onShowTeam(userid)	
	if _PlayerInfo(userid,"team") == TEAM_BLUE then	
		PlayerVoMenu(userid)
	elseif _PlayerInfo(userid,"team") == TEAM_RED then	
		_EntEmitSound(userid,"npc/stalker/go_alert2a.wav")
	else
		_PlaySoundPlayer(userid, "weapons/pistol/pistol_reload1.wav")
	end
end
	
function PlayerVoMenu(UID)	

_GModText_Start("BudgetLabel")
_GModText_SetPos(0.80, 0.26)
_GModText_SetTime(9999, 0.3, 0.3)
_GModText_SetText("Radio Chat")
_GModText_SetColor(250, 250, 250, 240)
_GModText_Send(UID, 32)

_GModText_Start("BrandingSmall")
  _GModText_SetPos(0.80, 0.29)
  _GModText_SetTime(99999, 1, 0.4)
  _GModText_SetText("1.Affirmative\n2.Be prepared\n3.Resistance\n4.Need backup\n5.Cover me\n6.Engaging\n7.Area clear\n8.Copy that\n9.Stay alert")
  _GModText_SetColor(250, 250, 250, 255)
  _GModText_Send(UID, 33)
  _PlayerOption(UID, "PlayerChooseSound", 99999)
	
end


function RadioIn(sound)
	for i=1, _MaxPlayers() do
		if _PlayerInfo(i, "team") == TEAM_BLUE then
			_EntEmitSound(i, sound)
		end
	end
end

function PlayerChooseSound(playerid, num, seconds)

_GModText_Hide(playerid, 32, 0.4, 0)
_GModText_Hide(playerid, 33, 0.4, 0)

  if num == 1 then 
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/affirmative2.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 2 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/prepforcontact.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 3 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/heavyresistance.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 4 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/sectorisnotsecure.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 5 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/coverme.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 6 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/engagedincleanup.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 7 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/reportallpositionsclear.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 8 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/copythat.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  elseif num == 9 then
--RadioIn("npc/overwatch/radiovoice/on1.wav")
RadioIn("npc/combine_soldier/vo/stayalertreportsightlines.wav")
AddTimer(2,1,RadioIn,"npc/overwatch/radiovoice/off4.wav")
  end
end
   
	
function onShowSpare1(userid)
	PlayerSecMenu(userid)
end
	
function onShowSpare2(userid)
	PlayerStalkMenu(userid)
end
	
function PlayerStalkMenu(UID)
_GModText_Start("BudgetLabel")
_GModText_SetPos(0.80, 0.26)
_GModText_SetTime(9999, 0.3, 0.3)
_GModText_SetText("Pick a Stalker Weapon")
_GModText_SetColor(250, 250, 250, 240)
_GModText_Send(UID, 42)

_GModText_Start("BrandingSmall")
  _GModText_SetPos(0.80, 0.29)
  _GModText_SetTime(99999, 1, 0.4)
  _GModText_SetText("1.Grenade\n2.Smoke Bomb\n")
  _GModText_SetColor(250, 250, 250, 255)
  _GModText_Send(UID, 43)
  _PlayerOption(UID, "PlayerChooseSecStalk", 99999)
end
  
function PlayerChooseSecStalk(playerid, num, seconds)

--_GModRect_Hide(playerid, 41, 0.4, 0)
_GModText_Hide(playerid, 42, 0.4, 0)
_GModText_Hide(playerid, 43, 0.4, 0)

  if (num == 1) then 

players[playerid].bSSecond = 1

_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )

  end

  if (num == 2) then

players[playerid].bSSecond = 2

_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )

  end
  
end
	
function PlayerSecMenu(UID)
_GModText_Start("BudgetLabel")
_GModText_SetPos(0.80, 0.26)
_GModText_SetTime(9999, 0.3, 0.3)
_GModText_SetText("Pick a Secondary I.R.I.S. Weapon")
_GModText_SetColor(250, 250, 250, 240)
_GModText_Send(UID, 42)

_GModText_Start("BrandingSmall")
  _GModText_SetPos(0.80, 0.29)
  _GModText_SetTime(99999, 1, 0.4)
  _GModText_SetText("1.P228\n2.USSOCOM\n3.Desert Eagle\n4.Medikit\n5.Flashlight")
  _GModText_SetColor(250, 250, 250, 255)
  _GModText_Send(UID, 43)
  _PlayerOption(UID, "PlayerChooseSec", 99999)
  
  end
  
function PlayerChooseSec(playerid, num, seconds)
_GModText_Hide(playerid, 42, 0.4, 0)
_GModText_Hide(playerid, 43, 0.4, 0)

	if num <= 5 and num > 0 then
		players[playerid].bSecond = num
		_PlaySoundPlayer( playerid, "weapons/pistol/pistol_reload1.wav" )
	end
end

function GetPlayerDamageScale( hitgroup ) 
	if hitgroup == HITGROUP_HEAD then
		return 3.3
	elseif hitgroup == HITGROUP_LEFTARM or
			hitgroup == HITGROUP_RIGHTARM or
			hitgroup == HITGROUP_LEFTLEG or
			hitgroup == HITGROUP_RIGHTLEG then
		return 0.5
	end
	return 1.0
end
