Jump to content

Recommended Posts

Hey!

I am working on my first ever mod to don't starve together (and it's a character mod).
I am still struggling a lot with the lua, but getting better. 

I would like to implement:

  • Custom values for food types (for example for monster meat i'd like him to take half the original penalty),

    I've trid this metod inside modmain.lua:
    GetPlayer = GLOBAL.GetPlayer
    
    -- Food Values
    AddPrefabPostInit("carrot", function(inst)
            if GetPlayer().prefab == "fiddlesticks" then
                inst.components.edible.healthvalue = 2
                inst.components.edible.hungervalue = 0
                inst.components.edible.sanityvalue = -3
            end
        end)

    but it resulted in instant error whenever i try to pick up a carrot :/ 

  • 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 Combustiblemonbut 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

    There's high chance that i've poorly implemented this code but so far it causes Disconnect once a monster is attacked by weapon with this code.
    I am attatching core files of the mod so anyone can get a nice inside of what's going on.
    Thanks in advance to everyone who will try to help me with my very first character :)

modmain.lua fiddlesticks.lua scare_scythe.lua

Edited by Near4422

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...