Jump to content

Recommended Posts

Hey there!

I've already created such subject but by misteake i placed it in a wrong forum (don't starve) and got suggested to repost it here - so maybe i'll get more help with it.

Thing is - i am currently working on my first mod ever and decided so that it is going to be character mod.
I checked dozens of subjects on forum, searched through it and made quite a decent progress so far.

I would like still to implement:

  • Special custom boomerang with infinite uses but using 10 health points per use (and if possible only usable by this custom character),
    I'd love to get a full tutorial on how to set up a new custom item.

  • Aura around character that deals 1 point of damage every 2 seconds to every hostile characters in certain radius, and per each point dealt heal 1 point of hp (this could be working with a certain item in hand or just as a aura around character - whatever is easier).

    I've already created a topic about this subject a moment ago, but decided to create a new one containing all desired things.

    So far i tried the method mentioned by Combustiblemon, but it still isn't finished yet:

    local function IsVaildTarget(target)
        return target ~= nil and target.components.health ~= nil
        --can't drain when target has no health
             and not ((target:HasTag("prey") and not target:HasTag("hostile")) or
                target:HasTag("structure") or
                target:HasTag("wall") or
                target:HasTag("companion"))
    end
    
    local function onattack(inst, owner, target)
        target:AddTag("scythevictim")
        local count = 0
        local pt = Vector3(target.Transform:GetWorldPosition())
        local range = 5
        local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, range)
        for i,ent in ipairs(ents) do
            if IsVaildTarget(ent) or ent and ent.components.health and ent:HasTag("scythevictim") then
                --because of scythevictim tag, you can even drain 'not vaild target(like wall, chester)' when it's directly attacked.
                if ent._scythedmgtask ~= nil then
                    ent._scythedmgtask:Cancel()
                    --it will reset its timer when it's re-attacked before timer done
                end
                ent._scythedmgtask = ent:DoTaskInTime(10, function(ent) ent._scythecount = nil ent._scythedmg = nil ent._scythedmgtask = nil end)
                --reset everything when 10 sec timer is done
                if ent._scythecount == nil then
                    ent._scythedmg = ent:DoPeriodicTask(2, function(ent) ent.components.health:DoDelta(-1, false, owner) end)
                    --every 2 seconds, it will deal 1 damage
                    ent._scythecount = ent._scythecount + 1
                else
                    --it can be applied multiple times!
                    ent._scythedmg = ent:DoPeriodicTask(2, function(ent) ent.components.health:DoDelta(-ent._scythecount, false, owner) end)
                    --every 2 seconds, it will deal 'ent._scythecount' damage
                    ent._scythecount = ent._scythecount + 1
                end
                count = count + ent._scythecount
                --since ent._scythecount = damage dealt, you will heal total amount of damage dealt
            end
        end
        if owner._draintask ~= nil then
            owner._draintask:Cancel()
            owner._drain:Cancel()
        end
        --it will reset its timer when it is attacked before time done
        owner._draintask = owner:DoTaskInTime(10, function(owner) owner._drain = nil owner._draintask = nil end)
        owner._drain = owner:DoPeriodicTask(2, function(owner) owner.components.health:DoDelta(count) end)
    end

    While aura does work - deals damage and heals character - it doesn't work propperly. 
    Even if I walk away far from target it still maintains it's effects.
    Even after the target is dead.

    I'd like to ask for a help, since I sit here ant juggle with variables trying to figure it out on my own. Maybe someone sees here an easy way to fix it.

Thank's in advance :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...