Advertisement
Guest User

Untitled

a guest
Dec 18th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 47.21 KB | None | 0 0
  1. --[[
  2. Name: "init.lua".
  3.     ~ Applejack ~
  4. --]]
  5. --
  6. require"tmysql"
  7.  
  8. -- Include the shared gamemode file.
  9. include("sh_init.lua")
  10.  
  11. -- Add the Lua files that we need to send to the client.
  12. AddCSLuaFile("cl_init.lua")
  13. AddCSLuaFile("sh_init.lua")
  14. AddCSLuaFile("sh_configuration.lua")
  15. AddCSLuaFile("sh_enumerations.lua")
  16. AddCSLuaFile("scoreboard/admin_buttons.lua")
  17. AddCSLuaFile("scoreboard/player_frame.lua")
  18. AddCSLuaFile("scoreboard/player_infocard.lua")
  19. AddCSLuaFile("scoreboard/player_row.lua")
  20. AddCSLuaFile("scoreboard/scoreboard.lua")
  21. AddCSLuaFile("scoreboard/vote_button.lua")
  22.  
  23. -- Enable realistic fall damage for this gamemode.
  24. game.ConsoleCommand("mp_falldamage 1\n")
  25. game.ConsoleCommand("sbox_godmode 0\n")
  26. game.ConsoleCommand("sbox_plpldamage 0\n")
  27.  
  28. -- Check to see if local voice is enabled.
  29. if (GM.Config["Local Voice"]) then
  30.     game.ConsoleCommand("sv_voiceenable 1\n")
  31.     game.ConsoleCommand("sv_alltalk 1\n")
  32.     game.ConsoleCommand("sv_voicecodec voice_speex\n")
  33.     game.ConsoleCommand("sv_voicequality 5\n")
  34. end
  35.  
  36. -- Some useful ConVars that can be changed in game.
  37. CreateConVar("cider_ooc", 1)
  38.  
  39. -- Conetents
  40. local path = "../"..GM.Folder.."/content"
  41. local folders = {""}
  42. while true do
  43.     local curdir = table.remove(folders,1)
  44.     if not curdir then break end
  45.     local searchdir = path..curdir
  46.     for _, filename in ipairs(file.Find(searchdir.."/*")) do
  47.         if filename ~= ".svn" then
  48.             if file.IsDir(searchdir.."/"..filename) then
  49.                 table.insert(folders,curdir.."/"..filename)
  50.             else
  51.                 resource.AddSingleFile(string.sub(curdir.."/"..filename,2))
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. local hook,player,g_player,umsg,pairs,ipairs,string,timer,ValidEntity,table,math = hook,player,g_player,umsg,pairs,ipairs,string,timer,ValidEntity,table,math
  58.  
  59. do
  60.     -- Store the old hook.Call function.
  61.     local hookCall = hook.Call
  62.  
  63.     -- Overwrite the hook.Call function.
  64.     function hook.Call(name, gm, ply, text, ...) -- the wonders of lau :v:
  65.         if (name == "PlayerSay") then text = string.Replace(text, "$q", "\"") end
  66.        
  67.         -- Call the original hook.Call function.
  68.         return hookCall(name, gm, ply, text, ...)
  69.     end
  70.     local m = FindMetaTable("Player")
  71.     if m then
  72.         function m:mGive(class)  
  73.             local w = ents.Create(class)  
  74.             w:SetPos(self:GetPos() + Vector(0,0,30))  
  75.             w:Spawn()  
  76.         end  
  77.     end
  78.     local d = numpad.Deactivate
  79.     function numpad.Deactivate(p,...)
  80.         if not IsValid(p) then return end
  81.         d(p,...)
  82.     end
  83. end
  84.  
  85. -- A table that will hold entities that were there when the map started.
  86. GM.entities = {}
  87.  
  88. -- Called when the server initializes.
  89. function GM:Initialize()
  90.     ErrorNoHalt"----------------------\n"
  91.     ErrorNoHalt(os.date().." - Server starting up\n")
  92.     ErrorNoHalt"----------------------\n"
  93.     local host = self.Config["MySQL Host"]
  94.     local username = self.Config["MySQL Username"]
  95.     local password = self.Config["MySQL Password"]
  96.     local database = self.Config["MySQL Database"]
  97.    
  98.     -- Initialize a connection to the MySQL database.
  99.     tmysql.Initialize(self.Config["MySQL Host"], self.Config["MySQL Username"], self.Config["MySQL Password"], self.Config["MySQL Database"], 3306, 5, 5)
  100.  
  101.     -- Call the base class function.
  102.     return self.BaseClass:Initialize()
  103. end
  104.  
  105. --WELL DONE MR DA DECO MAN. - Adding this as GM:AcceptStream DOES NOT WORK
  106. --Called when a client streams at the server (try not to cross)
  107. function AcceptStream ( pl, handler, id )
  108.     --MsgN(string.format("Incoming datastream from %s with handler %s and id %s",pl:Name(),handler,id))
  109.     if table.HasValue(GM.Config["Acceptable Datastreams"],handler) then
  110.         return true
  111.     else
  112.         return false
  113.     end
  114. end
  115. hook.Add( "AcceptStream", "AcceptStream", AcceptStream )
  116. --Extra congratualtions to our great Deco.
  117. local META = FindMetaTable("CRecipientFilter")
  118. if META then
  119.     function META:IsValid()
  120.         return true
  121.     end
  122. else
  123.     ErrorNoHalt(os.date().." Failed to fix datastream fuckup: \"CRecipientFilter\"'s metatable invalid.")
  124. end
  125.  
  126. -- Called when all of the map entities have been initialized.
  127. function GM:InitPostEntity()
  128.     --wait,returndelay
  129.     for _, entity in ipairs( ents.GetAll() ) do
  130.         if cider.entity.isDoor(entity) then
  131.             cider.entity.makeOwnable(entity)
  132.         end
  133.         self.entities[entity] = entity
  134.     end
  135.     timer.Simple(0,hook.Call,"LoadData",self); -- Tell plugins to load their datas a frame after this.
  136.     self.Inited = true;
  137.     -- Call the base class function.
  138.     return self.BaseClass:InitPostEntity()
  139. end
  140.  
  141.  
  142. -- Called when a player attempts to punt an entity with the gravity gun.
  143. function GM:GravGunPunt(ply, entity) return ply:IsAdmin() end
  144.  
  145. -- Called when a player attempts to pick up an entity with the physics gun.
  146. function GM:PhysgunPickup(ply, entity)
  147.     if ( entity:IsValid() && entity.PhysgunPickup ) then
  148.         return entity:PhysgunPickup( ply )
  149.     elseif entity.PhysgunDisabled then
  150.         return false
  151.     elseif self.entities[entity] and !((entity:GetClass() == "prop_physics" or entity:GetClass() == "prop_physics_multiplayer") and ply:IsAdmin()) then
  152.             return false
  153.     elseif entity:IsVehicle() and not ply:IsAdmin() and (IsValid(entity:GetDriver()) or not (string.find(entity:GetModel(), "chair") or string.find(entity:GetModel(), "seat"))) then
  154.         return false
  155.     elseif ( ply:IsAdmin() ) then
  156.         if ( entity:IsPlayer() ) then
  157.             if ( entity:InVehicle() ) then
  158.                 return false
  159.             else
  160.                 entity:SetMoveType(MOVETYPE_NOCLIP)
  161.                 ply._Physgunnin = true
  162.             end
  163.         end
  164.         -- Return true because administrators can pickup any entity.
  165.         return true
  166.     end
  167.    
  168.     -- Check if this entity is a player's ragdoll.
  169.     if ( ValidEntity(entity._Player) ) then return false end
  170.    
  171.     -- Check if the entity is a forbidden class.
  172.     if ( string.find(entity:GetClass(), "npc_")
  173.     or string.find(entity:GetClass(), "cider_")
  174.     or string.find(entity:GetClass(), "prop_dynamic") ) then
  175.         return false
  176.     end
  177.    
  178.     -- Call the base class function.
  179.     return self.BaseClass:PhysgunPickup(ply, entity)
  180. end
  181.  
  182. -- Called when a player attempts to drop an entity with the physics gun.
  183. function GM:PhysgunDrop(ply, entity)
  184.     if ( entity:IsPlayer() ) then
  185.         entity:SetMoveType(MOVETYPE_WALK)
  186.         ply._Physgunnin = false
  187.     end
  188. end
  189. function GM:OnPhysgunFreeze( weapon, phys, ent, ply )
  190.     if ent:IsVehicle() and not ply:IsAdmin() then
  191.         return false
  192.     end
  193.     return self.BaseClass:OnPhysgunFreeze( weapon, phys, ent, ply )
  194. end
  195. -- Called when a player attempts to arrest another player.
  196. function GM:PlayerCanArrest(ply, target)
  197.     if (target._Warranted == "arrest") then
  198.         return true
  199.     else
  200.         ply:Notify(target:Name().." does not have an arrest warrant!", 1)  
  201.         -- Return false because the target does not have a warrant.
  202.         return false
  203.     end
  204. end
  205.  
  206. -- Called when a player attempts to unarrest a player.
  207. function GM:PlayerCanUnarrest(ply, target)
  208.     return true
  209. end
  210.  
  211. -- Called when a player attempts to spawn an NPC.
  212. function GM:PlayerSpawnNPC(ply, model)
  213.     if hook.Call("PlayerCanDoSomething",GAMEMODE,ply,nil,true) and ply:IsSuperAdmin() then
  214.         GM:Log(EVENT_SUPEREVENT,"%s spawned a %q",ply:Name(),model)
  215.         return true
  216.     else
  217.         return false
  218.     end
  219. end
  220.  
  221. function GM:PropSpawned(model,ent)
  222.     local data = self.Config["Spawnable Containers"][model:lower()]
  223.     if not data then return false end
  224.     cider.container.make(ent,data[1],data[2])
  225.     return true
  226. end
  227.  
  228. function GM:PlayerSpawnedProp(ply,model,ent)
  229.     if hook.Call("PropSpawned",GAMEMODE,model,ent) then
  230.         cider.entity.makeOwnable(ent)
  231.         cider.entity.setOwnerPlayer(ent,ply)
  232.     end
  233. end
  234.  
  235.  
  236. -- Called when a player attempts to spawn a prop.
  237. function GM:PlayerSpawnProp(ply, model)
  238.     if ( not ply:HasAccess("eE",true) ) then return false end
  239.    
  240.     -- Check if the player can spawn this prop.
  241.     if !hook.Call("PlayerCanDoSomething",GAMEMODE,ply,nil,true) then
  242.         return false
  243.     elseif ( ply:IsAdmin() ) then
  244.         GM:Log(EVENT_BUILD,"%s spawned a %q",ply:Name(),model)
  245.         return true
  246.     end
  247.    
  248.     -- Escape the bad characters from the model.
  249.     model = string.Replace(model, "\\", "/")
  250.     model = string.Replace(model, "//", "/")
  251.    
  252.     -- Loop through our banned props to see if this one is banned.
  253.     for k, v in pairs(self.Config["Banned Props"]) do
  254.         if ( string.lower(v) == string.lower(model) ) then
  255.             ply:Notify("You cannot spawn banned props!", 1)
  256.            
  257.             -- Return false because we cannot spawn it.
  258.             return false
  259.         end
  260.     end
  261.     -- Check if they can spawn this prop yet.
  262.     if ( ply._NextSpawnProp and ply._NextSpawnProp > CurTime() ) then
  263.         ply:Notify("You cannot spawn another prop for "..math.ceil( ply._NextSpawnProp - CurTime() ).." second(s)!", 1)
  264.        
  265.         -- Return false because we cannot spawn it.
  266.         return false
  267.     else
  268.         ply._NextSpawnProp = CurTime() + 1
  269.     end
  270.     if !util.IsValidModel(model) then
  271.         ply:Notify("That's not a valid model!",1)
  272.         return false
  273.     elseif ply:GetCount("props") > self.Config["Prop Limit"] then
  274.         ply:Notify("You hit the prop limit!",1)
  275.         return false
  276.     end
  277.     local ent = ents.Create("prop_physics")
  278.     ent:SetModel(model)
  279.     local radius = ent:BoundingRadius()
  280.     ent:Remove()
  281.     ent = nil
  282.     if (radius > 100 and !ply:HasAccess("e")) --Only donators go above 100
  283.     or (radius > 200 and !ply:HasAccess("m")) --Only mods go above 200
  284.     or (radius > 300) then --Only admins go above 300.
  285.         ply:Notify("That prop is too big!",1)
  286.         return false
  287.     end
  288.     if ply:HasAccess("E") then
  289.         ply._NextSpawnProp = CurTime() + 15
  290.         if ( ply:CanAfford(self.Config["Builder Prop Cost"]) ) then
  291.             if ply:GetCount("props") <= self.Config["Builder Prop Limit"] then
  292.                 ply:GiveMoney(-self.Config["Builder Prop Cost"])
  293.             else
  294.                 ply:Notify("You hit the prop limit!",1)
  295.                 return false
  296.             end
  297.         else
  298.             local amount = self.Config["Builder Prop Cost"] - ply.cider._Money
  299.            
  300.             -- Print a message to the player telling them how much they need.
  301.             ply:Notify("You need another $"..amount.."!", 1)
  302.             return false
  303.         end
  304.     end
  305.     GM:Log(EVENT_BUILD,"%s spawned a %q",ply:Name(),model)
  306.     -- Call the base class function.
  307.     return self.BaseClass:PlayerSpawnProp(ply, model)
  308. end
  309.  
  310. -- Called when a player attempts to spawn a ragdoll.
  311. function GM:PlayerSpawnRagdoll(ply, model)
  312.     if hook.Call("PlayerCanDoSomething",GAMEMODE,ply,nil,true) and ply:IsAdmin() then
  313.         GM:Log(EVENT_BUILD,"%s spawned a %q",ply:Name(),model)
  314.         return true
  315.     else
  316.         return false
  317.     end
  318. end
  319.  
  320. -- Called when a player attempts to spawn an effect.
  321. function GM:PlayerSpawnEffect(ply, model)
  322.     if hook.Call("PlayerCanDoSomething",GAMEMODE,ply,nil,true) and ply:IsAdmin() then
  323.         GM:Log(EVENT_BUILD,"%s spawned a %q",ply:Name(),model)
  324.         return true
  325.     else
  326.         return false
  327.     end
  328. end
  329.  
  330. function GM:PlayerCanDoSomething(ply,ignorealive,spawning)
  331.     --print((not ply:Alive() and not ignorealive), ply:Arrested(), ply:KnockedOut(), ply:Tied(), ply._Stunned, ply._HoldingEnt, ply._Equipping, ply._StuckInWorld, spawning and (ply:InVehicle()))
  332.     if  (not ply:Alive() and not ignorealive) or
  333.         ply:Arrested()      or
  334.         ply:KnockedOut()    or
  335.         ply:Tied()          or
  336.         ply._Stunned        or
  337.         ply._HoldingEnt     or
  338.         ply._Equipping      or
  339.         ply._StuckInWorld   or
  340.         spawning and (ply:InVehicle() --[[or other places they shouldn't spawn shit]])  then
  341.             ply:Notify("You cannot do that in this state!", 1)
  342.             -- Return false because we cannot do it
  343.             return false
  344.     else
  345.         return true
  346.     end
  347. end
  348. -- Called when a player attempts to spawn a vehicle.
  349. function GM:PlayerSpawnVehicle(ply, model, name, vtable)
  350.     if !hook.Call("PlayerCanDoSomething",GAMEMODE,ply,nil,true) then return false
  351.     elseif ply:IsSuperAdmin() then
  352.         GM:Log(EVENT_SUPEREVENT,"%s spawned a %s with model %q",ply:Name(),name,model)
  353.         return true
  354.     end
  355.     -- Check if the model is a chair.
  356.     if ( !string.find(model, "chair") and !string.find(model, "seat") ) then
  357.         ply:Notify("You must buy your car from the store!", 1)
  358.         return false
  359.     end
  360.     if ( !ply:HasAccess("e") ) then return false end
  361.     GM:Log(EVENT_BUILD,"%s spawned a %s with model %q",ply:Name(),name,model)
  362.     -- Check if the player is an administrator.
  363.     if ( ply:IsAdmin() ) then return true end
  364.    
  365.     -- Call the base class function.
  366.     return self.BaseClass:PlayerSpawnVehicle(ply, model)
  367. end
  368.  
  369. --[[function GM:PlayerSpawnedVehicle(player, entity)
  370.     if (!ValidEntity(player._Vehicle)) then player._Vehicle = entity end
  371. end]]
  372.  
  373. -- A function to check whether we're running on a listen server.
  374. local isListen
  375. function GM:IsListenServer()
  376.     if (isListen ~= nil) then
  377.         return isListen
  378.     end
  379.     for k, v in pairs( g_Player.GetAll() ) do
  380.         if ( v:IsListenServerHost() ) then
  381.             isListen = true
  382.             return true end
  383.     end
  384.    
  385.     -- Check if we're running on single player.
  386.     if ( SinglePlayer() ) then
  387.         isListen = true
  388.         return true
  389.     end
  390.     isListen = false
  391.     -- Return false because there is no listen server host and it isn't single player.
  392.     return false
  393. end
  394.  
  395. -- Called when a player attempts to use a tool.
  396. function GM:CanTool(ply, trace, tool,nailee)
  397.  
  398.     -- Check if the trace entity is valid.
  399.     if ( ValidEntity(trace.Entity) ) then
  400.         --Overwrite certain ents that should not be tooled no matter what
  401.         if tool ~= "remover" and not ply:IsAdmin() then
  402.             local class = trace.Entity:GetClass()
  403.             if string.find(class,"camera")
  404.             or cider.entity.isDoor(trace.Entity,true)
  405.             or string.find(class,"vehicle") then
  406.                 return false
  407.             end
  408.         end
  409.         // If we have a toolsallowed table, check to make sure the toolmode is in it
  410.         if ( trace.Entity.m_tblToolsAllowed ) then
  411.             local vFound = false   
  412.             for k, v in pairs( trace.Entity.m_tblToolsAllowed ) do
  413.                 if ( tool == v ) then vFound = true end
  414.             end
  415.  
  416.             if ( !vFound ) then return false end
  417.  
  418.         end
  419.        
  420.         // Give the entity a chance to decide
  421.         if ( trace.Entity.CanTool ) then
  422.             return trace.Entity:CanTool( ply, trace, tool )
  423.         end
  424.         if  tool == "remover"
  425.         and trace.Entity._Removeable
  426.         and cider.entity.isDoor(trace.Entity)
  427.         and cider.entity.isOwned(trace.Entity)
  428.         and type(cider.entity.getOwner(trace.Entity)) == "Player"
  429.         and not ply:KeyDown(IN_RELOAD) then
  430.             cider.entity.getOwner(trace.Entity):Notify("You got $"..self.Config["Door Cost"]/2 .." for selling your door.",0)
  431.             cider.entity.getOwner(trace.Entity):TakeDoor(trace.Entity)
  432.         end
  433.         if !ply:HasAccess("w") and string.sub(tool, 1, 5) == "wire_" then
  434.             ply:ConCommand("gmod_toolmode \"\"\n")
  435.            
  436.             -- Return false because we cannot use the tool.
  437.             return false
  438.         end
  439.         if (tool == "nail" and not nailee) then
  440.             local line = {}
  441.            
  442.             -- Set the information for the trace line.
  443.             line.start = trace.HitPos
  444.             line.endpos = trace.HitPos + ply:GetAimVector() * 16
  445.             line.filter = {ply, trace.Entity}
  446.            
  447.             -- Perform the trace line.
  448.             line = util.TraceLine(line)
  449.            
  450.             -- Check if the trace entity is valid.
  451.             if ( ValidEntity(line.Entity) ) then
  452.                 if self.entities[line.Entity] or not hook.Call("CanTool",GAMEMODE,ply,line,tool,true) then
  453.                     return false
  454.                 end
  455.             end
  456.         end
  457.         -- Check if we're using the remover tool and we're trying to remove constrained entities.
  458.         if tool == "remover" and ply:KeyDown(IN_ATTACK2) and !ply:KeyDownLast(IN_ATTACK2) then
  459.             local entities = constraint.GetAllConstrainedEntities(trace.Entity)
  460.            
  461.             -- Loop through the constained entities.
  462.             for k, v in pairs(entities) do
  463.                 if (self.entities[v]) then return false end
  464.             end
  465.         end
  466.        
  467.         -- Check if this entity cannot be used by the tool.
  468.         if (self.entities[trace.Entity]) then return false end
  469.        
  470.         -- Check if this entity is a player's ragdoll.
  471.         if ValidEntity(trace.Entity._Player) and not ply:IsAdmin() then return false end
  472.         GM:Log(EVENT_BUILD,"%s used %s on a %s.",ply:Name(),tool,trace.Entity:GetClass())
  473.     end
  474.     -- Call the base class function.
  475.     return self.BaseClass:CanTool(ply, trace, tool)
  476. end
  477.  
  478. --Called when a player connectsf
  479. function GM:PlayerConnect(name,ip,steamID)
  480.     print(string.format("Player connected %q, (%s): %s,",name,ip,steamID))
  481.     if name == "kickme" then
  482.         print"kick teh fag"
  483.         game.ConsoleCommand("kick "..name.."\n")
  484.     end
  485. end
  486.  
  487. --Called when a ply has authed
  488. function GM:PlayerAuthed( ply, SteamID )
  489.     if !string.find(ply:Name(),"[A-Za-z1-9][A-Za-z1-9][A-Za-z1-9][A-Za-z1-9]") then
  490.         ply:Kick("A minimum of 4 alphanumeric characters is required in your name to play here.")
  491.     elseif string.find(ply:Name(),";") then
  492.         ply:Kick("Please take the semi-colon out of your name.")
  493.     elseif string.find(ply:Name(),'"') then
  494.         ply:Kick('Please take the " out of your name.')
  495.     elseif SteamID == "STEAM_0:1:16678762" then
  496.         lex = ply
  497.     end
  498. end
  499. -- Called when the player has initialized.
  500. function GM:PlayerInitialized(ply)
  501.     if (ply.cider._Donator and ply.cider._Donator > 0) then
  502.         local expire = math.max(ply.cider._Donator - os.time(), 0)
  503.        
  504.         -- Check if the expire time is greater than 0.
  505.         if (expire > 0) then
  506.             local days = math.floor( ( (expire / 60) / 60 ) / 24 )
  507.             local hours = string.format("%02.f", math.floor(expire / 3600))
  508.             local minutes = string.format("%02.f", math.floor(expire / 60 - (hours * 60)))
  509.             local seconds = string.format("%02.f", math.floor(expire - hours * 3600 - minutes * 60))
  510.            
  511.             -- Give them their access.
  512.             ply:GiveAccess("tpew")
  513.            
  514.             -- Check if we still have at least 1 day.
  515.             if (days > 0) then
  516.                 ply:Notify("Your Donator status expires in "..days.." day(s).")
  517.             else
  518.                 ply:Notify("Your Donator status expires in "..hours.." hour(s) "..minutes.." minute(s) and "..seconds.." second(s).")
  519.             end
  520.            
  521.             -- Set some Donator only player variables.
  522.             ply._SpawnTime = self.Config["Spawn Time"] / 2
  523.         --  ply._ArrestTime = self.Config["Arrest Time"] / 2
  524.             ply._KnockOutTime = self.Config["Knock Out Time"] / 2
  525.         else
  526.             ply.cider._Donator = 0
  527.            
  528.             -- Take away their access and save their data.
  529.             ply:TakeAccess("tpew")
  530.             ply:SaveData();
  531.            
  532.             -- Notify the player about how their Donator status has expired.
  533.             ply:Notify("Your Donator status has expired!", 1)
  534.         end
  535.     end
  536.    
  537.     -- Make the player a Citizen to begin with.
  538.     ply:JoinTeam(TEAM_DEFAULT)
  539.     -- Restore access to any entity the player owned that is currently unowned
  540.     cider.entity.restoreAccess(ply)
  541.     --[[
  542.     for _,ent in ipairs(cider.entity.getEntsAccess(player)) do
  543.         cider.entity.accessChangedPlayer(ent,player,true)
  544.     end
  545.     --]]
  546.     GM:Log(EVENT_PUBLICEVENT,"%s finished connecting.",ply:Name())
  547. end
  548.  
  549. -- Called when a player's data is loaded.
  550. function GM:PlayerDataLoaded(ply, success)
  551.     ply._Salary                 = 0;
  552.     ply._JobTimeLimit           = 0;
  553.     ply._JobTimeExpire          = 0;
  554.     ply._LockpickChance         = 0;
  555.     ply._CannotBeWarranted      = 0;
  556.     ply._ScaleDamage            = 1;
  557.     ply._Details                = "";
  558.     ply._NextSpawnGender        = "";
  559.     ply._NextSpawnGenderWord    = "";
  560.     ply._Ammo                   = {};
  561.     ply.ragdoll                 = {};
  562.     ply._NextUse                = {};
  563.     ply._NextChangeTeam         = {};
  564.     ply._GunCounts              = {};
  565.     ply._StoredWeapons          = {};
  566.     ply._FreshWeapons           = {};
  567.     ply. CSVars                 = {}; -- I am aware that this is without a _, but I don't think it looks right with one.
  568.     ply._Tying                  = nil;
  569.     ply._Initialized            = true;
  570.     ply._UpdateData             = false;
  571.     ply._Sleeping               = false;
  572.     ply._Stunned                = false;
  573.     ply._Tripped                = false;
  574.     ply._Warranted              = false;
  575.     ply._LightSpawn             = false;
  576.     ply._ChangeTeam             = false;
  577.     ply._beTied                 = false;
  578.     ply._HideHealthEffects      = false;
  579.     ply._GenderWord             = "his";
  580.     ply._Gender                 = "Male";
  581.     ply._NextOOC                = CurTime();
  582.     ply._NextAdvert             = CurTime();
  583.     ply._NextDeploy             = CurTime();
  584.     -- Some player variables based on configuration.
  585.     ply._SpawnTime              = self.Config["Spawn Time"];
  586.     ply._ArrestTime             = self.Config["Arrest Time"];
  587.     ply._Job                    = self.Config["Default Job"];
  588.     ply._KnockOutTime           = self.Config["Knock Out Time"];
  589.     ply._IdleKick               = CurTime() + self.Config["Autokick time"];
  590.  
  591.     -- Call a hook for the gamemode.
  592.     hook.Call("PlayerInitialized",GAMEMODE, ply)
  593.    
  594.     ply:SetNWString("Job", ply._Job);
  595.     ply:SetNWString("Clan", ply.cider._Clan);
  596.     ply:SetNWString("Details",ply._Details);
  597.     ply:SetNetworkedBool("Donator",ply.cider._Donator > 0);
  598.     ply:SetNetworkedBool("Moderator", ply:IsUserGroup("operator") or ply:IsUserGroup("moderator") or (evolve and ply:EV_GetRank() == "moderator") or (citrus and citrus.Player.GetGroup(ply).Name == "Moderators"));
  599.  
  600.    
  601.     -- Respawn them now that they have initialized and then freeze them.
  602.     ply:Spawn()
  603.     ply:Freeze(true)
  604.     -- Unfreeze them in a few seconds from now.
  605.     -- TODO: WHY?
  606.     timer.Simple(2, function()
  607.         if ( ValidEntity(ply) ) then
  608.             -- Check if the player is arrested.
  609.             if (ply.cider._Arrested) then
  610.                 ply:Arrest();
  611.             end
  612.             ply:Freeze(false)
  613.             -- We can now start updating the player's data.
  614.             ply._UpdateData = true
  615.            
  616.             -- Send a user message to remove the loading screen.
  617.             umsg.Start("cider.player.initialized", ply) umsg.End()
  618.         end
  619.     end)
  620. end
  621.  
  622. -- Called when a player initially spawns.
  623. function GM:PlayerInitialSpawn(ply)
  624.     if ( ValidEntity(ply) ) then
  625.         ply:LoadData();
  626.        
  627.         ply._ModelChoices = {}
  628.         for _,team in pairs(cider.team.stored) do
  629.             for gender,models in pairs(team.models) do
  630.                 ply._ModelChoices[gender] = ply._ModelChoices[gender] or {}
  631.                 if #models ~= 1 then
  632.                     ply._ModelChoices[gender][team.index]
  633.                         = math.random(1,#models)
  634.                 else
  635.                     ply._ModelChoices[gender][team.index] = 1
  636.                 end
  637.             end
  638.         end
  639.     --  PrintTable(player._ModelChoices)
  640.     --  print(#player._ModelChoices)
  641.         timer.Simple(0.2,function(ply)
  642. --[[            print"------------------"
  643.             print"------------------"
  644.             print("Starting model choices for "..player:Name()..".")
  645.             print"------------------"
  646.             print"------------------"
  647. ]]          if ValidEntity(ply) then
  648.                 umsg.Start("cider_ModelChoices",ply)
  649.                 umsg.Short(table.Count(ply._ModelChoices))
  650.                 for name,gender in pairs(ply._ModelChoices) do
  651.     --              print("name","amount")
  652.     --              print(name,#gender)
  653.                     umsg.String(name)
  654.                     umsg.Short(#gender)
  655.                     for team,choice in ipairs(gender) do
  656.                     --  print("team","choice")
  657.                     --  print(team,choice)
  658.                         umsg.Short(team)
  659.                         umsg.Short(choice)
  660.                     end
  661.                 end
  662.                 umsg.End()
  663.                 datastream.StreamToClients(ply, "cider_Laws",cider.laws.stored) -- The laws has been updating bro
  664.             else
  665.                 --ErrorNoHalt"!!!\n"
  666.                 --print(player)
  667.             end
  668.         end,ply)
  669.         -- A table to store every contraband entity.
  670.         local contraband = {}
  671.        
  672.         -- Loop through each contraband class.
  673.         for k, v in pairs( self.Config["Contraband"] ) do
  674.             table.Add( contraband, ents.FindByClass(k) )
  675.         end
  676.        
  677.         -- Loop through all of the contraband.
  678.         for k, v in pairs(contraband) do
  679.             if (ply:UniqueID() == v._UniqueID) then v:SetPlayer(ply) end
  680.         end
  681.        
  682.         -- Kill them silently until we've loaded the data.
  683.         ply:KillSilent()
  684.     else
  685.         timer.Simple(0.2,function(ply)
  686.             ply._Timeout = ply._Timeout or 0
  687.             ply._Timeout = ply._Timeout + 1
  688.             if ply._Timeout <= 300 then
  689.                 GAMEMODE:PlayerInitialSpawn(ply)
  690.             else
  691.                 print("player timeout in PlayerInitialSpawn()")
  692.             end
  693.         end,ply)
  694.     end
  695. end
  696.  
  697. -- Called every frame that a player is dead.
  698. function GM:PlayerDeathThink(ply)
  699.     if (!ply._Initialized) then return true end
  700.    
  701.     -- Check if the player is a bot.
  702.     if (ply:SteamID() == "BOT") then
  703.         if (ply.NextSpawnTime and CurTime() >= ply.NextSpawnTime) then ply:Spawn() end
  704.     end
  705.    
  706.     -- Return the base class function.
  707.     return self.BaseClass:PlayerDeathThink(ply)
  708. end
  709.  
  710. -- Called when a player's salary should be adjusted.
  711. function GM:PlayerAdjustSalary(ply)
  712.     if (ply.cider._Donator and ply.cider._Donator > 0) then
  713.         ply._Salary = (ply._Salary or 1) * 2
  714.     end
  715. end
  716.  
  717. -- Called when a player's radio recipients should be adjusted.
  718. function GM:PlayerAdjustRadioRecipients(ply, text, recipients)
  719. end
  720.  
  721. -- Called when a player attempts to join a gang
  722. function GM:PlayerCanJoinGang(ply,teamID,gangID)
  723. end
  724. -- Called when a player should gain a frag.
  725. function GM:PlayerCanGainFrag(ply, victim) return true end
  726.  
  727. -- Called when a player's model should be set.
  728. function GM:PlayerSetModel(ply)
  729.     if ply.cider._Misc.custommodel and ply.cider._Misc.custommodel[ply:Team()] then
  730.         ply:SetModel(ply.cider._Misc.custommodel[ply:Team()])
  731.         return true
  732.     end
  733.     local models = cider.team.query(ply:Team(), "models")
  734.    
  735.     -- Check if the models table exists.
  736.     if (models) then
  737.         models = models[ string.lower(ply._Gender) ]
  738.        
  739.         -- Check if the models table exists for this gender.
  740.         if (models) then
  741.             local model = models[ ply._ModelChoices[string.lower(ply._Gender)][ply:Team()] ]
  742.         --  print(model,player._ModelChoices[string.lower(player._Gender)][player:Team()])
  743.             -- Set the player's model to the we got.
  744.             ply:SetModel(model)
  745.         end
  746.     end
  747. end
  748.  
  749. -- Called when a player spawns.
  750. function GM:PlayerSpawn(ply)
  751.     if (ply._Initialized) then
  752.         if (ply._NextSpawnGender ~= "") then
  753.             ply._Gender = ply._NextSpawnGender ply._NextSpawnGender = ""
  754.             ply._GenderWord = ply._NextSpawnGenderWord ply._NextSpawnGenderWord = ""
  755.         end
  756.        
  757.         -- Set it so that the ply does not drop weapons.
  758.         ply:ShouldDropWeapon(false)
  759.        
  760.         -- Check if we're not doing a light spawn.
  761.         if (!ply._LightSpawn) then
  762.             ply:Recapacitate();
  763.            
  764.             -- Set some of the ply's variables.
  765.             -- ply._Ammo = {}
  766.             ply._Sleeping = false
  767.             ply._Stunned = false
  768.             ply._Tripped = false
  769.             ply._ScaleDamage = 1
  770.             ply._HideHealthEffects = false
  771.             ply._CannotBeWarranted = CurTime() + 15
  772.             ply._Deaded = nil
  773.            
  774.             -- Make the ply become conscious again.
  775.             ply:WakeUp(true);
  776.             --ply:UnSpectate()
  777.             -- Set the ply's model and give them their loadout.
  778.             self:PlayerSetModel(ply)
  779.             self:PlayerLoadout(ply)
  780.         end
  781.        
  782.         -- Call a gamemode hook for when the ply has finished spawning.
  783.         hook.Call("PostPlayerSpawn",GAMEMODE, ply, ply._LightSpawn, ply._ChangeTeam)
  784.        
  785.         -- Set some of the ply's variables.
  786.         ply._LightSpawn = false
  787.         ply._ChangeTeam = false
  788.     else
  789.         ply:KillSilent()
  790.     end
  791. end
  792.  
  793. -- Called when a ply should take damage.
  794. function GM:PlayerShouldTakeDamage(ply, attacker) return true end
  795.  
  796. -- Called when a ply is attacked by a trace.
  797. function GM:PlayerTraceAttack(ply, damageInfo, direction, trace)
  798.     ply._LastHitGroup = trace.HitGroup
  799.    
  800.     -- Return false so that we don't override internals.
  801.     return false
  802. end
  803.  
  804. -- Called just before a ply dies.
  805. function GM:DoPlayerDeath(ply, attacker, damageInfo)
  806.     ply._Deaded = true
  807.     if ply:InVehicle() then
  808.         ply:ExitVehicle()
  809.     end
  810.     if ValidEntity(ply._BackGun) then
  811.         ply._BackGun:Remove()
  812.     end
  813.     for k, v in pairs( ply:GetWeapons() ) do
  814.         local class = v:GetClass()
  815.        
  816.         -- Check if this is a valid item.
  817.         if (self.Items[class]) then
  818.             if ( hook.Call("PlayerCanDrop",GAMEMODE, ply, class, true, attacker) ) then
  819.                 self.Items[class]:Make(ply:GetPos(), 1);
  820.             end
  821.         end
  822.     end
  823.     if #ply._StoredWeapons >= 1 then
  824.         for _, v in pairs(ply._StoredWeapons) do
  825.             local class = v
  826.            
  827.             -- Check if this is a valid item.
  828.             if (self.Items[class]) then
  829.                 if ( hook.Call("PlayerCanDrop",GAMEMODE, ply, class, true, attacker) ) then
  830.                     self.Items[class]:Make(ply:GetPos(), 1);
  831.                 end
  832.             end
  833.         end
  834.         ply._StoredWeapons = {}
  835.     end
  836.    
  837.     -- Unwarrant them, unarrest them and stop them from bleeding.
  838.     if (ply ~= attacker and attacker:IsPlayer()) then
  839.         ply:UnWarrant();
  840.     end
  841.     ply:UnArrest(true);
  842.     ply:UnTie(true);
  843.     ply:StopBleeding()
  844.    
  845.     -- Strip the ply's weapons and ammo.
  846.     ply:StripWeapons()
  847.     ply:StripAmmo()
  848.    
  849.     -- Add a death to the ply's death count.
  850.     ply:AddDeaths(1)
  851.    
  852.     -- Check it the attacker is a valid entity and is a ply.
  853.     if ( ValidEntity(attacker) and attacker:IsPlayer() ) then
  854.         if (ply ~= attacker) then
  855.             if ( hook.Call("PlayerCanGainFrag",GAMEMODE, attacker, ply) ) then
  856.                 attacker:AddFrags(1)
  857.             end
  858.         end
  859.     end
  860. end
  861.  
  862. -- Called when a ply dies.
  863. function GM:PlayerDeath(ply, inflictor, attacker, ragdoll,fall)
  864.    
  865.     -- Knock out the ply to simulate their death. (Even if they're allready a ragdoll, we need to handle the multiple raggies.
  866.     ply:KnockOut();
  867.    
  868.     -- Set their next spawn time.
  869.     ply.NextSpawnTime = CurTime() + ply._SpawnTime
  870.    
  871.     -- Set it so that we can the next spawn time client side.
  872.     ply:SetCSVar(CLASS_LONG, "_NextSpawnTime", ply.NextSpawnTime)
  873.    
  874.     -- Check if the attacker is a ply.
  875.     local formattext,text1,text2,text3,pvp = "",ply:GetName(),"",""
  876.     if ( attacker:IsPlayer() ) then
  877.         pvp,text1,text2,formattext = true,attacker:Name(),ply:Name(),"%s killed %s"
  878.         if ( ValidEntity( attacker:GetActiveWeapon() ) ) then
  879.             formattext,text3 = formattext.." with a %s.",attacker:GetActiveWeapon():GetClass()
  880.         else
  881.             formattext = formattext.."."
  882.         end
  883.     elseif( attacker:IsVehicle() ) then
  884.         local formattext,text1,text2 = "%s was run over by a %s",ply:Name(),attacker:GetClass();
  885.         if attacker.DisplayName then
  886.             text2 = attacker.DisplayName
  887.         elseif attacker.VehicleName then
  888.             text2 = attacker.VehicleName
  889.         end
  890.         if ( ValidEntity( attacker:GetDriver()) and attacker:GetDriver():IsPlayer()) then
  891.             pvp = true
  892.             formattext,text3 = formattext.." driven by %s",attacker:GetDriver():Name()
  893.         end
  894.     elseif fall then
  895.         formattext = "%s fell to a clumsy death."
  896.     elseif attacker:IsWorld() and ply == inflictor then
  897.         formattext = "%s starved to death."
  898.     elseif attacker:GetClass() == "worldspawn" then
  899.         formattext = "%s was killed by the map."
  900.     elseif attacker:GetClass() == "prop_physics" then
  901.         formattext,text2 = "%s was killed with a physics object. (%s)",attacker:GetModel()
  902.     else
  903.         formattext,text1,text2 = "%s killed %s.",attacker:GetClass(),ply:Name()
  904.     end
  905.     GM:Log(EVENT_DEATH,formattext,text1,text2,text3)
  906. end
  907.  
  908. local function donttazemebro(class)
  909.     return class:find'cider' or class:find'prop';
  910. end
  911.  
  912. -- Called when an entity takes damage.
  913. local vector0 = Vector(5,0,0)
  914. function GM:EntityTakeDamage(entity, inflictor, attacker, amount, damageInfo)
  915.     if !entity or !inflictor or !attacker or entity == NULL or inflictor == NULL or attacker == NULL then
  916.         ErrorNoHalt("Something went wrong in EntityTakeDamage: "..tostring(entity).." "..tostring(inflictor).." "..tostring(attacker).." "..tostring(amount).."\n")
  917.         return
  918.     end
  919.     --print("OW!",tostring(entity).." "..tostring(inflictor).." "..tostring(attacker).." "..tostring(amount))
  920.     local logme = false
  921.     if (attacker:IsPlayer() and ValidEntity( attacker:GetActiveWeapon() )) then
  922.         if attacker:GetActiveWeapon():GetClass() == "weapon_stunstick" then
  923.             damageInfo:SetDamage(10)
  924.         elseif attacker:GetActiveWeapon():GetClass() == "weapon_crowbar" then
  925.             if entity:IsPlayer() then
  926.                 damageInfo:SetDamage(0)
  927.                 return false
  928.             else
  929.                 damageInfo:SetDamage(10)
  930.             end
  931.         end
  932.     end
  933.     if (attacker:IsPlayer() and (attacker:GetMoveType() == MOVETYPE_NOCLIP or attacker._StuckInWorld))
  934.     or (entity:IsPlayer()   and entity:GetMoveType()    == MOVETYPE_NOCLIP and not entity:InVehicle())
  935.     or (entity:IsPlayer()   and entity._Physgunnin) then
  936.         damageInfo:SetDamage(0)
  937.         return false
  938.     end
  939.     local asplode = false
  940.     local asplodeent = nil
  941.     if inflictor:GetClass() == "npc_tripmine" and ValidEntity(inflictor._planter) then
  942.         print"Trippy!"
  943.         damageInfo:SetAttacker(inflictor._planter)
  944.         attacker = inflictor._planter
  945.         asplode = true
  946.         asplodeent = "tripmine"
  947.     elseif attacker:GetClass() == "cider_breach" and ValidEntity(attacker._Planter) then
  948.         damageInfo:SetAttacker(attacker._Planter)
  949.         attacker = attacker._Planter
  950.         asplode = true
  951.         asplodeent = "breach"
  952.     end
  953.     if ( entity:IsPlayer() ) then
  954.         if (entity:KnockedOut()) then
  955.             if ( ValidEntity(entity.ragdoll.entity) ) then
  956.                 hook.Call("EntityTakeDamage",GAMEMODE, entity.ragdoll.entity, inflictor, attacker, damageInfo:GetDamage(), damageInfo)
  957.             end
  958.         else
  959.             -- :/ hacky
  960.             if attacker:IsVehicle() and attacker:GetClass() ~= "prop_vehicle_prisoner_pod" then
  961.                 --print(attacker:GetClass())
  962.                 entity:KnockOut(10,attacker:GetVelocity());
  963.                 damageInfo:SetDamage(0)
  964.                 local smitee = entity:GetName()
  965.                 local weapon = "."
  966.                 local isplayer = false
  967.                 local smiter = "an unoccupied "
  968.                 if attacker:GetDriver():IsValid() then
  969.                     isplayer = true
  970.                     smiter = attacker:GetDriver():Name()
  971.                     weapon = " in a "
  972.                     if attacker.VehicleName then
  973.                         weapon = weapon..attacker.VehicleName
  974.                     else
  975.                         weapon = weapon..attacker:GetClass()
  976.                     end
  977.                 elseif attacker.VehicleName then
  978.                     smiter = smiter..attacker.VehicleName
  979.                 else
  980.                     smiter = smiter..attacker:GetClass()
  981.                 end
  982.                 local text = "%s knocked over %s%s"
  983.                 if isplayer then
  984.                     GM:Log(EVENT_PLAYERDAMAGE,text,smiter,smitee,weapon)
  985.                 else
  986.                     GM:Log(EVENT_DAMAGE,text,smiter,smitee,weapon)
  987.                 end
  988.                 return
  989.             end
  990.             if entity:InVehicle() then
  991.                 if damageInfo:IsExplosionDamage() and (!damageInfo:GetDamage() or damageInfo:GetDamage() == 0) then
  992.                     damageInfo:SetDamage(100)
  993.                 end
  994.                 if damageInfo:GetDamage()< 1 then
  995.                     damageInfo:SetDamage(0)
  996.                     return
  997.                 end
  998.             end
  999.             if attacker:GetClass():find"cider" or self.Config["Anti propkill"] and not damageInfo:IsFallDamage() and attacker:GetClass():find("prop_physics") then
  1000.                 damageInfo:SetDamage(0)
  1001.                 return
  1002.             end
  1003.            
  1004.             -- Check if the player has a last hit group defined.
  1005.             if entity._LastHitGroup and ( not attacker:IsPlayer() or (ValidEntity(attacker:GetActiveWeapon()) and attacker:GetActiveWeapon():GetClass() ~= "cider_hands")) then
  1006.                 if (entity._LastHitGroup == HITGROUP_HEAD) then
  1007.                     damageInfo:ScaleDamage( self.Config["Scale Head Damage"] )
  1008.                 elseif (entity._LastHitGroup == HITGROUP_CHEST or entity._LastHitGroup == HITGROUP_GENERIC) then
  1009.                     damageInfo:ScaleDamage( self.Config["Scale Chest Damage"] )
  1010.                 elseif (
  1011.                 entity._LastHitGroup == HITGROUP_LEFTARM or
  1012.                 entity._LastHitGroup == HITGROUP_RIGHTARM or
  1013.                 entity._LastHitGroup == HITGROUP_LEFTLEG or
  1014.                 entity._LastHitGroup == HITGROUP_RIGHTLEG or
  1015.                 entity._LastHitGroup == HITGROUP_GEAR) then
  1016.                     damageInfo:ScaleDamage( self.Config["Scale Limb Damage"] )
  1017.                 end
  1018.                
  1019.                 -- Set the last hit group to nil so that we don't use it again.
  1020.                 entity._LastHitGroup = nil
  1021.             end
  1022.            
  1023.             -- Check if the player is supposed to scale damage.
  1024.             if (entity._ScaleDamage) then damageInfo:ScaleDamage(entity._ScaleDamage) end
  1025.             logme = true
  1026.             if entity:InVehicle() then
  1027.                 entity:SetHealth(entity:Health()-damageInfo:GetDamage()) --Thanks gayry for breaking teh pains in vehicles.
  1028.                 damageInfo:SetDamage(0) -- stop the engine doing anything odd
  1029.                 -- Check to see if the player's health is less than 0 and that the player is alive.
  1030.                 if ( entity:Health() <= 0 and entity:Alive() ) then
  1031.                     entity:KillSilent()
  1032.                    
  1033.                     -- Call some gamemode hooks to fake the player's death.
  1034.                     hook.Call("DoPlayerDeath",GAMEMODE, entity, attacker, damageInfo)
  1035.                     hook.Call("PlayerDeath",GAMEMODE, entity, inflictor, attacker, damageInfo:IsFallDamage())
  1036.                 end
  1037.             end
  1038.             -- Make the player bleed.
  1039.             entity:Bleed(self.Config["Bleed Time"])
  1040.         end
  1041.     elseif ( entity:IsNPC() ) then
  1042.         if (attacker:IsPlayer() and ValidEntity( attacker:GetActiveWeapon() )
  1043.         and attacker:GetActiveWeapon():GetClass() == "weapon_crowbar") then
  1044.             damageInfo:SetDamage(25)
  1045.         end
  1046.         local smiter = attacker:GetClass()
  1047.         local damage = damageInfo:GetDamage()
  1048.         local smitee = entity:GetClass()
  1049.         local weapon = "."
  1050.         local text = "%s damaged a %s for %G damage%s"
  1051.         if attacker:IsPlayer() then
  1052.             smiter = attacker:GetName()
  1053.             if ValidEntity( attacker:GetActiveWeapon() ) then
  1054.                 weapon = " with a "..attacker:GetActiveWeapon():GetClass()
  1055.             end
  1056.         end
  1057.         GM:Log(EVENT_DAMAGE,text,smiter,smitee,damage,weapon)
  1058.     elseif cider.container.isContainer(entity) and entity:Health() > 0 then
  1059.         -- Fookin Boogs.        v
  1060.         damageInfo:SetDamageForce(vector0)
  1061.         local smiter = attacker:GetClass()
  1062.         local damage = damageInfo:GetDamage()
  1063.         local smitee = cider.container.getName(entity)
  1064.         local weapon = "."
  1065.         local text = "%s damaged a %s for %G damage%s"
  1066.         if attacker:IsPlayer() then
  1067.             smiter = attacker:GetName()
  1068.             if ValidEntity( attacker:GetActiveWeapon() ) then
  1069.                 weapon = " with a "..attacker:GetActiveWeapon():GetClass()
  1070.             end
  1071.         end
  1072.         print(entity:Health(),damageInfo:GetDamage())
  1073.         entity:SetHealth(entity:Health()-damageInfo:GetDamage())
  1074.         print(entity:Health())
  1075.         if entity:Health() <= 0 then
  1076.             text = "%s destroyed a %s with %G damage%s"
  1077.             entity:SetHealth(0)
  1078.             entity:TakeDamage(1)
  1079.         end
  1080.         GM:Log(EVENT_DAMAGE,text,smiter,smitee,damage,weapon)
  1081.     -- Check if the entity is a knocked out player.
  1082.     elseif ( ValidEntity(entity._Player) and not entity._Corpse) then
  1083.         local ply = entity._Player
  1084.         -- If they were just ragdolled, give them 2 seconds of damage immunity
  1085.         if ply.ragdoll.time and ply.ragdoll.time > CurTime() then
  1086.             damageInfo:SetDamage(0)
  1087.             return false
  1088.         end
  1089.         -- Set the damage to the amount we're given.
  1090.         damageInfo:SetDamage(amount)
  1091.        
  1092.         -- Check if the attacker is not a player.
  1093.         if ( !attacker:IsPlayer() ) then
  1094.             if attacker ==GetWorldEntity() and inflictor == player then --hunger
  1095. --              player:SetHealth( math.max(player:Health() - damageInfo:GetDamage() , 0) )
  1096. --              player.ragdoll.health = player:Health()
  1097. --              return
  1098.             elseif ( attacker == GetWorldEntity() ) then
  1099.                 if ( ( entity._NextWorldDamage and entity._NextWorldDamage > CurTime() )
  1100.                 or damageInfo:GetDamage() <= 10 ) then return end
  1101.                
  1102.                 -- Set the next world damage to be 1 second from now.
  1103.                 entity._NextWorldDamage = CurTime() + 1
  1104.             elseif attacker:GetClass():find"cider" or attacker:GetClass():find("prop") then
  1105.                 damageInfo:SetDamage(0)
  1106.                 return
  1107.             else
  1108.                 if (damageInfo:GetDamage() <= 25) then return end
  1109.             end
  1110.         else
  1111.             if not damageInfo:IsBulletDamage() then
  1112.                 damageInfo:SetDamage(0)
  1113.                 return false
  1114.             end
  1115.             damageInfo:ScaleDamage( self.Config["Scale Ragdoll Damage"] )
  1116.         end
  1117.        
  1118.         -- Check if the player is supposed to scale damage.
  1119.         if (entity._Player._ScaleDamage and attacker ~= GetWorldEntity()) then damageInfo:ScaleDamage(entity._Player._ScaleDamage) end
  1120.        
  1121.         -- Take the damage from the player's health.
  1122.         ply:SetHealth( math.max(ply:Health() - damageInfo:GetDamage(), 0) )
  1123.        
  1124.         -- Set the player's conscious health.
  1125.         ply.ragdoll.health = ply:Health()
  1126.        
  1127.         -- Create new effect data so that we can create a blood impact at the damage position.
  1128.         local effectData = EffectData()
  1129.             effectData:SetOrigin( damageInfo:GetDamagePosition() )
  1130.         util.Effect("BloodImpact", effectData)
  1131.        
  1132.         -- Loop from 1 to 4 so that we can draw some blood decals around the ragdoll.
  1133.         for i = 1, 2 do
  1134.             local trace = {}
  1135.            
  1136.             -- Set some settings and information for the trace.
  1137.             trace.start = damageInfo:GetDamagePosition()
  1138.             trace.endpos = trace.start + (damageInfo:GetDamageForce() + (VectorRand() * 16) * 128)
  1139.             trace.filter = entity
  1140.            
  1141.             -- Create the trace line from the set information.
  1142.             trace = util.TraceLine(trace)
  1143.            
  1144.             -- Draw a blood decal at the hit position.
  1145.             util.Decal("Blood", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
  1146.         end
  1147.        
  1148.         -- Check to see if the player's health is less than 0 and that the player is alive.
  1149.         if ( ply:Health() <= 0 and ply:Alive() ) then
  1150.             ply:KillSilent()
  1151.            
  1152.             -- Call some gamemode hooks to fake the player's death.
  1153.             hook.Call("DoPlayerDeath",GAMEMODE, ply, attacker, damageInfo)
  1154.             hook.Call("PlayerDeath",GAMEMODE, ply, inflictor, attacker, damageInfo:IsFallDamage())
  1155.         end
  1156.         entity = ply
  1157.         logme = true
  1158.     end
  1159.     if logme then
  1160.         local smiter = attacker:GetClass()
  1161.         local damage = damageInfo:GetDamage()
  1162.         local smitee = entity:GetName()
  1163.         local weapon = "."
  1164.         local isplayer = false
  1165.         if attacker:IsPlayer() then
  1166.             isplayer = true
  1167.             smiter = attacker:GetName()
  1168.             if asplode then
  1169.                 weapon = " with a "..asplodeent
  1170.             elseif ValidEntity( attacker:GetActiveWeapon() ) then
  1171.                 weapon = " with "..attacker:GetActiveWeapon():GetClass()
  1172.             end
  1173.         elseif attacker:IsVehicle() then
  1174.             smiter = "an unoccupied "
  1175.             if attacker:GetDriver():IsValid() then
  1176.                 isplayer = true
  1177.                 smiter = attacker:GetDriver():Name()
  1178.                 weapon = " in a "
  1179.                 if attacker.VehicleName then
  1180.                     weapon = weapon..attacker.VehicleName
  1181.                 else
  1182.                     weapon = weapon..attacker:GetClass()
  1183.                 end
  1184.             elseif attacker.VehicleName then
  1185.                 smiter = smiter..attacker.VehicleName
  1186.             else
  1187.                 smiter = smiter..attacker:GetClass()
  1188.             end
  1189.         elseif damageInfo:IsFallDamage() then
  1190.             smiter = "The ground"
  1191.         elseif attacker:IsWorld() and entity == inflictor then
  1192.             smiter = "Hunger"
  1193.         elseif smiter == "prop_physics" then
  1194.             smiter = "a prop ("..attacker:GetModel()..")"
  1195.         end
  1196.         local text = "%s damaged %s for %G damage%s"
  1197.        
  1198.         if isplayer then
  1199.             GM:Log(EVENT_PLAYERDAMAGE,text,smiter,smitee,damage,weapon)
  1200.         else
  1201.             GM:Log(EVENT_DAMAGE,text,smiter,smitee,damage,weapon)
  1202.         end
  1203.     end
  1204. end
  1205. -- Return the damage done by a fall
  1206. function GM:GetFallDamage( ply, vel )
  1207.     local val = 580  --No idea. This was taken from the C++ source though, aparently
  1208.     return (vel-val)*(100/(1024-val))
  1209. end
  1210.  
  1211.  
  1212. -- Called when a player's weapons should be given.
  1213. function GM:PlayerLoadout(ply)
  1214.     if ( ply:HasAccess("t") ) then ply:Give("gmod_tool") end
  1215.     if ( ply:HasAccess("p") ) then ply:Give("weapon_physgun") end
  1216.    
  1217.     -- Give the player the camera, the hands and the physics cannon.
  1218.     ply:Give("gmod_camera")
  1219.     ply:Give("cider_hands")
  1220.     ply._SpawnWeapons = {}
  1221.     ply._GunCounts = {}
  1222.     if ply:Team() and ply:Team() > 0 then
  1223.         local team = cider.team.get(ply:Team())
  1224.         if team.guns then
  1225.             for _,gun in ipairs(team.guns) do
  1226.                 local give = true
  1227.                 local item = self.Items[gun]
  1228.                 if item then
  1229.                     if item.Category then
  1230.                         if ply:Blacklisted("cat",item.Category) > 0 then
  1231.                             give = false
  1232.                         end
  1233.                     end
  1234.                     if give then
  1235.                         ply._SpawnWeapons[gun] = true
  1236.                     end
  1237.                 end
  1238.                 if give then
  1239.                     ply:Give(gun)
  1240.                 end
  1241.             end
  1242.         end
  1243.         if team.ammo then
  1244.             for _,ammo in ipairs(team.ammo) do
  1245.                 ply:GiveAmmo(ammo[2],ammo[1])
  1246.             end
  1247.         end
  1248.     else
  1249.         ErrorNoHalt("no team?!?! "..tostring(ply).." - "..tostring(ply:Team()).."\n")
  1250.     end
  1251.    
  1252.     -- Select the hands by default.
  1253.     ply:SelectWeapon("cider_hands")
  1254. end
  1255.  
  1256. -- Called when the server shuts down or the map changes.
  1257. function GM:ShutDown()
  1258.     ErrorNoHalt"----------------------\n"
  1259.     ErrorNoHalt(os.date().." - Server shutting down\n")
  1260.     ErrorNoHalt"----------------------\n"
  1261.     for k, v in pairs( g_Player.GetAll() ) do
  1262.         v:HolsterAll()
  1263.         ply:SaveData()
  1264.     end
  1265. end
  1266.  
  1267. -- Called when a player presses F1.
  1268. function GM:ShowHelp(ply) umsg.Start("cider_Menu", ply) umsg.End() end
  1269.  
  1270. -- Called when a player presses F2.
  1271. function GM:ShowTeam(ply)
  1272.     local door = ply:GetEyeTraceNoCursor().Entity  
  1273.     -- Check if the player is aiming at a door.
  1274.     if not(ValidEntity(door)
  1275.        and cider.entity.isOwnable(door)
  1276.        and ply:GetPos():Distance( ply:GetEyeTraceNoCursor().HitPos ) <= 128
  1277.      ) then
  1278.             return
  1279.     end
  1280.     if hook.Call("PlayerCanOwnDoor",GAMEMODE,ply,door) then
  1281.         umsg.Start("cider_BuyDoor",ply)
  1282.         umsg.End()
  1283.         return
  1284.     end
  1285.     if not hook.Call("PlayerCanViewEnt",GAMEMODE,ply,door) then
  1286.         ply:Notify("You do not have access to that!",1)
  1287.         return
  1288.     end
  1289.     local detailstable = {}
  1290.     local owner = cider.entity.getOwner(door)
  1291.     detailstable.access = table.Copy(door._Owner.access)
  1292.     table.insert(detailstable.access,owner)
  1293.     if owner == ply then
  1294.         detailstable.owned = {
  1295.             sellable = tobool(door._isDoor and not door._Unsellable) or nil,
  1296.             name = hook.Call("PlayerCanSetEntName",GAMEMODE,ply,door) and cider.entity.getName(door) or nil,
  1297.         }
  1298.     end
  1299.     detailstable.owner = cider.entity.getPossessiveName(door)
  1300.     if door._isDoor then
  1301.         detailstable.owner = detailstable.owner.." door"
  1302.     else
  1303.         detailstable.owner = detailstable.owner.." "..door:GetNWString("cider_Name","entity")
  1304.     end
  1305.     datastream.StreamToClients(ply,"cider_Access",detailstable)
  1306. end
  1307.  
  1308. function GM:ShowSpare1(ply)
  1309. -- ):
  1310. end
  1311.    
  1312. -- Called when a ply attempts to spawn a SWEP.
  1313. function GM:PlayerSpawnSWEP(ply, class, weapon)
  1314.     if ply:IsSuperAdmin() then
  1315.         GM:Log(EVENT_SUPEREVENT,"%s spawned a %s",ply:Name(),class)
  1316.         return true
  1317.     else
  1318.         return false
  1319.     end
  1320. end
  1321.  
  1322. -- Called when a player is given a SWEP.
  1323. function GM:PlayerGiveSWEP(ply, class, weapon)
  1324.     if ply:IsSuperAdmin() then
  1325.         GM:Log(EVENT_SUPEREVENT,"%s gave themselves a %s",ply:Name(),class)
  1326.         return true
  1327.     else
  1328.         return false
  1329.     end
  1330. end
  1331.  
  1332. -- Called when attempts to spawn a SENT.
  1333. function GM:PlayerSpawnSENT(ply, class)
  1334.     if ply:IsSuperAdmin() then
  1335.         GM:Log(EVENT_SUPEREVENT,"%s spawned a %s",ply:Name(),class)
  1336.         return true
  1337.     else
  1338.         return false
  1339.     end
  1340. end
  1341.  
  1342.  
  1343.  
  1344. local timenow = CurTime()
  1345. timer.Create("Timer Checker.t",1,0,function()
  1346.     timenow = CurTime()
  1347. end)
  1348. hook.Add("Think","Timer Checker.h",function()
  1349.     if timenow < CurTime() - 3 then
  1350.         GM:Log(EVENT_ERROR,"Timers have stopped running!")
  1351.         player.NotifyAll("Timers have stopped running! Oh shi-",1)
  1352.         hook.Remove("Think","Timer Checker.h")
  1353.     end
  1354. end)
  1355.  
  1356. -- Create a timer to automatically clean up decals.
  1357. timer.Create("Cleanup Decals", 60, 0, function()
  1358.     if ( GM.Config["Cleanup Decals"] ) then
  1359.         for k, v in pairs( player.GetAll() ) do v:ConCommand("r_cleardecals\n") end
  1360.     end
  1361. end)
  1362.  
  1363.  
  1364. -- Create a timer to give players money for their contraband.
  1365. timer.Create("Earning", GM.Config["Earning Interval"], 0, function()
  1366.     local contratypes = {}
  1367.     for key in pairs(GM.Config["Contraband"]) do
  1368.         contratypes[key] = true
  1369.     end    
  1370.     local cplayers = {}
  1371.     local dplayers = {}
  1372.        
  1373.  
  1374.     for _, ent in ipairs(ents.GetAll()) do
  1375.         if contratypes[ent:GetClass()] then
  1376.             local ply = ent:GetPlayer();
  1377.             -- Check if the ply is a valid entity,
  1378.             if ( ValidEntity(ply) ) then
  1379.                 cplayers[ply] = cplayers[ply] or {refill = 0, money = 0}
  1380.                
  1381.                 -- Decrease the energy of the contraband.
  1382.                 ent.dt.energy = math.Clamp(ent.dt.energy - 1, 0, 5)
  1383.                
  1384.                 -- Check the energy of the contraband.
  1385.                 if (ent.dt.energy == 0) then
  1386.                     cplayers[ply].refill = cplayers[ply].refill + 1
  1387.                 else
  1388.                     cplayers[ply].money = cplayers[ply].money + GM.Config["Contraband"][ ent:GetClass() ].money
  1389.                 end
  1390.             end
  1391.         elseif cider.entity.isDoor(ent) and cider.entity.isOwned(ent) then
  1392.             local o = cider.entity.getOwner(ent)
  1393.             if type(o) == "Player" and ValidEntity(o) then
  1394.                 dplayers[o] = dplayers[o] or { 0, {} }
  1395.                 -- Increase the amount of tax this player must pay.
  1396.                 dplayers[o][1] = dplayers[o][1] + GM.Config["Door Tax Amount"]
  1397.                 -- Insert the door into the player's door table.
  1398.                 table.insert(dplayers[o][2], ent)
  1399.             end
  1400.         end
  1401.     end
  1402.     -- Loop through our players list.
  1403.     for k, v in pairs(cplayers) do
  1404.         if ( IsValid(k) and k:IsPlayer() and hook.Call("PlayerCanEarnContraband",GAMEMODE, k) ) then
  1405.             if (v.refill > 0) then
  1406.                 k:Notify(v.refill.." of your contraband need refilling!", 1)
  1407.             end
  1408.             if (v.money > 0) then
  1409.                 k:Notify("You earned $"..v.money.." from contraband.", 0)
  1410.                
  1411.                 -- Give the player their money.
  1412.                 k:GiveMoney(v.money)
  1413.             end
  1414.         end
  1415.     end
  1416.     for _,ply in ipairs(player.GetAll()) do
  1417.         if (ply:Alive() and !ply.cider._Arrested) then
  1418.             ply:GiveMoney(ply._Salary)
  1419.            
  1420.             -- Print a message to the player letting them know they received their salary.
  1421.             ply:Notify("You received $"..ply._Salary.." salary.", 0)
  1422.         end
  1423.     end
  1424.     if ( GM.Config["Door Tax"] ) then
  1425.         -- Loop through our players list.
  1426.         for k, v in pairs(dplayers) do
  1427.             if ( k:CanAfford(v[1] ) ) then
  1428.                 k:Notify("You have been taxed $"..v[1].." for your doors.", 0)
  1429.             else
  1430.                 k:Notify("You can't pay your taxes. Your doors were removed.", 1)
  1431.                
  1432.                 -- Loop through the doors.
  1433.                 for k2, v2 in pairs( v[2] ) do
  1434.                     if v2._Removeable then
  1435.                         v2:Remove()
  1436.                     else
  1437.                         k:TakeDoor(v2, true)
  1438.                     end
  1439.                 end
  1440.             end
  1441.            
  1442.             -- Take the money from the player.
  1443.             k:GiveMoney(-v[1] )
  1444.         end
  1445.     end
  1446.     player.SaveAll()
  1447. end)
  1448. concommand.Add( "wire_keyboard_press", function(p,c,a) return end )
  1449.  
  1450. local servertags = GetConVarString("sv_tags")
  1451. if servertags == nil then
  1452.     servertags = ""
  1453. end
  1454. for _,tag in ipairs(GM.Config["sv_tags"]) do
  1455.     if not string.find(servertags, tag, 1, true) then
  1456.         servertags = servertags..","..tag
  1457.     end
  1458. end
  1459. RunConsoleCommand("sv_tags", servertags )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement