Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- ENT.Type = "anim"
- ENT.Base = "base_anim"
- ENT.Model = ""
- ENT.Spawnable = false
- local RestrictedSpellsByClass = {}
- RestrictedSpellsByClass['entity_hpwand_spell_accio'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_accio_statum'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_aguamenti'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_arresto_momentum'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_ascendio'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_depulso'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_duro'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_episkey'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_everte_statum'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_expelliarmus'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_fumos'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_heyedillio'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_impedimenta'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_lumos'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_lux_bulbus'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_mobilicorpus'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_mostro'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_petrificus_totalus'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_protego'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_punchek'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_rennervate'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_rictusempra'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_salvio_hexia'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_shield_charm'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_slugulus_eructo'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_speedom'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_spongify'] = "Charms"
- RestrictedSpellsByClass['entity_hpwand_spell_stupefy'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_verdimillious'] = "DADA"
- RestrictedSpellsByClass['entity_hpwand_spell_vulnera_sanentur'] = "Wizardry"
- RestrictedSpellsByClass['entity_hpwand_spell_wingardium_leviosa'] = "Charms"
- if SERVER then
- hook.Add("canBuyCustomEntity", "CheckCanBuyFuckingBooks", function(ply, entTable)
- local canSpawn = false
- local classFromSpell = RestrictedSpellsByClass[entTable.ent]
- if classFromSpell then
- for k,v in pairs(HP_CLASS_SYSTEM:GetActualSubjects()) do
- if classFromSpell == v.name then canSpawn = true end
- end
- if not canSpawn then
- ply:ChatPrint("You can only buy that book during "..RestrictedSpellsByClass[entTable.ent].." class.")
- return canSpawn,false,"You can only buy that book during "..RestrictedSpellsByClass[entTable.ent].." class."
- end
- end
- end)
- hook.Add("canBuyCustomEntity", "CheckBookClasses", function(ply, entTable)
- local classFromSpell = RestrictedSpellsByClass[entTable.ent]
- if classFromSpell then
- local classes = HP_CLASS_SYSTEM.Classes
- local book;
- if classes[1][2].name == classFromSpell then
- book = HP_CLASS_SYSTEM.Books[1]
- end
- if classes[2][2].name == classFromSpell then
- book = HP_CLASS_SYSTEM.Books[2]
- end
- if book and book ~= entTable.ent then
- return false,false,"A book has already been spawned for the "..classFromSpell.." class."
- end
- end
- end)
- hook.Add("playerBoughtCustomEntity", "RegisterBookClasses", function(ply, entTable)
- local bookSubject = RestrictedSpellsByClass[entTable.ent]
- if bookSubject then
- if HP_CLASS_SYSTEM.Classes[1][2].name == bookSubject then
- HP_CLASS_SYSTEM.Books[1] = entTable.ent
- end
- if HP_CLASS_SYSTEM.Classes[2][2].name == bookSubject then
- HP_CLASS_SYSTEM.Books[2] = entTable.ent
- end
- end
- end)
- function ENT:CheckCanSpawn(ply)
- --if not IsValid(ply) then return false end
- if HpwRewrite:IsSpellInAdminOnly(self.PrintName) and not HpwRewrite.CheckAdmin(ply) then
- HpwRewrite:DoNotify(ply, "Only admins can spawn " .. self.PrintName .. "!", 1)
- return false
- end
- return true
- end
- -- To setup owner
- function ENT:SetupOwner(ply)
- self.Owner = ply
- end
- -- SpawnFunction is only sandbox function??? --Q menu function
- function ENT:SpawnFunction(ply, tr, class)
- if not tr.Hit then return end
- local ent = ents.Create(class)
- ent:SetupOwner(ply)
- ent:SetPos(tr.HitPos + tr.HitNormal * 16)
- ent:SetAngles(Angle(0, (ply:GetPos() - tr.HitPos):Angle().y, 0))
- ent:Spawn()
- ent:Activate()
- return ent
- end
- function ENT:Initialize()
- -- Notifying server admins that they're doing something wrong
- if self.Owner == nil then
- 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."
- ErrorNoHalt(text .. "\n")
- HpwRewrite:LogDebug("[ERROR] " .. text)
- self:Remove()
- return
- end
- if HP_CLASS_SYSTEM and RestrictedSpellsByClass[self:GetClass()] then
- local subjects = HP_CLASS_SYSTEM:GetActualSubjects()
- local canSpawn = false
- for k,v in pairs(subjects) do
- if v.name == RestrictedSpellsByClass[self:GetClass()] then
- canSpawn = true
- end
- end
- if not canSpawn then
- HpwRewrite:DoNotify(self.Owner, "You can only spawn that spellbook during " .. RestrictedSpellsByClass[self:GetClass()] .. " class!" )
- self:Remove()
- end
- end
- --[[if not self:CheckCanSpawn(self.Owner) then
- self:Remove()
- return
- end]]
- self:SetModel(self.Model)
- self:SetMoveType(MOVETYPE_VPHYSICS)
- self:SetSolid(SOLID_VPHYSICS)
- self:PhysicsInit(SOLID_VPHYSICS)
- self:SetUseType(SIMPLE_USE)
- local phys = self:GetPhysicsObject()
- if IsValid(phys) then
- phys:Wake()
- else
- self:Remove()
- end
- end
- function ENT:GiveSpells()
- return true
- end
- function ENT:OnTakeDamage(dmg)
- self:TakePhysicsDamage(dmg)
- end
- function ENT:Use(activator, caller)
- if not activator:IsPlayer() then return end
- 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
- local houseFileNumber = file.Read( "sorting/"..caller:SteamID64()..".txt", "DATA")
- if houseFileNumber then houseFileNumber = tonumber(houseFileNumber) else caller:ChatPrint("You have to be sorted to get that spell.") return end
- local housesByNumber = {'Hufflepuff','Gryffindor','Slytherin','Ravenclaw'}
- local classes = HP_CLASS_SYSTEM.Classes
- local subject = table.HasValue(classes[1][1], housesByNumber[houseFileNumber]) and classes[1][2].name or classes[2][2].name
- local spellclass = RestrictedSpellsByClass[self:GetClass()]
- if subject ~= spellclass then
- caller:ChatPrint("You don't have ".. spellclass .. " class right now.")
- return
- end
- end
- -- Spells
- if not self:GiveSpells(activator, caller) then return end
- self:EmitSound("garrysmod/save_load1.wav", 60)
- SafeRemoveEntity(self)
- end
- else
- function ENT:Draw()
- self:DrawModel()
- if not HpwRewrite.CVars.DrawBookText:GetBool() then return end
- local pos = self:LocalToWorld(self:OBBCenter()) + vector_up * (self:OBBMaxs().z + 6)
- local ang = (pos - EyePos()):Angle()
- local a = 170 - math.Clamp(self:GetPos():Distance(EyePos()) * 0.8, 0, 170)
- cam.Start3D2D(pos, Angle(0, ang.y - 90, -ang.p + 90), 0.05)
- local name = self.PrintName
- local color = Color(255, 255, 255, a + math.sin(CurTime() * 5) * a * 0.3)
- draw.SimpleText(name, "HPW_fontbig", 0, 0, color, TEXT_ALIGN_CENTER)
- if self.CustomIcon then
- local lenw, lenh = surface.GetTextSize(name)
- surface.SetMaterial(self.CustomIcon)
- color.a = math.min(255, a * 1.7)
- surface.SetDrawColor(color)
- local x = -(lenw / 2) - 142
- local y = -lenh / 2 + 32
- local w, h = 128, 128
- surface.DrawTexturedRect(x, y, w, h)
- color.r, color.g, color.b = 0, 0, 0
- surface.SetDrawColor(color)
- surface.DrawOutlinedRect(x - 2, y - 2, w + 4, h + 4)
- end
- cam.End3D2D()
- end
- end
- hook.Add("PlayerSpawnSENT", "BlockBooks", function( ply, class )
- if string.find(class, "entity_hpwand_spell_") then
- return false
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement