Jump to content

Recommended Posts

Hello, everyone, It's one of my first times modding on DST, tho i have experience with C++ and a bit of java lol And I was trying to make a new character with an item perk but found a couple difficulties, hoped someone could help :D. Well, what i had in mind is that, depending on things on their inventory, they'd get certain penalties or bonuses as long as the item remained with them.

My first idea was to make my own itemaffinity component, much like wurt's.

function ItemAffinity:AddAffinity(prefab, tag, sanity_bonus, priority)
    table.insert(self.affinities, {prefab = prefab, tag= tag, sanity_bonus = sanity_bonus, priority = priority})
    self:RefreshAffinity()
end


Except what i wanted to happen is that instead of a sanity bonus the item would cause a temperature modifier (or a temperature penalty?). For example, if you had a certain amount of ice in your inventory, your temp would slowly start to drop. How would I do that? Is it even possible? My idea was also that the most ice u carried quicker you'd start to freeze but if we can only make penalties through item type priority that's fine.

Analysing how wurt's component worked thats what i found

 

function ItemAffinity:RefreshAffinity()
    self:SortAffinities()
    self.inst.components.sanity.externalmodifiers:RemoveModifier(self.inst)

    for i,v in ipairs(self.affinities) do
        if v.prefab and self.inst.components.inventory:Has(v.prefab, 1) then
            self.inst.components.sanity.externalmodifiers:SetModifier(self.inst, v.sanity_bonus)
            break
        elseif v.tag and self.inst.components.inventory:HasItemWithTag(v.tag, 1) then
            self.inst.components.sanity.externalmodifiers:SetModifier(self.inst, v.sanity_bonus)
            break
        end
    end
end

I'm aware that what is changing depends on the "self.inst.components.sanity.externalmodifiers:SetModifier" , and I also thought about stealing smth from the chilling amulet or the heatstone to put in its place (since they also drop ur temp with time) but i, honestly, didnt undertand much how their code worked KLSFLDFD Any ideas? Is there another way to do this? Thank you in advance ^^

Edited by 7Meias

Took some time but i did it- gonna post in case someone else gets this same doubt on the future
All I did was make a new "ItemApathy" component (with a ListenForEvent ) and add this lil  "CreateApathy" function in it 

 if v.prefab and self.inst.components.inventory:Has(v.prefab, 1) then
			 
			self.task = self.inst:DoPeriodicTask(1, function(inst)
			if self.inst.components.temperature.current < 90 and self.inst.components.temperature.current > 4 then
			   self.inst.components.temperature:DoDelta(-2) end
			
			end)
			 
			
        else
		
		if self.task ~= nil then
                self.task:Cancel()
                self.task = nil
            end
			
        end

I'm going to test some more of the task's speed and the modifier- but the hard part, which is this basic skeleton, is already done and ready :>

Edited by 7Meias
  • Like 1

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