+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: [E2]Damage Functions Mk2: Complete Rehash

  1. #1
    Wirererer Flieboy's Avatar
    Join Date
    Jul 2008
    Posts
    243

    Talking [E2]Damage Functions Mk2: Complete Rehash

    Hi guys,

    I am sure some of you remember that a while ago I made some "damage functions" for e2, getting attacker, inflictor, damage etc. Today I decided, with some encouragement from "Dav1d" that I would remake them with a nicer layout and a few more functions, as well as a new datatype.

    The functions included in this version are:

    runOnDamage(N) -- Runs every time damage is inflicted on anything

    dmgClk() -- Returns 1 every time damage is inflicted on anything

    entity:dmginfo() -- Returns the "damage" datatype, this is used for the rest of the functions, you retrieve the damage data from it

    damage:getDamage() -- Returns the damage inflicted on the entity from the damage datatype

    damage:getAttacker() -- Returns the entity attacking the entity from the damage datatype

    damage:getInflictor() -- Returns the entity inflicting the damage on the entity from the damage datatype

    damage:getVictim() -- Basically just returns the entity from the entity:dmginfo()

    getVictim() -- Returns the entity of ANYTHING that has damage inflicted on it

    damage:dmgPos() -- Returns the position that the entity was hit

    damage:dmgForce() -- Returns the force inflicted on the entity as a directional vector

    damage:dmgNormal() -- Returns a normalized vector, denoting the direction in which the entity was hit

    I hope these functions are better than my old ones and I WILL accept suggestions and requests, I also appreciate bug reports. I plan to also create a table function to receive all of the data in a table and also the type of damage. Anyway, here's the code:

    Code:
    local registered_chips = {}
    local dmgrun = 0
    local damageData = nil
    local damagedEnt = nil
    
    
    registerType("damage", "dmg", nil,
    	nil,
    	nil,
    	function(retval)
    		if retval == nil then return end
    		if type(retval) ~= "table" then error("Return value is neither nil nor a table, but a "..type(retval).."!",0) end
    	end,
    	function(v)
    		return type(v) ~= "table"  or not v.HitPos
    	end
    )
    
    e2function damage operator=(damage lhs, damage rhs)
    	self.vars[lhs] = rhs
    	self.vclk[lhs] = true
    	return damage
    end
    
    registerCallback("destruct",function(self)
    	registered_chips[self.entity] = nil
    end)
    
    __e2setcost(1)
    
    
    e2function void runOnDamage(activate)
        if activate ~= 0 then
            registered_chips[self.entity] = true
        else
    		registered_chips[self.entity] = nil
        end
    end
    
    
    e2function number dmgClk()
    	return dmgrun
    end
    
    e2function damage entity:dmginfo()
    if damagedEnt ~= this then return nil end
    return damageData
    end
    
    e2function number damage:getDamage()
    if this == nil then return 0 end
    return this:GetDamage()
    end
    
    e2function entity damage:getAttacker()
    if this == nil then return end
    return this:GetAttacker()
    end
    
    e2function entity damage:getInflictor()
    if this == nil then return end
    return this:GetInflictor()
    end
    
    e2function entity damage:getVictim()
    if this == nil then return end
    return damagedEnt
    end
    
    e2function entity getVictim()
    return damagedEnt
    end
    
    e2function vector damage:dmgPos()
    if this == nil then return {0,0,0} end
    return this:GetDamagePosition()
    end
    
    e2function vector damage:dmgForce()
    if this == nil then return {0,0,0} end
    return this:GetDamageForce()
    end
    
    e2function vector damage:dmgNormal()
    if this == nil then return {0,0,0} end
    local force = this:GetDamageForce()
    return force:Normalize()
    end
    
    local function DamageClock(ent, inflictor, attacker, amount, dmginfo)
    	local ents = {}
    	
    	-- this additional step is needed because we cant modify registered_chips while it is being iterated.
    	for entity,_ in pairs(registered_chips) do
    		if entity:IsValid() then table.insert(ents, entity) end
    	end
    	
    	dmgrun = 1
    	damagedEnt = ent
        damageData = dmginfo
    	for _,entity in ipairs(ents) do
    		entity:Execute()
    	end
    	dmgrun = 0	
        damagedEnt = nil
        damageData = nil
    end
    
    hook.Add("EntityTakeDamage", "DamageClock", DamageClock)
    
    __e2setcost(nil)
    ENJOY!

  2. #2
    ส็็็็็็็็็็็็็็็็ส็็ ็็็็็ Dav1d's Avatar
    Join Date
    May 2009
    Posts
    1,118

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Aha, yay!
    Nice work flieboy :3

  3. #3
    aka Colonel Never Online Colonel Thirty Two's Avatar
    Join Date
    Oct 2009
    Posts
    2,683
    Blog Entries
    5

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Kewl

  4. #4
    Wire Sofaking Hitman271's Avatar
    Join Date
    Feb 2008
    Location
    Why? You looking for somebody?
    Posts
    731

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    This has now usurped my old damage scale lua addon.....
    Quote Originally Posted by Anticept View Post
    This is not some place where you can toss your dick around and expect people to suck it.
    Community Gpu Thread. Post Yours!

    Bouncy Ball

  5. #5
    Wire Noob libintia's Avatar
    Join Date
    Jul 2010
    Location
    Sweden (But not a swed )
    Posts
    13

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    very nice

  6. #6
    Wirererer Flieboy's Avatar
    Join Date
    Jul 2008
    Posts
    243

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Quote Originally Posted by Hitman271 View Post
    This has now usurped my old damage scale lua addon.....
    Haha sorry, Hitman, but always take solace in the fact that yours is an actual entity (and one I have used frequently at that!) and this is just a few extensions.

  7. #7
    ส็็็็็็็็็็็็็็็็ส็็ ็็็็็ Dav1d's Avatar
    Join Date
    May 2009
    Posts
    1,118

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Bumpity Bump bump!
    Didn't Bull say something about committing Flie's old damage detection functions?
    What about these sexy new shiny ones? I would love for them to be SVN'd and I'm sure there are lots of people who would agree with me.

  8. #8
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,662
    Blog Entries
    1

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Whats wrong with using the wired damage detector entity?

  9. #9
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    Quote Originally Posted by Drunkie View Post
    Whats wrong with using the wired damage detector entity?
    Can it detect damage done to all and any entity on the entire server simultaneously?
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  10. #10
    Wirererer Flieboy's Avatar
    Join Date
    Jul 2008
    Posts
    243

    Default Re: [E2]Damage Functions Mk2: Complete Rehash

    And can it detect the force inflicted as a directional vector and the position that the damage was inflicted?

+ Reply to Thread
Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots