Advertisement
Guest User

sv_gamemode_functions.lua

a guest
Nov 9th, 2014
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.67 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. DarkRP hooks
  3. ---------------------------------------------------------------------------*/
  4. function GM:Initialize()
  5.     self.BaseClass:Initialize()
  6. end
  7.  
  8. function GM:playerBuyDoor(ply, ent)
  9.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].hobo then
  10.         return false, DarkRP.getPhrase("door_hobo_unable")
  11.     end
  12.  
  13.     return true
  14. end
  15.  
  16. function GM:getDoorCost(ply, ent)
  17.     return GAMEMODE.Config.doorcost ~= 0 and GAMEMODE.Config.doorcost or 30
  18. end
  19.  
  20. function GM:getVehicleCost(ply, ent)
  21.     return GAMEMODE.Config.vehiclecost ~= 0 and  GAMEMODE.Config.vehiclecost or 40
  22. end
  23.  
  24. function GM:CanChangeRPName(ply, RPname)
  25.     if string.find(RPname, "\160") or string.find(RPname, " ") == 1 then -- disallow system spaces
  26.         return false
  27.     end
  28.  
  29.     if table.HasValue({"ooc", "shared", "world", "n/a", "world prop"}, RPname) then
  30.         return false
  31.     end
  32. end
  33.  
  34. function GM:canDemote(ply, target, reason)
  35.  
  36. end
  37.  
  38. function GM:canVote(ply, vote)
  39.  
  40. end
  41.  
  42. function GM:playerWalletChanged(ply, amount)
  43.  
  44. end
  45.  
  46. function GM:playerGetSalary(ply, amount)
  47.  
  48. end
  49.  
  50. function GM:DarkRPVarChanged(ply, var, oldvar, newvalue)
  51.  
  52. end
  53.  
  54. function GM:playerBoughtVehicle(ply, ent, cost)
  55.  
  56. end
  57.  
  58. function GM:playerBoughtDoor(ply, ent, cost)
  59.  
  60. end
  61.  
  62. function GM:canDropWeapon(ply, weapon)
  63.     if not IsValid(weapon) then return false end
  64.     local class = string.lower(weapon:GetClass())
  65.     local team = ply:Team()
  66.  
  67.     if not GAMEMODE.Config.dropspawnedweapons then
  68.     if RPExtraTeams[team] and table.HasValue(RPExtraTeams[team].weapons, class) then return false end
  69.     end
  70.  
  71.     if self.Config.DisallowDrop[class] then return false end
  72.  
  73.     if not GAMEMODE.Config.restrictdrop then return true end
  74.  
  75.     for k,v in pairs(CustomShipments) do
  76.         if v.entity ~= class then continue end
  77.  
  78.         return true
  79.     end
  80.  
  81.     return false
  82. end
  83.  
  84. function GM:DatabaseInitialized()
  85.     DarkRP.initDatabase()
  86. end
  87.  
  88. function GM:canSeeLogMessage(ply, message, colour)
  89.     return ply:IsAdmin()
  90. end
  91.  
  92. function GM:UpdatePlayerSpeed(ply)
  93.     if ply:isArrested() then
  94.         GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.arrestspeed, GAMEMODE.Config.arrestspeed)
  95.     elseif ply:isCP() then
  96.         GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeedcp)
  97.     else
  98.         GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeed)
  99.     end
  100. end
  101.  
  102. /*---------------------------------------------------------
  103.  Gamemode functions
  104.  ---------------------------------------------------------*/
  105.  
  106. function GM:PlayerSpawnProp(ply, model)
  107.     -- If prop spawning is enabled or the user has admin or prop privileges
  108.     local allowed = ((GAMEMODE.Config.propspawning or (FAdmin and FAdmin.Access.PlayerHasPrivilege(ply, "rp_prop")) or ply:IsAdmin()) and true) or false
  109.  
  110.     if ply:isArrested() then return false end
  111.     model = string.gsub(tostring(model), "\\", "/")
  112.     model = string.gsub(tostring(model), "//", "/")
  113.  
  114.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSpawnProp then
  115.         RPExtraTeams[ply:Team()].PlayerSpawnProp(ply, model)
  116.     end
  117.  
  118.     if not allowed then return false end
  119.  
  120.     return self.BaseClass:PlayerSpawnProp(ply, model)
  121. end
  122.  
  123. function GM:PlayerSpawnedProp(ply, model, ent)
  124.     self.BaseClass:PlayerSpawnedProp(ply, model, ent)
  125.     ent.SID = ply.SID
  126.     ent:CPPISetOwner(ply)
  127.  
  128.     local phys = ent:GetPhysicsObject()
  129.     if phys and phys:IsValid() then
  130.         ent.RPOriginalMass = phys:GetMass()
  131.     end
  132.  
  133.     if GAMEMODE.Config.proppaying then
  134.         if ply:canAfford(GAMEMODE.Config.propcost) then
  135.             DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("deducted_money", DarkRP.formatMoney(GAMEMODE.Config.propcost)))
  136.             ply:addMoney(-GAMEMODE.Config.propcost)
  137.         else
  138.             DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_money", DarkRP.formatMoney(GAMEMODE.Config.propcost)))
  139.             SafeRemoveEntity(ent)
  140.             return false
  141.         end
  142.     end
  143. end
  144.  
  145.  
  146. local function checkAdminSpawn(ply, configVar, errorStr)
  147.     local config = GAMEMODE.Config[configVar]
  148.  
  149.     if (config == true or config == 1) and ply:EntIndex() ~= 0 and not ply:IsAdmin() then
  150.         DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("need_admin", DarkRP.getPhrase(errorStr) or errorStr))
  151.         return false
  152.     elseif config == 2 and ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() then
  153.         DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("need_sadmin", DarkRP.getPhrase(errorStr) or errorStr))
  154.         return false
  155.     elseif config == 3 and ply:EntIndex() ~= 0 then
  156.         DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("disabled", DarkRP.getPhrase(errorStr) or errorStr, DarkRP.getPhrase("see_settings")))
  157.         return false
  158.     end
  159.  
  160.     return true
  161. end
  162.  
  163. function GM:PlayerSpawnSENT(ply, class)
  164.     return checkAdminSpawn(ply, "adminsents", "gm_spawnsent") and self.BaseClass:PlayerSpawnSENT(ply, class) and not ply:isArrested()
  165. end
  166.  
  167. function GM:PlayerSpawnedSENT(ply, ent)
  168.     self.BaseClass:PlayerSpawnedSENT(ply, ent)
  169.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") spawned SENT "..ent:GetClass(), Color(255, 255, 0))
  170. end
  171.  
  172. local function canSpawnWeapon(ply)
  173.     if (GAMEMODE.Config.adminweapons == 0 and ply:IsAdmin()) or
  174.     (GAMEMODE.Config.adminweapons == 1 and ply:IsSuperAdmin()) then
  175.         return true
  176.     end
  177.     DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("cant_spawn_weapons"))
  178.  
  179.     return false
  180. end
  181.  
  182. function GM:PlayerSpawnSWEP(ply, class, info)
  183.     return canSpawnWeapon(ply) and self.BaseClass:PlayerSpawnSWEP(ply, class, info) and not ply:isArrested()
  184. end
  185.  
  186. function GM:PlayerGiveSWEP(ply, class, info)
  187.     return canSpawnWeapon(ply) and self.BaseClass:PlayerGiveSWEP(ply, class, info) and not ply:isArrested()
  188. end
  189.  
  190. function GM:PlayerSpawnEffect(ply, model)
  191.     return self.BaseClass:PlayerSpawnEffect(ply, model) and not ply:isArrested()
  192. end
  193.  
  194. function GM:PlayerSpawnVehicle(ply, model, class, info)
  195.     return checkAdminSpawn(ply, "adminvehicles", "gm_spawnvehicle") and self.BaseClass:PlayerSpawnVehicle(ply, model, class, info) and not ply:isArrested()
  196. end
  197.  
  198. function GM:PlayerSpawnedVehicle(ply, ent)
  199.     self.BaseClass:PlayerSpawnedVehicle(ply, ent)
  200.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") spawned Vehicle "..ent:GetClass(), Color(255, 255, 0))
  201. end
  202.  
  203. function GM:PlayerSpawnNPC(ply, type, weapon)
  204.     return checkAdminSpawn(ply, "adminnpcs", "gm_spawnnpc") and self.BaseClass:PlayerSpawnNPC(ply, type, weapon) and not ply:isArrested()
  205. end
  206.  
  207. function GM:PlayerSpawnedNPC(ply, ent)
  208.     self.BaseClass:PlayerSpawnedNPC(ply, ent)
  209.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") spawned NPC "..ent:GetClass(), Color(255, 255, 0))
  210. end
  211.  
  212. function GM:PlayerSpawnRagdoll(ply, model)
  213.     return self.BaseClass:PlayerSpawnRagdoll(ply, model) and not ply:isArrested()
  214. end
  215.  
  216. function GM:PlayerSpawnedRagdoll(ply, model, ent)
  217.     self.BaseClass:PlayerSpawnedRagdoll(ply, model, ent)
  218.     ent.SID = ply.SID
  219. end
  220.  
  221. function GM:EntityRemoved(ent)
  222.     self.BaseClass:EntityRemoved(ent)
  223.     if ent:IsVehicle() then
  224.         local found = ent:CPPIGetOwner()
  225.         if IsValid(found) then
  226.             found.Vehicles = found.Vehicles or 1
  227.             found.Vehicles = found.Vehicles - 1
  228.         end
  229.     end
  230.  
  231.     local owner = ent.Getowning_ent and ent:Getowning_ent() or Player(ent.SID or 0)
  232.     if ent.DarkRPItem and IsValid(owner) then owner:removeCustomEntity(ent.DarkRPItem) end
  233.     if ent.isKeysOwnable and ent:isKeysOwnable() then ent:removeDoorData() end
  234. end
  235.  
  236. function GM:ShowSpare1(ply)
  237.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].ShowSpare1 then
  238.         return RPExtraTeams[ply:Team()].ShowSpare1(ply)
  239.     end
  240. end
  241.  
  242. function GM:ShowSpare2(ply)
  243.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].ShowSpare2 then
  244.         return RPExtraTeams[ply:Team()].ShowSpare2(ply)
  245.     end
  246. end
  247.  
  248. function GM:ShowTeam(ply)
  249. end
  250.  
  251. function GM:ShowHelp(ply)
  252. end
  253.  
  254. function GM:OnNPCKilled(victim, ent, weapon)
  255.     -- If something killed the npc
  256.     if not ent then return end
  257.  
  258.     if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
  259.  
  260.     -- If it wasn't a player directly, find out who owns the prop that did the killing
  261.     if not ent:IsPlayer() then
  262.         ent = Player(tonumber(ent.SID) or 0)
  263.     end
  264.  
  265.     -- If we know by now who killed the NPC, pay them.
  266.     if IsValid(ent) and GAMEMODE.Config.npckillpay > 0 then
  267.         ent:addMoney(GAMEMODE.Config.npckillpay)
  268.         DarkRP.notify(ent, 0, 4, DarkRP.getPhrase("npc_killpay", DarkRP.formatMoney(GAMEMODE.Config.npckillpay)))
  269.     end
  270. end
  271.  
  272. function GM:KeyPress(ply, code)
  273.     self.BaseClass:KeyPress(ply, code)
  274. end
  275.  
  276. local function IsInRoom(listener, talker) -- IsInRoom function to see if the player is in the same room.
  277.     local tracedata = {}
  278.     tracedata.start = talker:GetShootPos()
  279.     tracedata.endpos = listener:GetShootPos()
  280.     local trace = util.TraceLine(tracedata)
  281.  
  282.     return not trace.HitWorld
  283. end
  284.  
  285. local threed = GM.Config.voice3D
  286. local vrad = GM.Config.voiceradius
  287. local dynv = GM.Config.dynamicvoice
  288. -- proxy function to take load from PlayerCanHearPlayersVoice, which is called a quadratic amount of times per tick,
  289. -- causing a lagfest when there are many players
  290. local function calcPlyCanHearPlayerVoice(listener)
  291.     if not IsValid(listener) then return end
  292.     listener.DrpCanHear = listener.DrpCanHear or {}
  293.     for _, talker in pairs(player.GetAll()) do
  294.         listener.DrpCanHear[talker] = not vrad or -- Voiceradius is off, everyone can hear everyone
  295.             (listener:GetShootPos():DistToSqr(talker:GetShootPos()) < 302500 and -- voiceradius is on and the two are within hearing distance
  296.                 (not dynv or IsInRoom(listener, talker))) -- Dynamic voice is on and players are in the same room
  297.     end
  298. end
  299. hook.Add("PlayerInitialSpawn", "DarkRPCanHearVoice", function(ply)
  300.     timer.Create(ply:UserID() .. "DarkRPCanHearPlayersVoice", 0.5, 0, fn.Curry(calcPlyCanHearPlayerVoice, 2)(ply))
  301. end)
  302. hook.Add("PlayerDisconnected", "DarkRPCanHearVoice", function(ply)
  303.     if not ply.DrpCanHear then return end
  304.     for k,v in pairs(player.GetAll()) do
  305.         if not v.DrpCanHear then continue end
  306.         v.DrpCanHear[ply] = nil
  307.     end
  308.     timer.Destroy(ply:UserID() .. "DarkRPCanHearPlayersVoice")
  309. end)
  310.  
  311. function GM:PlayerCanHearPlayersVoice(listener, talker)
  312.     local canHear = listener.DrpCanHear and listener.DrpCanHear[talker]
  313.     return canHear, threed
  314. end
  315.  
  316. function GM:CanTool(ply, trace, mode)
  317.     if not self.BaseClass:CanTool(ply, trace, mode) then return false end
  318.  
  319.     if IsValid(trace.Entity) then
  320.         if trace.Entity.onlyremover then
  321.             if mode == "remover" then
  322.                 return (ply:IsAdmin() or ply:IsSuperAdmin())
  323.             else
  324.                 return false
  325.             end
  326.         end
  327.  
  328.         if trace.Entity.nodupe and (mode == "weld" or
  329.                     mode == "weld_ez" or
  330.                     mode == "spawner" or
  331.                     mode == "duplicator" or
  332.                     mode == "adv_duplicator") then
  333.             return false
  334.         end
  335.  
  336.         if trace.Entity:IsVehicle() and mode == "nocollide" and not GAMEMODE.Config.allowvnocollide then
  337.             return false
  338.         end
  339.     end
  340.     return true
  341. end
  342.  
  343. function GM:CanPlayerSuicide(ply)
  344.     if ply.IsSleeping then
  345.         DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "suicide", ""))
  346.         return false
  347.     end
  348.     if ply:isArrested() then
  349.         DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "suicide", ""))
  350.         return false
  351.     end
  352.     if GAMEMODE.Config.wantedsuicide and ply:getDarkRPVar("wanted") then
  353.         DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "suicide", ""))
  354.         return false
  355.     end
  356.  
  357.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].CanPlayerSuicide then
  358.         return RPExtraTeams[ply:Team()].CanPlayerSuicide(ply)
  359.     end
  360.     return true
  361. end
  362.  
  363. function GM:CanDrive(ply, ent)
  364.     DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("drive_disabled"))
  365.     return false -- Disabled until people can't minge with it anymore
  366. end
  367.  
  368. function GM:CanProperty(ply, property, ent)
  369.     if self.Config.allowedProperties[property] and ent:CPPICanTool(ply, "remover") then
  370.         return true
  371.     end
  372.  
  373.     if property == "persist" and ply:IsSuperAdmin() then
  374.         return true
  375.     end
  376.     DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("property_disabled"))
  377.     return false -- Disabled until antiminge measure is found
  378. end
  379.  
  380. function GM:PlayerShouldTaunt(ply, actid)
  381.     return false
  382. end
  383.  
  384. function GM:DoPlayerDeath(ply, attacker, dmginfo, ...)
  385.     local weapon = ply:GetActiveWeapon()
  386.     local canDrop = hook.Call("canDropWeapon", self, ply, weapon)
  387.  
  388.     if GAMEMODE.Config.dropweapondeath and IsValid(weapon) and canDrop then
  389.         ply:dropDRPWeapon(weapon)
  390.     end
  391.     self.BaseClass:DoPlayerDeath(ply, attacker, dmginfo, ...)
  392. end
  393.  
  394. function GM:PlayerDeath(ply, weapon, killer)
  395.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerDeath then
  396.         RPExtraTeams[ply:Team()].PlayerDeath(ply, weapon, killer)
  397.     end
  398.  
  399.     if GAMEMODE.Config.deathblack then
  400.         SendUserMessage("blackScreen", ply, true)
  401.     end
  402.  
  403.     if weapon:IsVehicle() and weapon:GetDriver():IsPlayer() then killer = weapon:GetDriver() end
  404.  
  405.     if GAMEMODE.Config.showdeaths then
  406.         self.BaseClass:PlayerDeath(ply, weapon, killer)
  407.     end
  408.  
  409.     ply:Extinguish()
  410.  
  411.     if ply:InVehicle() then ply:ExitVehicle() end
  412.  
  413.     if ply:isArrested() and not GAMEMODE.Config.respawninjail  then
  414.         -- If the player died in jail, make sure they can't respawn until their jail sentance is over
  415.         ply.NextSpawnTime = CurTime() + math.ceil(GAMEMODE.Config.jailtimer - (CurTime() - ply.LastJailed)) + 1
  416.         for a, b in pairs(player.GetAll()) do
  417.             b:PrintMessage(HUD_PRINTCENTER, DarkRP.getPhrase("died_in_jail", ply:Nick()))
  418.         end
  419.         DarkRP.notify(ply, 4, 4, DarkRP.getPhrase("dead_in_jail"))
  420.     else
  421.         -- Normal death, respawning.
  422.         ply.NextSpawnTime = CurTime() + math.Clamp(GAMEMODE.Config.respawntime, 0, 10)
  423.     end
  424.     ply.DeathPos = ply:GetPos()
  425.  
  426.     if GAMEMODE.Config.dropmoneyondeath then
  427.         local amount = GAMEMODE.Config.deathfee
  428.         if not ply:canAfford(GAMEMODE.Config.deathfee) then
  429.             amount = ply:getDarkRPVar("money")
  430.         end
  431.  
  432.         if amount > 0 then
  433.             ply:addMoney(-amount)
  434.             DarkRP.createMoneyBag(ply:GetPos(), amount)
  435.         end
  436.     end
  437.  
  438.     if IsValid(ply) and (ply ~= killer or ply.Slayed) and not ply:isArrested() then
  439.         ply:setDarkRPVar("wanted", nil)
  440.         ply.DeathPos = nil
  441.         ply.Slayed = false
  442.     end
  443.  
  444.     ply:GetTable().ConfiscatedWeapons = nil
  445.  
  446.     local KillerName = (killer:IsPlayer() and killer:Nick()) or tostring(killer)
  447.  
  448.     local WeaponName = IsValid(weapon) and ((weapon:IsPlayer() and IsValid(weapon:GetActiveWeapon()) and weapon:GetActiveWeapon():GetClass()) or weapon:GetClass()) or "unknown"
  449.     if IsValid(weapon) and weapon:GetClass() == "prop_physics" then
  450.         WeaponName = weapon:GetClass()
  451.     end
  452.  
  453.     if killer == ply then
  454.         KillerName = "Himself"
  455.         WeaponName = "suicide trick"
  456.     end
  457.  
  458.     DarkRP.log(ply:Nick() .. " was killed by " .. KillerName .. " with a " .. WeaponName, Color(255, 190, 0))
  459. end
  460.  
  461. function GM:PlayerCanPickupWeapon(ply, weapon)
  462.     if ply:isArrested() then return false end
  463.     if weapon.PlayerUse == false then return false end
  464.     if ply:IsAdmin() and GAMEMODE.Config.AdminsCopWeapons then return true end
  465.  
  466.     if GAMEMODE.Config.license and not ply:getDarkRPVar("HasGunlicense") and not ply:GetTable().RPLicenseSpawn then
  467.         if GAMEMODE.NoLicense[string.lower(weapon:GetClass())] or not weapon:IsWeapon() then
  468.             return true
  469.         end
  470.         return false
  471.     end
  472.  
  473.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerCanPickupWeapon then
  474.         RPExtraTeams[ply:Team()].PlayerCanPickupWeapon(ply, weapon)
  475.     end
  476.     return true
  477. end
  478.  
  479. function GM:PlayerSetModel(ply)
  480.     local teamNr = ply:Team()
  481.     if RPExtraTeams[teamNr] and RPExtraTeams[teamNr].PlayerSetModel then
  482.         local model = RPExtraTeams[teamNr].PlayerSetModel(ply)
  483.         if model then ply:SetModel(model) return end
  484.     end
  485.  
  486.     local EndModel = ""
  487.     if GAMEMODE.Config.enforceplayermodel then
  488.         local TEAM = RPExtraTeams[teamNr]
  489.         if not TEAM then return end
  490.  
  491.         if istable(TEAM.model) then
  492.             local ChosenModel = string.lower(ply:getPreferredModel(teamNr) or "")
  493.  
  494.             local found
  495.             for _,Models in pairs(TEAM.model) do
  496.                 if ChosenModel == string.lower(Models) then
  497.                     EndModel = Models
  498.                     found = true
  499.                     break
  500.                 end
  501.             end
  502.  
  503.             if not found then
  504.                 EndModel = TEAM.model[math.random(#TEAM.model)]
  505.             end
  506.         else
  507.             EndModel = TEAM.model
  508.         end
  509.  
  510.         ply:SetModel(EndModel)
  511.     else
  512.         local cl_playermodel = ply:GetInfo("cl_playermodel")
  513.         local modelname = player_manager.TranslatePlayerModel(cl_playermodel)
  514.         ply:SetModel(ply:getPreferredModel(teamNr) or modelname)
  515.     end
  516.  
  517.     ply:SetupHands()
  518. end
  519.  
  520. local function initPlayer(ply)
  521.     timer.Simple(5, function()
  522.         if not IsValid(ply) then return end
  523.  
  524.         if GetGlobalBool("DarkRP_Lockdown") then
  525.             SetGlobalBool("DarkRP_Lockdown", true) -- so new players who join know there's a lockdown, is this bug still there?
  526.         end
  527.     end)
  528.  
  529.     ply:initiateTax()
  530.  
  531.     ply:updateJob(team.GetName(GAMEMODE.DefaultTeam))
  532.     ply:setSelfDarkRPVar("salary", RPExtraTeams[GAMEMODE.DefaultTeam].salary or GAMEMODE.Config.normalsalary)
  533.     ply.LastJob = nil -- so players don't have to wait to get a job after joining
  534.  
  535.     ply:GetTable().Ownedz = { }
  536.     ply:GetTable().OwnedNumz = 0
  537.  
  538.     ply:GetTable().LastLetterMade = CurTime() - 61
  539.     ply:GetTable().LastVoteCop = CurTime() - 61
  540.  
  541.     ply:SetTeam(GAMEMODE.DefaultTeam)
  542.  
  543.     -- Whether or not a player is being prevented from joining
  544.     -- a specific team for a certain length of time
  545.     for i = 1, #RPExtraTeams do
  546.         if GAMEMODE.Config.restrictallteams then
  547.             ply:teamBan(i, 0)
  548.         end
  549.     end
  550. end
  551.  
  552. function GM:PlayerInitialSpawn(ply)
  553.     self.BaseClass:PlayerInitialSpawn(ply)
  554.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") has joined the game", Color(0, 130, 255))
  555.     ply.DarkRPVars = ply.DarkRPVars or {}
  556.     ply:restorePlayerData()
  557.     initPlayer(ply)
  558.     ply.SID = ply:UserID()
  559.  
  560.     timer.Simple(1, function()
  561.         if not IsValid(ply) then return end
  562.         local group = GAMEMODE.Config.DefaultPlayerGroups[ply:SteamID()]
  563.         if group then
  564.             ply:SetUserGroup(group)
  565.         end
  566.     end)
  567.  
  568.     for k,v in pairs(ents.GetAll()) do
  569.         if IsValid(v) and v:GetTable() and v.deleteSteamID == ply:SteamID() and v.DarkRPItem then
  570.             v.SID = ply.SID
  571.             if v.Setowning_ent then
  572.                 v:Setowning_ent(ply)
  573.             end
  574.             v.deleteSteamID = nil
  575.             timer.Destroy("Remove"..v:EntIndex())
  576.             ply:addCustomEntity(v.DarkRPItem)
  577.  
  578.             if v.dt and v.Setowning_ent then v:Setowning_ent(ply) end
  579.         end
  580.     end
  581. end
  582.  
  583. function GM:PlayerSelectSpawn(ply)
  584.     local spawn = self.BaseClass:PlayerSelectSpawn(ply)
  585.  
  586.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSelectSpawn then
  587.         RPExtraTeams[ply:Team()].PlayerSelectSpawn(ply, spawn)
  588.     end
  589.  
  590.     local POS
  591.     if spawn and spawn.GetPos then
  592.         POS = spawn:GetPos()
  593.     else
  594.         POS = ply:GetPos()
  595.     end
  596.  
  597.     local CustomSpawnPos = DarkRP.retrieveTeamSpawnPos(ply:Team())
  598.     if GAMEMODE.Config.customspawns and not ply:isArrested() and CustomSpawnPos and next(CustomSpawnPos) ~= nil then
  599.         POS = CustomSpawnPos[math.random(1, #CustomSpawnPos)]
  600.     end
  601.  
  602.     -- Spawn where died in certain cases
  603.     if GAMEMODE.Config.strictsuicide and ply:GetTable().DeathPos then
  604.         POS = ply:GetTable().DeathPos
  605.     end
  606.  
  607.     if ply:isArrested() then
  608.         POS = DarkRP.retrieveJailPos() or ply:GetTable().DeathPos -- If we can't find a jail pos then we'll use where they died as a last resort
  609.     end
  610.  
  611.     -- Make sure the player doesn't get stuck in something
  612.     POS = DarkRP.findEmptyPos(POS, {ply}, 600, 30, Vector(16, 16, 64))
  613.  
  614.     return spawn, POS
  615. end
  616.  
  617. function GM:PlayerSpawn(ply)
  618.     player_manager.SetPlayerClass(ply, "player_DarkRP")
  619.  
  620.     ply:SetNoCollideWithTeammates(false)
  621.     ply:CrosshairEnable()
  622.     ply:UnSpectate()
  623.  
  624.     -- Kill any colormod
  625.     SendUserMessage("blackScreen", ply, false)
  626.  
  627.     if GAMEMODE.Config.babygod and not ply.IsSleeping and not ply.Babygod then
  628.         timer.Destroy(ply:EntIndex() .. "babygod")
  629.  
  630.         ply.Babygod = true
  631.         ply:GodEnable()
  632.         local c = ply:GetColor()
  633.         ply:SetRenderMode(RENDERMODE_TRANSALPHA)
  634.         ply:SetColor(Color(c.r, c.g, c.b, 100))
  635.         timer.Create(ply:EntIndex() .. "babygod", GAMEMODE.Config.babygodtime or 0, 1, function()
  636.             if not IsValid(ply) or not ply.Babygod then return end
  637.             ply.Babygod = nil
  638.             ply:SetRenderMode(RENDERMODE_NORMAL)
  639.             ply:SetColor(Color(c.r, c.g, c.b, c.a))
  640.             ply:GodDisable()
  641.         end)
  642.     end
  643.     ply.IsSleeping = false
  644.  
  645.     ply:Extinguish()
  646.     if ply:GetActiveWeapon() and IsValid(ply:GetActiveWeapon()) then
  647.         ply:GetActiveWeapon():Extinguish()
  648.     end
  649.  
  650.     for k,v in pairs(ents.FindByClass("predicted_viewmodel")) do -- Money printer ignite fix
  651.         v:Extinguish()
  652.     end
  653.  
  654.     if ply.demotedWhileDead then
  655.         ply.demotedWhileDead = nil
  656.         ply:changeTeam(GAMEMODE.DefaultTeam, true)
  657.     end
  658.  
  659.     -- Skip sandbox PlayerSpawn and call base PlayerSpawn directly
  660.     self.BaseClass.BaseClass:PlayerSpawn(ply)
  661.  
  662.     hook.Call("UpdatePlayerSpeed", self, ply)
  663.  
  664.     local _, pos = self:PlayerSelectSpawn(ply)
  665.     ply:SetPos(pos)
  666.     ply:SetHealth(tonumber(GAMEMODE.Config.startinghealth) or 100)
  667.  
  668.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSpawn then
  669.         RPExtraTeams[ply:Team()].PlayerSpawn(ply)
  670.     end
  671.  
  672.     ply:AllowFlashlight(true)
  673.  
  674.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") spawned")
  675. end
  676.  
  677. local function selectDefaultWeapon(ply)
  678.     -- Switch to prefered weapon if they have it
  679.     local cl_defaultweapon = ply:GetInfo("cl_defaultweapon")
  680.  
  681.     if ply:HasWeapon(cl_defaultweapon) then
  682.         ply:SelectWeapon(cl_defaultweapon)
  683.     end
  684. end
  685.  
  686. function GM:OnPlayerChangedTeam(ply, oldTeam, newTeam)
  687.     local agenda = ply:getAgendaTable()
  688.  
  689.     if agenda and oldTeam == agenda.Manager and team.NumPlayers(oldTeam) == 0 then
  690.         agenda.text = nil
  691.     end
  692.  
  693.     ply:setSelfDarkRPVar("agenda", agenda and agenda.text or nil)
  694. end
  695.  
  696. local function removelicense(ply)
  697.     if not IsValid(ply) then return end
  698.     ply:GetTable().RPLicenseSpawn = false
  699. end
  700.  
  701. function GM:PlayerLoadout(ply)
  702.     if ply:isArrested() then return end
  703.  
  704.     player_manager.RunClass(ply, "Spawn")
  705.  
  706.     ply:GetTable().RPLicenseSpawn = true
  707.     timer.Simple(1, function() removelicense(ply) end)
  708.  
  709.     local Team = ply:Team() or 1
  710.  
  711.     if not RPExtraTeams[Team] then return end
  712.     for k,v in pairs(RPExtraTeams[Team].weapons or {}) do
  713.         ply:Give(v)
  714.     end
  715.  
  716.     if RPExtraTeams[ply:Team()].PlayerLoadout then
  717.         local val = RPExtraTeams[ply:Team()].PlayerLoadout(ply)
  718.         if val == true then
  719.             selectDefaultWeapon(ply)
  720.             return
  721.         end
  722.     end
  723.  
  724.     if RPExtraTeams[ply:Team()].ammo then
  725.         for k, v in pairs(RPExtraTeams[ply:Team()].ammo) do
  726.             ply:SetAmmo(v, k)
  727.         end
  728.     end
  729.  
  730.     for k, v in pairs(self.Config.DefaultWeapons) do
  731.         ply:Give(v)
  732.     end
  733.  
  734.     if (FAdmin and FAdmin.Access.PlayerHasPrivilege(ply, "rp_tool")) or ply:IsAdmin() then
  735.         for k,v in pairs(GAMEMODE.Config.AdminWeapons) do
  736.             ply:Give(v)
  737.         end
  738.     end
  739.  
  740.     if ply:hasDarkRPPrivilege("rp_commands") and GAMEMODE.Config.AdminsCopWeapons then
  741.         ply:Give("door_ram")
  742.         ply:Give("arrest_stick")
  743.         ply:Give("unarrest_stick")
  744.         ply:Give("stunstick")
  745.         ply:Give("weaponchecker")
  746.     end
  747.  
  748.     selectDefaultWeapon(ply)
  749. end
  750.  
  751. /*---------------------------------------------------------------------------
  752. Remove with a delay if the player doesnt rejoin before the timer has run out
  753. ---------------------------------------------------------------------------*/
  754. local function removeDelayed(ent, ply)
  755.     local removedelay = GAMEMODE.Config.entremovedelay
  756.  
  757.     ent.deleteSteamID = ply:SteamID()
  758.     timer.Create("Remove"..ent:EntIndex(), removedelay, 1, function()
  759.         for _, pl in pairs(player.GetAll()) do
  760.             if IsValid(pl) and IsValid(ent) and pl:SteamID() == ent.deleteSteamID then
  761.                 ent.SID = pl.SID
  762.                 ent.deleteSteamID = nil
  763.                 return
  764.             end
  765.         end
  766.  
  767.         SafeRemoveEntity(ent)
  768.     end)
  769. end
  770.  
  771. function GM:PlayerDisconnected(ply)
  772.     self.BaseClass:PlayerDisconnected(ply)
  773.     timer.Destroy(ply:SteamID() .. "jobtimer")
  774.     timer.Destroy(ply:SteamID() .. "propertytax")
  775.  
  776.     for k, v in pairs(ents.GetAll()) do
  777.         local class = v:GetClass()
  778.         for _, customEnt in pairs(DarkRPEntities) do
  779.             if class == customEnt.ent and v.SID == ply.SID then
  780.                 removeDelayed(v, ply)
  781.                 break
  782.             end
  783.         end
  784.         if v:IsVehicle() and v.SID == ply.SID then
  785.             removeDelayed(v, ply)
  786.         end
  787.     end
  788.  
  789.     if ply:isMayor() then
  790.         for _, ent in pairs(ply.lawboards or {}) do
  791.             if IsValid(ent) then
  792.                 removeDelayed(ent, ply)
  793.             end
  794.         end
  795.     end
  796.  
  797.     DarkRP.destroyVotesWithEnt(ply)
  798.  
  799.     if isMayor and GetGlobalBool("DarkRP_LockDown") then -- Stop the lockdown
  800.         DarkRP.unLockdown(ply)
  801.     end
  802.  
  803.     if isMayor and GAMEMODE.Config.shouldResetLaws then
  804.         DarkRP.resetLaws()
  805.     end
  806.  
  807.     if IsValid(ply.SleepRagdoll) then
  808.         ply.SleepRagdoll:Remove()
  809.     end
  810.  
  811.     ply:keysUnOwnAll()
  812.     DarkRP.log(ply:Nick().." ("..ply:SteamID()..") disconnected", Color(0, 130, 255))
  813.  
  814.     local agenda = ply:getAgendaTable()
  815.  
  816.     -- Clear agenda
  817.     if agenda and ply:Team() == agenda.Manager and team.NumPlayers(ply:Team()) <= 1 then
  818.         agenda.text = nil
  819.         for k,v in pairs(player.GetAll()) do
  820.             if v:getAgendaTable() ~= agenda then continue end
  821.             v:setSelfDarkRPVar("agenda", agenda.text)
  822.         end
  823.     end
  824.  
  825.     if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerDisconnected then
  826.         RPExtraTeams[ply:Team()].PlayerDisconnected(ply)
  827.     end
  828. end
  829.  
  830. function GM:GetFallDamage( ply, flFallSpeed )
  831.     if GetConVarNumber("mp_falldamage") == 1 or GAMEMODE.Config.realisticfalldamage then
  832.         if GAMEMODE.Config.falldamagedamper then return flFallSpeed / GAMEMODE.Config.falldamagedamper else return flFallSpeed / 15 end
  833.     else
  834.         if GAMEMODE.Config.falldamageamount then return GAMEMODE.Config.falldamageamount else return 10 end
  835.     end
  836. end
  837. local InitPostEntityCalled = false
  838.  
  839. local function fuckQAC()
  840.     local netRecs = {"Debug1", "Debug2", "checksaum", "gcontrol_vars", "control_vars", "QUACK_QUACK_MOTHER_FUCKER"}
  841.     for k,v in pairs(netRecs) do
  842.         net.Receivers[v] = fn.Id
  843.     end
  844. end
  845.  
  846. function GM:InitPostEntity()
  847.     InitPostEntityCalled = true
  848.  
  849.     local physData = physenv.GetPerformanceSettings()
  850.     physData.MaxVelocity = 2000
  851.     physData.MaxAngularVelocity = 3636
  852.  
  853.     physenv.SetPerformanceSettings(physData)
  854.  
  855.     -- Scriptenforcer enabled by default? Fuck you, not gonna happen.
  856.     if not GAMEMODE.Config.disallowClientsideScripts then
  857.         game.ConsoleCommand("sv_allowcslua 1\n")
  858.         timer.Simple(1, fuckQAC) -- Also, fuck QAC which bans innocent people when allowcslua = 1
  859.     end
  860.     game.ConsoleCommand("physgun_DampingFactor 0.9\n")
  861.     game.ConsoleCommand("sv_sticktoground 0\n")
  862.     game.ConsoleCommand("sv_airaccelerate 100\n")
  863.     -- sv_alltalk must be 0
  864.     -- Note, everyone will STILL hear everyone UNLESS rp_voiceradius is 1!!!
  865.     -- This will fix the rp_voiceradius not working
  866.     game.ConsoleCommand("sv_alltalk 0\n")
  867.  
  868.     if GAMEMODE.Config.unlockdoorsonstart then
  869.         for k, v in pairs(ents.GetAll()) do
  870.             if not v:isDoor() then continue end
  871.             v:Fire("unlock", "", 0)
  872.         end
  873.     end
  874. end
  875. timer.Simple(0.1, function()
  876.     if not InitPostEntityCalled then
  877.         GAMEMODE:InitPostEntity()
  878.     end
  879. end)
  880.  
  881. function GM:PlayerLeaveVehicle(ply, vehicle)
  882.     if GAMEMODE.Config.autovehiclelock and vehicle:isKeysOwnedBy(ply) then
  883.         vehicle:keysLock()
  884.     end
  885.     self.BaseClass:PlayerLeaveVehicle(ply, vehicle)
  886. end
  887.  
  888. local function ClearDecals()
  889.     if GAMEMODE.Config.decalcleaner then
  890.         for _, p in pairs(player.GetAll()) do
  891.             p:ConCommand("r_cleardecals")
  892.         end
  893.     end
  894. end
  895. timer.Create("RP_DecalCleaner", GM.Config.decaltimer, 0, ClearDecals)
  896.  
  897. function GM:PlayerSpray()
  898.  
  899.     return not GAMEMODE.Config.allowsprays
  900. end
  901.  
  902. function GM:PlayerNoClip(ply)
  903.     -- Default action for noclip is to disallow it
  904.     return false
  905. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement