Advertisement
Guest User

Untitled

a guest
Jun 27th, 2013
3,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.70 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2. DarkRP hooks
  3. ---------------------------------------------------------------------------*/
  4. function GM:Initialize()
  5. self.BaseClass:Initialize()
  6. end
  7.  
  8. function GM:PlayerBuyDoor( objPl, objEnt )
  9. return true;
  10. end
  11.  
  12. function GM:PlayerSellDoor( objPl, objEnt )
  13. return false;
  14. end
  15.  
  16. function GM:GetDoorCost( objPl, objEnt )
  17. return GAMEMODE.Config.doorcost ~= 0 and GAMEMODE.Config.doorcost or 30;
  18. end
  19.  
  20. function GM:GetVehicleCost( objPl, objEnt )
  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. if self.Config.DisallowDrop[class] then return false end
  66.  
  67. if not GAMEMODE.Config.restrictdrop then return true end
  68.  
  69. for k,v in pairs(CustomShipments) do
  70. if v.entity ~= class then continue end
  71.  
  72. return true
  73. end
  74.  
  75. return false
  76. end
  77.  
  78. function GM:DatabaseInitialized()
  79. FPP.Init()
  80. DB.Init()
  81. end
  82.  
  83. function GM:CanSeeLogMessage(ply, message, colour)
  84. return ply:IsAdmin()
  85. end
  86.  
  87. function GM:UpdatePlayerSpeed(ply)
  88. if ply:isArrested() then
  89. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.arrestspeed, GAMEMODE.Config.arrestspeed)
  90. elseif ply:IsCP() then
  91. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeedcp)
  92. else
  93. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeed)
  94. end
  95. end
  96.  
  97. /*---------------------------------------------------------
  98. Gamemode functions
  99. ---------------------------------------------------------*/
  100.  
  101. function GM:PlayerSpawnProp(ply, model)
  102. -- If prop spawning is enabled or the user has admin or prop privileges
  103. local allowed = ((GAMEMODE.Config.propspawning or (FAdmin and FAdmin.Access.PlayerHasPrivilege(ply, "rp_prop")) or ply:IsAdmin()) and true) or false
  104.  
  105. if ply:isArrested() then return false end
  106. model = string.gsub(tostring(model), "\\", "/")
  107. model = string.gsub(tostring(model), "//", "/")
  108.  
  109. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSpawnProp then
  110. RPExtraTeams[ply:Team()].PlayerSpawnProp(ply, model)
  111. end
  112.  
  113. if not allowed then return false end
  114.  
  115. return self.BaseClass:PlayerSpawnProp(ply, model)
  116. end
  117.  
  118. function GM:PlayerSpawnSENT(ply, model)
  119. if GAMEMODE.Config.adminsents then
  120. if ply:EntIndex() ~= 0 and not ply:IsAdmin() then
  121. GAMEMODE:Notify(ply, 1, 2, string.format(LANGUAGE.need_admin, "gm_spawnsent"))
  122. return
  123. end
  124. end
  125. return self.BaseClass:PlayerSpawnSENT(ply, model) and not ply:isArrested()
  126. end
  127.  
  128. local function canSpawnWeapon(ply, class)
  129. if (not GAMEMODE.Config.adminweapons == 0 and ply:IsAdmin()) or
  130. (GAMEMODE.Config.adminweapons == 1 and ply:IsSuperAdmin()) then
  131. return true
  132. end
  133. GAMEMODE:Notify(ply, 1, 4, "You can't spawn weapons")
  134.  
  135. return false
  136. end
  137.  
  138. function GM:PlayerSpawnSWEP(ply, class, model)
  139. return canSpawnWeapon(ply, class) and self.BaseClass:PlayerSpawnSWEP(ply, class, model) and not ply:isArrested()
  140. end
  141.  
  142. function GM:PlayerGiveSWEP(ply, class, model)
  143. return canSpawnWeapon(ply, class) and self.BaseClass:PlayerGiveSWEP(ply, class, model) and not ply:isArrested()
  144. end
  145.  
  146. function GM:PlayerSpawnEffect(ply, model)
  147. return self.BaseClass:PlayerSpawnEffect(ply, model) and not ply:isArrested()
  148. end
  149.  
  150. function GM:PlayerSpawnVehicle(ply, model)
  151. return self.BaseClass:PlayerSpawnVehicle(ply, model) and not ply:isArrested()
  152. end
  153.  
  154. function GM:PlayerSpawnNPC(ply, model)
  155. if GAMEMODE.Config.adminnpcs and not ply:IsAdmin() then return false end
  156.  
  157. return self.BaseClass:PlayerSpawnNPC(ply, model) and not ply:isArrested()
  158. end
  159.  
  160. function GM:PlayerSpawnRagdoll(ply, model)
  161. return self.BaseClass:PlayerSpawnRagdoll(ply, model) and not ply:isArrested()
  162. end
  163.  
  164. function GM:PlayerSpawnedProp(ply, model, ent)
  165. self.BaseClass:PlayerSpawnedProp(ply, model, ent)
  166. ent.SID = ply.SID
  167. ent:CPPISetOwner(ply)
  168.  
  169. local phys = ent:GetPhysicsObject()
  170. if phys and phys:IsValid() then
  171. ent.RPOriginalMass = phys:GetMass()
  172. end
  173.  
  174. if GAMEMODE.Config.proppaying then
  175. if ply:CanAfford(GAMEMODE.Config.propcost) then
  176. GAMEMODE:Notify(ply, 0, 4, "Deducted " .. GAMEMODE.Config.currency .. GAMEMODE.Config.propcost)
  177. ply:AddMoney(-GAMEMODE.Config.propcost)
  178. else
  179. GAMEMODE:Notify(ply, 1, 4, "Need " .. GAMEMODE.Config.currency .. GAMEMODE.Config.propcost)
  180. return false
  181. end
  182. end
  183. end
  184.  
  185. function GM:PlayerSpawnedRagdoll(ply, model, ent)
  186. self.BaseClass:PlayerSpawnedRagdoll(ply, model, ent)
  187. ent.SID = ply.SID
  188. end
  189.  
  190. function GM:EntityRemoved(ent)
  191. self.BaseClass:EntityRemoved(ent)
  192. if ent:IsVehicle() then
  193. local found = ent:CPPIGetOwner()
  194. if IsValid(found) then
  195. found.Vehicles = found.Vehicles or 1
  196. found.Vehicles = found.Vehicles - 1
  197. end
  198. end
  199.  
  200. for k,v in pairs(DarkRPEntities or {}) do
  201. if ent:IsValid() and ent:GetClass() == v.ent and ent.dt and IsValid(ent.dt.owning_ent) and not ent.IsRemoved then
  202. local ply = ent.dt.owning_ent
  203. local cmdname = string.gsub(v.ent, " ", "_")
  204. if not ply["max"..cmdname] then
  205. ply["max"..cmdname] = 1
  206. end
  207. ply["max"..cmdname] = ply["max"..cmdname] - 1
  208. ent.IsRemoved = true
  209. end
  210. end
  211. end
  212.  
  213. function GM:ShowSpare1(ply)
  214. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].ShowSpare1 then
  215. return RPExtraTeams[ply:Team()].ShowSpare1(ply)
  216. end
  217. end
  218.  
  219. function GM:ShowSpare2(ply)
  220. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].ShowSpare2 then
  221. return RPExtraTeams[ply:Team()].ShowSpare2(ply)
  222. end
  223. umsg.Start("ChangeJobVGUI", ply)
  224. umsg.End()
  225. end
  226.  
  227. function GM:OnNPCKilled(victim, ent, weapon)
  228. -- If something killed the npc
  229. if ent then
  230. if ent:IsVehicle() and ent:GetDriver():IsPlayer() then ent = ent:GetDriver() end
  231.  
  232. -- If it wasn't a player directly, find out who owns the prop that did the killing
  233. if not ent:IsPlayer() then
  234. ent = Player(tonumber(ent.SID) or 0)
  235. end
  236.  
  237. -- If we know by now who killed the NPC, pay them.
  238. if IsValid(ent) and GAMEMODE.Config.npckillpay > 0 then
  239. ent:AddMoney(GAMEMODE.Config.npckillpay)
  240. GAMEMODE:Notify(ent, 0, 4, string.format(LANGUAGE.npc_killpay, GAMEMODE.Config.currency .. GAMEMODE.Config.npckillpay))
  241. end
  242. end
  243. end
  244.  
  245. function GM:KeyPress(ply, code)
  246. self.BaseClass:KeyPress(ply, code)
  247. end
  248.  
  249. local function IsInRoom(listener, talker) -- IsInRoom function to see if the player is in the same room.
  250. local tracedata = {}
  251. tracedata.start = talker:GetShootPos()
  252. tracedata.endpos = listener:GetShootPos()
  253. local trace = util.TraceLine( tracedata )
  254.  
  255. return not trace.HitWorld
  256. end
  257.  
  258. local threed = GM.Config.voice3D
  259. local vrad = GM.Config.voiceradius
  260. local dynv = GM.Config.dynamicvoice
  261. function GM:PlayerCanHearPlayersVoice(listener, talker, other)
  262. if vrad and listener:GetShootPos():Distance(talker:GetShootPos()) < 550 then
  263. if dynv then
  264. if IsInRoom(listener, talker) then
  265. return true, threed
  266. else
  267. return false, threed
  268. end
  269. end
  270. return true, threed
  271. elseif vrad then
  272. return false, threed
  273. end
  274. return true, threed
  275. end
  276.  
  277. function GM:CanTool(ply, trace, mode)
  278. if not self.BaseClass:CanTool(ply, trace, mode) then return false end
  279.  
  280. if IsValid(trace.Entity) then
  281. if trace.Entity.onlyremover then
  282. if mode == "remover" then
  283. return (ply:IsAdmin() or ply:IsSuperAdmin())
  284. else
  285. return false
  286. end
  287. end
  288.  
  289. if trace.Entity.nodupe and (mode == "weld" or
  290. mode == "weld_ez" or
  291. mode == "spawner" or
  292. mode == "duplicator" or
  293. mode == "adv_duplicator") then
  294. return false
  295. end
  296.  
  297. if trace.Entity:IsVehicle() and mode == "nocollide" and not GAMEMODE.Config.allowvnocollide then
  298. return false
  299. end
  300. end
  301. return true
  302. end
  303.  
  304. function GM:CanPlayerSuicide(ply)
  305. if ply.IsSleeping then
  306. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.unable, "suicide", ""))
  307. return false
  308. end
  309. if ply:isArrested() then
  310. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.unable, "suicide", ""))
  311. return false
  312. end
  313. if GAMEMODE.Config.wantedsuicide and ply:getDarkRPVar("wanted") then
  314. GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.unable, "suicide", ""))
  315. return false
  316. end
  317.  
  318. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].CanPlayerSuicide then
  319. return RPExtraTeams[ply:Team()].CanPlayerSuicide(ply)
  320. end
  321. return true
  322. end
  323.  
  324. function GM:CanDrive(ply, ent)
  325. GAMEMODE:Notify(ply, 1, 4, "Drive disabled for now.")
  326. return false -- Disabled until people can't minge with it anymore
  327. end
  328.  
  329. local allowedProperty = {
  330. remover = true,
  331. ignite = false,
  332. extinguish = true,
  333. keepupright = true,
  334. gravity = true,
  335. collision = true,
  336. skin = true,
  337. bodygroups = true
  338. }
  339. function GM:CanProperty(ply, property, ent)
  340. if allowedProperty[property] and ent:CPPICanTool(ply, "remover") then
  341. return true
  342. end
  343.  
  344. if property == "persist" and ply:IsSuperAdmin() then
  345. return true
  346. end
  347. GAMEMODE:Notify(ply, 1, 4, "Property disabled for now.")
  348. return false -- Disabled until antiminge measure is found
  349. end
  350.  
  351. function GM:DoPlayerDeath(ply, attacker, dmginfo, ...)
  352. local weapon = ply:GetActiveWeapon()
  353. local canDrop = hook.Call("CanDropWeapon", self, ply, weapon)
  354.  
  355. if GAMEMODE.Config.dropweapondeath and IsValid(weapon) and canDrop then
  356. ply:DropDRPWeapon(weapon)
  357. end
  358. self.BaseClass:DoPlayerDeath(ply, attacker, dmginfo, ...)
  359. end
  360.  
  361. function GM:PlayerDeath(ply, weapon, killer)
  362. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerDeath then
  363. RPExtraTeams[ply:Team()].PlayerDeath(ply, weapon, killer)
  364. end
  365.  
  366. if GAMEMODE.Config.deathblack then
  367. SendUserMessage("blackScreen", ply, true)
  368. end
  369.  
  370. if weapon:IsVehicle() and weapon:GetDriver():IsPlayer() then killer = weapon:GetDriver() end
  371.  
  372. if GAMEMODE.Config.showdeaths then
  373. self.BaseClass:PlayerDeath(ply, weapon, killer)
  374. end
  375.  
  376. ply:Extinguish()
  377.  
  378. if ply:InVehicle() then ply:ExitVehicle() end
  379.  
  380. if ply:isArrested() and not GAMEMODE.Config.respawninjail then
  381. -- If the player died in jail, make sure they can't respawn until their jail sentance is over
  382. ply.NextSpawnTime = CurTime() + math.ceil(GAMEMODE.Config.jailtimer - (CurTime() - ply.LastJailed)) + 1
  383. for a, b in pairs(player.GetAll()) do
  384. b:PrintMessage(HUD_PRINTCENTER, string.format(LANGUAGE.died_in_jail, ply:Nick()))
  385. end
  386. GAMEMODE:Notify(ply, 4, 4, LANGUAGE.dead_in_jail)
  387. else
  388. -- Normal death, respawning.
  389. ply.NextSpawnTime = CurTime() + math.Clamp(GAMEMODE.Config.respawntime, 0, 10)
  390. end
  391. ply.DeathPos = ply:GetPos()
  392.  
  393. if GAMEMODE.Config.dropmoneyondeath then
  394. local amount = GAMEMODE.Config.deathfee
  395. if not ply:CanAfford(GAMEMODE.Config.deathfee) then
  396. amount = ply:getDarkRPVar("money")
  397. end
  398.  
  399. if amount > 0 then
  400. ply:AddMoney(-amount)
  401. DarkRPCreateMoneyBag(ply:GetPos(), amount)
  402. end
  403. end
  404.  
  405. if IsValid(ply) and (ply ~= killer or ply.Slayed) and not ply:isArrested() then
  406. ply:SetDarkRPVar("wanted", false)
  407. ply.DeathPos = nil
  408. ply.Slayed = false
  409. end
  410.  
  411. ply:GetTable().ConfiscatedWeapons = nil
  412.  
  413. local KillerName = (killer:IsPlayer() and killer:Nick()) or tostring(killer)
  414.  
  415. local WeaponName = IsValid(weapon) and ((weapon:IsPlayer() and IsValid(weapon:GetActiveWeapon()) and weapon:GetActiveWeapon():GetClass()) or weapon:GetClass()) or "unknown"
  416. if IsValid(weapon) and weapon:GetClass() == "prop_physics" then
  417. WeaponName = weapon:GetClass() .. " (" .. (weapon:GetModel() or "unknown") .. ")"
  418. end
  419.  
  420. if killer == ply then
  421. KillerName = "Himself"
  422. WeaponName = "suicide trick"
  423. end
  424.  
  425. DB.Log(ply:Nick() .. " was killed by " .. KillerName .. " with a " .. WeaponName, nil, Color(255, 190, 0))
  426. end
  427.  
  428. function GM:PlayerCanPickupWeapon(ply, weapon)
  429. if ply:isArrested() then return false end
  430. if weapon.PlayerUse == false then return false end
  431. if ply:IsAdmin() and GAMEMODE.Config.AdminsCopWeapons then return true end
  432.  
  433. if GAMEMODE.Config.license and not ply:getDarkRPVar("HasGunlicense") and not ply:GetTable().RPLicenseSpawn then
  434. if GAMEMODE.NoLicense[string.lower(weapon:GetClass())] or not weapon:IsWeapon() then
  435. return true
  436. end
  437. return false
  438. end
  439.  
  440. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerCanPickupWeapon then
  441. RPExtraTeams[ply:Team()].PlayerCanPickupWeapon(ply, weapon)
  442. end
  443. return true
  444. end
  445.  
  446. local function removelicense(ply)
  447. if not IsValid(ply) then return end
  448. ply:GetTable().RPLicenseSpawn = false
  449. end
  450.  
  451. local function SetPlayerModel(ply, cmd, args)
  452. if not args[1] then return end
  453. ply.rpChosenModel = args[1]
  454. end
  455. concommand.Add("_rp_ChosenModel", SetPlayerModel)
  456.  
  457. function GM:PlayerSetModel(ply)
  458. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSetModel then
  459. return RPExtraTeams[ply:Team()].PlayerSetModel(ply)
  460. end
  461.  
  462. local EndModel = ""
  463. if GAMEMODE.Config.enforceplayermodel then
  464. local TEAM = RPExtraTeams[ply:Team()]
  465. if not TEAM then return end
  466.  
  467. if type(TEAM.model) == "table" then
  468. local ChosenModel = ply.rpChosenModel or ply:GetInfo("rp_playermodel")
  469. ChosenModel = string.lower(ChosenModel)
  470.  
  471. local found
  472. for _,Models in pairs(TEAM.model) do
  473. if ChosenModel == string.lower(Models) then
  474. EndModel = Models
  475. found = true
  476. break
  477. end
  478. end
  479.  
  480. if not found then
  481. EndModel = TEAM.model[math.random(#TEAM.model)]
  482. end
  483. else
  484. EndModel = TEAM.model
  485. end
  486.  
  487. ply:SetModel(EndModel)
  488. else
  489. local cl_playermodel = ply:GetInfo("cl_playermodel")
  490. local modelname = player_manager.TranslatePlayerModel( cl_playermodel )
  491. ply:SetModel( modelname )
  492. end
  493. end
  494.  
  495. function GM:PlayerInitialSpawn(ply)
  496. self.BaseClass:PlayerInitialSpawn(ply)
  497. DB.Log(ply:Nick().." ("..ply:SteamID()..") has joined the game", nil, Color(0, 130, 255))
  498. ply.bannedfrom = {}
  499. ply.DarkRPVars = ply.DarkRPVars or {}
  500. ply:NewData()
  501. ply.SID = ply:UserID()
  502.  
  503. for k,v in pairs(ents.GetAll()) do
  504. if IsValid(v) and v.deleteSteamID == ply:SteamID() and v.dt then
  505. v.SID = ply.SID
  506. if v.Setowning_ent then
  507. v:Setowning_ent(ply)
  508. end
  509. v.deleteSteamID = nil
  510. timer.Destroy("Remove"..v:EntIndex())
  511. ply["max"..v:GetClass()] = (ply["max"..v:GetClass()] or 0) + 1
  512. if v.dt and v.Setowning_ent then v:Setowning_ent(ply) end
  513. end
  514. end
  515. end
  516.  
  517. local function formatDarkRPValue(value)
  518. if value == nil then return "nil" end
  519.  
  520. if isentity(value) and not IsValid(value) then return "NULL" end
  521. if isentity(value) and value:IsPlayer() then return string.format("Entity [%s][Player]", value:EntIndex()) end
  522.  
  523. return tostring(value)
  524. end
  525.  
  526. local meta = FindMetaTable("Player")
  527. function meta:SetDarkRPVar(var, value, target)
  528. if not IsValid(self) then return end
  529. target = target or RecipientFilter():AddAllPlayers()
  530.  
  531. hook.Call("DarkRPVarChanged", nil, self, var, (self.DarkRPVars and self.DarkRPVars[var]) or nil, value)
  532.  
  533. self.DarkRPVars = self.DarkRPVars or {}
  534. self.DarkRPVars[var] = value
  535.  
  536. value = formatDarkRPValue(value)
  537.  
  538. umsg.Start("DarkRP_PlayerVar", target)
  539. -- The index because the player handle might not exist clientside yet
  540. umsg.Short(self:EntIndex())
  541. umsg.String(var)
  542. umsg.String(value)
  543. umsg.End()
  544. end
  545.  
  546. function meta:SetSelfDarkRPVar(var, value)
  547. self.privateDRPVars = self.privateDRPVars or {}
  548. self.privateDRPVars[var] = true
  549.  
  550. self:SetDarkRPVar(var, value, self)
  551. end
  552.  
  553. function meta:getDarkRPVar(var)
  554. self.DarkRPVars = self.DarkRPVars or {}
  555. return self.DarkRPVars[var]
  556. end
  557.  
  558. local function SendDarkRPVars(ply)
  559. if ply.DarkRPVarsSent and ply.DarkRPVarsSent > (CurTime() - 1) then return end --prevent spammers
  560. ply.DarkRPVarsSent = CurTime()
  561.  
  562. local sendtable = {}
  563. for k,v in pairs(player.GetAll()) do
  564. sendtable[v] = {}
  565. for a,b in pairs(v.DarkRPVars or {}) do
  566. if not (v.privateDRPVars or {})[a] or ply == v then
  567. sendtable[v][a] = b
  568. end
  569. end
  570. end
  571. net.Start("DarkRP_InitializeVars")
  572. net.WriteTable(sendtable)
  573. net.Send(ply)
  574. end
  575. concommand.Add("_sendDarkRPvars", SendDarkRPVars)
  576.  
  577. local function refreshDoorData(ply, _, args)
  578. if ply.DoorDataSent and ply.DoorDataSent > (CurTime() - 0.5) then return end
  579. ply.DoorDataSent = CurTime()
  580.  
  581. local ent = Entity(tonumber(args[1]) or -1)
  582. if not IsValid(ent) or not ent.DoorData then return end
  583.  
  584. net.Start("DarkRP_DoorData")
  585. net.WriteEntity(ent)
  586. net.WriteTable(ent.DoorData)
  587. net.Send(ply)
  588. ply.DRP_DoorMemory = ply.DRP_DoorMemory or {}
  589. ply.DRP_DoorMemory[ent] = table.Copy(ent.DoorData)
  590. end
  591. concommand.Add("_RefreshDoorData", refreshDoorData)
  592.  
  593. function GM:PlayerSelectSpawn(ply)
  594. local spawn = self.BaseClass:PlayerSelectSpawn(ply)
  595.  
  596. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSelectSpawn then
  597. RPExtraTeams[ply:Team()].PlayerSelectSpawn(ply, spawn)
  598. end
  599.  
  600. local POS
  601. if spawn and spawn.GetPos then
  602. POS = spawn:GetPos()
  603. else
  604. POS = ply:GetPos()
  605. end
  606.  
  607. local CustomSpawnPos = DB.RetrieveTeamSpawnPos(ply)
  608. if GAMEMODE.Config.customspawns and not ply:isArrested() and CustomSpawnPos then
  609. POS = CustomSpawnPos[math.random(1, #CustomSpawnPos)]
  610. end
  611.  
  612. -- Spawn where died in certain cases
  613. if GAMEMODE.Config.strictsuicide and ply:GetTable().DeathPos then
  614. POS = ply:GetTable().DeathPos
  615. end
  616.  
  617. if ply:isArrested() then
  618. POS = DB.RetrieveJailPos() or ply:GetTable().DeathPos -- If we can't find a jail pos then we'll use where they died as a last resort
  619. end
  620.  
  621. -- Make sure the player doesn't get stuck in something
  622. POS = GAMEMODE:FindEmptyPos(POS, {ply}, 600, 30, Vector(16, 16, 64))
  623.  
  624. return spawn, POS
  625. end
  626.  
  627. function GM:PlayerSpawn(ply)
  628. self.BaseClass:PlayerSpawn(ply)
  629.  
  630. player_manager.SetPlayerClass(ply, "player_DarkRP")
  631.  
  632. ply:SetNoCollideWithTeammates(false)
  633. ply:CrosshairEnable()
  634. ply:UnSpectate()
  635. ply:SetHealth(tonumber(GAMEMODE.Config.startinghealth) or 100)
  636.  
  637. if not GAMEMODE.Config.showcrosshairs then
  638. ply:CrosshairDisable()
  639. end
  640.  
  641. -- Kill any colormod
  642. SendUserMessage("blackScreen", ply, false)
  643.  
  644. if GAMEMODE.Config.babygod and not ply.IsSleeping and not ply.Babygod then
  645. timer.Destroy(ply:EntIndex() .. "babygod")
  646.  
  647. ply.Babygod = true
  648. ply:GodEnable()
  649. local c = ply:GetColor()
  650. ply:SetRenderMode(RENDERMODE_TRANSALPHA)
  651. ply:SetColor(Color(c.r, c.g, c.b, 100))
  652. ply:SetCollisionGroup(COLLISION_GROUP_WORLD)
  653. timer.Create(ply:EntIndex() .. "babygod", GAMEMODE.Config.babygodtime or 0, 1, function()
  654. if not IsValid(ply) or not ply.Babygod then return end
  655. ply.Babygod = nil
  656. ply:SetColor(Color(c.r, c.g, c.b, c.a))
  657. ply:GodDisable()
  658. ply:SetCollisionGroup(COLLISION_GROUP_PLAYER)
  659. end)
  660. end
  661. ply.IsSleeping = false
  662.  
  663. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeed)
  664. if ply:IsCP() then
  665. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.walkspeed, GAMEMODE.Config.runspeedcp)
  666. end
  667.  
  668. if ply:isArrested() then
  669. GAMEMODE:SetPlayerSpeed(ply, GAMEMODE.Config.arrestspeed, GAMEMODE.Config.arrestspeed)
  670. end
  671.  
  672. ply:Extinguish()
  673. if ply:GetActiveWeapon() and IsValid(ply:GetActiveWeapon()) then
  674. ply:GetActiveWeapon():Extinguish()
  675. end
  676.  
  677. for k,v in pairs(ents.FindByClass("predicted_viewmodel")) do -- Money printer ignite fix
  678. v:Extinguish()
  679. end
  680.  
  681. if ply.demotedWhileDead then
  682. ply.demotedWhileDead = nil
  683. ply:ChangeTeam(TEAM_CITIZEN)
  684. end
  685.  
  686. ply:GetTable().StartHealth = ply:Health()
  687. gamemode.Call("PlayerSetModel", ply)
  688. gamemode.Call("PlayerLoadout", ply)
  689.  
  690. local _, pos = self:PlayerSelectSpawn(ply)
  691. ply:SetPos(pos)
  692.  
  693. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerSpawn then
  694. RPExtraTeams[ply:Team()].PlayerSpawn(ply)
  695. end
  696.  
  697. ply:AllowFlashlight(true)
  698. DB.Log(ply:Nick().." ("..ply:SteamID()..") spawned")
  699. end
  700.  
  701. local function selectDefaultWeapon(ply)
  702. -- Switch to prefered weapon if they have it
  703. local cl_defaultweapon = ply:GetInfo("cl_defaultweapon")
  704.  
  705. if ply:HasWeapon(cl_defaultweapon) then
  706. ply:SelectWeapon(cl_defaultweapon)
  707. end
  708. end
  709.  
  710. function GM:OnPlayerChangedTeam(ply, oldTeam, newTeam)
  711. end
  712.  
  713. function GM:PlayerLoadout(ply)
  714. if ply:isArrested() then return end
  715.  
  716. player_manager.RunClass(ply, "Spawn")
  717.  
  718. ply:GetTable().RPLicenseSpawn = true
  719. timer.Simple(1, function() removelicense(ply) end)
  720.  
  721. local Team = ply:Team() or 1
  722.  
  723. if not RPExtraTeams[Team] then return end
  724. for k,v in pairs(RPExtraTeams[Team].weapons or {}) do
  725. ply:Give(v)
  726. end
  727.  
  728. if RPExtraTeams[ply:Team()].PlayerLoadout then
  729. local val = RPExtraTeams[ply:Team()].PlayerLoadout(ply)
  730. if val == true then
  731. selectDefaultWeapon(ply)
  732. return
  733. end
  734. end
  735.  
  736. for k, v in pairs(self.Config.DefaultWeapons) do
  737. ply:Give(v)
  738. end
  739.  
  740. if (FAdmin and FAdmin.Access.PlayerHasPrivilege(ply, "rp_tool")) or ply:IsAdmin() then
  741. ply:Give("gmod_tool")
  742. end
  743.  
  744. if (FAdmin and FAdmin.Access.PlayerHasPrivilege(ply, "rp_tool")) or ply:IsAdmin() then
  745. ply:Give("weapon_keypadchecker")
  746. end
  747.  
  748. if ply:HasPriv("rp_commands") and GAMEMODE.Config.AdminsCopWeapons then
  749. ply:Give("door_ram")
  750. ply:Give("arrest_stick")
  751. ply:Give("unarrest_stick")
  752. ply:Give("stunstick")
  753. ply:Give("weaponchecker")
  754. end
  755.  
  756. selectDefaultWeapon(ply)
  757. end
  758.  
  759. local function removeDelayed(ent, ply)
  760. local removedelay = GAMEMODE.Config.entremovedelay
  761.  
  762. ent.deleteSteamID = ply:SteamID()
  763. timer.Create("Remove"..ent:EntIndex(), removedelay, 1, function()
  764. for _, pl in pairs(player.GetAll()) do
  765. if IsValid(pl) and IsValid(ent) and pl:SteamID() == ent.deleteSteamID then
  766. ent.SID = pl.SID
  767. ent.deleteSteamID = nil
  768. return
  769. end
  770. end
  771.  
  772. SafeRemoveEntity(ent)
  773. end)
  774. end
  775.  
  776. function GM:PlayerDisconnected(ply)
  777. self.BaseClass:PlayerDisconnected(ply)
  778. timer.Destroy(ply:SteamID() .. "jobtimer")
  779. timer.Destroy(ply:SteamID() .. "propertytax")
  780.  
  781. for k, v in pairs(ents.GetAll()) do
  782. local class = v:GetClass()
  783. for _, customEnt in pairs(DarkRPEntities) do
  784. if class == customEnt.ent and v.SID == ply.SID then
  785. removeDelayed(v, ply)
  786. break
  787. end
  788. end
  789. if v:IsVehicle() and v.SID == ply.SID then
  790. removeDelayed(v, ply)
  791. end
  792. end
  793.  
  794. if ply:Team() == TEAM_MAYOR then
  795. for _, ent in pairs(ply.lawboards or {}) do
  796. if IsValid(ent) then
  797. removeDelayed(ent, ply)
  798. end
  799. end
  800. end
  801.  
  802. GAMEMODE.vote.DestroyVotesWithEnt(ply)
  803.  
  804. if ply:Team() == TEAM_MAYOR and tobool(GetConVarNumber("DarkRP_LockDown")) then -- Stop the lockdown
  805. GAMEMODE:UnLockdown(ply)
  806. end
  807.  
  808. if IsValid(ply.SleepRagdoll) then
  809. ply.SleepRagdoll:Remove()
  810. end
  811.  
  812. ply:UnownAll()
  813. DB.Log(ply:Nick().." ("..ply:SteamID()..") disconnected", nil, Color(0, 130, 255))
  814.  
  815. if RPExtraTeams[ply:Team()] and RPExtraTeams[ply:Team()].PlayerDisconnected then
  816. RPExtraTeams[ply:Team()].PlayerDisconnected(ply)
  817. end
  818. end
  819.  
  820. local function PlayerDoorCheck()
  821. for k, ply in pairs(player.GetAll()) do
  822. local trace = ply:GetEyeTrace()
  823. if IsValid(trace.Entity) and (trace.Entity:IsDoor() or trace.Entity:IsVehicle()) and ply.LookingAtDoor ~= trace.Entity and trace.HitPos:Distance(ply:GetShootPos()) < 410 then
  824. ply.LookingAtDoor = trace.Entity -- Variable that prevents streaming to clients every frame
  825.  
  826. trace.Entity.DoorData = trace.Entity.DoorData or {}
  827.  
  828. local DoorString = "Data:\n"
  829. for key, v in pairs(trace.Entity.DoorData) do
  830. DoorString = DoorString .. key.."\t\t".. tostring(v) .. "\n"
  831. end
  832.  
  833. if not ply.DRP_DoorMemory or not ply.DRP_DoorMemory[trace.Entity] then
  834. net.Start("DarkRP_DoorData")
  835. net.WriteEntity(trace.Entity)
  836. net.WriteTable(trace.Entity.DoorData)
  837. net.Send(ply)
  838. ply.DRP_DoorMemory = ply.DRP_DoorMemory or {}
  839. ply.DRP_DoorMemory[trace.Entity] = table.Copy(trace.Entity.DoorData)
  840. else
  841. for key, v in pairs(trace.Entity.DoorData) do
  842. if not ply.DRP_DoorMemory[trace.Entity][key] or ply.DRP_DoorMemory[trace.Entity][key] ~= v then
  843. ply.DRP_DoorMemory[trace.Entity][key] = v
  844. umsg.Start("DRP_UpdateDoorData", ply)
  845. umsg.Entity(trace.Entity)
  846. umsg.String(key)
  847. umsg.String(tostring(v))
  848. umsg.End()
  849. end
  850. end
  851.  
  852. for key, v in pairs(ply.DRP_DoorMemory[trace.Entity]) do
  853. if not trace.Entity.DoorData[key] then
  854. ply.DRP_DoorMemory[trace.Entity][key] = nil
  855. umsg.Start("DRP_UpdateDoorData", ply)
  856. umsg.Entity(trace.Entity)
  857. umsg.String(key)
  858. umsg.String("nil")
  859. umsg.End()
  860. end
  861. end
  862. end
  863. elseif ply.LookingAtDoor ~= trace.Entity then
  864. ply.LookingAtDoor = nil
  865. end
  866. end
  867. end
  868. timer.Create("RP_DoorCheck", 0.1, 0, PlayerDoorCheck)
  869.  
  870. function GM:GetFallDamage( ply, flFallSpeed )
  871. if GetConVarNumber("mp_falldamage") == 1 then
  872. return flFallSpeed / 15
  873. end
  874. return 10
  875. end
  876.  
  877. local InitPostEntityCalled = false
  878. function GM:InitPostEntity()
  879. if not RP_MySQLConfig or not RP_MySQLConfig.EnableMySQL then
  880. hook.Call("DatabaseInitialized")
  881. end
  882.  
  883. InitPostEntityCalled = true
  884. timer.Simple(1, function()
  885. if RP_MySQLConfig and RP_MySQLConfig.EnableMySQL then
  886. DB.ConnectToMySQL(RP_MySQLConfig.Host, RP_MySQLConfig.Username, RP_MySQLConfig.Password, RP_MySQLConfig.Database_name, RP_MySQLConfig.Database_port)
  887. return
  888. end
  889. end)
  890.  
  891. local physData = physenv.GetPerformanceSettings()
  892. physData.MaxVelocity = 2000
  893. physData.MaxAngularVelocity = 3636
  894.  
  895. physenv.SetPerformanceSettings(physData)
  896.  
  897. -- Scriptenforcer enabled by default? Fuck you, not gonna happen.
  898. game.ConsoleCommand("sv_allowcslua 1\n")
  899. game.ConsoleCommand("physgun_DampingFactor 0.9\n")
  900. game.ConsoleCommand("sv_sticktoground 0\n")
  901. game.ConsoleCommand("sv_airaccelerate 100\n")
  902.  
  903. for k, v in pairs(ents.GetAll()) do
  904. local class = v:GetClass()
  905. if GAMEMODE.Config.unlockdoorsonstart and v:IsDoor() then
  906. v:Fire("unlock", "", 0)
  907. end
  908. end
  909.  
  910. self:ReplaceChatHooks()
  911. end
  912. timer.Simple(0.1, function()
  913. if not InitPostEntityCalled then
  914. GAMEMODE:InitPostEntity()
  915. end
  916. end)
  917.  
  918. function GM:PlayerLeaveVehicle(ply, vehicle)
  919. if GAMEMODE.Config.autovehiclelock and vehicle:OwnedBy(ply) then
  920. vehicle:KeysLock()
  921. end
  922. self.BaseClass:PlayerLeaveVehicle(ply, vehicle)
  923. end
  924.  
  925. local function ClearDecals()
  926. if GAMEMODE.Config.decalcleaner then
  927. for _, p in pairs( player.GetAll() ) do
  928. p:ConCommand("r_cleardecals")
  929. end
  930. end
  931. end
  932. timer.Create("RP_DecalCleaner", GM.Config.decaltimer, 0, ClearDecals)
  933.  
  934. function GM:PlayerSpray()
  935.  
  936. return not GAMEMODE.Config.allowsprays
  937. end
  938.  
  939. function GM:PlayerNoClip(ply)
  940. -- Default action for noclip is to disallow it
  941. return false
  942. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement