Jump to content

Last 3 tips to finish my first character


Folthan

Recommended Posts

Hello everyone, happy to announce I am almost done with my first don't starve character! Took quite some days, tips and research to get this far but I am happy with the result.

 

To finish my character I need 3 more lines of code. Sadly I made this character because I love drawing and designing and not because I am good at coding.

 

I know it's in general rude to ask but could someone enlighten me with 3 lines of components to let me finish my project? Because everyone knows code makes the world more interesting.

 

To be clear, I am looking for lines like this:

"inst.components.sanity.night_drain_mult = 0.8"

 

I am looking for:

- Increasing sanity loss when it rains

- Getting sanity points for clicking koalefant tracks

- Getting sanity points (or removing loss of them) for digging up a grave

 

Thanks so much for the trouble. If you know only one of the lines, please reply as well because every bit makes the mod better :).

Link to comment
Share on other sites

well here's the koalefant "line":

 

in modmain.lua (we need to know when a track is found)

 

local function OnInvestigatedNew(inst, doer)
    local pt = Vector3(inst.Transform:GetWorldPosition())
    trace("dirtpile - OnInvestigated", pt)
    if GetWorld().components.hunter then
        GetWorld().components.hunter:OnDirtInvestigated(pt)
    end

 

    GetPlayer():PushEvent("tracking") --why didn't they do anything like that in the first place u_u
    local fx = SpawnPrefab("small_puff")
    local pos = inst:GetPosition()
    fx.Transform:SetPosition(pos.x, pos.y, pos.z)
    --PlayFX(Vector3(inst.Transform:GetWorldPosition()), "small_puff", "smoke_puff_small", "puff", "dontstarve/common/deathpoof", nil, Vector3(216/255, 154/255, 132/255))
    inst:Remove()
end

 

local function OverrideDirt(inst)

    inst.components.activatable.OnActivate = OnInvestigatedNew

end

 

AddPrefabPostInit("dirtpile",OverrideDirt)

 

in your character file, add this function

 

local function MakeHappy(inst)

    inst.components.sanity:DoDelta(20) --value

end

 

the line in your character file

 

inst:ListenForEvent("tracking",MakeHappy)

 

Edit: I should say that this is not tested and merely theoretic

Link to comment
Share on other sites

Wow Mobbstar, I could have never imagined something like that to be that much code! Thanks a lot for taking the time to give me the answer. I put everything in my files and am trying to find a koalefant track now to test it.

Link to comment
Share on other sites

 

@Mobbstar,  code was just theoretical, however, it definitely is on the right track. You need to make all the nil variables which are global into global variables by either adding 'GLOBAL.' in front of them or by importing them as global.

 

Example Adding GLOBAL in front:

GLOBAL.Vector3

 

Example importing them as global:

Vector3 = GLOBAL.Vector3
Link to comment
Share on other sites

 

Mobbstar's code was just theoretical, however, it definitely is on the right track. You need to make all the nil variables which are global into global variables by either adding 'GLOBAL.' in front of them or by importing them as global.

 

Example Adding GLOBAL in front:

GLOBAL.Vector3

Example importing them as global:

Vector3 = GLOBAL.Vector3

 

Yes, I forgot about that. The former method must be applied to all functions, the latter just once above the code.

 

Link to comment
Share on other sites

Thanks both Mobbstar and Kzisor for the help! However I cannot seem to figure out where to put global in my code. Would you mind being a little more specific for a code noob like me?

 

Now I have:

 

(modmain.lua)

-- Tracking skill
local function OnInvestigatedNew(inst, doer)
    local pt = Vector3(inst.Transform:GetWorldPosition())
    trace("dirtpile - OnInvestigated", pt)
    if GetWorld().components.hunter then
        GetWorld().components.hunter:OnDirtInvestigated(pt)
    end

    GetPlayer():PushEvent("tracking")
    local fx = SpawnPrefab("small_puff")
    local pos = inst:GetPosition()
    fx.Transform:SetPosition(pos.x, pos.y, pos.z)
    --PlayFX(Vector3(inst.Transform:GetWorldPosition()), "small_puff", "smoke_puff_small", "puff", "dontstarve/common/deathpoof", nil, Vector3(216/255, 154/255, 132/255))
    inst:Remove()
end

local function OverrideDirt(inst)

    inst.components.activatable.OnActivate = OnInvestigatedNew
end

AddPrefabPostInit("dirtpile",OverrideDirt)

 

(wolf.lua)

local fn = function(inst)

    -- Tracking skill
    local function MakeHappy(inst)
    inst.components.sanity:DoDelta(10)
    end

 

    -- Stats  

    inst:ListenForEvent("tracking",MakeHappy)

Link to comment
Share on other sites

Thanks both Mobbstar and Kzisor for the help! However I cannot seem to figure out where to put global in my code. Would you mind being a little more specific for a code noob like me?

 

 

Look back at your error log, and notice this specific line.

 

...pps/common/dont_starve/../mods/Wolf/modmain.lua:30: attempt to call global 'Vector3' (a nil value)

 

This gives you the line number which is 30 and the function which is Vector3. Adding Vector3 = GLOBAL.Vector3 at the very top of your modmain.lua file will fix that error. Rerun your mod to get the next function which needs to be global. The next error you should get will be 2 lines directly below the previous error.

 

...pps/common/dont_starve/../mods/Wolf/modmain.lua:32: attempt to call global 'GetWorld' (a nil value)

 

Once again at the top of your modmain.lua simply add GetWorld = GLOBAL.GetWorld()

 

I hope this helps you read and understand the error log a little better.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...