Advertisement
Guest User

Untitled

a guest
Nov 16th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.19 KB | None | 0 0
  1. local plyMeta = FindMetaTable("Player")
  2. -- automatically block players from doing certain things with their DarkRP entities
  3. local blockTypes = {"Physgun1", "Spawning1", "Toolgun1"}
  4.  
  5.  
  6. local checkModel = function(model) return model ~= nil and (CLIENT or util.IsValidModel(model)) end
  7. local requiredTeamItems = {"color", "model", "description", "weapons", "command", "max", "salary", "admin", "vote"}
  8. local validShipment = {
  9. model = checkModel, "entity",
  10. price = function(v, tbl) return isnumber(v) or isfunction(tbl.getPrice) end,
  11. "amount",
  12. "seperate",
  13. allowed = fn.FOr{fp{fn.Eq, nil}, istable, isnumber}
  14. }
  15. local validVehicle = {"name", model = checkModel, price = function(v, tbl) return isnumber(v) or isfunction(tbl.getPrice) end}
  16. local validEntity = {
  17. "ent",
  18. model = checkModel,
  19. price = function(v, tbl) return isnumber(v) or isfunction(tbl.getPrice) end,
  20. max = function(v, tbl) return isnumber(v) or isfunction(tbl.getMax) end, "cmd", "name"
  21. }
  22.  
  23. local function checkValid(tbl, requiredItems)
  24. for k,v in pairs(requiredItems) do
  25. local isFunction = type(v) == "function"
  26.  
  27. if (isFunction and not v(tbl[k], tbl)) or (not isFunction and tbl[v] == nil) then
  28. return isFunction and k or v
  29. end
  30. end
  31. end
  32.  
  33. -----------------------------------------------------------
  34. -- Job commands --
  35. -----------------------------------------------------------
  36. local function declareTeamCommands(CTeam)
  37. local k = 0
  38. for num,v in pairs(RPExtraTeams) do
  39. if v.command == CTeam.command then
  40. k = num
  41. end
  42. end
  43.  
  44. if CTeam.vote or CTeam.RequiresVote then
  45. DarkRP.declareChatCommand{
  46. command = "vote"..CTeam.command,
  47. description = "Vote to become " .. CTeam.name .. ".",
  48. delay = 1.5,
  49. condition = fn.FAnd
  50. {
  51. fn.If(
  52. fn.Curry(isfunction, 2)(CTeam.RequiresVote),
  53. fn.Curry(fn.Flip(fn.FOr{fn.Curry(fn.Const, 2)(CTeam.RequiresVote), fn.Curry(fn.Const, 2)(-1)}()), 2)(k),
  54. fn.Curry(fn.Const, 2)(true)
  55. )(),
  56. fn.If(
  57. fn.Curry(isnumber, 2)(CTeam.NeedToChangeFrom),
  58. fn.Compose{fn.Curry(fn.Eq, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  59. fn.If(
  60. fn.Curry(istable, 2)(CTeam.NeedToChangeFrom),
  61. fn.Compose{fn.Curry(table.HasValue, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  62. fn.Curry(fn.Const, 2)(true)
  63. )()
  64. )(),
  65. fn.If(
  66. fn.Curry(isfunction, 2)(CTeam.customCheck),
  67. CTeam.customCheck,
  68. fn.Curry(fn.Const, 2)(true)
  69. )(),
  70. fn.Compose{fn.Curry(fn.Neq, 2)(k), plyMeta.Team},
  71. fn.FOr {
  72. fn.Curry(fn.Lte, 3)(CTeam.admin)(0),
  73. fn.FAnd{fn.Curry(fn.Eq, 3)(CTeam.admin)(1), plyMeta.IsAdmin},
  74. fn.FAnd{fn.Curry(fn.Gte, 3)(CTeam.admin)(2), plyMeta.IsSuperAdmin}
  75. }
  76. }
  77. }
  78.  
  79. DarkRP.declareChatCommand{
  80. command = CTeam.command,
  81. description = "Become " .. CTeam.name .. " and skip the vote.",
  82. delay = 1.5,
  83. condition = fn.FAnd {
  84. fn.FOr {
  85. fn.Curry(fn.Flip(plyMeta.hasDarkRPPrivilege), 2)("rp_"..CTeam.command),
  86. fn.FAnd {
  87. fn.FOr {
  88. fn.Curry(fn.Lte, 3)(CTeam.admin)(0),
  89. fn.FAnd{fn.Curry(fn.Eq, 3)(CTeam.admin)(1), plyMeta.IsAdmin},
  90. fn.FAnd{fn.Curry(fn.Gte, 3)(CTeam.admin)(2), plyMeta.IsSuperAdmin}
  91. },
  92. fn.If(
  93. fn.Curry(isfunction, 2)(CTeam.RequiresVote),
  94. fn.Curry(fn.Flip(fn.FOr{fn.Curry(fn.Const, 2)(CTeam.RequiresVote), fn.Curry(fn.Const, 2)(-1)}()), 2)(k),
  95. fn.FOr {
  96. fn.FAnd{fn.Curry(fn.Eq, 3)(CTeam.admin)(0), plyMeta.IsAdmin},
  97. fn.FAnd{fn.Curry(fn.Eq, 3)(CTeam.admin)(1), plyMeta.IsSuperAdmin}
  98. }
  99. )()
  100. }
  101. },
  102. fn.Compose{fn.Not, plyMeta.isArrested},
  103. fn.If(
  104. fn.Curry(isnumber, 2)(CTeam.NeedToChangeFrom),
  105. fn.Compose{fn.Curry(fn.Eq, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  106. fn.If(
  107. fn.Curry(istable, 2)(CTeam.NeedToChangeFrom),
  108. fn.Compose{fn.Curry(table.HasValue, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  109. fn.Curry(fn.Const, 2)(true)
  110. )()
  111. )(),
  112. fn.If(
  113. fn.Curry(isfunction, 2)(CTeam.customCheck),
  114. CTeam.customCheck,
  115. fn.Curry(fn.Const, 2)(true)
  116. )(),
  117. fn.Compose{fn.Curry(fn.Neq, 2)(k), plyMeta.Team}
  118. }
  119. }
  120. else
  121. DarkRP.declareChatCommand{
  122. command = CTeam.command,
  123. description = "Become " .. CTeam.name .. ".",
  124. delay = 1.5,
  125. condition = fn.FAnd
  126. {
  127. fn.Compose{fn.Not, plyMeta.isArrested},
  128. fn.If(
  129. fn.Curry(isnumber, 2)(CTeam.NeedToChangeFrom),
  130. fn.Compose{fn.Curry(fn.Eq, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  131. fn.If(
  132. fn.Curry(istable, 2)(CTeam.NeedToChangeFrom),
  133. fn.Compose{fn.Curry(table.HasValue, 2)(CTeam.NeedToChangeFrom), plyMeta.Team},
  134. fn.Curry(fn.Const, 2)(true)
  135. )()
  136. )(),
  137. fn.If(
  138. fn.Curry(isfunction, 2)(CTeam.customCheck),
  139. CTeam.customCheck,
  140. fn.Curry(fn.Const, 2)(true)
  141. )(),
  142. fn.Compose{fn.Curry(fn.Neq, 2)(k), plyMeta.Team},
  143. fn.FOr {
  144. fn.Curry(fn.Lte, 3)(CTeam.admin)(0),
  145. fn.FAnd{fn.Curry(fn.Eq, 3)(CTeam.admin)(1), plyMeta.IsAdmin},
  146. fn.FAnd{fn.Curry(fn.Gte, 3)(CTeam.admin)(2), plyMeta.IsSuperAdmin}
  147. }
  148. }
  149. }
  150. end
  151. end
  152.  
  153. local function addTeamCommands(CTeam, max)
  154. if CLIENT then return end
  155.  
  156. if not GAMEMODE:CustomObjFitsMap(CTeam) then return end
  157. local k = 0
  158. for num,v in pairs(RPExtraTeams) do
  159. if v.command == CTeam.command then
  160. k = num
  161. end
  162. end
  163.  
  164. if CTeam.vote or CTeam.RequiresVote then
  165. DarkRP.defineChatCommand("vote"..CTeam.command, function(ply)
  166. if CTeam.RequiresVote and not CTeam.RequiresVote(ply, k) then
  167. DarkRP.notify(ply, 1,4, DarkRP.getPhrase("job_doesnt_require_vote_currently"))
  168. return ""
  169. end
  170.  
  171. if CTeam.canStartVote and not CTeam.canStartVote(ply) then
  172. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/vote"..CTeam.command, CTeam.canStartVoteReason or ""))
  173. return ""
  174. end
  175.  
  176. if CTeam.admin == 1 and not ply:IsAdmin() then
  177. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_admin", "/".."vote"..CTeam.command))
  178. return ""
  179. elseif CTeam.admin > 1 and not ply:IsSuperAdmin() then
  180. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_sadmin", "/".."vote"..CTeam.command))
  181. return ""
  182. end
  183.  
  184. if type(CTeam.NeedToChangeFrom) == "number" and ply:Team() ~= CTeam.NeedToChangeFrom then
  185. DarkRP.notify(ply, 1,4, DarkRP.getPhrase("need_to_be_before", team.GetName(CTeam.NeedToChangeFrom), CTeam.name))
  186. return ""
  187. elseif type(CTeam.NeedToChangeFrom) == "table" and not table.HasValue(CTeam.NeedToChangeFrom, ply:Team()) then
  188. local teamnames = ""
  189. for a,b in pairs(CTeam.NeedToChangeFrom) do teamnames = teamnames.." or "..team.GetName(b) end
  190. DarkRP.notify(ply, 1,4, DarkRP.getPhrase("need_to_be_before", string.sub(teamnames, 5), CTeam.name))
  191. return ""
  192. end
  193.  
  194. if CTeam.customCheck and not CTeam.customCheck(ply) then
  195. DarkRP.notify(ply, 1, 4, CTeam.CustomCheckFailMsg or DarkRP.getPhrase("unable", team.GetName(t), ""))
  196. return ""
  197. end
  198. if not ply:changeAllowed(k) then
  199. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/vote"..CTeam.command, DarkRP.getPhrase("banned_or_demoted")))
  200. return ""
  201. end
  202. if ply:Team() == k then
  203. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", CTeam.command, ""))
  204. return ""
  205. end
  206. local max = CTeam.max
  207. if max ~= 0 and ((max % 1 == 0 and team.NumPlayers(k) >= max) or (max % 1 ~= 0 and (team.NumPlayers(k) + 1) / #player.GetAll() > max)) then
  208. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("team_limit_reached", CTeam.name))
  209. return ""
  210. end
  211. if ply.LastJob and 10 - (CurTime() - ply.LastJob) >= 0 then
  212. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", math.ceil(10 - (CurTime() - ply.LastJob)), GAMEMODE.Config.chatCommandPrefix..CTeam.command))
  213. return ""
  214. end
  215. if #player.GetAll() == 1 then
  216. DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("vote_alone"))
  217. ply:changeTeam(k)
  218. return ""
  219. end
  220. if CurTime() - ply:GetTable().LastVoteCop < 80 then
  221. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", math.ceil(80 - (CurTime() - ply:GetTable().LastVoteCop)), GAMEMODE.Config.chatCommandPrefix..CTeam.command))
  222. return ""
  223. end
  224. DarkRP.createVote(DarkRP.getPhrase("wants_to_be", ply:Nick(), CTeam.name), "job", ply, 20, function(vote, choice)
  225. local ply = vote.target
  226.  
  227. if not IsValid(ply) then return end
  228. if choice >= 0 then
  229. ply:changeTeam(k)
  230. else
  231. DarkRP.notifyAll(1, 4, DarkRP.getPhrase("has_not_been_made_team", ply:Nick(), CTeam.name))
  232. end
  233. end, nil, nil, {targetTeam = k})
  234. ply:GetTable().LastVoteCop = CurTime()
  235. return ""
  236. end)
  237.  
  238. DarkRP.defineChatCommand(CTeam.command, function(ply)
  239. if ply:hasDarkRPPrivilege("rp_"..CTeam.command) then
  240. ply:changeTeam(k)
  241. return ""
  242. end
  243.  
  244. local a = CTeam.admin
  245. if a > 0 and not ply:IsAdmin()
  246. or a > 1 and not ply:IsSuperAdmin()
  247. then
  248. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_admin", CTeam.name))
  249. return ""
  250. end
  251.  
  252. if not CTeam.RequiresVote and
  253. (a == 0 and not ply:IsAdmin()
  254. or a == 1 and not ply:IsSuperAdmin()
  255. or a == 2)
  256. or CTeam.RequiresVote and CTeam.RequiresVote(ply, k)
  257. then
  258. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_to_make_vote", CTeam.name))
  259. return ""
  260. end
  261.  
  262. ply:changeTeam(k)
  263. return ""
  264. end)
  265. else
  266. DarkRP.defineChatCommand(CTeam.command, function(ply)
  267. if CTeam.admin == 1 and not ply:IsAdmin() then
  268. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_admin", "/"..CTeam.command))
  269. return ""
  270. end
  271. if CTeam.admin > 1 and not ply:IsSuperAdmin() then
  272. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("need_sadmin", "/"..CTeam.command))
  273. return ""
  274. end
  275. ply:changeTeam(k)
  276. return ""
  277. end)
  278. end
  279.  
  280. concommand.Add("rp_"..CTeam.command, function(ply, cmd, args)
  281. if ply:EntIndex() ~= 0 and not ply:IsAdmin() then
  282. ply:PrintMessage(2, DarkRP.getPhrase("need_admin", cmd))
  283. return
  284. end
  285.  
  286. if CTeam.admin > 1 and not ply:IsSuperAdmin() and ply:EntIndex() ~= 0 then
  287. ply:PrintMessage(2, DarkRP.getPhrase("need_sadmin", cmd))
  288. return
  289. end
  290.  
  291. if CTeam.vote then
  292. if CTeam.admin >= 1 and ply:EntIndex() ~= 0 and not ply:IsSuperAdmin() then
  293. ply:PrintMessage(2, DarkRP.getPhrase("need_sadmin", cmd))
  294. return
  295. elseif CTeam.admin > 1 and ply:IsSuperAdmin() and ply:EntIndex() ~= 0 then
  296. ply:PrintMessage(2, DarkRP.getPhrase("need_to_make_vote", CTeam.name))
  297. return
  298. end
  299. end
  300.  
  301. if not args or not args[1] then
  302. if ply:EntIndex() == 0 then
  303. print(DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
  304. else
  305. ply:PrintMessage(2, DarkRP.getPhrase("invalid_x", DarkRP.getPhrase("arguments"), ""))
  306. end
  307. return
  308. end
  309.  
  310. local target = DarkRP.findPlayer(args[1])
  311.  
  312. if (target) then
  313. target:changeTeam(k, true)
  314. local nick
  315. if (ply:EntIndex() ~= 0) then
  316. nick = ply:Nick()
  317. else
  318. nick = "Console"
  319. end
  320. target:PrintMessage(2, DarkRP.getPhrase("x_made_you_a_y", nick, CTeam.name))
  321. else
  322. if (ply:EntIndex() == 0) then
  323. print(DarkRP.getPhrase("could_not_find", tostring(args[1])))
  324. else
  325. ply:PrintMessage(2, DarkRP.getPhrase("could_not_find", tostring(args[1])))
  326. end
  327. end
  328. end)
  329. end
  330.  
  331. local function addEntityCommands(tblEnt)
  332. DarkRP.declareChatCommand{
  333. command = tblEnt.cmd,
  334. description = "Purchase a " .. tblEnt.name,
  335. delay = 2,
  336. condition = fn.FAnd
  337. {
  338. fn.Compose{fn.Not, plyMeta.isArrested},
  339. fn.If(
  340. fn.Curry(istable, 2)(tblEnt.allowed),
  341. fn.Compose{fn.Curry(table.HasValue, 2)(tblEnt.allowed), plyMeta.Team},
  342. fn.Curry(fn.Const, 2)(true)
  343. )(),
  344. fn.If(
  345. fn.Curry(isfunction, 2)(tblEnt.customCheck),
  346. tblEnt.customCheck,
  347. fn.Curry(fn.Const, 2)(true)
  348. )(),
  349. fn.Curry(fn.Flip(plyMeta.canAfford), 2)(tblEnt.price)
  350. }
  351. }
  352. if CLIENT then return end
  353.  
  354. local function buythis(ply, args)
  355. if ply:isArrested() then return "" end
  356. if type(tblEnt.allowed) == "table" and not table.HasValue(tblEnt.allowed, ply:Team()) then
  357. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("incorrect_job", tblEnt.cmd))
  358. return ""
  359. end
  360.  
  361. if tblEnt.customCheck and not tblEnt.customCheck(ply) then
  362. DarkRP.notify(ply, 1, 4, tblEnt.CustomCheckFailMsg or DarkRP.getPhrase("not_allowed_to_purchase"))
  363. return ""
  364. end
  365.  
  366. if ply:customEntityLimitReached(tblEnt) then
  367. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("limit", tblEnt.cmd))
  368. return ""
  369. end
  370.  
  371. local canbuy, suppress, message, price = hook.Call("canBuyCustomEntity", nil, ply, tblEnt)
  372.  
  373. local cost = price or tblEnt.getPrice and tblEnt.getPrice(ply, tblEnt.price) or tblEnt.price
  374.  
  375. if not ply:canAfford(cost) then
  376. DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("cant_afford", tblEnt.cmd))
  377. return ""
  378. end
  379.  
  380. if canbuy == false then
  381. if not suppress and message then DarkRP.notify(ply, 1, 4, message) end
  382. return ""
  383. end
  384.  
  385. ply:addMoney(-cost)
  386.  
  387. local trace = {}
  388. trace.start = ply:EyePos()
  389. trace.endpos = trace.start + ply:GetAimVector() * 85
  390. trace.filter = ply
  391.  
  392. local tr = util.TraceLine(trace)
  393.  
  394. local item = ents.Create(tblEnt.ent)
  395. if not item:IsValid() then error("Entity '"..tblEnt.ent.."' does not exist or is not valid.") end
  396. item.dt = item.dt or {}
  397. item.dt.owning_ent = ply
  398. if item.Setowning_ent then item:Setowning_ent(ply) end
  399. item:SetPos(tr.HitPos)
  400. item.SID = ply.SID
  401. item.onlyremover = true
  402. item.allowed = tblEnt.allowed
  403. item.DarkRPItem = tblEnt
  404. item:Spawn()
  405. local phys = item:GetPhysicsObject()
  406. if phys:IsValid() then phys:Wake() end
  407.  
  408. hook.Call("playerBoughtCustomEntity", nil, ply, tblEnt, item, cost)
  409.  
  410. DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("you_bought", tblEnt.name, DarkRP.formatMoney(cost), ""))
  411.  
  412. ply:addCustomEntity(tblEnt)
  413. return ""
  414. end
  415. DarkRP.defineChatCommand(tblEnt.cmd, buythis)
  416. end
  417.  
  418. RPExtraTeams = {}
  419. local jobByCmd = {}
  420. DarkRP.getJobByCommand = function(cmd)
  421. if not jobByCmd[cmd] then return nil, nil end
  422. return RPExtraTeams[jobByCmd[cmd]], jobByCmd[cmd]
  423. end
  424. plyMeta.getJobTable = fn.FOr{fn.Compose{fn.Curry(fn.Flip(fn.GetValue), 2)(RPExtraTeams), plyMeta.Team}, fn.Curry(fn.Id, 2)({})}
  425. local jobCount = 0
  426. function DarkRP.createJob(Name, colorOrTable, model, Description, Weapons, command, maximum_amount_of_this_class, Salary, admin, Vote, Haslicense, NeedToChangeFrom, CustomCheck)
  427. local tableSyntaxUsed = not IsColor(colorOrTable)
  428.  
  429. local CustomTeam = tableSyntaxUsed and colorOrTable or
  430. {color = colorOrTable, model = model, description = Description, weapons = Weapons, command = command,
  431. max = maximum_amount_of_this_class, salary = Salary, admin = admin or 0, vote = tobool(Vote), hasLicense = Haslicense,
  432. NeedToChangeFrom = NeedToChangeFrom, customCheck = CustomCheck
  433. }
  434. CustomTeam.name = Name
  435.  
  436. -- Disabled job
  437. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["jobs"][CustomTeam.command] then return end
  438.  
  439. local corrupt = checkValid(CustomTeam, requiredTeamItems)
  440. if corrupt then ErrorNoHalt("Corrupt team \"" ..(CustomTeam.name or "") .. "\": element " .. corrupt .. " is incorrect.\n") end
  441. jobCount = jobCount + 1
  442. CustomTeam.team = jobCount
  443.  
  444. CustomTeam.salary = math.floor(CustomTeam.salary)
  445.  
  446. jobByCmd[CustomTeam.command] = table.insert(RPExtraTeams, CustomTeam)
  447. team.SetUp(#RPExtraTeams, Name, CustomTeam.color)
  448. local Team = #RPExtraTeams
  449.  
  450. timer.Simple(0, function()
  451. declareTeamCommands(CustomTeam)
  452. addTeamCommands(CustomTeam, CustomTeam.max)
  453. end)
  454.  
  455. // Precache model here. Not right before the job change is done
  456. if type(CustomTeam.model) == "table" then
  457. for k,v in pairs(CustomTeam.model) do util.PrecacheModel(v) end
  458. else
  459. util.PrecacheModel(CustomTeam.model)
  460. end
  461. return Team
  462. end
  463. AddExtraTeam = DarkRP.createJob
  464.  
  465. RPExtraTeamDoors = {}
  466. function DarkRP.createEntityGroup(name, ...)
  467. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["doorgroups"][name] then return end
  468. RPExtraTeamDoors[name] = {...}
  469. end
  470. AddDoorGroup = DarkRP.createEntityGroup
  471.  
  472. CustomVehicles = {}
  473. CustomShipments = {}
  474. local shipByName = {}
  475. DarkRP.getShipmentByName = function(name)
  476. name = string.lower(name or "")
  477.  
  478. if not shipByName[name] then return nil, nil end
  479. return CustomShipments[shipByName[name]], shipByName[name]
  480. end
  481.  
  482. function DarkRP.createShipment(name, model, entity, price, Amount_of_guns_in_one_shipment, Sold_seperately, price_seperately, noshipment, classes, shipmodel, CustomCheck)
  483. local tableSyntaxUsed = type(model) == "table"
  484.  
  485. local AllowedClasses = classes or {}
  486. if not classes then
  487. for k,v in pairs(team.GetAllTeams()) do
  488. table.insert(AllowedClasses, k)
  489. end
  490. end
  491.  
  492. local price = tonumber(price)
  493. local shipmentmodel = shipmodel or "models/Items/item_item_crate.mdl"
  494.  
  495. local customShipment = tableSyntaxUsed and model or
  496. {model = model, entity = entity, price = price, amount = Amount_of_guns_in_one_shipment,
  497. seperate = Sold_seperately, pricesep = price_seperately, noship = noshipment, allowed = AllowedClasses,
  498. shipmodel = shipmentmodel, customCheck = CustomCheck, weight = 5}
  499.  
  500. if customShipment.separate ~= nil then
  501. customShipment.seperate = customShipment.separate
  502. end
  503. customShipment.name = name
  504. customShipment.allowed = customShipment.allowed or {}
  505.  
  506. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["shipments"][customShipment.name] then return end
  507.  
  508. local corrupt = checkValid(customShipment, validShipment)
  509. if corrupt then ErrorNoHalt("Corrupt shipment \"" .. (name or "") .. "\": element " .. corrupt .. " is corrupt.\n") end
  510.  
  511. customShipment.allowed = isnumber(customShipment.allowed) and {customShipment.allowed} or customShipment.allowed
  512.  
  513. -- if SERVER and FPP then
  514. -- FPP.AddDefaultBlocked(blockTypes, customShipment.entity)
  515. -- end
  516.  
  517. shipByName[string.lower(name or "")] = table.insert(CustomShipments, customShipment)
  518. util.PrecacheModel(customShipment.model)
  519. end
  520. AddCustomShipment = DarkRP.createShipment
  521.  
  522. function DarkRP.createVehicle(Name_of_vehicle, model, price, Jobs_that_can_buy_it, customcheck)
  523. local vehicle = istable(Name_of_vehicle) and Name_of_vehicle or
  524. {name = Name_of_vehicle, model = model, price = price, allowed = Jobs_that_can_buy_it, customCheck = customcheck}
  525.  
  526. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["vehicles"][vehicle.name] then return end
  527.  
  528. local found = false
  529. for k,v in pairs(DarkRP.getAvailableVehicles()) do
  530. if string.lower(k) == string.lower(vehicle.name) then found = true break end
  531. end
  532.  
  533. local corrupt = checkValid(vehicle, validVehicle)
  534. if corrupt then ErrorNoHalt("Corrupt vehicle \"" .. (vehicle.name or "") .. "\": element " .. corrupt .. " is corrupt.\n") end
  535. if not found then ErrorNoHalt("Vehicle invalid: " .. vehicle.name .. ". Unknown vehicle name.") end
  536.  
  537. table.insert(CustomVehicles, vehicle)
  538. end
  539. AddCustomVehicle = DarkRP.createVehicle
  540.  
  541. /*---------------------------------------------------------------------------
  542. Decides whether a custom job or shipmet or whatever can be used in a certain map
  543. ---------------------------------------------------------------------------*/
  544. function GM:CustomObjFitsMap(obj)
  545. if not obj or not obj.maps then return true end
  546.  
  547. local map = string.lower(game.GetMap())
  548. for k,v in pairs(obj.maps) do
  549. if string.lower(v) == map then return true end
  550. end
  551. return false
  552. end
  553.  
  554. DarkRPEntities = {}
  555. function DarkRP.createEntity(name, entity, model, price, max, command, classes, CustomCheck)
  556. local tableSyntaxUsed = type(entity) == "table"
  557.  
  558. local tblEnt = tableSyntaxUsed and entity or
  559. {ent = entity, model = model, price = price, max = max,
  560. cmd = command, allowed = classes, customCheck = CustomCheck}
  561. tblEnt.name = name
  562.  
  563. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["entities"][tblEnt.name] then return end
  564.  
  565. if type(tblEnt.allowed) == "number" then
  566. tblEnt.allowed = {tblEnt.allowed}
  567. end
  568.  
  569. local corrupt = checkValid(tblEnt, validEntity)
  570. if corrupt then ErrorNoHalt("Corrupt Entity \"" .. (name or "") .. "\": element " .. corrupt .. " is corrupt.\n") end
  571.  
  572. -- if SERVER and FPP then
  573. -- FPP.AddDefaultBlocked(blockTypes, tblEnt.ent)
  574. -- end
  575.  
  576. table.insert(DarkRPEntities, tblEnt)
  577. timer.Simple(0, function() addEntityCommands(tblEnt) end)
  578. end
  579. AddEntity = DarkRP.createEntity
  580.  
  581. -- here for backwards compatibility
  582. DarkRPAgendas = {}
  583.  
  584. local agendas = {}
  585. plyMeta.getAgenda = fn.Compose{fn.Curry(fn.Flip(fn.GetValue), 2)(DarkRPAgendas), plyMeta.Team}
  586.  
  587. function plyMeta:getAgendaTable()
  588. local set = agendas[self:Team()]
  589. return set and disjoint.FindSet(set).value or nil
  590. end
  591.  
  592. function DarkRP.createAgenda(Title, Manager, Listeners)
  593. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["agendas"][Title] then return end
  594.  
  595. if not Manager then
  596. hook.Add("PlayerSpawn", "AgendaError", function(ply)
  597. if ply:IsAdmin() then ply:ChatPrint("WARNING: Agenda made incorrectly, there is no manager! failed to load!") end end)
  598. return
  599. end
  600.  
  601. DarkRPAgendas[Manager] = {Manager = Manager, Title = Title, Listeners = Listeners} -- backwards compat
  602.  
  603. agendas[Manager] = disjoint.MakeSet(DarkRPAgendas[Manager])
  604.  
  605. for k,v in pairs(Listeners) do
  606. agendas[v] = disjoint.MakeSet(v, agendas[Manager]) -- have the manager as parent
  607. end
  608.  
  609. if SERVER then
  610. timer.Simple(0, function()
  611. -- Run after scripts have loaded
  612. DarkRPAgendas[Manager].text = hook.Run("agendaUpdated", nil, DarkRPAgendas[Manager], "")
  613. end)
  614. end
  615. end
  616. AddAgenda = DarkRP.createAgenda
  617.  
  618. GM.DarkRPGroupChats = {}
  619. local groupChatNumber = 0
  620. function DarkRP.createGroupChat(funcOrTeam, ...)
  621. local gm = GM or GAMEMODE
  622. gm.DarkRPGroupChats = gm.DarkRPGroupChats or {}
  623. if DarkRP.DARKRP_LOADING then
  624. groupChatNumber = groupChatNumber + 1
  625. if DarkRP.disabledDefaults["groupchat"][groupChatNumber] then return end
  626. end
  627. -- People can enter either functions or a list of teams as parameter(s)
  628. if type(funcOrTeam) == "function" then
  629. table.insert(gm.DarkRPGroupChats, funcOrTeam)
  630. else
  631. local teams = {funcOrTeam, ...}
  632. table.insert(gm.DarkRPGroupChats, function(ply) return table.HasValue(teams, ply:Team()) end)
  633. end
  634. end
  635. GM.AddGroupChat = function(GM, ...) DarkRP.createGroupChat(...) end
  636.  
  637. GM.AmmoTypes = {}
  638.  
  639. function DarkRP.createAmmoType(ammoType, name, model, price, amountGiven, customCheck)
  640. local gm = GM or GAMEMODE
  641. gm.AmmoTypes = gm.AmmoTypes or {}
  642. local ammo = istable(name) and name or {
  643. name = name,
  644. model = model,
  645. price = price,
  646. amountGiven = amountGiven,
  647. customCheck = customCheck
  648. }
  649. ammo.ammoType = ammoType
  650.  
  651. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["ammo"][ammo.name] then return end
  652. table.insert(gm.AmmoTypes, ammo)
  653. end
  654. GM.AddAmmoType = function(GM, ...) DarkRP.createAmmoType(...) end
  655.  
  656. local demoteGroups = {}
  657. function DarkRP.createDemoteGroup(name, tbl)
  658. if DarkRP.DARKRP_LOADING and DarkRP.disabledDefaults["demotegroups"][name] then return end
  659. if not tbl or not tbl[1] then error("No members in the demote group!") end
  660.  
  661. local set = demoteGroups[tbl[1]] or disjoint.MakeSet(tbl[1])
  662. for i = 2, #tbl do
  663. set = set + (demoteGroups[tbl[i]] or disjoint.MakeSet(tbl[i]))
  664. end
  665.  
  666. for _, teamNr in pairs(tbl) do
  667. if demoteGroups[teamNr] then
  668. -- Unify the sets if there was already one there
  669. demoteGroups[teamNr] = demoteGroups[teamNr] + set
  670. else
  671. demoteGroups[teamNr] = set
  672. end
  673. end
  674. end
  675.  
  676. function DarkRP.getDemoteGroup(teamNr)
  677. demoteGroups[teamNr] = demoteGroups[teamNr] or disjoint.MakeSet(teamNr)
  678. return disjoint.FindSet(demoteGroups[teamNr])
  679. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement