Guest User

sv_player

a guest
Feb 3rd, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.94 KB | None | 0 0
  1. local PlayerMeta = FindMetaTable("Player")
  2. local EntityMeta = FindMetaTable("Entity")
  3.  
  4. function GM:PlayerInitialSpawn( ply )
  5.     ply.LootCollected = 0
  6.     ply.MurdererChance = 1
  7.  
  8.     timer.Simple(0, function ()
  9.         if IsValid(ply) then
  10.             ply:KillSilent()
  11.         end
  12.     end)
  13.    
  14.     ply.HasMoved = true
  15.     ply:SetTeam(2)
  16.  
  17.     self:NetworkRound(ply)
  18.  
  19. end
  20.  
  21. function GM:PlayerSpawn( ply )
  22.  
  23.     -- If the player doesn't have a team
  24.     -- then spawn him as a spectator
  25.     if ply:Team() == 1 || ply:Team() == TEAM_UNASSIGNED then
  26.  
  27.         GAMEMODE:PlayerSpawnAsSpectator( ply )
  28.         return
  29.    
  30.     end
  31.  
  32.     -- Stop observer mode
  33.     ply:UnCSpectate()
  34.     ply:SetMurdererRevealed(false)
  35.  
  36.     player_manager.OnPlayerSpawn( ply )
  37.     player_manager.RunClass( ply, "Spawn" )
  38.  
  39.     hook.Call( "PlayerLoadout", GAMEMODE, ply )
  40.     hook.Call( "PlayerSetModel", GAMEMODE, ply )
  41.  
  42.     ply:CalculateSpeed()
  43.  
  44.     local oldhands = ply:GetHands()
  45.     if ( IsValid( oldhands ) ) then oldhands:Remove() end
  46.  
  47.     local hands = ents.Create( "gmod_hands" )
  48.     if ( IsValid( hands ) ) then
  49.         ply:SetHands( hands )
  50.         hands:SetOwner( ply )
  51.  
  52.         -- Which hands should we use?
  53.         local cl_playermodel = ply:GetInfo( "cl_playermodel" )
  54.         local info = player_manager.TranslatePlayerHands( cl_playermodel )
  55.         if ( info ) then
  56.             hands:SetModel( info.model )
  57.             hands:SetSkin( info.skin )
  58.             hands:SetBodyGroups( info.body )
  59.         end
  60.  
  61.         -- Attach them to the viewmodel
  62.         local vm = ply:GetViewModel( 0 )
  63.         hands:AttachToViewmodel( vm )
  64.  
  65.         vm:DeleteOnRemove( hands )
  66.         ply:DeleteOnRemove( hands )
  67.  
  68.         hands:Spawn()
  69.     end
  70.  
  71.     local spawnPoint = self:PlayerSelectTeamSpawn(ply:Team(), ply)
  72.     if IsValid(spawnPoint) then
  73.         ply:SetPos(spawnPoint:GetPos())
  74.     end
  75.  
  76.     local vec = Vector(0,0,0)
  77.     vec.x = math.Rand(0, 1)
  78.     vec.y = math.Rand(0, 1)
  79.     vec.z = math.Rand(0, 1)
  80.     ply:SetPlayerColor(vec)
  81. end
  82.  
  83. function GM:PlayerLoadout(ply)
  84.  
  85.     ply:Give("weapon_rp_hands")
  86.     -- ply:Give("weapon_fists")
  87.  
  88.     if ply:GetMurderer() then
  89.         ply:Give("weapon_mu_knife")
  90.     end
  91.  
  92.  
  93. end
  94.  
  95. local playerModels = {}
  96. local function addModel(model, sex)
  97.     local t = {}
  98.     t.model = model
  99.     t.sex = sex
  100.     table.insert(playerModels, t)
  101. end
  102.  
  103. addModel("male03", "male")
  104. addModel("male04", "male")
  105. addModel("male05", "male")
  106. addModel("male07", "male")
  107. addModel("male06", "male")
  108. addModel("male09", "male")
  109. addModel("male01", "male")
  110. addModel("male02", "male")
  111. addModel("male08", "male")
  112. addModel("female06", "female")
  113. addModel("female01", "female")
  114. addModel("female03", "female")
  115. addModel("female05", "female")
  116. addModel("female02", "female")
  117. addModel("female04", "female")
  118. addModel("refugee01", "male")
  119. addModel("refugee02", "male")
  120. addModel("refugee03", "male")
  121. addModel("refugee04", "male")
  122.  
  123. function GM:PlayerSetModel( ply )
  124.  
  125.     local cl_playermodel = ply:GetInfo( "cl_playermodel" )
  126.  
  127.     local playerModel = table.Random(playerModels)
  128.     cl_playermodel = playerModel.model
  129.  
  130.     local modelname = player_manager.TranslatePlayerModel( cl_playermodel )
  131.     util.PrecacheModel( modelname )
  132.     ply:SetModel( modelname )
  133.     ply.ModelSex = playerModel.sex
  134.  
  135. end
  136.  
  137. function GM:DoPlayerDeath( ply, attacker, dmginfo )
  138.  
  139.     for k, weapon in pairs(ply:GetWeapons()) do
  140.         if weapon:GetClass() == "weapon_mu_magnum" then
  141.             ply:DropWeapon(weapon)
  142.         end
  143.     end
  144.  
  145.     ply:Freeze(false) // why?, *sigh*
  146.     ply:CreateRagdoll()
  147.  
  148.     local ent = ply:GetNWEntity("DeathRagdoll")
  149.     if IsValid(ent) then
  150.         ply:CSpectate(OBS_MODE_CHASE, ent)
  151.     end
  152.  
  153.     ply:AddDeaths( 1 )
  154.  
  155.     if ( attacker:IsValid() && attacker:IsPlayer() ) then
  156.  
  157.         if ( attacker == ply ) then
  158.             attacker:AddFrags( -1 )
  159.         else
  160.             attacker:AddFrags( 1 )
  161.         end
  162.  
  163.     end
  164.  
  165. end
  166.  
  167. local plyMeta = FindMetaTable("Player")
  168.  
  169. function plyMeta:CalculateSpeed()
  170.     // set the defaults
  171.     local walk,run,canrun = 250,310,false
  172.     local jumppower = 200
  173.  
  174.     if self:GetMurderer() then
  175.         canrun = true
  176.     end
  177.  
  178.     if self.LastTKTime then
  179.         walk = walk * 0.7
  180.         run = run * 0.7
  181.         jumppower = jumppower * 0.5
  182.     end
  183.  
  184.     // handcuffs
  185.     -- if self:GetHandcuffed() then
  186.     --  walk = walk * 0.3
  187.     --  jumppower = 150
  188.     --  canrun = false
  189.     -- end
  190.     -- if self:GetTasered() then
  191.     --  walk = 40
  192.     --  jumppower = 100
  193.     --  canrun = false
  194.     -- end
  195.  
  196.     // set out new speeds
  197.     if canrun then
  198.         self:SetRunSpeed(run)
  199.     else
  200.         self:SetRunSpeed(walk)
  201.     end
  202.     self.CanRun = canrun
  203.     self:SetWalkSpeed(walk)
  204.     self:SetJumpPower(jumppower)
  205. end
  206.  
  207. local function isValid() return true end
  208. local function getPos(self) return self.pos end
  209.  
  210. local function generateSpawnEntities(spawnList)
  211.     local tbl = {}
  212.  
  213.     for k, pos in pairs(spawnList) do
  214.         local t = {}
  215.         t.IsValid = isValid
  216.         t.GetPos = getPos
  217.         t.pos = pos
  218.         table.insert(tbl, t)
  219.     end
  220.  
  221.     return tbl
  222. end
  223.  
  224. function GM:PlayerSelectTeamSpawn( TeamID, pl )
  225.  
  226.     local SpawnPoints = team.GetSpawnPoints( TeamID )
  227.  
  228.     SpawnPoints = generateSpawnEntities(TeamSpawns["spawns"])
  229.  
  230.     if ( !SpawnPoints || table.Count( SpawnPoints ) == 0 ) then return end
  231.    
  232.     local ChosenSpawnPoint = nil
  233.    
  234.     for i=0, 6 do
  235.    
  236.         local ChosenSpawnPoint = table.Random( SpawnPoints )
  237.         if ( GAMEMODE:IsSpawnpointSuitable( pl, ChosenSpawnPoint, i==6 ) ) then
  238.             return ChosenSpawnPoint
  239.         end
  240.    
  241.     end
  242.    
  243.     return ChosenSpawnPoint
  244.  
  245. end
  246.  
  247.  
  248. function GM:PlayerDeathSound()
  249.     // don't play sound
  250.     return true
  251. end
  252.  
  253. function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
  254.     // Don't scale it depending on hitgroup
  255. end
  256.  
  257. function GM:PlayerDeath(ply, Inflictor, attacker )
  258.  
  259.     self:DoRoundDeaths(ply, attacker)
  260.  
  261.     if !ply:GetMurderer() then
  262.  
  263.         self.MurdererLastKill = CurTime()
  264.         local murderer
  265.         local players = team.GetPlayers(2)
  266.         for k,v in pairs(players) do
  267.             if v:GetMurderer() then
  268.                 murderer = v
  269.             end
  270.         end
  271.         if murderer then
  272.             murderer:SetMurdererRevealed(false)
  273.         end
  274.  
  275.         if IsValid(attacker) && attacker:IsPlayer() then
  276.             if attacker:GetMurderer() then
  277.                 -- self:SendMessageAll("The murderer has struck again")
  278.             elseif attacker != ply then
  279.                 if self.ShowBystanderTKs:GetBool() then
  280.                     local ct = ChatText()
  281.                     local col = attacker:GetPlayerColor()
  282.                     ct:Add(attacker:Nick() .. ", " .. attacker:GetBystanderName(), Color(col.x * 255, col.y * 255, col.z * 255))
  283.                     ct:Add(" killed an innocent bystander")
  284.                     ct:SendAll()
  285.                 end
  286.                 attacker.LastTKTime = CurTime()
  287.                 attacker:CalculateSpeed()
  288.                 timer.Simple(0, function ()
  289.                     if IsValid(attacker) && attacker:HasWeapon("weapon_mu_magnum") then
  290.                         local wep = attacker:GetWeapon("weapon_mu_magnum")
  291.                         wep.LastTK = attacker
  292.                         wep.LastTKTime = CurTime()
  293.                         attacker:DropWeapon(wep)
  294.                     end
  295.                 end)
  296.             end
  297.         else
  298.             -- self:SendMessageAll("An bystander died in mysterious circumstances")
  299.         end
  300.     else
  301.         if attacker != ply && IsValid(attacker) && attacker:IsPlayer() then
  302.             local ct = ChatText()
  303.             local col = attacker:GetPlayerColor()
  304.             ct:Add(attacker:Nick() .. ", " .. attacker:GetBystanderName(), Color(col.x * 255, col.y * 255, col.z * 255))
  305.             ct:Add(" killed the murderer")
  306.             ct:SendAll()
  307.         else
  308.             local ct = ChatText()
  309.             ct:Add("The murderer died in mysterious circumstances")
  310.             ct:SendAll()
  311.         end
  312.     end
  313.  
  314.     ply.NextSpawnTime = CurTime() + 5
  315.     ply.DeathTime = CurTime()
  316.     ply.SpectateTime = CurTime() + 4
  317.  
  318.     umsg.Start("rp_death", ply)
  319.     umsg.Long(5)
  320.     umsg.Long(4)
  321.     umsg.End()
  322.    
  323.     if ( Inflictor && Inflictor == attacker && (Inflictor:IsPlayer() || Inflictor:IsNPC()) ) then
  324.    
  325.         Inflictor = Inflictor:GetActiveWeapon()
  326.         if ( !Inflictor || Inflictor == NULL ) then Inflictor = attacker end
  327.    
  328.     end
  329.  
  330.     self:RagdollSetDeathDetails(ply, Inflictor, attacker)
  331. end
  332.  
  333. function GM:PlayerDeathThink(ply)
  334.     if self:CanRespawn(ply) then
  335.         ply:Spawn()
  336.     else
  337.         self:ChooseSpectatee(ply)
  338.     end
  339.    
  340. end
  341.  
  342. function EntityMeta:GetPlayerColor()
  343.     return self.playerColor or Vector()
  344. end
  345.  
  346. function EntityMeta:SetPlayerColor(vec)
  347.     self.playerColor = vec
  348.     self:SetNWVector("playerColor", vec)
  349. end
  350.  
  351. function GM:PlayerFootstep(ply, pos, foot, sound, volume, filter)
  352.     self:FootstepsOnFootstep(ply, pos, foot, sound, volume, filter)
  353. end
  354.  
  355. function GM:PlayerCanPickupWeapon( ply, ent )
  356.  
  357.     // can't pickup a weapon twice
  358.     if ply:HasWeapon(ent:GetClass()) then
  359.         return false
  360.     end
  361.  
  362.     if ent:GetClass() == "weapon_mu_magnum" then
  363.         // murderer can't have the gun
  364.         if ply:GetMurderer() then
  365.             return false
  366.         end
  367.  
  368.         // penalty for killing a bystander
  369.         if ply.LastTKTime && ply.LastTKTime + self:GetTKPenaltyTime() > CurTime() then
  370.             if ply.TempGiveMagnum then
  371.                 ply.TempGiveMagnum = nil
  372.                 return true
  373.             end
  374.             return false
  375.         end
  376.     end
  377.  
  378.     if ent:GetClass() == "weapon_mu_knife" then
  379.         // bystanders can't have the knife
  380.         if !ply:GetMurderer() then
  381.             return false
  382.         end
  383.     end
  384.  
  385.     return true
  386. end
  387.  
  388. function GM:PlayerCanHearPlayersVoice( listener, talker )
  389.     return self:PlayerCanHearChatVoice(listener, talker)
  390. end
  391.  
  392. function GM:PlayerCanHearChatVoice(listener, talker)
  393.     if self.RoundStage != 1 then
  394.         return true
  395.     end
  396.     if !listener:Alive() || listener:Team() != 2 then
  397.         return true
  398.     end
  399.     if talker:Team() != 2 then
  400.         return false
  401.     end
  402.     if !talker:Alive() then
  403.         return false
  404.     end
  405.     return true
  406. end
  407.  
  408. function GM:PlayerDisconnected(ply)
  409.     self:PlayerLeavePlay(ply)
  410. end
  411.  
  412. function GM:PlayerOnChangeTeam(ply, newTeam, oldTeam)
  413.     if oldTeam == 2 then
  414.         self:PlayerLeavePlay(ply)  
  415.     end
  416.     ply:SetMurderer(false)
  417.     if newteam == 1 then
  418.        
  419.     end
  420.     ply.HasMoved = true
  421.     ply:KillSilent()
  422. end
  423.  
  424. concommand.Add("mu_jointeam", function (ply, com, args)
  425.     if ply.LastChangeTeam && ply.LastChangeTeam + 10 > CurTime() then return end
  426.     ply.LastChangeTeam = CurTime()
  427.  
  428.     local curTeam = ply:Team()
  429.     local newTeam = tonumber(args[1] or "") or 0
  430.     if newTeam >= 1 && newTeam <= 2 && newTeam != curTeam then
  431.         ply:SetTeam(newTeam)
  432.         GAMEMODE:PlayerOnChangeTeam(ply, newTeam, curTeam)
  433.         local ct = ChatText()
  434.         ct:Add(ply:Nick() .. " changed team to ")
  435.         ct:Add(team.GetName(newTeam), team.GetColor(newTeam))
  436.         ct:SendAll()
  437.     end
  438. end)
  439.  
  440. concommand.Add("mu_movetospectate", function (ply, com, args)
  441.     if !ply:IsAdmin() then return end
  442.     if #args < 1 then return end
  443.  
  444.     local ent = Entity(tonumber(args[1]) or -1)
  445.     if !IsValid(ent) || !ent:IsPlayer() then return end
  446.    
  447.     local curTeam = ent:Team()
  448.     if 1 != curTeam then
  449.         ent:SetTeam(1)
  450.         GAMEMODE:PlayerOnChangeTeam(ent, 1, curTeam)
  451.         local ct = ChatText()
  452.         ct:Add(ent:Nick() .. " was moved to ")
  453.         ct:Add(team.GetName(1), team.GetColor(1))
  454.         ct:SendAll()
  455.     end
  456. end)
  457.  
  458. concommand.Add("mu_spectate", function (ply, com, args)
  459.     if !ply:IsAdmin() then return end
  460.     if #args < 1 then return end
  461.  
  462.     local ent = Entity(tonumber(args[1]) or -1)
  463.     if !IsValid(ent) || !ent:IsPlayer() then return end
  464.    
  465.     if ply:Alive() && ply:Team() != 1 then
  466.         local ct = ChatText()
  467.         ct:Add("You can't spectate. You ain't dead.")
  468.         ct:SendAll()
  469.         return
  470.     end
  471.     ply:CSpectate(OBS_MODE_IN_EYE, ent)
  472. end)
  473.  
  474. function GM:PlayerCanSeePlayersChat( text, teamOnly, listener, speaker )
  475.     return self:PlayerCanHearChatVoice(listener, speaker)
  476. end
  477.  
  478. function GM:PlayerSay( ply, text, team)
  479.     if ply:Team() == 2 && ply:Alive() && self:GetRound() != 0 then
  480.         local ct = ChatText()
  481.         local col = ply:GetPlayerColor()
  482.         ct:Add(ply:GetBystanderName(), Color(col.x * 255, col.y * 255, col.z * 255))
  483.         ct:Add(": " .. text, color_white)
  484.         ct:SendAll()
  485.         return false
  486.     end
  487.     return true
  488. end
  489.  
  490. function GM:PlayerShouldTaunt( ply, actid )
  491.     return false
  492. end
  493.  
  494. function GM:KeyPress( ply, key )
  495.     if key == IN_USE then
  496.         local tr = ply:GetEyeTraceNoCursor()
  497.  
  498.         // press e on windows to break them
  499.         if IsValid(tr.Entity) && (tr.Entity:GetClass() == "func_breakable" || tr.Entity:GetClass() == "func_breakable_surf") && tr.HitPos:Distance(tr.StartPos) < 50 then
  500.             local dmg = DamageInfo()
  501.             dmg:SetAttacker(game.GetWorld())
  502.             dmg:SetInflictor(game.GetWorld())
  503.             dmg:SetDamage(10)
  504.             dmg:SetDamageType(DMG_BULLET)
  505.             dmg:SetDamageForce(ply:GetAimVector() * 500)
  506.             dmg:SetDamagePosition(tr.HitPos)
  507.             tr.Entity:TakeDamageInfo(dmg)
  508.         end
  509.     end
  510. end
  511.  
  512. function GM:GetTKPenaltyTime()
  513.     return math.max(0, self.TKPenaltyTime:GetFloat())
  514. end
Advertisement
Add Comment
Please, Sign In to add comment