Jump to content

[Help] Tweak Fire Staff to do damage and burn sometimes


Recommended Posts

The thing is, this is my first mod, and I want to tweak the staffs overall, at the moment I want the fire staff to do damage, and have a chance to burn instead of always burning. I got the damage part, what I do not have is the burning chance, I stumbled into Code4240's topic where he wanted to do something similar, but what he does completely eliminates the burn AND the sanity drain when using the staff because he alters the OnAttack function:

Spoiler

----Here is the code I had at the beginning based on another mod that makes the fire and ice staff to do damage (Staff Tweaks I think is the name of the mod):

PrefabFiles = {
}
Assets = {
}

local TUNING = GLOBAL.TUNING

local fixStaffDamage = function(damage)
	return function(prefab)
		if prefab.components.weapon then
			prefab.components.weapon:SetDamage(damage)
		end
	end
end

--Fire Staff

AddPrefabPostInit("firestaff", fixStaffDamage(TUNING.AXE_DAMAGE))

----Here is the code of Code4240, I usually comment the damage part, and the setDamage value I change for onattack_red_mod,since he changes onAttack, it no longer accepts what was on the code

AddPrefabPostInit("firestaff", function(inst)
	inst.components.weapon:SetDamage(34)
	inst.components.weapon:SetOnAttack(setDamage)
end)

----This is my try to make it work by brute force so that later I can edit what I need and add the chance of burning, this code is an exact copy of the actual fire staff code onattack_red, but it does not work when paired with SetOnAttack (the staff does not burn and does not drain sanity)

local onattack_red_mod = function(inst, attacker, target, skipsanity)
	if not skipsanity and attacker ~= nil and attacker.components.sanity ~= nil then
        attacker.components.sanity:DoDelta(-TUNING.SANITY_SUPERTINY)
    end

    attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo")

    if not target:IsValid() then
        --target killed or removed in combat damage phase
        return
    end

----The next part is what I believe is the burning effect of the staff, more specifically the part: "target.components.burnable:Ignite(true)", since it uses boolean, I thought on using a random number generator, compare it, and use that value

    if target.components.burnable ~= nil and not target.components.burnable:IsBurning() then
        if target.components.freezable ~= nil and target.components.freezable:IsFrozen() then
            target.components.freezable:Unfreeze()
        elseif target.components.fueled == nil then
            target.components.burnable:Ignite(true)
        elseif target.components.fueled.fueltype == FUELTYPE.BURNABLE
            or target.components.fueled.secondaryfueltype == FUELTYPE.BURNABLE then
            local fuel = SpawnPrefab("cutgrass")
            if fuel ~= nil then
                if fuel.components.fuel ~= nil and
                    fuel.components.fuel.fueltype == FUELTYPE.BURNABLE then
                    target.components.fueled:TakeFuelItem(fuel)
                else
                    fuel:Remove()
                end
            end
        end
        --V2C: don't ignite if it doens't accespt burnable fuel!
    end

    if target.components.freezable ~= nil then
        target.components.freezable:AddColdness(-1) --Does this break ice staff?
        if target.components.freezable:IsFrozen() then
            target.components.freezable:Unfreeze()
        end
    end

    if target.components.sleeper ~= nil and target.components.sleeper:IsAsleep() then
        target.components.sleeper:WakeUp()
    end

    if target.components.combat ~= nil then
        target.components.combat:SuggestTarget(attacker)
    end

    target:PushEvent("attacked", { attacker = attacker, damage = TUNING.AXE_DAMAGE, weapon = inst })
end

 

Just in case it helps: here is the code on the fire staff that I have been using as reference:

Spoiler

local assets =
{
    Asset("ANIM", "anim/staffs.zip"),
    Asset("ANIM", "anim/swap_staffs.zip"),
}

local prefabs =
{
    blue =
    {
        "ice_projectile",
    },

    red =
    {
        "fire_projectile",
        "cutgrass",
    },

    --purple = nil,

    orange =
    {
        "sand_puff_large_front",
        "sand_puff_large_back",
        "reticule",
    },

    green =
    {
        "splash_ocean",
        "collapse_small",
    },

    yellow =
    {
        "stafflight",
        "reticule",
    },

    opal =
    {
        "staffcoldlight",
        "reticule",
    },
}

---------RED STAFF---------

