--[[
Chat Indicator
by Nicholas "Lavacano" O'Connor
Purpose: So people know when other people are typing.

Subfile: server.lua
Purpose: Define concommands for client_hooks.lua to run, spawn indicators,
	 etc.
]]

if CLIENT then
	error("Somehow, you got the server Lua for the typing indicator. That's not supposed to happen.")
	return nil
end

local tableoents = {}

-- The concommand for when someone STARTS typing
concommand.Add("TypingIndicator_On", function(ply, command, args)
	local IndicatorEnt = ents.Create("prop_physics")

	IndicatorEnt:SetMoveType(MOVETYPE_NONE)

	-- Set the model to the speech bubble thing.
	-- (TODO: GET MY MODEL, BITCH.)
	IndicatorEnt:SetModel("models/extras/info_speech.mdl")

	-- Angles to match the player's.
	IndicatorEnt:SetAngles(ply:GetAngles())

	-- Above the players head...let's say 100 units.
	IndicatorEnt:SetPos(ply:GetPos() + Vector(0,0,100))

	-- PARENT MEH
	IndicatorEnt:SetParent(ply)

	-- SPAWN MEH
	IndicatorEnt:Spawn()

	-- Save it in our table so we can delete it later.
	tableoents[ply:UniqueID()] = IndicatorEnt
end)

-- Now, in the event that they STOP typing (such as they send the message
-- or they change their mind and hit <ESC>), we have something simpler.

-- Just remove the indicator.
concommand.Add("TypingIndicator_Off", function(Ply, command, args) tableoents[Ply:UniqueID()]:Remove() end)
