Jump to content

Recommended Posts

Hi everyone, it's me, again ... x)

Im currently trying to improve my character with more perks.

Im not really good with coding, for now im only taking some parts of others mods to create mine BUT ...

Do y'all think it's possible to add a perks that can spawn a bee every time i get hit, they would basicaly protect the character and attack the enemies ?

And i saw a few times peoples talking about a perk that give you sanity when you get hit too, i didnt quite understood how to make this up but if someone can help me with that too, this would be great.

In your character .lua, above common and master postinit functions:

local function SpawnBeesOnHit(inst, attacker, damage, spdamage)
    local x, y, z = inst.Transform:GetWorldPosition()

    --Cooldown of sorts. 5 Seconds between each spawn.
    if inst._spawnedbees == true then
        return
    end

    inst._spawnedbees = true
    inst:DoTaskInTime(5, function()
        inst._spawnedbees = false
    end)

    if attacker:IsValid() and attacker.components.combat and attacker.components.health then
        --Should spawn 3 bees; all of them drop nothing
        for i = 1, 3 do
            local bee = SpawnPrefab("bee")
            bee.Transform:SetPosition(x + math.random(2), y, z + math.random(2))
            bee.components.combat:SuggestTarget(attacker)

            bee.components.lootdropper:ClearRandomLoot()

            --Kills the bee in 2 secs after it deaggros from its target
            bee:ListenForEvent("droppedtarget", function()
                bee:DoTaskInTime(2, function() bee.components.health:Kill() end)
            end)
        end
    end

end

Then, in your master_postinit, same file, insert:

inst.components.combat:SetOnHit(SpawnBeesOnHit)

 

I may or may haven't missed something. Hopefully this'll help in the slightest, however.

Edit: For sanity on hit, type

inst.components.sanity:DoDelta(PutYourNumberHere)

right below local x, y, z for it to always trigger on hit regardless of bee cooldown.

Also, character perks are mostly done by combining a lot of the available basegame components together into one functioning... function. Once you delve deeper into DST modding however, you can even create your own component that does your own desired thing. Keep going though, I took a while to learn also :)

Edited by Baguettes
Added sanity delta
15 hours ago, Baguettes said:

In your character .lua, above common and master postinit functions:

local function SpawnBeesOnHit(inst, attacker, damage, spdamage)
    local x, y, z = inst.Transform:GetWorldPosition()

    --Cooldown of sorts. 5 Seconds between each spawn.
    if inst._spawnedbees == true then
        return
    end

    inst._spawnedbees = true
    inst:DoTaskInTime(5, function()
        inst._spawnedbees = false
    end)

    if attacker:IsValid() and attacker.components.combat and attacker.components.health then
        --Should spawn 3 bees; all of them drop nothing
        for i = 1, 3 do
            local bee = SpawnPrefab("bee")
            bee.Transform:SetPosition(x + math.random(2), y, z + math.random(2))
            bee.components.combat:SuggestTarget(attacker)

            bee.components.lootdropper:ClearRandomLoot()

            --Kills the bee in 2 secs after it deaggros from its target
            bee:ListenForEvent("droppedtarget", function()
                bee:DoTaskInTime(2, function() bee.components.health:Kill() end)
            end)
        end
    end

end

Then, in your master_postinit, same file, insert:

inst.components.combat:SetOnHit(SpawnBeesOnHit)

 

I may or may haven't missed something. Hopefully this'll help in the slightest, however.

Edit: For sanity on hit, type

inst.components.sanity:DoDelta(PutYourNumberHere)

right below local x, y, z for it to always trigger on hit regardless of bee cooldown.

Also, character perks are mostly done by combining a lot of the available basegame components together into one functioning... function. Once you delve deeper into DST modding however, you can even create your own component that does your own desired thing. Keep going though, I took a while to learn also :)

Damn that's awesome, i didnt have any expectation posting my request but im really happy with the results x)

The bees are spawing on hit (3 bees), one of them die sometimes for no reason but it work !

Same for sanity thing, it's working perfectly.

Thank you again really :)

  • Like 1
10 hours ago, BeeChoc said:

one of them die sometimes for no reason but it work !

Once your spawned bees stop targeting your attacker, they'll die out in 2 seconds right after, I did this so you don't slowly amass up too many homeless bees onscreen.

5 hours ago, Baguettes said:

Once your spawned bees stop targeting your attacker, they'll die out in 2 seconds right after, I did this so you don't slowly amass up too many homeless bees onscreen.

Nice ! It is indeed pretty smart, im trying to do some balanced perks here because my original ideas are pretty god like tier and it would make the character too easy to play with and i dont want to do a character that is not as dark and difficult as the game.

The character in itself isnt designed for Dont Starve, he have is own story but i like to integrate him pretty much everywhere i can.

But in his original story he is a god so, im trying to do something balance between the fact that he is suppose to be powerful buuut the Dont Starve Universe is weakening him reaaly bad.

But overall i find it funny to do because the modding parts give a real freedom for creation.

 

(Sorry for bad english tho)

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