Advertisement
Guest User

init.lua

a guest
Jul 31st, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 KB | None | 0 0
  1. include("shared.lua")
  2.  
  3. -- Define GM12 fonts for compatibility
  4. surface.CreateFont("DefaultBold", {font = "Tahoma",
  5. size = 13,
  6. weight = 1000})
  7. surface.CreateFont("TabLarge", {font = "Tahoma",
  8. size = 13,
  9. weight = 700,
  10. shadow = true, antialias = false})
  11. surface.CreateFont("Trebuchet22", {font = "Trebuchet MS",
  12. size = 22,
  13. weight = 900})
  14.  
  15. include("scoring_shd.lua")
  16. include("corpse_shd.lua")
  17. include("player_ext_shd.lua")
  18. include("weaponry_shd.lua")
  19.  
  20. include("vgui/ColoredBox.lua")
  21. include("vgui/SimpleIcon.lua")
  22. include("vgui/ProgressBar.lua")
  23. include("vgui/ScrollLabel.lua")
  24.  
  25. include("cl_radio.lua")
  26. include("cl_disguise.lua")
  27. include("cl_transfer.lua")
  28. include("cl_targetid.lua")
  29. include("cl_search.lua")
  30. include("cl_radar.lua")
  31. include("cl_tbuttons.lua")
  32. include("cl_scoreboard.lua")
  33. include("cl_tips.lua")
  34. include("cl_help.lua")
  35. include("cl_hud.lua")
  36. include("cl_msgstack.lua")
  37. include("cl_hudpickup.lua")
  38. include("cl_keys.lua")
  39. include("cl_wepswitch.lua")
  40. include("cl_scoring.lua")
  41. include("cl_scoring_events.lua")
  42. include("cl_popups.lua")
  43. include("cl_equip.lua")
  44. include("cl_voice.lua")
  45.  
  46. function GM:Initialize()
  47. MsgN("TTT Client initializing...")
  48.  
  49. GAMEMODE.round_state = ROUND_WAIT
  50.  
  51. LANG.Init()
  52.  
  53. self.BaseClass:Initialize()
  54.  
  55. RunConsoleCommand("ttt_spectate", GetConVar("ttt_spectator_mode"):GetInt())
  56. end
  57.  
  58. function GM:InitPostEntity()
  59. MsgN("TTT Client post-init...")
  60.  
  61. if not game.SinglePlayer() then
  62. timer.Create("idlecheck", 5, 0, CheckIdle)
  63. end
  64.  
  65. -- make sure player class extensions are loaded up, and then do some
  66. -- initialization on them
  67. if IsValid(LocalPlayer()) and LocalPlayer().GetTraitor then
  68. GAMEMODE:ClearClientState()
  69. end
  70.  
  71. timer.Create("cache_ents", 1, 0, GAMEMODE.DoCacheEnts)
  72.  
  73. RunConsoleCommand("_ttt_request_serverlang")
  74. RunConsoleCommand("_ttt_request_rolelist")
  75. end
  76.  
  77. function GM:DoCacheEnts()
  78. RADAR:CacheEnts()
  79. TBHUD:CacheEnts()
  80. end
  81.  
  82. function GM:HUDClear()
  83. RADAR:Clear()
  84. TBHUD:Clear()
  85. end
  86.  
  87. KARMA = {}
  88. function KARMA.IsEnabled() return GetGlobalBool("ttt_karma", false) end
  89.  
  90. function GetRoundState() return GAMEMODE.round_state end
  91.  
  92. local function RoundStateChange(o, n)
  93. if n == ROUND_PREP then
  94. -- prep starts
  95. GAMEMODE:ClearClientState()
  96. GAMEMODE:CleanUpMap()
  97.  
  98. -- show warning to spec mode players
  99. if GetConVar("ttt_spectator_mode"):GetBool() and IsValid(LocalPlayer())then
  100. LANG.Msg("spec_mode_warning")
  101. end
  102.  
  103. -- reset cached server language in case it has changed
  104. RunConsoleCommand("_ttt_request_serverlang")
  105. elseif n == ROUND_ACTIVE then
  106. -- round starts
  107. VOICE.CycleMuteState(MUTE_NONE)
  108.  
  109. CLSCORE:ClearPanel()
  110.  
  111. -- people may have died and been searched during prep
  112. for _, p in pairs(player.GetAll()) do
  113. p.search_result = nil
  114. end
  115.  
  116. -- clear blood decals produced during prep
  117. RunConsoleCommand("r_cleardecals")
  118.  
  119. GAMEMODE.StartingPlayers = #util.GetAlivePlayers()
  120. elseif n == ROUND_POST then
  121. RunConsoleCommand("ttt_cl_traitorpopup_close")
  122. end
  123.  
  124. -- stricter checks when we're talking about hooks, because this function may
  125. -- be called with for example o = WAIT and n = POST, for newly connecting
  126. -- players, which hooking code may not expect
  127. if n == ROUND_PREP then
  128. -- can enter PREP from any phase due to ttt_roundrestart
  129. hook.Call("TTTPrepareRound", GAMEMODE)
  130. elseif (o == ROUND_PREP) and (n == ROUND_ACTIVE) then
  131. hook.Call("TTTBeginRound", GAMEMODE)
  132. elseif (o == ROUND_ACTIVE) and (n == ROUND_POST) then
  133. hook.Call("TTTEndRound", GAMEMODE)
  134. end
  135.  
  136. -- whatever round state we get, clear out the voice flags
  137. for k,v in pairs(player.GetAll()) do
  138. v.traitor_gvoice = false
  139. end
  140. end
  141.  
  142. concommand.Add("ttt_print_playercount", function() print(GAMEMODE.StartingPlayers) end)
  143.  
  144. --- optional sound cues on round start and end
  145. CreateConVar("ttt_cl_soundcues", "0", FCVAR_ARCHIVE)
  146.  
  147. local cues = {
  148. Sound("ttt/thump01e.mp3"),
  149. Sound("ttt/thump02e.mp3")
  150. };
  151. local function PlaySoundCue()
  152. if GetConVar("ttt_cl_soundcues"):GetBool() then
  153. surface.PlaySound(table.Random(cues))
  154. end
  155. end
  156.  
  157. GM.TTTBeginRound = PlaySoundCue
  158. GM.TTTEndRound = PlaySoundCue
  159.  
  160. --- usermessages
  161.  
  162. local function ReceiveRole()
  163. local client = LocalPlayer()
  164. local role = net.ReadUInt(2)
  165.  
  166. -- after a mapswitch, server might have sent us this before we are even done
  167. -- loading our code
  168. if not client.SetRole then return end
  169.  
  170. client:SetRole(role)
  171.  
  172. Msg("You are: ")
  173. if client:IsTraitor() then MsgN("TRAITOR")
  174. elseif client:IsDetective() then MsgN("DETECTIVE")
  175. else MsgN("INNOCENT") end
  176. end
  177. net.Receive("TTT_Role", ReceiveRole)
  178.  
  179. local function ReceiveRoleList()
  180. local role = net.ReadUInt(2)
  181. local num_ids = net.ReadUInt(8)
  182.  
  183. for i=1, num_ids do
  184. local eidx = net.ReadUInt(7) + 1 -- we - 1 worldspawn=0
  185.  
  186. local ply = player.GetByID(eidx)
  187. if IsValid(ply) and ply.SetRole then
  188. ply:SetRole(role)
  189.  
  190. if ply:IsTraitor() then
  191. ply.traitor_gvoice = false -- assume traitorchat by default
  192. end
  193. end
  194. end
  195. end
  196. net.Receive("TTT_RoleList", ReceiveRoleList)
  197.  
  198. -- Round state comm
  199. local function ReceiveRoundState()
  200. local o = GetRoundState()
  201. GAMEMODE.round_state = net.ReadUInt(3)
  202.  
  203. if o != GAMEMODE.round_state then
  204. RoundStateChange(o, GAMEMODE.round_state)
  205. end
  206.  
  207. MsgN("Round state: " .. GAMEMODE.round_state)
  208. end
  209. net.Receive("TTT_RoundState", ReceiveRoundState)
  210.  
  211. -- Cleanup at start of new round
  212. function GM:ClearClientState()
  213. GAMEMODE:HUDClear()
  214.  
  215. local client = LocalPlayer()
  216. if not client.SetRole then return end -- code not loaded yet
  217.  
  218. client:SetRole(ROLE_INNOCENT)
  219.  
  220. client.equipment_items = EQUIP_NONE
  221. client.equipment_credits = 0
  222. client.bought = {}
  223. client.last_id = nil
  224. client.radio = nil
  225. client.called_corpses = {}
  226.  
  227. VOICE.InitBattery()
  228.  
  229. for _, p in pairs(player.GetAll()) do
  230. if IsValid(p) then
  231. p.sb_tag = nil
  232. p:SetRole(ROLE_INNOCENT)
  233. p.search_result = nil
  234. end
  235. end
  236.  
  237. VOICE.CycleMuteState(MUTE_NONE)
  238. RunConsoleCommand("ttt_mute_team_check", "0")
  239.  
  240. if GAMEMODE.ForcedMouse then
  241. gui.EnableScreenClicker(false)
  242. end
  243. end
  244. net.Receive("TTT_ClearClientState", GM.ClearClientState)
  245.  
  246. function GM:CleanUpMap()
  247. -- Ragdolls sometimes stay around on clients. Deleting them can create issues
  248. -- so all we can do is try to hide them.
  249. for _, ent in pairs(ents.FindByClass("prop_ragdoll")) do
  250. if IsValid(ent) and CORPSE.GetPlayerNick(ent, "") != "" then
  251. ent:SetNoDraw(true)
  252. ent:SetSolid(SOLID_NONE)
  253. ent:SetColor(Color(0,0,0,0))
  254.  
  255. -- Horrible hack to make targetid ignore this ent, because we can't
  256. -- modify the collision group clientside.
  257. ent.NoTarget = true
  258. end
  259. end
  260.  
  261. -- This cleans up decals since GMod v100
  262. game.CleanUpMap()
  263. end
  264.  
  265. -- server tells us to call this when our LocalPlayer has spawned
  266. local function PlayerSpawn()
  267. local as_spec = net.ReadBit() == 1
  268. if as_spec then
  269. TIPS.Show()
  270. else
  271. TIPS.Hide()
  272. end
  273. end
  274. net.Receive("TTT_PlayerSpawned", PlayerSpawn)
  275.  
  276. local function PlayerDeath()
  277. TIPS.Show()
  278. end
  279. net.Receive("TTT_PlayerDied", PlayerDeath)
  280.  
  281. function GM:ShouldDrawLocalPlayer(ply) return false end
  282.  
  283. local view = {origin = vector_origin, angles = angle_zero, fov=0}
  284. function GM:CalcView( ply, origin, angles, fov )
  285. view.origin = origin
  286. view.angles = angles
  287. view.fov = fov
  288.  
  289. -- first person ragdolling
  290. if ply:Team() == TEAM_SPEC and ply:GetObserverMode() == OBS_MODE_IN_EYE then
  291. local tgt = ply:GetObserverTarget()
  292. if IsValid(tgt) and (not tgt:IsPlayer()) then
  293. -- assume if we are in_eye and not speccing a player, we spec a ragdoll
  294. local eyes = tgt:LookupAttachment("eyes") or 0
  295. eyes = tgt:GetAttachment(eyes)
  296. if eyes then
  297. view.origin = eyes.Pos
  298. view.angles = eyes.Ang
  299. end
  300. end
  301. end
  302.  
  303.  
  304. local wep = ply:GetActiveWeapon()
  305. if IsValid(wep) then
  306. local func = wep.CalcView
  307. if func then
  308. view.origin, view.angles, view.fov = func( wep, ply, origin*1, angles*1, fov )
  309. end
  310. end
  311.  
  312. return view
  313. end
  314.  
  315. function GM:AddDeathNotice() end
  316. function GM:DrawDeathNotice() end
  317.  
  318. function GM:Tick()
  319. local client = LocalPlayer()
  320. if IsValid(client) then
  321. if client:Alive() and client:Team() != TEAM_SPEC then
  322. WSWITCH:Think()
  323. RADIO:StoreTarget()
  324. end
  325.  
  326. VOICE.Tick()
  327. end
  328. end
  329.  
  330.  
  331. -- Simple client-based idle checking
  332. local idle = {ang = nil, pos = nil, mx = 0, my = 0, t = 0}
  333. function CheckIdle()
  334. local client = LocalPlayer()
  335. if not IsValid(client) then return end
  336.  
  337. if not idle.ang or not idle.pos then
  338. -- init things
  339. idle.ang = client:GetAngles()
  340. idle.pos = client:GetPos()
  341. idle.mx = gui.MouseX()
  342. idle.my = gui.MouseY()
  343. idle.t = CurTime()
  344.  
  345. return
  346. end
  347.  
  348. if GetRoundState() == ROUND_ACTIVE and client:IsTerror() and client:Alive() then
  349. local idle_limit = GetGlobalInt("ttt_idle_limit", 300) or 300
  350. if idle_limit <= 0 then idle_limit = 300 end -- networking sucks sometimes
  351.  
  352.  
  353. if client:GetAngles() != idle.ang then
  354. -- Normal players will move their viewing angles all the time
  355. idle.ang = client:GetAngles()
  356. idle.t = CurTime()
  357. elseif gui.MouseX() != idle.mx or gui.MouseY() != idle.my then
  358. -- Players in eg. the Help will move their mouse occasionally
  359. idle.mx = gui.MouseX()
  360. idle.my = gui.MouseY()
  361. idle.t = CurTime()
  362. elseif client:GetPos():Distance(idle.pos) > 10 then
  363. -- Even if players don't move their mouse, they might still walk
  364. idle.pos = client:GetPos()
  365. idle.t = CurTime()
  366. elseif CurTime() > (idle.t + idle_limit) then
  367. RunConsoleCommand("say", "(AUTOMATED MESSAGE) I have been moved to the Spectator team because I was idle/AFK.")
  368.  
  369. timer.Simple(0.3, function()
  370. RunConsoleCommand("ttt_spectator_mode", 1)
  371. RunConsoleCommand("ttt_cl_idlepopup")
  372. end)
  373. elseif CurTime() > (idle.t + (idle_limit / 2)) then
  374. -- will repeat
  375. LANG.Msg("idle_warning")
  376. end
  377. end
  378. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement