Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.62 KB | None | 0 0
  1. /*---------------------------------------------------------
  2.  Variables
  3.  ---------------------------------------------------------*/
  4. local meta = FindMetaTable("Player")
  5. /*---------------------------------------------------------
  6.  RP names
  7.  ---------------------------------------------------------*/
  8. local function RPName(ply, args)
  9.     if GetConVarNumber("allowrpnames") ~= 1 then
  10.         Notify(ply, 1, 6,  string.format(LANGUAGE.disabled, "RPname", ""))
  11.         return ""
  12.     end
  13.  
  14.     local len = string.len(args)
  15.     local low = string.lower(args)
  16.  
  17.     if len > 30 then
  18.         Notify(ply, 1, 4, string.format(LANGUAGE.unable, "RPname", "<=30"))
  19.         return ""
  20.     elseif len < 3 then
  21.         Notify(ply, 1, 4, string.format(LANGUAGE.unable, "RPname", ">2"))
  22.         return ""
  23.     end
  24.    
  25.     if string.find(args, "\160") or string.find(args, " ") == 1 then --No system spaces in your name bro!
  26.         Notify(ply, 1, 4, string.format(LANGUAGE.unable, "RPname", ""))
  27.         return ""
  28.     end
  29.    
  30.     if low == "ooc" or low == "shared" or low == "world" or low == "n/a" or low == "world prop" then
  31.         Notify(ply, 1, 4, string.format(LANGUAGE.unable, "RPname", ""))
  32.         return ""
  33.     end
  34.    
  35.     local allowed = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  36.     'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
  37.     'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l',
  38.     'z', 'x', 'c', 'v', 'b', 'n', 'm', ' ',
  39.     '(', ')', '[', ']', '!', '@', '#', '$', '%', '^', '&', '*', '-', '_', '=', '+', '|', '\\'}
  40.    
  41.     for k in string.gmatch(args, ".") do
  42.         if not table.HasValue(allowed, string.lower(k)) then
  43.             Notify(ply, 1, 4, string.format(LANGUAGE.unable, "RPname", k))
  44.             return ""
  45.         end
  46.     end
  47.     ply:SetRPName(args)
  48.     return ""
  49. end
  50. AddChatCommand("/rpname", RPName)
  51. AddChatCommand("/name", RPName)
  52. AddChatCommand("/nick", RPName)
  53.  
  54. function meta:IsCP()
  55.     local Team = self:Team()
  56.     if Team == TEAM_POLICE or Team == TEAM_CHIEF or Team == TEAM_MAYOR then
  57.         return true
  58.     end
  59.     return false
  60. end
  61.  
  62. function meta:SetRPName(name, firstRun)
  63.     -- Make sure nobody on this server already has this RP name
  64.     local lowername = string.lower(tostring(name))
  65.     DB.RetrieveRPNames(function(rpNames)
  66.         local taken = false
  67.  
  68.         for id, row in pairs(rpNames) do
  69.             if row.name and lowername == string.lower(row.name) and row.steam ~= self:SteamID() and row.steam ~= "STEAM_ID_PENDING" and row.steam ~= "UNKNOWN" then
  70.                 taken = true
  71.             end
  72.         end
  73.        
  74.         if string.len(lowername) < 2 and not firstrun then return end
  75.         -- If we found that this name exists for another player
  76.         if taken then
  77.             if firstRun then
  78.                 -- If we just connected and another player happens to be using our steam name as their RP name
  79.                 -- Put a 1 after our steam name
  80.                 DB.StoreRPName(self, name .. " 1")
  81.                 Notify(self, 1, 12, "Someone is already using your Steam name as their RP name so we gave you a '1' after your name.")
  82.             else
  83.                 Notify(self, 1, 5, string.format(LANGUAGE.unable, "RPname", ""))
  84.                 return ""
  85.             end
  86.         else
  87.             if not firstRun then -- Don't save the steam name in the database
  88.                 NotifyAll(2, 6, string.format(LANGUAGE.rpname_changed, self:SteamName(), name))
  89.                 DB.StoreRPName(self, name)
  90.             end
  91.         end
  92.     end)
  93. end
  94.  
  95. function meta:RestoreRPName()
  96.     if not ValidEntity(self) then return end
  97.     DB.RetrieveRPName(self, function(name)
  98.         if not name or name == "" then name = string.gsub(self:SteamName(), "\\\"", "\"") end
  99.  
  100.         self:SetDarkRPVar("rpname", name)
  101.     end)
  102. end
  103.  
  104. /*---------------------------------------------------------
  105.  Admin/automatic stuff
  106.  ---------------------------------------------------------*/
  107. function meta:HasPriv(priv)
  108.     return (FAdmin and FAdmin.Access.PlayerHasPrivilege(self, priv)) or self:IsAdmin()
  109. end
  110.  
  111. function meta:ChangeAllowed(t)
  112.     if not self.bannedfrom then return true end
  113.     if self.bannedfrom[t] == 1 then return false else return true end
  114. end
  115.  
  116. function meta:ResetDMCounter()
  117.     if not ValidEntity(self) then return end
  118.     self.kills = 0
  119.     return true
  120. end
  121.  
  122. function meta:TeamUnBan(Team)
  123.     if not ValidEntity(self) then return end
  124.     if not self.bannedfrom then self.bannedfrom = {} end
  125.     self.bannedfrom[Team] = 0
  126. end
  127.  
  128. function meta:TeamBan()
  129.     if not self.bannedfrom then self.bannedfrom = {} end
  130.     self.bannedfrom[self:Team()] = 1
  131.     timer.Simple(GetConVarNumber("demotetime"), self.TeamUnBan, self, self:Team())
  132. end
  133.  
  134. function meta:CompleteSentence()
  135.     if not ValidEntity(self) then return end
  136.     for k,v in pairs(ToggleCmds) do
  137.         local value = GetConVarNumber(v.var)
  138.         if value ~= v.default then
  139.             RunConsoleCommand(v.var, v.default)
  140.             timer.Simple(0, RunConsoleCommand, v.var, value)
  141.         end
  142.     end
  143.    
  144.     for k,v in pairs(ValueCmds) do
  145.         local value = GetConVarNumber(v.var)
  146.         if value ~= v.default then
  147.             RunConsoleCommand(v.var, v.default)
  148.             timer.Simple(0, RunConsoleCommand, v.var, value)
  149.         end
  150.     end
  151.    
  152.     local ID = self:SteamID()
  153.     if ValidEntity(self) and ID ~= nil and RPArrestedPlayers[ID] then
  154.         local time = GetConVarNumber("jailtimer")
  155.         self:Arrest(time, true)
  156.         Notify(self, 0, 5, string.format(LANGUAGE.jail_punishment, time))
  157.     end
  158. end
  159.  
  160. local CSFiles = {}
  161. function includeCS(dir)
  162.     AddCSLuaFile(dir)
  163.     table.insert(CSFiles, dir)
  164. end
  165.  
  166. function meta:NewData()
  167.     if not ValidEntity(self) then return end
  168.     local function ModuleDelay(ply)
  169.         umsg.Start("LoadModules", ply)
  170.             umsg.Short(#CSFiles)
  171.             for n = 1, #CSFiles do
  172.                 umsg.String(CSFiles[n])
  173.             end
  174.         umsg.End()
  175.     end
  176.  
  177.     timer.Simple(.01, ModuleDelay, self)
  178.  
  179.     self:RestoreRPName()
  180.  
  181.     DB.StoreSalary(self, GetConVarNumber("normalsalary"))
  182.  
  183.     self:UpdateJob(team.GetName(1))
  184.  
  185.     self:GetTable().Ownedz = { }
  186.     self:GetTable().OwnedNumz = 0
  187.  
  188.     self:GetTable().LastLetterMade = CurTime() - 61
  189.     self:GetTable().LastVoteCop = CurTime() - 61
  190.  
  191.     self:SetTeam(1)
  192.  
  193.     -- Whether or not a player is being prevented from joining
  194.     -- a specific team for a certain length of time
  195.     for i = 1, #RPExtraTeams do
  196.         if GetConVarNumber("restrictallteams") == 1 then
  197.             self.bannedfrom[i] = 1
  198.         else
  199.             self.bannedfrom[i] = 0
  200.         end
  201.     end
  202. end
  203.  
  204. /*---------------------------------------------------------
  205.  Teams/jobs
  206.  ---------------------------------------------------------*/
  207. function meta:ChangeTeam(t, force)
  208.     if RPArrestedPlayers[self:SteamID()] and not force then
  209.         if not self:Alive() then
  210.             Notify(self, 1, 4, string.format(LANGUAGE.unable, team.GetName(t), ""))
  211.             return
  212.         else
  213.             Notify(self, 1, 4, string.format(LANGUAGE.unable, team.GetName(t), ""))
  214.             return
  215.         end
  216.     end
  217.    
  218.     self:SetDarkRPVar("helpBoss",false)
  219.     self:SetDarkRPVar("helpCop",false)
  220.     self:SetDarkRPVar("helpMayor",false)
  221.  
  222.    
  223.     if t ~= TEAM_CITIZEN and not self:ChangeAllowed(t) and not force then
  224.         Notify(self, 1, 4, string.format(LANGUAGE.unable, team.GetName(t), "banned/demoted"))
  225.         return
  226.     end
  227.    
  228.     if self.LastJob and 10 - (CurTime() - self.LastJob) >= 0 and not force then
  229.         Notify(self, 1, 4, string.format(LANGUAGE.have_to_wait,  math.ceil(10 - (CurTime() - self.LastJob)), "/job"))
  230.         return
  231.     end
  232.    
  233.  if (t == TEAM_BAR and not self:IsUserGroup("superadmin")) then
  234.     Notify(self, 1, 4, "To access this class you must donate! :P")
  235.     return  
  236. end
  237.    
  238.      if (t == TEAM_BAR and not self:IsUserGroup("admin")) then
  239.     Notify(self, 1, 4, "To access this class you must donate! :P")
  240.     return  
  241. end
  242.    
  243.      if (t == TEAM_BAR and not self:IsUserGroup("operator")) then
  244.     Notify(self, 1, 4, "To access this class you must donate! :P")
  245.     return  
  246. end
  247.    
  248.      if (t == TEAM_BAR and not self:IsUserGroup("moderator")) then
  249.     Notify(self, 1, 4, "To access this class you must donate! :P")
  250.     return  
  251. end
  252.    
  253.      if (t == TEAM_BAR and not self:IsUserGroup("subscriber")) then
  254.     Notify(self, 1, 4, "To access this class you must donate! :P")
  255.     return  
  256. end
  257.    
  258.     for k,v in pairs(RPExtraTeams) do
  259.         if t == k then
  260.             if self:Team() == t then
  261.                 Notify(self, 1, 4, string.format(LANGUAGE.unable, team.GetName(t), ""))
  262.                 return
  263.             end
  264.            
  265.             if not self.DarkRPVars["Priv"..v.command] then
  266.                 if type(v.NeedToChangeFrom) == "number" and self:Team() ~= v.NeedToChangeFrom and not force then
  267.                     Notify(self, 1,4, string.format(LANGUAGE.need_to_be_before, team.GetName(v.NeedToChangeFrom), v.name))
  268.                     return
  269.                 elseif type(v.NeedToChangeFrom) == "table" and not table.HasValue(v.NeedToChangeFrom, self:Team()) and not force then
  270.                     local teamnames = ""
  271.                     for a,b in pairs(v.NeedToChangeFrom) do teamnames = teamnames.." or "..team.GetName(b) end
  272.                     Notify(self, 1,4, string.format(string.sub(teamnames, 5), team.GetName(v.NeedToChangeFrom), v.name))
  273.                     return
  274.                 end
  275.                 if GetConVarNumber("max"..v.command.."s") and GetConVarNumber("max"..v.command.."s") ~= 0 and team.NumPlayers(t) >= GetConVarNumber("max"..v.command.."s") and not force then
  276.                     Notify(self, 1, 4, string.format(LANGUAGE.team_limit_reached, v.name))
  277.                     return
  278.                 end
  279.             end
  280.             if self:Team() == TEAM_MAYOR and tobool(GetConVarNumber("DarkRP_LockDown")) then
  281.                 UnLockdown(self)
  282.             end
  283.             self:UpdateJob(v.name)
  284.             DB.StoreSalary(self, v.salary)
  285.             NotifyAll(1, 4, string.format(LANGUAGE.job_has_become, self:Nick(), v.name))
  286.             if self.DarkRPVars.HasGunlicense then
  287.                 self:SetDarkRPVar("HasGunlicense", false)
  288.             end
  289.             if v.Haslicense and GetConVarNumber("license") ~= 0 then
  290.                 self:SetDarkRPVar("HasGunlicense", true)
  291.             end
  292.            
  293.             break
  294.         end
  295.     end
  296.  
  297.    
  298.     self.LastJob = CurTime()
  299.    
  300.    
  301.     if t == TEAM_POLICE then   
  302.         self:SetDarkRPVar("helpCop", true)
  303.     elseif t == TEAM_MOB then
  304.         self:SetDarkRPVar("helpBoss", true)
  305.     elseif t == TEAM_MAYOR then
  306.         self:SetDarkRPVar("helpMayor", true)
  307.     end
  308.    
  309.     if GetConVarNumber("removeclassitems") == 1 then
  310.         for k, v in pairs(ents.FindByClass("microwave")) do
  311.             if v.SID == self.SID then v:Remove() end
  312.         end
  313.         for k, v in pairs(ents.FindByClass("gunlab")) do
  314.             if v.SID == self.SID then v:Remove() end
  315.         end
  316.        
  317.         if t ~= TEAM_MOB and t ~= TEAM_GANG then
  318.             for k, v in pairs(ents.FindByClass("drug_lab")) do
  319.                 if v.SID == self.SID then v:Remove() end
  320.             end
  321.         end
  322.        
  323.         for k,v in pairs(ents.FindByClass("spawned_shipment")) do
  324.             if v.SID == self.SID then v:Remove() end
  325.         end
  326.     end
  327.    
  328.     self:SetTeam(t)
  329.     DB.Log(self:SteamName().." ("..self:SteamID()..") changed to "..team.GetName(t))
  330.     if self:InVehicle() then self:ExitVehicle() end
  331.     if GetConVarNumber("norespawn") == 1 and self:Alive() then
  332.         self:StripWeapons()
  333.         local vPoint = self:GetShootPos() + Vector(0,0,50)
  334.         local effectdata = EffectData()
  335.         effectdata:SetEntity(self)
  336.         effectdata:SetStart( vPoint ) -- not sure if we need a start and origin (endpoint) for this effect, but whatever
  337.         effectdata:SetOrigin( vPoint )
  338.         effectdata:SetScale(1)
  339.         util.Effect( "entity_remove", effectdata)
  340.         GAMEMODE:PlayerSetModel(self)
  341.         GAMEMODE:PlayerLoadout(self)
  342.     else
  343.         self:KillSilent()
  344.     end
  345. end
  346.  
  347. function meta:UpdateJob(job)
  348.     self:SetDarkRPVar("job", job)
  349.     self:GetTable().Pay = 1
  350.     self:GetTable().LastPayDay = CurTime()
  351.  
  352.     timer.Create(self:SteamID() .. "jobtimer", GetConVarNumber("paydelay"), 0, self.PayDay, self)
  353. end
  354.  
  355. /*---------------------------------------------------------
  356.  Money
  357.  ---------------------------------------------------------*/
  358. function meta:CanAfford(amount)
  359.     if not amount then return false end
  360.     return math.floor(amount) >= 0 and self.DarkRPVars.money - math.floor(amount) >= 0
  361. end
  362.  
  363. function meta:AddMoney(amount)
  364.     if not amount then return false end
  365.     DB.StoreMoney(self, self.DarkRPVars.money + math.floor(amount))
  366. end
  367.  
  368. function meta:PayDay()
  369.     if ValidEntity(self) and self:GetTable().Pay == 1 then
  370.         if not RPArrestedPlayers[self:SteamID()] then
  371.             DB.RetrieveSalary(self, function(amount)
  372.                 amount = math.floor(amount or GetConVarNumber("normalsalary"))
  373.                 if amount == 0 then
  374.                     Notify(self, 4, 4, LANGUAGE.payday_unemployed)
  375.                 else
  376.                     self:AddMoney(amount)
  377.                     Notify(self, 4, 4, string.format(LANGUAGE.payday_message, CUR .. amount))
  378.                 end
  379.             end)
  380.         else
  381.             Notify(self, 4, 4, LANGUAGE.payday_missed)
  382.         end
  383.     end
  384. end
  385.  
  386. /*---------------------------------------------------------
  387.  Jail/arrest
  388.  ---------------------------------------------------------*/
  389. local function JailPos(ply)
  390.     -- Admin or Chief can set the Jail Position
  391.     if (ply:Team() == TEAM_CHIEF and GetConVarNumber("chiefjailpos") == 1) or ply:HasPriv("rp_commands") then
  392.         DB.StoreJailPos(ply)
  393.     else
  394.         local str = "Admin only!"
  395.         if GetConVarNumber("chiefjailpos") == 1 then
  396.             str = "Chief or " .. str
  397.         end
  398.  
  399.         Notify(ply, 1, 4, str)
  400.     end
  401.     return ""
  402. end
  403. AddChatCommand("/jailpos", JailPos)
  404.  
  405. local function AddJailPos(ply)
  406.     -- Admin or Chief can add Jail Positions
  407.     if (ply:Team() == TEAM_CHIEF and GetConVarNumber("chiefjailpos") == 1) or ply:HasPriv("rp_commands") then
  408.         DB.StoreJailPos(ply, true)
  409.     else
  410.         local str = LANGUAGE.admin_only
  411.         if GetConVarNumber("chiefjailpos") == 1 then
  412.             str = LANGUAGE.chief_or .. str
  413.         end
  414.  
  415.         Notify(ply, 1, 4, str)
  416.     end
  417.     return ""
  418. end
  419. AddChatCommand("/addjailpos", AddJailPos)
  420.  
  421. function meta:Arrest(time, rejoin)
  422.     self:SetDarkRPVar("wanted", false)
  423.     self.warranted = false
  424.     self:SetDarkRPVar("HasGunlicense", false)
  425.     self:SetDarkRPVar("Arrested", true)
  426.     GAMEMODE:SetPlayerSpeed(self, GetConVarNumber("aspd"), GetConVarNumber("aspd"))
  427.     self:StripWeapons()
  428.    
  429.     if tobool(GetConVarNumber("droppocketarrest")) and self.Pocket then
  430.         for k, v in pairs(self.Pocket) do
  431.             if ValidEntity(v) then
  432.                 v:SetMoveType(MOVETYPE_VPHYSICS)
  433.                 v:SetNoDraw(false)
  434.                 v:SetCollisionGroup(4)
  435.                 v:SetPos(self:GetPos() + Vector(0,0,10))
  436.                 local phys = v:GetPhysicsObject()
  437.                 if phys:IsValid() then
  438.                     phys:EnableCollisions(true)
  439.                     phys:Wake()
  440.                 end
  441.             end
  442.         end
  443.         self.Pocket = nil
  444.     end
  445.    
  446.     -- Always get sent to jail when Arrest() is called, even when already under arrest
  447.     if GetConVarNumber("teletojail") == 1 and DB.CountJailPos() and DB.CountJailPos() ~= 0 then
  448.         local jailpos = DB.RetrieveJailPos()
  449.         if jailpos then
  450.             self:SetPos(jailpos)
  451.         end
  452.     end
  453.    
  454.     if not RPArrestedPlayers[self:SteamID()] or rejoin then
  455.         local ID = self:SteamID()
  456.         RPArrestedPlayers[ID] = true
  457.         self.LastJailed = CurTime()
  458.        
  459.         -- If the player has no remaining jail time,
  460.         -- set it back to the max for this new sentence
  461.         if not time or time == 0 then
  462.             time = (GetConVarNumber("jailtimer") ~= 0 and GetConVarNumber("jailtimer")) or 120
  463.         end
  464.  
  465.         self:PrintMessage(HUD_PRINTCENTER, string.format(LANGUAGE.youre_arrested, time))
  466.         for k, v in pairs(player.GetAll()) do
  467.             if v ~= self then
  468.                 v:PrintMessage(HUD_PRINTCENTER, string.format(LANGUAGE.hes_arrested, self:Name(), time))
  469.             end
  470.         end
  471.        
  472.         timer.Create(ID .. "jailtimer", time, 1, function() if ValidEntity(self) then self:Unarrest(ID) end end)
  473.         umsg.Start("GotArrested", self)
  474.             umsg.Float(time)
  475.         umsg.End()
  476.     end
  477. end
  478.  
  479. function meta:Unarrest(ID)
  480.     self:SetDarkRPVar("Arrested", false)
  481.     if not ValidEntity(self) then
  482.         RPArrestedPlayers[ID] = nil
  483.         return
  484.     end
  485.    
  486.     if self.Sleeping then
  487.         KnockoutToggle(self, "force")
  488.     end
  489.  
  490.     if RPArrestedPlayers[self:SteamID()] ~= nil then
  491.         RPArrestedPlayers[self:SteamID()] = nil
  492.        
  493.         GAMEMODE:SetPlayerSpeed(self, GetConVarNumber("wspd"), GetConVarNumber("rspd"))
  494.         GAMEMODE:PlayerLoadout(self)
  495.         if GetConVarNumber("telefromjail") == 1 then
  496.             local _, pos = GAMEMODE:PlayerSelectSpawn(self)
  497.             self:SetPos(pos)
  498.         end
  499.        
  500.         timer.Destroy(self:SteamID() .. "jailtimer")
  501.         NotifyAll(1, 4, string.format(LANGUAGE.hes_unarrested, self:Name()))
  502.     end
  503. end
  504.  
  505. /*---------------------------------------------------------
  506.  Items
  507.  ---------------------------------------------------------*/
  508. function meta:UnownAll()
  509.     for k, v in pairs(ents.GetAll()) do
  510.         if v:IsOwnable() and v:OwnedBy(self) == true then
  511.             v:Fire("unlock", "", 0.6)
  512.         end
  513.     end
  514.  
  515.     if self:GetTable().Ownedz then
  516.         for k, v in pairs(self:GetTable().Ownedz) do
  517.             v:UnOwn(self)
  518.             self:GetTable().Ownedz[v:EntIndex()] = nil
  519.         end
  520.     end
  521.  
  522.     for k, v in pairs(player.GetAll()) do
  523.         if v:GetTable().Ownedz then
  524.             for n, m in pairs(v:GetTable().Ownedz) do
  525.                 if ValidEntity(m) and m:AllowedToOwn(self) then
  526.                     m:RemoveAllowed(self)
  527.                 end
  528.             end
  529.         end
  530.     end
  531.  
  532.     self:GetTable().OwnedNumz = 0
  533. end
  534.  
  535. function meta:DoPropertyTax()
  536.     if GetConVarNumber("propertytax") == 0 then return end
  537.     if (self:Team() == TEAM_POLICE or self:Team() == TEAM_MAYOR or self:Team() == TEAM_CHIEF) and GetConVarNumber("cit_propertytax") == 1 then return end
  538.  
  539.     local numowned = self:GetTable().OwnedNumz
  540.  
  541.     if numowned <= 0 then return end
  542.  
  543.     local price = 10
  544.     local tax = price * numowned + math.random(-5, 5)
  545.  
  546.     if self:CanAfford(tax) then
  547.         if tax ~= 0 then
  548.             self:AddMoney(-tax)
  549.             Notify(self, 1, 5, string.format(LANGUAGE.property_tax, CUR .. tax))
  550.         end
  551.     else
  552.         Notify(self, 1, 8, LANGUAGE.property_tax_cant_afford)
  553.         self:UnownAll()
  554.     end
  555. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement