• Help with scale damage.
    2 replies, posted
I have a problem with a particular piece of code which until a few weeks ago has been working fine. [CODE]local function ReduceDamage(ent, dmginfo) local infl =dmginfo:GetInflictor() local att =dmginfo:GetAttacker() local amount =dmginfo:GetDamage() if activator:IsPlayer() and ent.ShouldReduceDamage and dmginfo:GetDamage() then dmginfo:ScaleDamage(.1) end end hook.Add("EntityTakeDamage", "ReduceDamage", ReduceDamage) end[/CODE] It was working fine so i don't know if an update broke it or not. Any help is appreciated. The whole file is here. [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') //Initialize function ENT:Initialize() //Precache sounds util.PrecacheSound("plats/train_use1.wav") util.PrecacheSound("common/null.wav") //Draw model self.Entity:SetModel("models/props_phx/construct/plastic/plastic_angle_360.mdl") self.Entity:SetMaterial("models/props_lab/cornerunit_cloud") self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end //Default values self.charged = true self.auxcharged = true self.othercharged = true self.used = false self.disabled = false self.pickedup = false self.player = nil self.touched = false end //Spawn module function ENT:SpawnFunction(ply, tr) //Create this sent if !tr.Hit then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create("sent_Magic") ent:SetPos(SpawnPos) ent:Spawn() ent:Activate() return ent end //Equip when touched function ENT:Touch(activator) if !self.touched then if activator:IsPlayer() then local a = ents.FindByClass("sent_Magic") local found = false local n = nil for k,v in ipairs(a) do if (v.player == activator) then found = true end end //Don't let anyone have more than one pack at the time if !found then self.Entity:SetOwner(activator) self.Entity:SetPos(activator:GetPos()) self.Entity:SetGravity(1) self.Entity:SetParent(activator) self.Entity:SetCollisionGroup( COLLISION_GROUP_NONE ) self.player = activator self.pickedup = true self.touched = true self.player.ShouldReduceDamage = true self.player:Give("Magic") //This part is dumb, but how else do you make it invisible? self.Entity:SetModel("models/dav0r/hoverball.mdl") self.Entity:SetMaterial("freezenade/freezenade_red") self.Entity:SetRenderMode(1) self.Entity:SetColor(Color(0,0,0,0)) self.Entity:EmitSound("ambient/atmosphere/cave_hit1.wav") else self.Entity:EmitSound( "common/null.wav", 500, 100 ) //Bug end if math.Rand(1,2) <= 1 then local function ReduceDamage(ent, dmginfo) local infl =dmginfo:GetInflictor() local att =dmginfo:GetAttacker() local amount =dmginfo:GetDamage() if activator:IsPlayer() and ent.ShouldReduceDamage and dmginfo:GetDamage() then dmginfo:ScaleDamage(.1) end end hook.Add("EntityTakeDamage", "ReduceDamage", ReduceDamage) end end end end //Helper function function ENT:Enable() self.disabled = false end //Main function function ENT:Think() //Remove if player isn't there if !self.pickedup and self.touched then self.Entity:Remove() end end[/CODE]
Move the hook outside of any of other functions.
Like this? [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') //Initialize function ENT:Initialize() //Precache sounds util.PrecacheSound("plats/train_use1.wav") util.PrecacheSound("common/null.wav") //Draw model self.Entity:SetModel("models/props_phx/construct/plastic/plastic_angle_360.mdl") self.Entity:SetMaterial("models/props_lab/cornerunit_cloud") self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end //Default values self.charged = true self.auxcharged = true self.othercharged = true self.used = false self.disabled = false self.pickedup = false self.player = nil self.touched = false end //Spawn module function ENT:SpawnFunction(ply, tr) //Create this sent if !tr.Hit then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create("sent_Magic") ent:SetPos(SpawnPos) ent:Spawn() ent:Activate() return ent end hook.Add("EntityTakeDamage", "ReduceDamage", ReduceDamage) //Equip when touched function ENT:Touch(activator) if !self.touched then if activator:IsPlayer() then local a = ents.FindByClass("sent_Magic") local found = false local n = nil for k,v in ipairs(a) do if (v.player == activator) then found = true end end //Don't let anyone have more than one pack at the time if !found then self.Entity:SetOwner(activator) self.Entity:SetPos(activator:GetPos()) self.Entity:SetGravity(1) self.Entity:SetParent(activator) self.Entity:SetCollisionGroup( COLLISION_GROUP_NONE ) self.player = activator self.pickedup = true self.touched = true self.player.ShouldReduceDamage = true self.player:Give("Magic") //This part is dumb, but how else do you make it invisible? self.Entity:SetModel("models/dav0r/hoverball.mdl") self.Entity:SetMaterial("freezenade/freezenade_red") self.Entity:SetRenderMode(1) self.Entity:SetColor(Color(0,0,0,0)) self.Entity:EmitSound("ambient/atmosphere/cave_hit1.wav") else self.Entity:EmitSound( "common/null.wav", 500, 100 ) //Bug end if math.Rand(1,2) <= 1 then local function ReduceDamage(ent, dmginfo) local infl =dmginfo:GetInflictor() local att =dmginfo:GetAttacker() local amount =dmginfo:GetDamage() if activator:IsPlayer() and ent.ShouldReduceDamage and dmginfo:GetDamage() then dmginfo:ScaleDamage(.1) end end end end end end //Helper function function ENT:Enable() self.disabled = false end //Main function function ENT:Think() //Remove if player isn't there if !self.pickedup and self.touched then self.Entity:Remove() end end[/CODE] Are you talking about moving the whole scale damage piece outside of the Ent:touch function then i cant. I am sure i have done something wrong. I only know some gmod lua basics.
Sorry, you need to Log In to post a reply to this thread.