Jump to content

Help with trap teeth!


Recommended Posts

I want to change trap_teeth's prefab,so tooth trap can active to flying creatures

where should I change ?

local function OnExplode(inst, target)

    inst.AnimState:PlayAnimation("trap")

    if target then

        inst.SoundEmitter:PlaySound("dontstarve/common/trap_teeth_trigger")

        target.components.combat:GetAttacked(inst, TUNING.TRAP_TEETH_DAMAGE)

    end

    if inst.components.finiteuses then

        inst.components.finiteuses:Use(1)

    end

end

 

or here?

 

 local function OnHaunt(inst, haunter)
    if inst.components.mine == nil or inst.components.mine.inactive then
        inst.components.hauntable.hauntvalue = TUNING.HAUNT_TINY
        Launch(inst, haunter, TUNING.LAUNCH_SPEED_SMALL)
        return true
    elseif not inst.components.mine.issprung then
        return false
    elseif math.random() <= TUNING.HAUNT_CHANCE_OFTEN then
        inst.components.hauntable.hauntvalue = TUNING.HAUNT_SMALL
        inst.components.mine:Reset()
        return true
    end
    return false
end

local function SetInactive(inst)
    if inst.components.inventoryitem ~= nil then
        inst.components.inventoryitem.nobounce = false
    end
    inst.MiniMapEntity:SetEnabled(false)
    inst.AnimState:PlayAnimation("inactive")
end

 

Now I have two guesses:

1,Function explode's code controls trggering inactive against those flying creatures,because diffrent"creature" contains different tags like "target",so that means I should change all flying creatures' code

2,On haunt's code judge whether trap should be active or inactive ,but I really don't know how to change.

 

I don't even learned coding or programming, 

would someone explain how those code control trap be inactive to flying creature?

Link to comment
Share on other sites

9 hours ago, pachina said:

I want to change trap_teeth's prefab,so tooth trap can active to flying creatures

would someone explain how those code control trap be inactive to flying creature?

Neither of those cases.

The place where it does the check is inside the mine component added to the entity.

scripts/components/mine.lua:

local mine_test_tags = { "monster", "character", "animal" }
-- See entityreplica.lua
local mine_must_tags = { "_combat" }

local function MineTest(inst, self)
    if self.radius ~= nil then
        local notags = { "notraptrigger", "flying", "ghost", "playerghost", "spawnprotection" }
        table.insert(notags, self.alignment)

        local target = FindEntity(inst, self.radius, mine_test_fn, mine_must_tags, notags, mine_test_tags)
        if target ~= nil then
            self:Explode(target)
        end
    end
end



-- Some bits of code
    self.testtask = self.inst:DoPeriodicTask(next_test_time, MineTest, .9 + math.random() * .1, self)

So, this component in specific is absolutely horrible for mods to get at and modify.  There's local scope for pretty much everything, and to edit the 'notags' part is going to involve upvalue digging.  This would be a component I'd suggest to Klei to rework to not be like this, to let it be more modify-friendly and ultimately more versitile.

 

If you're looking to buff the tooth trap itself and not worry about future compliance with the core game, then the easiest approach without having to pull out some hair over the frustrations that is local scope issues is to create a clone of this component (call it mine_flyer or something) for your mod and add it to the tooth trap.

Then have either of the spring callbacks 'spring' the other component so it's not a multi-use trap (one for ground, one for air).

 

Ideally you'd just mod out the flyer tag from the avoid list in the component, but this component is written poorly for mods to get at.

  • Like 1
  • Sad 1
Link to comment
Share on other sites

6 hours ago, CarlZalph said:

If you're looking to buff the tooth trap itself and not worry about future compliance with the core game, then the easiest approach without having to pull out some hair over the frustrations that is local scope issues is to create a clone of this component (call it mine_flyer or something) for your mod and add it to the tooth trap.

Then have either of the spring callbacks 'spring' the other component so it's not a multi-use trap (one for ground, one for air).

 

Ideally you'd just mod out the flyer tag from the avoid list in the component, but this component is written poorly for mods to get at.

Thanks for your answer,

So, if I want to complete my mod , I'd better write another "mine_flyer"then change "notag" part,and I should change my mod's tooth_trap's code to use "mine_flyer" but not original"mine" component.

If I just want buff my tooth_trap so that it can trigger against to ghosts or flying creatures like bee\butterfly,I can just change the original "mine",and put it into my mod's scripts/component folder.that means it may cause future problem if that "mine" involved by other mod.

I tryed to delete "notag" part "flying",it still can't be active to those flying creatures,Am I doing wrong?

Sorry but I still can't figure out which code controls mine become inactive

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