Guest User

Untitled

a guest
Feb 24th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. local PLUGIN = PLUGIN
  2. PLUGIN.name = "World Item Spawner"
  3. PLUGIN.author = "Calloway" -- ORIGINALLY PUBLISHED BY BLACKTEA, THIS IS A FIXED VERSION
  4. PLUGIN.desc = "World Item Spawner."
  5. PLUGIN.itempoints = PLUGIN.itempoints or {}
  6.  
  7. PLUGIN.spawngroups = { -- Example is based on HL2RP items.
  8. ["default"] = {
  9. {"bleach"},
  10. },
  11. ["example"] = {
  12. {"ration"},
  13. },
  14. ["junks"] = { -- for machine plugin.
  15. {"junk_ws"},
  16. {"junk_wj"},
  17. {"junk_be"},
  18. {"junk_bt"},
  19. {"junk_p"},
  20. {"junk_ss"},
  21. {"junk_bl"},
  22. {"junk_k"},
  23. {"junk_p"},
  24. {"junk_hp"},
  25. {"junk_ec"},
  26. {"junk_ej"},
  27. },
  28. -- this is an example of a primaries spawngroup
  29. ["primary"] = {
  30. {"ar2"},
  31. },
  32. -- this is an example of a secondary spawngroup
  33. ["secondary"] = {
  34. {"357"},
  35. -- {"usp"},
  36. },
  37. -- single weapon spawngroups below
  38. ["smg1"] = {
  39. {"smg1"},
  40. }
  41.  
  42. PLUGIN.spawnrate = 20 -- in seconds
  43. PLUGIN.maxitems = 10 -- Max items until the spawner stops (every second amount)
  44. PLUGIN.itemsperspawn = 1 -- every item spawn amount in seconds
  45. PLUGIN.spawneditems = PLUGIN.spawneditems or {}
  46.  
  47. if SERVER then
  48. local spawntime = 1
  49.  
  50. function PLUGIN:ItemShouldSave(entity)
  51. return (!entity.generated)
  52. end
  53.  
  54. function PLUGIN:Think()
  55. if spawntime > CurTime() then return end
  56. spawntime = CurTime() + self.spawnrate
  57. for k, v in ipairs(self.spawneditems) do
  58. if (!v:IsValid()) then
  59. table.remove(self.spawneditems, k)
  60. end
  61. end
  62.  
  63. if #self.spawneditems >= self.maxitems then return end
  64.  
  65. for i = 1, self.itemsperspawn do
  66. if #self.spawneditems >= self.maxitems then
  67. table.remove(self.spawneditems)
  68. return
  69. end
  70.  
  71. local v = table.Random(self.itempoints)
  72.  
  73. if (!v) then
  74. return
  75. end
  76.  
  77.  
  78. local data = {}
  79. data.start = v[1]
  80. data.endpos = data.start + Vector(0, 0, 1)
  81. data.filter = client
  82. data.mins = Vector(-16, -16, 0)
  83. data.maxs = Vector(16, 16, 16)
  84. local trace = util.TraceHull(data)
  85.  
  86. if trace.Entity:IsValid() then
  87. continue
  88. end
  89.  
  90. local idat = table.Random(self.spawngroups[v[2]] or self.spawngroups["default"])
  91. nut.item.spawn(idat[1], v[1] + Vector( math.Rand(-8,8), math.Rand(-8,8), 10 ), nil, AngleRand(), idat[2] or {})
  92. end
  93. end
  94.  
  95. function PLUGIN:LoadData()
  96. self.itempoints = self:getData() or {}
  97. end
  98.  
  99. function PLUGIN:SaveData()
  100. self:setData(self.itempoints)
  101. end
  102.  
  103. else
  104.  
  105. netstream.Hook("nut_DisplaySpawnPoints", function(data)
  106. for k, v in pairs(data) do
  107. local emitter = ParticleEmitter( v[1] )
  108. local smoke = emitter:Add( "sprites/glow04_noz", v[1] )
  109. smoke:SetVelocity( Vector( 0, 0, 1 ) )
  110. smoke:SetDieTime(10)
  111. smoke:SetStartAlpha(255)
  112. smoke:SetEndAlpha(255)
  113. smoke:SetStartSize(64)
  114. smoke:SetEndSize(64)
  115. smoke:SetColor(255,186,50)
  116. smoke:SetAirResistance(300)
  117. end
  118. end)
  119.  
  120. end
  121.  
  122. nut.command.add("itemspawnadd", {
  123. adminOnly = true,
  124. syntax = "<string itemgroup>",
  125. onRun = function(client, arguments)
  126. local trace = client:GetEyeTraceNoCursor()
  127. local hitpos = trace.HitPos + trace.HitNormal*5
  128. local spawngroup = arguments[1] or "default"
  129. table.insert( PLUGIN.itempoints, { hitpos, spawngroup } )
  130. client:notify( "You added the".. spawngroup .. " item spawner." )
  131. end
  132. })
  133.  
  134. nut.command.add("itemspawnremove", {
  135. adminOnly = true,
  136. onRun = function(client, arguments)
  137. local trace = client:GetEyeTraceNoCursor()
  138. local hitpos = trace.HitPos + trace.HitNormal*5
  139. local range = arguments[1] or 128
  140. local mt = 0
  141. for k, v in pairs( PLUGIN.itempoints ) do
  142. local distance = v[1]:Distance( hitpos )
  143. if distance <= tonumber(range) then
  144. PLUGIN.itempoints[k] = nil
  145. mt = mt + 1
  146. end
  147. end
  148. client:notify( mt .. " item spawners has been removed.")
  149. end
  150. })
  151.  
  152. nut.command.add("itemspawndisplay", {
  153. adminOnly = true,
  154. onRun = function(client, arguments)
  155. if SERVER then
  156. netstream.Start(client, "nut_DisplaySpawnPoints", PLUGIN.itempoints)
  157. client:notify( "Displayed All Points for 10 secs. (i.e Yellow stars on map.)" )
  158. end
  159. end
  160. })
Add Comment
Please, Sign In to add comment