local function onattack_red(inst, attacker, target, skipsanity)
    if not skipsanity and attacker ~= nil and attacker.components.sanity ~= nil then
        attacker.components.sanity:DoDelta(-TUNING.SANITY_SUPERTINY)
    end

    attacker.SoundEmitter:PlaySound("dontstarve/wilson/fireball_explo")

    if not target:IsValid() then
        --target killed or removed in combat damage phase
        return
    end

    if target.components.burnable ~= nil and not target.components.burnable:IsBurning() then
        if target.components.freezable ~= nil and target.components.freezable:IsFrozen() then
            target.components.freezable:Unfreeze()
        elseif target.components.fueled == nil then
            target.components.burnable:Ignite(true)
        elseif target.components.fueled.fueltype == FUELTYPE.BURNABLE
            or target.components.fueled.secondaryfueltype == FUELTYPE.BURNABLE then
            local fuel = SpawnPrefab("cutgrass")
            if fuel ~= nil then
                if fuel.components.fuel ~= nil and
                    fuel.components.fuel.fueltype == FUELTYPE.BURNABLE then
                    target.components.fueled:TakeFuelItem(fuel)
                else
                    fuel:Remove()
                end
            end
        end
        --V2C: don't ignite if it doens't accespt burnable fuel!
    end

    if target.components.freezable ~= nil then
        target.components.freezable:AddColdness(-1) --Does this break ice staff?
        if target.components.freezable:IsFrozen() then
            target.components.freezable:Unfreeze()
        end
    end

    if target.components.sleeper ~= nil and target.components.sleeper:IsAsleep() then
        target.components.sleeper:WakeUp()
    end

    if target.components.combat ~= nil then
        target.components.combat:SuggestTarget(attacker)
    end

    target:PushEvent("attacked", { attacker = attacker, damage = 0, weapon = inst })
end

local function onlight(inst, target)
    if inst.components.finiteuses ~= nil then
        inst.components.finiteuses:Use(1)
    end
end

local function onhauntred(inst, haunter)
    if math.random() <= TUNING.HAUNT_CHANCE_RARE then
        local x, y, z = inst.Transform:GetWorldPosition() 
        local ents = TheSim:FindEntities(x, y, z, 6, { "canlight" }, { "fire", "burnt", "INLIMBO" })
        if #ents > 0 then
            for i, v in ipairs(ents) do
                if v:IsValid() and not v:IsInLimbo() then
                    onattack_red(inst, haunter, v, true) 
                end
            end
            inst.components.hauntable.hauntvalue = TUNING.HAUNT_LARGE
            return true
        end
    end
    return false
end
      
---------COLOUR SPECIFIC CONSTRUCTIONS---------

local function red()
    local inst = commonfn("red", { "firestaff", "rangedweapon", "rangedlighter" }, true)

    inst.projectiledelay = FRAMES

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(0)
    inst.components.weapon:SetRange(8, 10)
    inst.components.weapon:SetOnAttack(onattack_red)
    inst.components.weapon:SetProjectile("fire_projectile")

    inst.components.finiteuses:SetMaxUses(TUNING.FIRESTAFF_USES)
    inst.components.finiteuses:SetUses(TUNING.FIRESTAFF_USES)

    MakeHauntableLaunch(inst)
    AddHauntableCustomReaction(inst, onhauntred, true, false, true)

    return inst
end

 

 

Edited by pedregales
A bit of redundancy :/
Link to comment
Share on other sites

Maybe consider using something similar to the firebug components coding that willow used in DS where her burning the ground would only happen by chance while insane? Not sure if that coding could be tweaked but that's the closest I can think of for something that already has a "chance of" burning code

Link to comment
Share on other sites

1 hour ago, verdago7 said:

Maybe consider using something similar to the firebug components coding that willow used in DS where her burning the ground would only happen by chance while insane? Not sure if that coding could be tweaked but that's the closest I can think of for something that already has a "chance of" burning code

My main problem was that I had the burning function outside the AddPrefabPostInIt *facepalm*. I also found, thanks to you, that I do not have to make my own burning chance code :D, I found that the lighter has a formula of burning chance when hitting an enemy with it (it is set to 50%), it's similar to what I envisioned, but has a few other things that I did not know existed (like flammability). Thanks a bunch :).

Edited by pedregales
Do you know how to add smilies?
Link to comment
Share on other sites

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
 Share

×
  • Create New...