Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. AddCSLuaFile()
  2. ENT.Type = "anim"
  3. ENT.Base = "base_anim"
  4. ENT.Model = ""
  5. ENT.Spawnable = false
  6.  
  7. local RestrictedSpellsByClass = {}
  8. RestrictedSpellsByClass['entity_hpwand_spell_accio'] = "Charms"
  9. RestrictedSpellsByClass['entity_hpwand_spell_accio_statum'] = "Charms"
  10. RestrictedSpellsByClass['entity_hpwand_spell_aguamenti'] = "Charms"
  11. RestrictedSpellsByClass['entity_hpwand_spell_arresto_momentum'] = "Charms"
  12. RestrictedSpellsByClass['entity_hpwand_spell_ascendio'] = "Wizardry"
  13. RestrictedSpellsByClass['entity_hpwand_spell_depulso'] = "Charms"
  14. RestrictedSpellsByClass['entity_hpwand_spell_duro'] = "DADA"
  15. RestrictedSpellsByClass['entity_hpwand_spell_episkey'] = "Wizardry"
  16. RestrictedSpellsByClass['entity_hpwand_spell_everte_statum'] = "DADA"
  17. RestrictedSpellsByClass['entity_hpwand_spell_expelliarmus'] = "DADA"
  18. RestrictedSpellsByClass['entity_hpwand_spell_fumos'] = "DADA"
  19. RestrictedSpellsByClass['entity_hpwand_spell_heyedillio'] = "Wizardry"
  20. RestrictedSpellsByClass['entity_hpwand_spell_impedimenta'] = "Wizardry"
  21. RestrictedSpellsByClass['entity_hpwand_spell_lumos'] = "Charms"
  22. RestrictedSpellsByClass['entity_hpwand_spell_lux_bulbus'] = "Charms"
  23. RestrictedSpellsByClass['entity_hpwand_spell_mobilicorpus'] = "Wizardry"
  24. RestrictedSpellsByClass['entity_hpwand_spell_mostro'] = "DADA"
  25. RestrictedSpellsByClass['entity_hpwand_spell_petrificus_totalus'] = "Wizardry"
  26. RestrictedSpellsByClass['entity_hpwand_spell_protego'] = "DADA"
  27. RestrictedSpellsByClass['entity_hpwand_spell_punchek'] = "Wizardry"
  28. RestrictedSpellsByClass['entity_hpwand_spell_rennervate'] = "Wizardry"
  29. RestrictedSpellsByClass['entity_hpwand_spell_rictusempra'] = "DADA"
  30. RestrictedSpellsByClass['entity_hpwand_spell_salvio_hexia'] = "Wizardry"
  31. RestrictedSpellsByClass['entity_hpwand_spell_shield_charm'] = "DADA"
  32. RestrictedSpellsByClass['entity_hpwand_spell_slugulus_eructo'] = "Charms"
  33. RestrictedSpellsByClass['entity_hpwand_spell_speedom'] = "Charms"
  34. RestrictedSpellsByClass['entity_hpwand_spell_spongify'] = "Charms"
  35. RestrictedSpellsByClass['entity_hpwand_spell_stupefy'] = "DADA"
  36. RestrictedSpellsByClass['entity_hpwand_spell_verdimillious'] = "DADA"
  37. RestrictedSpellsByClass['entity_hpwand_spell_vulnera_sanentur'] = "Wizardry"
  38. RestrictedSpellsByClass['entity_hpwand_spell_wingardium_leviosa'] = "Charms"
  39.  
  40.  
  41.  
  42.  
  43. if SERVER then
  44.  
  45. hook.Add("canBuyCustomEntity", "CheckCanBuyFuckingBooks", function(ply, entTable)
  46. local canSpawn = false
  47. local classFromSpell = RestrictedSpellsByClass[entTable.ent]
  48. if classFromSpell then
  49. for k,v in pairs(HP_CLASS_SYSTEM:GetActualSubjects()) do
  50. if classFromSpell == v.name then canSpawn = true end
  51. end
  52. if not canSpawn then
  53. ply:ChatPrint("You can only buy that book during "..RestrictedSpellsByClass[entTable.ent].." class.")
  54. return canSpawn,false,"You can only buy that book during "..RestrictedSpellsByClass[entTable.ent].." class."
  55. end
  56. end
  57. end)
  58.  
  59. hook.Add("canBuyCustomEntity", "CheckBookClasses", function(ply, entTable)
  60. local classFromSpell = RestrictedSpellsByClass[entTable.ent]
  61. if classFromSpell then
  62.  
  63. local classes = HP_CLASS_SYSTEM.Classes
  64. local book;
  65. if classes[1][2].name == classFromSpell then
  66. book = HP_CLASS_SYSTEM.Books[1]
  67. end
  68. if classes[2][2].name == classFromSpell then
  69. book = HP_CLASS_SYSTEM.Books[2]
  70. end
  71.  
  72. if book and book ~= entTable.ent then
  73. return false,false,"A book has already been spawned for the "..classFromSpell.." class."
  74. end
  75. end
  76. end)
  77.  
  78. hook.Add("playerBoughtCustomEntity", "RegisterBookClasses", function(ply, entTable)
  79.  
  80. local bookSubject = RestrictedSpellsByClass[entTable.ent]
  81.  
  82. if bookSubject then
  83. if HP_CLASS_SYSTEM.Classes[1][2].name == bookSubject then
  84. HP_CLASS_SYSTEM.Books[1] = entTable.ent
  85. end
  86. if HP_CLASS_SYSTEM.Classes[2][2].name == bookSubject then
  87. HP_CLASS_SYSTEM.Books[2] = entTable.ent
  88. end
  89. end
  90.  
  91. end)
  92.  
  93. function ENT:CheckCanSpawn(ply)
  94. --if not IsValid(ply) then return false end
  95.  
  96. if HpwRewrite:IsSpellInAdminOnly(self.PrintName) and not HpwRewrite.CheckAdmin(ply) then
  97. HpwRewrite:DoNotify(ply, "Only admins can spawn " .. self.PrintName .. "!", 1)
  98. return false
  99. end
  100.  
  101.  
  102.  
  103. return true
  104. end
  105.  
  106. -- To setup owner
  107. function ENT:SetupOwner(ply)
  108. self.Owner = ply
  109. end
  110.  
  111. -- SpawnFunction is only sandbox function??? --Q menu function
  112. function ENT:SpawnFunction(ply, tr, class)
  113. if not tr.Hit then return end
  114.  
  115.  
  116.  
  117.  
  118. local ent = ents.Create(class)
  119. ent:SetupOwner(ply)
  120. ent:SetPos(tr.HitPos + tr.HitNormal * 16)
  121. ent:SetAngles(Angle(0, (ply:GetPos() - tr.HitPos):Angle().y, 0))
  122. ent:Spawn()
  123. ent:Activate()
  124.  
  125. return ent
  126. end
  127.  
  128. function ENT:Initialize()
  129. -- Notifying server admins that they're doing something wrong
  130. if self.Owner == nil then
  131. local text = "Spell book owner is not valid! It seems like you're running server on DarkRP or other not Sandbox gamemode! To setup owner use ENT:SetupOwner(ply) function in spawn code. If you do not understand what to do, contact Magic Wand developers."
  132.  
  133. ErrorNoHalt(text .. "\n")
  134. HpwRewrite:LogDebug("[ERROR] " .. text)
  135.  
  136. self:Remove()
  137. return
  138. end
  139.  
  140. if HP_CLASS_SYSTEM and RestrictedSpellsByClass[self:GetClass()] then
  141. local subjects = HP_CLASS_SYSTEM:GetActualSubjects()
  142.  
  143.  
  144. local canSpawn = false
  145. for k,v in pairs(subjects) do
  146. if v.name == RestrictedSpellsByClass[self:GetClass()] then
  147. canSpawn = true
  148. end
  149. end
  150. if not canSpawn then
  151. HpwRewrite:DoNotify(self.Owner, "You can only spawn that spellbook during " .. RestrictedSpellsByClass[self:GetClass()] .. " class!" )
  152. self:Remove()
  153. end
  154. end
  155.  
  156. --[[if not self:CheckCanSpawn(self.Owner) then
  157. self:Remove()
  158. return
  159. end]]
  160.  
  161. self:SetModel(self.Model)
  162. self:SetMoveType(MOVETYPE_VPHYSICS)
  163. self:SetSolid(SOLID_VPHYSICS)
  164. self:PhysicsInit(SOLID_VPHYSICS)
  165. self:SetUseType(SIMPLE_USE)
  166.  
  167. local phys = self:GetPhysicsObject()
  168. if IsValid(phys) then
  169. phys:Wake()
  170. else
  171. self:Remove()
  172. end
  173. end
  174.  
  175. function ENT:GiveSpells()
  176. return true
  177. end
  178.  
  179. function ENT:OnTakeDamage(dmg)
  180. self:TakePhysicsDamage(dmg)
  181. end
  182.  
  183. function ENT:Use(activator, caller)
  184. if not activator:IsPlayer() then return end
  185.  
  186. if not (activator:GetUserGroup() == "vip") and not (activator:GetUserGroup() == "moderator") and not (activator:GetUserGroup() == "admin") and not (activator:GetUserGroup() == "superadmin") and not (activator:GetUserGroup() == "gamemaker") and not (activator:GetUserGroup() == "staffmanager") and not (activator:GetUserGroup() == "servermanager") and not (activator:GetUserGroup() == "communitysupervisor") then
  187.  
  188. local houseFileNumber = file.Read( "sorting/"..caller:SteamID64()..".txt", "DATA")
  189. if houseFileNumber then houseFileNumber = tonumber(houseFileNumber) else caller:ChatPrint("You have to be sorted to get that spell.") return end
  190. local housesByNumber = {'Hufflepuff','Gryffindor','Slytherin','Ravenclaw'}
  191.  
  192.  
  193.  
  194. local classes = HP_CLASS_SYSTEM.Classes
  195. local subject = table.HasValue(classes[1][1], housesByNumber[houseFileNumber]) and classes[1][2].name or classes[2][2].name
  196.  
  197. local spellclass = RestrictedSpellsByClass[self:GetClass()]
  198.  
  199. if subject ~= spellclass then
  200. caller:ChatPrint("You don't have ".. spellclass .. " class right now.")
  201. return
  202. end
  203. end
  204. -- Spells
  205. if not self:GiveSpells(activator, caller) then return end
  206.  
  207. self:EmitSound("garrysmod/save_load1.wav", 60)
  208. SafeRemoveEntity(self)
  209. end
  210. else
  211. function ENT:Draw()
  212. self:DrawModel()
  213.  
  214. if not HpwRewrite.CVars.DrawBookText:GetBool() then return end
  215.  
  216. local pos = self:LocalToWorld(self:OBBCenter()) + vector_up * (self:OBBMaxs().z + 6)
  217. local ang = (pos - EyePos()):Angle()
  218.  
  219. local a = 170 - math.Clamp(self:GetPos():Distance(EyePos()) * 0.8, 0, 170)
  220.  
  221. cam.Start3D2D(pos, Angle(0, ang.y - 90, -ang.p + 90), 0.05)
  222. local name = self.PrintName
  223. local color = Color(255, 255, 255, a + math.sin(CurTime() * 5) * a * 0.3)
  224. draw.SimpleText(name, "HPW_fontbig", 0, 0, color, TEXT_ALIGN_CENTER)
  225.  
  226. if self.CustomIcon then
  227. local lenw, lenh = surface.GetTextSize(name)
  228.  
  229. surface.SetMaterial(self.CustomIcon)
  230. color.a = math.min(255, a * 1.7)
  231. surface.SetDrawColor(color)
  232.  
  233. local x = -(lenw / 2) - 142
  234. local y = -lenh / 2 + 32
  235. local w, h = 128, 128
  236. surface.DrawTexturedRect(x, y, w, h)
  237.  
  238. color.r, color.g, color.b = 0, 0, 0
  239. surface.SetDrawColor(color)
  240. surface.DrawOutlinedRect(x - 2, y - 2, w + 4, h + 4)
  241. end
  242. cam.End3D2D()
  243. end
  244. end
  245.  
  246. hook.Add("PlayerSpawnSENT", "BlockBooks", function( ply, class )
  247. if string.find(class, "entity_hpwand_spell_") then
  248. return false
  249. end
  250. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement