Advertisement
Guest User

player.lua

a guest
Apr 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.60 KB | None | 0 0
  1.  
  2. --[[---------------------------------------------------------
  3. Name: gamemode:OnPhysgunFreeze( weapon, phys, ent, player )
  4. Desc: The physgun wants to freeze a prop
  5. -----------------------------------------------------------]]
  6. function GM:OnPhysgunFreeze( weapon, phys, ent, ply )
  7.  
  8. -- Object is already frozen (!?)
  9. if ( !phys:IsMoveable() ) then return false end
  10. if ( ent:GetUnFreezable() ) then return false end
  11.  
  12. phys:EnableMotion( false )
  13.  
  14. -- With the jeep we need to pause all of its physics objects
  15. -- to stop it spazzing out and killing the server.
  16. if ( ent:GetClass() == "prop_vehicle_jeep" ) then
  17.  
  18. local objects = ent:GetPhysicsObjectCount()
  19.  
  20. for i = 0, objects - 1 do
  21.  
  22. local physobject = ent:GetPhysicsObjectNum( i )
  23. physobject:EnableMotion( false )
  24.  
  25. end
  26.  
  27. end
  28.  
  29. -- Add it to the player's frozen props
  30. ply:AddFrozenPhysicsObject( ent, phys )
  31.  
  32. return true
  33.  
  34. end
  35.  
  36. --[[---------------------------------------------------------
  37. Name: gamemode:OnPhysgunReload( weapon, player )
  38. Desc: The physgun wants to freeze a prop
  39. -----------------------------------------------------------]]
  40. function GM:OnPhysgunReload( weapon, ply )
  41.  
  42. ply:PhysgunUnfreeze( weapon )
  43.  
  44. end
  45.  
  46. --[[---------------------------------------------------------
  47. Name: gamemode:PlayerAuthed()
  48. Desc: Player's STEAMID has been authed
  49. -----------------------------------------------------------]]
  50. function GM:PlayerAuthed( ply, SteamID, UniqueID )
  51. end
  52.  
  53. --[[---------------------------------------------------------
  54. Name: gamemode:PlayerCanPickupWeapon()
  55. Desc: Called when a player tries to pickup a weapon.
  56. return true to allow the pickup.
  57. -----------------------------------------------------------]]
  58. function GM:PlayerCanPickupWeapon( ply, entity )
  59.  
  60. return true
  61.  
  62. end
  63.  
  64. --[[---------------------------------------------------------
  65. Name: gamemode:PlayerCanPickupItem()
  66. Desc: Called when a player tries to pickup an item.
  67. return true to allow the pickup.
  68. -----------------------------------------------------------]]
  69. function GM:PlayerCanPickupItem( ply, entity )
  70.  
  71. return true
  72.  
  73. end
  74.  
  75. --[[---------------------------------------------------------
  76. Name: gamemode:CanPlayerUnfreeze()
  77. Desc: Can the player unfreeze this entity & physobject
  78. -----------------------------------------------------------]]
  79. function GM:CanPlayerUnfreeze( ply, entity, physobject )
  80.  
  81. return true
  82.  
  83. end
  84.  
  85. --[[---------------------------------------------------------
  86. Name: gamemode:PlayerDisconnected()
  87. Desc: Player has disconnected from the server.
  88. -----------------------------------------------------------]]
  89. function GM:PlayerDisconnected( ply )
  90. end
  91.  
  92. --[[---------------------------------------------------------
  93. Name: gamemode:PlayerSay()
  94. Desc: A player (or server) has used say. Return a string
  95. for the player to say. Return an empty string if the
  96. player should say nothing.
  97. -----------------------------------------------------------]]
  98. function GM:PlayerSay( ply, text, teamonly )
  99.  
  100. return text
  101.  
  102. end
  103.  
  104.  
  105. --[[---------------------------------------------------------
  106. Name: gamemode:PlayerDeathThink( player )
  107. Desc: Called when the player is waiting to respawn
  108. -----------------------------------------------------------]]
  109. function GM:PlayerDeathThink( pl )
  110.  
  111. if ( pl.NextSpawnTime && pl.NextSpawnTime > CurTime() ) then return end
  112.  
  113. if ( pl:IsBot() || pl:KeyPressed( IN_ATTACK ) || pl:KeyPressed( IN_ATTACK2 ) || pl:KeyPressed( IN_JUMP ) ) then
  114.  
  115. pl:Spawn()
  116.  
  117. end
  118.  
  119. end
  120.  
  121. --[[---------------------------------------------------------
  122. Name: gamemode:PlayerUse( player, entity )
  123. Desc: A player has attempted to use a specific entity
  124. Return true if the player can use it
  125. ------------------------------------------------------------]]
  126. function GM:PlayerUse( ply, entity )
  127.  
  128. return true
  129.  
  130. end
  131.  
  132. --[[---------------------------------------------------------
  133. Name: gamemode:PlayerSilentDeath()
  134. Desc: Called when a player dies silently
  135. -----------------------------------------------------------]]
  136. function GM:PlayerSilentDeath( Victim )
  137.  
  138. Victim.NextSpawnTime = CurTime() + 2
  139. Victim.DeathTime = CurTime()
  140.  
  141. end
  142.  
  143. -- Pool network strings used for PlayerDeaths.
  144. util.AddNetworkString( "PlayerKilled" )
  145. util.AddNetworkString( "PlayerKilledSelf" )
  146. util.AddNetworkString( "PlayerKilledByPlayer" )
  147.  
  148. --[[---------------------------------------------------------
  149. Name: gamemode:PlayerDeath()
  150. Desc: Called when a player dies.
  151. -----------------------------------------------------------]]
  152. function GM:PlayerDeath( ply, inflictor, attacker )
  153.  
  154. -- Don't spawn for at least 2 seconds
  155. ply.NextSpawnTime = CurTime() + 2
  156. ply.DeathTime = CurTime()
  157.  
  158. if ( IsValid( attacker ) && attacker:GetClass() == "trigger_hurt" ) then attacker = ply end
  159.  
  160. if ( IsValid( attacker ) && attacker:IsVehicle() && IsValid( attacker:GetDriver() ) ) then
  161. attacker = attacker:GetDriver()
  162. end
  163.  
  164. if ( !IsValid( inflictor ) && IsValid( attacker ) ) then
  165. inflictor = attacker
  166. end
  167.  
  168. -- Convert the inflictor to the weapon that they're holding if we can.
  169. -- This can be right or wrong with NPCs since combine can be holding a
  170. -- pistol but kill you by hitting you with their arm.
  171. if ( IsValid( inflictor ) && inflictor == attacker && ( inflictor:IsPlayer() || inflictor:IsNPC() ) ) then
  172.  
  173. inflictor = inflictor:GetActiveWeapon()
  174. if ( !IsValid( inflictor ) ) then inflictor = attacker end
  175.  
  176. end
  177.  
  178. if ( attacker == ply ) then
  179.  
  180. net.Start( "PlayerKilledSelf" )
  181. net.WriteEntity( ply )
  182. net.Broadcast()
  183.  
  184. MsgAll( attacker:Nick() .. " suicided!\n" )
  185.  
  186. return end
  187.  
  188. if ( attacker:IsPlayer() ) then
  189.  
  190. net.Start( "PlayerKilledByPlayer" )
  191.  
  192. net.WriteEntity( ply )
  193. net.WriteString( inflictor:GetClass() )
  194. net.WriteEntity( attacker )
  195.  
  196. net.Broadcast()
  197.  
  198. MsgAll( attacker:Nick() .. " killed " .. ply:Nick() .. " using " .. inflictor:GetClass() .. "\n" )
  199.  
  200. return end
  201.  
  202. net.Start( "PlayerKilled" )
  203.  
  204. net.WriteEntity( ply )
  205. net.WriteString( inflictor:GetClass() )
  206. net.WriteString( attacker:GetClass() )
  207.  
  208. net.Broadcast()
  209.  
  210. MsgAll( ply:Nick() .. " was killed by " .. attacker:GetClass() .. "\n" )
  211.  
  212. end
  213.  
  214. --[[---------------------------------------------------------
  215. Name: gamemode:PlayerInitialSpawn()
  216. Desc: Called just before the player's first spawn
  217. -----------------------------------------------------------]]
  218. function GM:PlayerInitialSpawn( pl )
  219.  
  220. pl:SetTeam( TEAM_UNASSIGNED )
  221.  
  222. if ( GAMEMODE.TeamBased ) then
  223. pl:ConCommand( "gm_showteam" )
  224. end
  225.  
  226. end
  227.  
  228. --[[---------------------------------------------------------
  229. Name: gamemode:PlayerSpawnAsSpectator()
  230. Desc: Player spawns as a spectator
  231. -----------------------------------------------------------]]
  232. function GM:PlayerSpawnAsSpectator( pl )
  233.  
  234. pl:StripWeapons()
  235.  
  236. if ( pl:Team() == TEAM_UNASSIGNED ) then
  237.  
  238. pl:Spectate( OBS_MODE_FIXED )
  239. return
  240.  
  241. end
  242.  
  243. pl:SetTeam( TEAM_SPECTATOR )
  244. pl:Spectate( OBS_MODE_ROAMING )
  245.  
  246. end
  247.  
  248. --[[---------------------------------------------------------
  249. Name: gamemode:PlayerSpawn()
  250. Desc: Called when a player spawns
  251. -----------------------------------------------------------]]
  252. function GM:PlayerSpawn( pl )
  253.  
  254. --
  255. -- If the player doesn't have a team in a TeamBased game
  256. -- then spawn him as a spectator
  257. --
  258. if ( self.TeamBased && ( pl:Team() == TEAM_SPECTATOR || pl:Team() == TEAM_UNASSIGNED ) ) then
  259.  
  260. self:PlayerSpawnAsSpectator( pl )
  261. return
  262.  
  263. end
  264.  
  265. -- Stop observer mode
  266. pl:UnSpectate()
  267.  
  268. pl:SetupHands()
  269.  
  270. player_manager.OnPlayerSpawn( pl )
  271. player_manager.RunClass( pl, "Spawn" )
  272.  
  273. -- Call item loadout function
  274. hook.Call( "PlayerLoadout", GAMEMODE, pl )
  275.  
  276. -- Set player model
  277. hook.Call( "PlayerSetModel", GAMEMODE, pl )
  278.  
  279. end
  280.  
  281. --[[---------------------------------------------------------
  282. Name: gamemode:PlayerSetModel()
  283. Desc: Set the player's model
  284. -----------------------------------------------------------]]
  285. function GM:PlayerSetModel( pl )
  286.  
  287. player_manager.RunClass( pl, "SetModel" )
  288.  
  289. end
  290.  
  291. --[[---------------------------------------------------------
  292. Name: gamemode:PlayerSetHandsModel()
  293. Desc: Sets the player's view model hands model
  294. -----------------------------------------------------------]]
  295. function GM:PlayerSetHandsModel( pl, ent )
  296.  
  297. local info = player_manager.RunClass( pl, "GetHandsModel" )
  298. if ( !info ) then
  299. local playermodel = player_manager.TranslateToPlayerModelName( pl:GetModel() )
  300. info = player_manager.TranslatePlayerHands( playermodel )
  301. end
  302.  
  303. if ( info ) then
  304. ent:SetModel( info.model )
  305. ent:SetSkin( info.skin )
  306. ent:SetBodyGroups( info.body )
  307. end
  308.  
  309. end
  310.  
  311. --[[---------------------------------------------------------
  312. Name: gamemode:PlayerLoadout()
  313. Desc: Give the player the default spawning weapons/ammo
  314. -----------------------------------------------------------]]
  315. function GM:PlayerLoadout( pl )
  316.  
  317. player_manager.RunClass( pl, "Loadout" )
  318.  
  319. end
  320.  
  321. --[[---------------------------------------------------------
  322. Name: gamemode:PlayerSelectTeamSpawn( player )
  323. Desc: Find a spawn point entity for this player's team
  324. -----------------------------------------------------------]]
  325. function GM:PlayerSelectTeamSpawn( TeamID, pl )
  326.  
  327. local SpawnPoints = team.GetSpawnPoints( TeamID )
  328. if ( !SpawnPoints || table.Count( SpawnPoints ) == 0 ) then return end
  329.  
  330. local ChosenSpawnPoint = nil
  331.  
  332. for i = 0, 6 do
  333.  
  334. local ChosenSpawnPoint = table.Random( SpawnPoints )
  335. if ( hook.Call( "IsSpawnpointSuitable", GAMEMODE, pl, ChosenSpawnPoint, i == 6 ) ) then
  336. return ChosenSpawnPoint
  337. end
  338.  
  339. end
  340.  
  341. return ChosenSpawnPoint
  342.  
  343. end
  344.  
  345.  
  346. --[[---------------------------------------------------------
  347. Name: gamemode:IsSpawnpointSuitable( player )
  348. Desc: Find out if the spawnpoint is suitable or not
  349. -----------------------------------------------------------]]
  350. function GM:IsSpawnpointSuitable( pl, spawnpointent, bMakeSuitable )
  351.  
  352. local Pos = spawnpointent:GetPos()
  353.  
  354. -- Note that we're searching the default hull size here for a player in the way of our spawning.
  355. -- This seems pretty rough, seeing as our player's hull could be different.. but it should do the job
  356. -- (HL2DM kills everything within a 128 unit radius)
  357. local Ents = ents.FindInBox( Pos + Vector( -16, -16, 0 ), Pos + Vector( 16, 16, 64 ) )
  358.  
  359. if ( pl:Team() == TEAM_SPECTATOR ) then return true end
  360.  
  361. local Blockers = 0
  362.  
  363. for k, v in pairs( Ents ) do
  364. if ( IsValid( v ) && v != pl && v:GetClass() == "player" && v:Alive() ) then
  365.  
  366. Blockers = Blockers + 1
  367.  
  368. if ( bMakeSuitable ) then
  369. v:Kill()
  370. end
  371.  
  372. end
  373. end
  374.  
  375. if ( bMakeSuitable ) then return true end
  376. if ( Blockers > 0 ) then return false end
  377. return true
  378.  
  379. end
  380.  
  381. --[[---------------------------------------------------------
  382. Name: gamemode:PlayerSelectSpawn( player )
  383. Desc: Find a spawn point entity for this player
  384. -----------------------------------------------------------]]
  385. function GM:PlayerSelectSpawn( pl )
  386.  
  387. if ( self.TeamBased ) then
  388.  
  389. local ent = self:PlayerSelectTeamSpawn( pl:Team(), pl )
  390. if ( IsValid( ent ) ) then return ent end
  391.  
  392. end
  393.  
  394. -- Save information about all of the spawn points
  395. -- in a team based game you'd split up the spawns
  396. if ( !IsTableOfEntitiesValid( self.SpawnPoints ) ) then
  397.  
  398. self.LastSpawnPoint = 0
  399. self.SpawnPoints = ents.FindByClass( "info_player_start" )
  400. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_deathmatch" ) )
  401. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_combine" ) )
  402. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_rebel" ) )
  403.  
  404. -- CS Maps
  405. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_counterterrorist" ) )
  406. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_terrorist" ) )
  407.  
  408. -- DOD Maps
  409. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_axis" ) )
  410. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_allies" ) )
  411.  
  412. -- (Old) GMod Maps
  413. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "gmod_player_start" ) )
  414.  
  415. -- TF Maps
  416. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_teamspawn" ) )
  417.  
  418. -- INS Maps
  419. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "ins_spawnpoint" ) )
  420.  
  421. -- AOC Maps
  422. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "aoc_spawnpoint" ) )
  423.  
  424. -- Dystopia Maps
  425. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "dys_spawn_point" ) )
  426.  
  427. -- PVKII Maps
  428. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_pirate" ) )
  429. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_viking" ) )
  430. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_knight" ) )
  431.  
  432. -- DIPRIP Maps
  433. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "diprip_start_team_blue" ) )
  434. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "diprip_start_team_red" ) )
  435.  
  436. -- OB Maps
  437. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_red" ) )
  438. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_blue" ) )
  439.  
  440. -- SYN Maps
  441. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_coop" ) )
  442.  
  443. -- ZPS Maps
  444. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_human" ) )
  445. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_zombie" ) )
  446.  
  447. -- ZM Maps
  448. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_player_zombiemaster" ) )
  449.  
  450. -- L4D2
  451. self.SpawnPoints = table.Add( self.SpawnPoints, ents.FindByClass( "info_survivor_position" ) )
  452.  
  453. end
  454.  
  455. local Count = table.Count( self.SpawnPoints )
  456.  
  457. if ( Count == 0 ) then
  458. Msg("[PlayerSelectSpawn] Error! No spawn points!\n")
  459. return nil
  460. end
  461.  
  462. -- If any of the spawnpoints have a MASTER flag then only use that one.
  463. -- This is needed for single player maps.
  464. for k, v in pairs( self.SpawnPoints ) do
  465.  
  466. if ( v:HasSpawnFlags( 1 ) && hook.Call( "IsSpawnpointSuitable", GAMEMODE, pl, v, true ) ) then
  467. return v
  468. end
  469.  
  470. end
  471.  
  472. local ChosenSpawnPoint = nil
  473.  
  474. -- Try to work out the best, random spawnpoint
  475. for i = 1, Count do
  476.  
  477. ChosenSpawnPoint = table.Random( self.SpawnPoints )
  478.  
  479. if ( IsValid( ChosenSpawnPoint ) && ChosenSpawnPoint:IsInWorld() ) then
  480. if ( ( ChosenSpawnPoint == pl:GetVar( "LastSpawnpoint" ) || ChosenSpawnPoint == self.LastSpawnPoint ) && Count > 1 ) then continue end
  481.  
  482. if ( hook.Call( "IsSpawnpointSuitable", GAMEMODE, pl, ChosenSpawnPoint, i == Count ) ) then
  483.  
  484. self.LastSpawnPoint = ChosenSpawnPoint
  485. pl:SetVar( "LastSpawnpoint", ChosenSpawnPoint )
  486. return ChosenSpawnPoint
  487.  
  488. end
  489.  
  490. end
  491.  
  492. end
  493.  
  494. return ChosenSpawnPoint
  495.  
  496. end
  497.  
  498. --[[---------------------------------------------------------
  499. Name: gamemode:WeaponEquip( weapon )
  500. Desc: Player just picked up (or was given) weapon
  501. -----------------------------------------------------------]]
  502. function GM:WeaponEquip( weapon )
  503. end
  504.  
  505. --[[---------------------------------------------------------
  506. Name: gamemode:ScalePlayerDamage( ply, hitgroup, dmginfo )
  507. Desc: Scale the damage based on being shot in a hitbox
  508. Return true to not take damage
  509. -----------------------------------------------------------]]
  510. function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
  511.  
  512. -- More damage if we're shot in the head
  513. if ( hitgroup == HITGROUP_HEAD ) then
  514.  
  515. dmginfo:ScaleDamage( 2 )
  516.  
  517. end
  518.  
  519. -- Less damage if we're shot in the arms or legs
  520. if ( hitgroup == HITGROUP_LEFTARM ||
  521. hitgroup == HITGROUP_RIGHTARM ||
  522. hitgroup == HITGROUP_LEFTLEG ||
  523. hitgroup == HITGROUP_RIGHTLEG ||
  524. hitgroup == HITGROUP_GEAR ) then
  525.  
  526. dmginfo:ScaleDamage( 0.25 )
  527.  
  528. end
  529.  
  530. end
  531.  
  532. --[[---------------------------------------------------------
  533. Name: gamemode:PlayerDeathSound()
  534. Desc: Return true to not play the default sounds
  535. -----------------------------------------------------------]]
  536. function GM:PlayerDeathSound()
  537. return false
  538. end
  539.  
  540. --[[---------------------------------------------------------
  541. Name: gamemode:SetupPlayerVisibility()
  542. Desc: Add extra positions to the player's PVS
  543. -----------------------------------------------------------]]
  544. function GM:SetupPlayerVisibility( pPlayer, pViewEntity )
  545. --AddOriginToPVS( vector_position_here )
  546. end
  547.  
  548. --[[---------------------------------------------------------
  549. Name: gamemode:OnDamagedByExplosion( ply, dmginfo)
  550. Desc: Player has been hurt by an explosion
  551. -----------------------------------------------------------]]
  552. function GM:OnDamagedByExplosion( ply, dmginfo )
  553. ply:SetDSP( 35, false )
  554. end
  555.  
  556. --[[---------------------------------------------------------
  557. Name: gamemode:CanPlayerSuicide( ply )
  558. Desc: Player typed KILL in the console. Can they kill themselves?
  559. -----------------------------------------------------------]]
  560. function GM:CanPlayerSuicide( ply )
  561. return true
  562. end
  563.  
  564. --[[---------------------------------------------------------
  565. Name: gamemode:CanPlayerEnterVehicle( player, vehicle, role )
  566. Desc: Return true if player can enter vehicle
  567. -----------------------------------------------------------]]
  568. function GM:CanPlayerEnterVehicle( ply, vehicle, role )
  569. return true
  570. end
  571.  
  572. --[[---------------------------------------------------------
  573. Name: gamemode:PlayerEnteredVehicle( player, vehicle, role )
  574. Desc: Player entered the vehicle fine
  575. -----------------------------------------------------------]]
  576. function GM:PlayerEnteredVehicle( ply, vehicle, role )
  577. end
  578.  
  579. --[[---------------------------------------------------------
  580. Name: gamemode:CanExitVehicle()
  581. Desc: If the player is allowed to leave the vehicle, return true
  582. -----------------------------------------------------------]]
  583. function GM:CanExitVehicle( vehicle, passenger )
  584. return true
  585. end
  586.  
  587. --[[---------------------------------------------------------
  588. Name: gamemode:PlayerLeaveVehicle()
  589. Desc: Player left the vehicle
  590. -----------------------------------------------------------]]
  591. function GM:PlayerLeaveVehicle( ply, vehicle )
  592. end
  593.  
  594. --[[---------------------------------------------------------
  595. Name: gamemode:PlayerSwitchFlashlight()
  596. Desc: Return true to allow action
  597. -----------------------------------------------------------]]
  598. function GM:PlayerSwitchFlashlight( ply, SwitchOn )
  599. return ply:CanUseFlashlight()
  600. end
  601.  
  602. --[[---------------------------------------------------------
  603. Name: gamemode:PlayerCanJoinTeam( ply, teamid )
  604. Desc: Allow mods/addons to easily determine whether a player
  605. can join a team or not
  606. -----------------------------------------------------------]]
  607. function GM:PlayerCanJoinTeam( ply, teamid )
  608.  
  609. local TimeBetweenSwitches = GAMEMODE.SecondsBetweenTeamSwitches or 10
  610. if ( ply.LastTeamSwitch && RealTime()-ply.LastTeamSwitch < TimeBetweenSwitches ) then
  611. ply.LastTeamSwitch = ply.LastTeamSwitch + 1
  612. ply:ChatPrint( Format( "Please wait %i more seconds before trying to change team again", ( TimeBetweenSwitches - ( RealTime() - ply.LastTeamSwitch ) ) + 1 ) )
  613. return false
  614. end
  615.  
  616. -- Already on this team!
  617. if ( ply:Team() == teamid ) then
  618. ply:ChatPrint( "You're already on that team" )
  619. return false
  620. end
  621.  
  622. return true
  623.  
  624. end
  625.  
  626. --[[---------------------------------------------------------
  627. Name: gamemode:PlayerRequestTeam()
  628. Desc: Player wants to change team
  629. -----------------------------------------------------------]]
  630. function GM:PlayerRequestTeam( ply, teamid )
  631.  
  632. -- No changing teams if not teambased!
  633. if ( !GAMEMODE.TeamBased ) then return end
  634.  
  635. -- This team isn't joinable
  636. if ( !team.Joinable( teamid ) ) then
  637. ply:ChatPrint( "You can't join that team" )
  638. return end
  639.  
  640. -- This team isn't joinable
  641. if ( !GAMEMODE:PlayerCanJoinTeam( ply, teamid ) ) then
  642. -- Messages here should be outputted by this function
  643. return end
  644.  
  645. GAMEMODE:PlayerJoinTeam( ply, teamid )
  646.  
  647. end
  648.  
  649. --[[---------------------------------------------------------
  650. Name: gamemode:PlayerJoinTeam()
  651. Desc: Make player join this team
  652. -----------------------------------------------------------]]
  653. function GM:PlayerJoinTeam( ply, teamid )
  654.  
  655. local iOldTeam = ply:Team()
  656.  
  657. if ( ply:Alive() ) then
  658. if ( iOldTeam == TEAM_SPECTATOR || iOldTeam == TEAM_UNASSIGNED ) then
  659. ply:KillSilent()
  660. else
  661. ply:Kill()
  662. end
  663. end
  664.  
  665. ply:SetTeam( teamid )
  666. ply.LastTeamSwitch = RealTime()
  667.  
  668. GAMEMODE:OnPlayerChangedTeam( ply, iOldTeam, teamid )
  669.  
  670. end
  671.  
  672. --[[---------------------------------------------------------
  673. Name: gamemode:OnPlayerChangedTeam( ply, oldteam, newteam )
  674. -----------------------------------------------------------]]
  675. function GM:OnPlayerChangedTeam( ply, oldteam, newteam )
  676.  
  677. -- Here's an immediate respawn thing by default. If you want to
  678. -- re-create something more like CS or some shit you could probably
  679. -- change to a spectator or something while dead.
  680. if ( newteam == TEAM_SPECTATOR ) then
  681.  
  682. -- If we changed to spectator mode, respawn where we are
  683. local Pos = ply:EyePos()
  684. ply:Spawn()
  685. ply:SetPos( Pos )
  686.  
  687. elseif ( oldteam == TEAM_SPECTATOR ) then
  688.  
  689. -- If we're changing from spectator, join the game
  690. ply:Spawn()
  691.  
  692. else
  693.  
  694. -- If we're straight up changing teams just hang
  695. -- around until we're ready to respawn onto the
  696. -- team that we chose
  697.  
  698. end
  699.  
  700. PrintMessage( HUD_PRINTTALK, Format( "%s joined '%s'", ply:Nick(), team.GetName( newteam ) ) )
  701.  
  702. end
  703.  
  704. --[[---------------------------------------------------------
  705. Name: gamemode:PlayerSpray()
  706. Desc: Return true to prevent player spraying
  707. -----------------------------------------------------------]]
  708. function GM:PlayerSpray( ply )
  709.  
  710. return false
  711.  
  712. end
  713.  
  714. --[[---------------------------------------------------------
  715. Name: gamemode:OnPlayerHitGround()
  716. Desc: Return true to disable default action
  717. -----------------------------------------------------------]]
  718. function GM:OnPlayerHitGround( ply, bInWater, bOnFloater, flFallSpeed )
  719.  
  720. -- Apply damage and play collision sound here
  721. -- then return true to disable the default action
  722. --MsgN( ply, bInWater, bOnFloater, flFallSpeed )
  723. --return true
  724.  
  725. end
  726.  
  727. --[[---------------------------------------------------------
  728. Name: gamemode:GetFallDamage()
  729. Desc: return amount of damage to do due to fall
  730. -----------------------------------------------------------]]
  731. function GM:GetFallDamage( ply, flFallSpeed )
  732.  
  733. if( GetConVarNumber( "mp_falldamage" ) > 0 ) then -- realistic fall damage is on
  734. return ( flFallSpeed - 526.5 ) * ( 100 / 396 ) -- the Source SDK value
  735. end
  736.  
  737. return 10
  738.  
  739. end
  740.  
  741. --[[---------------------------------------------------------
  742. Name: gamemode:PlayerCanSeePlayersChat()
  743. Desc: Can this player see the other player's chat?
  744. -----------------------------------------------------------]]
  745. function GM:PlayerCanSeePlayersChat( strText, bTeamOnly, pListener, pSpeaker )
  746.  
  747. if ( bTeamOnly ) then
  748. if ( !IsValid( pSpeaker ) || !IsValid( pListener ) ) then return false end
  749. if ( pListener:Team() != pSpeaker:Team() ) then return false end
  750. end
  751.  
  752. return true
  753.  
  754. end
  755.  
  756. local sv_alltalk = GetConVar( "sv_alltalk" )
  757.  
  758. --[[---------------------------------------------------------
  759. Name: gamemode:PlayerCanHearPlayersVoice()
  760. Desc: Can this player see the other player's voice?
  761. Returns 2 bools.
  762. 1. Can the player hear the other player
  763. 2. Can they hear them spacially
  764. -----------------------------------------------------------]]
  765. function GM:PlayerCanHearPlayersVoice( pListener, pTalker )
  766.  
  767. local alltalk = sv_alltalk:GetInt()
  768. if ( alltalk >= 1 ) then return true, alltalk == 2 end
  769.  
  770. return pListener:Team() == pTalker:Team(), false
  771.  
  772. end
  773.  
  774. --[[---------------------------------------------------------
  775. Name: gamemode:NetworkIDValidated()
  776. Desc: Called when Steam has validated this as a valid player
  777. -----------------------------------------------------------]]
  778. function GM:NetworkIDValidated( name, steamid )
  779.  
  780. -- MsgN( "GM:NetworkIDValidated", name, steamid )
  781.  
  782. end
  783.  
  784. --[[---------------------------------------------------------
  785. Name: gamemode:PlayerShouldTaunt( ply, actid )
  786. -----------------------------------------------------------]]
  787. function GM:PlayerShouldTaunt( ply, actid )
  788.  
  789. -- The default behaviour is to always let them act
  790. -- Some gamemodes will obviously want to stop this for certain players by returning false
  791. return true
  792.  
  793. end
  794.  
  795. --[[---------------------------------------------------------
  796. Name: gamemode:PlayerStartTaunt( ply, actid, length )
  797. -----------------------------------------------------------]]
  798. function GM:PlayerStartTaunt( ply, actid, length )
  799. end
  800.  
  801. --[[---------------------------------------------------------
  802. Name: gamemode:AllowPlayerPickup( ply, object )
  803. -----------------------------------------------------------]]
  804. function GM:AllowPlayerPickup( ply, object )
  805.  
  806. -- Should the player be allowed to pick this object up (using ENTER)?
  807. -- If no then return false. Default is HELL YEAH
  808.  
  809. return true
  810.  
  811. end
  812.  
  813. --[[---------------------------------------------------------
  814. Name: gamemode:PlayerDroppedWeapon()
  815. Desc: Player has dropped a weapon
  816. -----------------------------------------------------------]]
  817. function GM:PlayerDroppedWeapon( ply, weapon )
  818. end
  819.  
  820. --[[---------------------------------------------------------
  821. These are buttons that the client is pressing. They're used
  822. in Sandbox mode to control things like wheels, thrusters etc.
  823. -----------------------------------------------------------]]
  824. function GM:PlayerButtonDown( ply, btn ) end
  825. function GM:PlayerButtonUp( ply, btn ) end
  826.  
  827. concommand.Add( "changeteam", function( pl, cmd, args ) hook.Call( "PlayerRequestTeam", GAMEMODE, pl, tonumber( args[ 1 ] ) ) end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement