Jump to content

Recommended Posts

So I'm going insane and trying to make a mod. You may be asking am I going insane because the mod is giving me trouble or am I making the mod because I am insane already; answer, yes.

Still, I want to make an item functionally identical to the hambat with some minor differences, including but not limited to being marginally weaker, only losing some of its damage output as it rots, lasting a bit longer, being edible, and having a different crafting recipe. I also want to make one or two others with similar changes.

But I don't see anywhere in the files as to how the Hambat scales its damage, and the only Mod I've found that effects its damage scaling makes a change to a line of code I don't see in the main file, nor in any directly related files, perhaps I'm looking in the wrong place.

I'd also like to include this other mods change with yet another tweak to it so the Hambat too still loses damage as it gets old but not nearly as much as it does.

Edited by Gotheran
11 minutes ago, Gotheran said:

But I don't see anywhere in the files as to how the Hambat scales its damage, and the only Mod I've found that effects its damage scaling makes a change to a line of code I don't see in the main file, nor in any directly related files, perhaps I'm looking in the wrong place.

I'd also like to include this other mods change with yet another tweak to it so the Hambat too still loses damage as it gets old but not nearly as much as it does.

data/DLC0001/scripts/prefabs/hambat.lua

Everything you want is already in the file by uncommenting the edible part and changing the perishable's SetPerishTime.

local function UpdateDamage(inst)
    if inst.components.perishable and inst.components.weapon then
        local dmg = TUNING.HAMBAT_DAMAGE * inst.components.perishable:GetPercent()
        dmg = Remap(dmg, 0, TUNING.HAMBAT_DAMAGE, TUNING.HAMBAT_MIN_DAMAGE_MODIFIER*TUNING.HAMBAT_DAMAGE, TUNING.HAMBAT_DAMAGE)
        inst.components.weapon:SetDamage(dmg)
    end
end

local function OnLoad(inst, data)
    UpdateDamage(inst)
end

local function onequip(inst, owner) 
    UpdateDamage(inst)
    owner.AnimState:OverrideSymbol("swap_object", "swap_ham_bat", "swap_ham_bat")
    owner.AnimState:Show("ARM_carry") 
    owner.AnimState:Hide("ARM_normal") 
end

local function onunequip(inst, owner) 
    UpdateDamage(inst)
    owner.AnimState:Hide("ARM_carry") 
    owner.AnimState:Show("ARM_normal") 
end



inst.components.weapon:SetOnAttack(UpdateDamage)

When the hambat loads, is equipped, or unequipped, or is used to attack, it updates its damage.

It uses it's perish percent to determine how much damage it will have.

Then it remaps it so the value doesn't go below the damage multiplied by a minimum damage modifier.

Then it applies the new damage to the weapon.

 

This only occurs for ROG and SW. Vanilla Don't Starve doesn't have this for the hambat.

1 hour ago, Gotheran said:

Ah, I was looking in the vanilla files

 

EDIT: How would one inverse the hambat damage scaling?

Remap(input, input_min, input_max, output_min, output_max)

So taking the hambat as base, just flip either the input_(min/max) arguments around or the output_(min/max) arguments around.

The function Remap is a simple linear calculator.

--Remap a value (i) from one range (a - b) to another (x - y)
function Remap(i, a, b, x, y)
    return (((i - a)/(b - a)) * (y - x)) + x
end

 

17 minutes ago, Gotheran said:

Did I mention I know 0 about modding or that I'm insane?

for k=0,1,0.1
do
    print(k, Remap(k, 0, 1, 30, 80))
end
Spoiler

0.0    30.0
0.1    35.0
0.2    40.0
0.3    45.0
0.4    50.0
0.5    55.0
0.6    60.0
0.7    65.0
0.8    70.0
0.9    75.0
1.0    80.0

for k=0,1,0.1
do
    print(k, Remap(k, 0, 1, 80, 30))
end
Spoiler

0.0    80.0
0.1    75.0
0.2    70.0
0.3    65.0
0.4    60.0
0.5    55.0
0.6    50.0
0.7    45.0
0.8    40.0
0.9    35.0
1.0    30.0

for k=-10,10,1.0
do
    print(k, Remap(k, 0, 1, 80, 30))
end
Spoiler

-10.0    580.0
-9.0    530.0
-8.0    480.0
-7.0    430.0
-6.0    380.0
-5.0    330.0
-4.0    280.0
-3.0    230.0
-2.0    180.0
-1.0    130.0
0.0    80.0
1.0    30.0
2.0    -20.0
3.0    -70.0
4.0    -120.0
5.0    -170.0
6.0    -220.0
7.0    -270.0
8.0    -320.0
9.0    -370.0
10.0    -420.0

Note how the expected input range was [0,1] but it works with inputs out of spec.

It's a linear mapping taking a range from A to B and mapping it exactly in the range from C to D, and anything out of the range will be calculated since it's just a scaling factor.

2 hours ago, Gotheran said:

okay, crisis 1 solved, crisis 2, would it be possible to create a post init that is only used when RoG is not enabled, to add the Hambat damage scaling to the vanilla version.

GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS)
GLOBAL.IsDLCEnabled(GLOBAL.CAPY_DLC)

To see which DLCs are enabled or not.

So check that both are not enabled and you'll know that it's just Don't Starve with no expansions.

Sadly the portion of code I wanted to add is more complex than first expected, and way out of my skill level (rotten potato if you're wondering) so I've moved on to the new items, which in an ideal world will work as they are now, so I need someone to make art and or put the art for the animations for weapon swinging etc etc.

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