Jump to content

Recommended Posts

I've been working on this mod and I can't seem to get it to work. I want her to lose sanity from attacking and hit harder/move slower while insane.


 

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {
}

-- When the character is revived from human
local function onbecamehuman(inst)

end

local function onbecameghost(inst)

end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end


local function OnKill(inst, data)
    inst.components.sanity:DoDelta(-10)
end

local function OnAttack(inst, data)
    inst.components.sanity:DoDelta(-1)
end


-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "yanderechan.tex" )

    if inst.components.sanity.current < 0.3 then
        inst.components.combat.damagemultiplier = 2
        inst.components.locomotor.walkspeed = 1
        inst.components.locomotor.runspeed = 2    
    end

    if inst.components.sanity.current > 0.3 then
        inst.components.combat.damagemultiplier = 1
        inst.components.locomotor.walkspeed = 4
        inst.components.locomotor.runspeed = 5
    end
    
end
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.soundsname = "wendy"
    
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(100)
    inst.components.hunger:SetMax(150)
    inst.components.sanity:SetMax(150)
    
    -- Damage multiplier (optional)

    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = TUNING.WILSON_HUNGER_RATE
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    
end

return MakePlayerCharacter("yanderechan", prefabs, assets, common_postinit, master_postinit, start_inv)

 

It doesn't recognize sanity as being a component (It causes a crash) and nothing happens when attacking a creature or killing one.

Any help would be greatly appriciated


    if inst.components.sanity.current < 0.3 then
        inst.components.combat.damagemultiplier = 2
        inst.components.locomotor.walkspeed = 1
        inst.components.locomotor.runspeed = 2    
    end

    if inst.components.sanity.current > 0.3 then
        inst.components.combat.damagemultiplier = 1
        inst.components.locomotor.walkspeed = 4
        inst.components.locomotor.runspeed = 5
    end

So i'm not sure, but this way to manage it could be problematic because what would happen if the number is 0.3 ? You have the case when it's lower, and when it's higher, but not the case when it's 0.3. So maybe it's better to do :


    if inst.components.sanity.current < 0.3 then
        inst.components.combat.damagemultiplier = 2
        inst.components.locomotor.walkspeed = 1
        inst.components.locomotor.runspeed = 2    
    else
        inst.components.combat.damagemultiplier = 1
        inst.components.locomotor.walkspeed = 4
        inst.components.locomotor.runspeed = 5
 
    end

(I can't help about inst.component.sanity because i don't know this part)

 

For the "lose sanity when attacking", the best way is probably to use the function

local function OnAttackOther(inst, data)


Search in the game code for example of enemy using this function to see how it work. Hound use it if i'm not wrong.

47 minutes ago, Eusong said:

local function OnAttack(inst, data)     inst.components.sanity:DoDelta(-1) end

I didn't saw this. This is only a part of the code. You need to add ::

 

    inst:ListenForEvent("onattackother", OnAttack)

Into the main function, for example after

 

48 minutes ago, Eusong said:

    inst.OnNewSpawn = onload

 

For losing sanity from attacking something, put this in YOURCHARACTER.lua inside the master_postinit

Spoiler

inst:ListenForEvent("onattackother", function(inst, data)
   inst.components.sanity:DoDelta(-1) -- Replace "-1" with any number u want
end)

-- If you want only lose sanity on attack when insane then use below 1
inst:ListenForEvent("onattackother", function(inst, data)
  if not inst.components.sanity:IsSane() then
     inst.components.sanity:DoDelta(-1)
  end
end)

 

For your character becoming slower when insane put this in YOURCHARACTER.lua inside the master_postinit

Spoiler

inst:ListenForEvent("gosane", function(inst, data)
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "insane_spd_debuff")
end)

inst:ListenForEvent("goinsane", function(inst, data)
   inst.components.locomotor:SetExternalSpeedMultiplier(inst, "insane_spd_debuff", .7)
end)

 

Hopefully, this works for you :D!!

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