Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. function PS:LoadItems()
  2. local _, dirs = file.Find('pointshop/items/*', 'LUA')
  3.  
  4. for _, category in pairs(dirs) do
  5. local f, _ = file.Find('pointshop/items/' .. category .. '/__category.lua', 'LUA')
  6.  
  7. if #f > 0 then
  8. CATEGORY = {}
  9.  
  10. CATEGORY.Name = ''
  11. CATEGORY.Icon = ''
  12. CATEGORY.Order = 0
  13. CATEGORY.AllowedEquipped = -1
  14. CATEGORY.AllowedUserGroups = {}
  15. CATEGORY.CanPlayerSee = function() return true end
  16. CATEGORY.ModifyTab = function(tab) return end
  17.  
  18. if SERVER then AddCSLuaFile('pointshop/items/' .. category .. '/__category.lua') end
  19. include('pointshop/items/' .. category .. '/__category.lua')
  20.  
  21. if not PS.Categories[category] then
  22. PS.Categories[category] = CATEGORY
  23. end
  24.  
  25. local files, _ = file.Find('pointshop/items/' .. category .. '/*.lua', 'LUA')
  26.  
  27. for _, name in pairs(files) do
  28. if name ~= '__category.lua' then
  29. if SERVER then AddCSLuaFile('pointshop/items/' .. category .. '/' .. name) end
  30.  
  31. ITEM = {}
  32.  
  33. ITEM.__index = ITEM
  34. ITEM.ID = string.gsub(string.lower(name), '.lua', '')
  35. ITEM.Category = CATEGORY.Name
  36. ITEM.Price = 0
  37.  
  38. -- model and material are missing but there's no way around it, there's a check below anyway
  39.  
  40. ITEM.AdminOnly = false
  41. ITEM.AllowedUserGroups = {} -- this will fail the #ITEM.AllowedUserGroups test and continue
  42. ITEM.SingleUse = false
  43. ITEM.NoPreview = false
  44.  
  45. ITEM.CanPlayerBuy = true
  46. ITEM.CanPlayerSell = true
  47.  
  48. ITEM.CanPlayerEquip = true
  49. ITEM.CanPlayerHolster = true
  50.  
  51. ITEM.OnBuy = function() end
  52. ITEM.OnSell = function() end
  53. ITEM.OnEquip = function() end
  54. ITEM.OnHolster = function() end
  55. ITEM.OnModify = function() end
  56. ITEM.ModifyClientsideModel = function(ITEM, ply, model, pos, ang)
  57. return model, pos, ang
  58. end
  59.  
  60. include('pointshop/items/' .. category .. '/' .. name)
  61.  
  62. if not ITEM.Name then
  63. ErrorNoHalt("[POINTSHOP] Item missing name: " .. category .. '/' .. name .. "\n")
  64. continue
  65. elseif not ITEM.Price then
  66. ErrorNoHalt("[POINTSHOP] Item missing price: " .. category .. '/' .. name .. "\n")
  67. continue
  68. elseif not ITEM.Model and not ITEM.Material then
  69. ErrorNoHalt("[POINTSHOP] Item missing model or material: " .. category .. '/' .. name .. "\n")
  70. continue
  71. end
  72.  
  73. -- precache
  74.  
  75. if ITEM.Model then
  76. util.PrecacheModel(ITEM.Model)
  77. end
  78.  
  79. -- item hooks
  80. local item = ITEM
  81.  
  82. for prop, val in pairs(item) do
  83. if type(val) == "function" then -- although this hooks every function, it doesn't matter because the non-hook functions will never get called
  84. hook.Add(prop, 'PS_Item_' .. item.Name .. '_' .. prop, function(...)
  85. for _, ply in pairs(player.GetAll()) do
  86. if ply:PS_HasItemEquipped(item.ID) then -- hooks are only called if the player has the item equipped
  87. item[prop](item, ply, ply.PS_Items[item.ID].Modifiers, unpack({...}))
  88. end
  89. end
  90. end)
  91. end
  92. end
  93.  
  94. self.Items[ITEM.ID] = ITEM
  95.  
  96. ITEM = nil
  97. end
  98. end
  99.  
  100. CATEGORY = nil
  101. end
  102. end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement