Jump to content

Recommended Posts

Just now, Tezumoto said:

How to create mod to edit wilson.lua?
I want to be able to change the settings in the local master_postinit = function (inst)

as in, you want to make a postinit that changes Wilson's stats? Or a mod that directly overwrites his lua file? what are you trying to do exactly?

3 minutes ago, mf99k said:

as in, you want to make a postinit that changes Wilson's stats? Or a mod that directly overwrites his lua file? what are you trying to do exactly?

I want will replace the original file on the file from the mod.
Or maybe someone can create a character mod based on Wilson?
The second option is better, but it is difficult?

Just now, Tezumoto said:

I want will replace the original file on the file from the mod.
Or maybe someone can create a character mod based on Wilson?
The second option is better, but it is difficult?

so you want to replace the wilson.lua file with a modded wilson.lua file? Then you wouldn't need to use a postinit since the game would overwrite the base file with the modded one automatically.

 

what I'm asking when I ask what you're trying to do though, is what do you want the end result to be? depending on what exactly you're trying to get to happen, there are different ways to do it.

10 minutes ago, mf99k said:

so you want to replace the wilson.lua file with a modded wilson.lua file? Then you wouldn't need to use a postinit since the game would overwrite the base file with the modded one automatically.

 

what I'm asking when I ask what you're trying to do though, is what do you want the end result to be? depending on what exactly you're trying to get to happen, there are different ways to do it.

I want create a mod to add to wilson.lua new ability.
And unlock one recipe in modmain.lua by code: 

AddPrefabPostInit("wilson", function(inst)
	if (inst.components and inst.components.builder) then
		inst.components.builder:UnlockRecipe("")
	end
end)

 

Edited by Tezumoto

ok, for starters, that code would only work for a character albert.lua file, which I'm assuming you know.

I'm not sure what the ability is, and I haven't done much with postinits, but if you wanted wilson to automatically unlock the ability to craft shovels, and put "wilson" where it says "albert" it should probably work

 

6 minutes ago, mf99k said:

ok, for starters, that code would only work for a character albert.lua file, which I'm assuming you know.

I'm not sure what the ability is, and I haven't done much with postinits, but if you wanted wilson to automatically unlock the ability to craft shovels, and put "wilson" where it says "albert" it should probably work

 

Code for wilson.lua and modmain.lua, I will be able to write.
But how to create the foundation of mod?
How to force the game to replace the original wilson.lua file on my file?

Edited by Tezumoto
  1. download Don't Starve Mod Tools if you haven't already. (there's a tutorial for that somewhere on the forums)
  2. make a folder for your mod files to go in.
  3. download these files and put them in your mod folder modinfo.lua modmain.lua
  4. create a scripts folder inside that mod folder
  5. create a prefab folder inside the scripts folder
  6. put the modded wilson.lua file in there
  7. add your mod name, etc to modinfo.lua
  8. (I think) add your postinit code to modmain.lua
  9. use mod tools to upload your mod. if you don't have a mod preview image, put two hyphens in front of the line that asks for mod images.
14 minutes ago, mf99k said:
  1. download Don't Starve Mod Tools if you haven't already. (there's a tutorial for that somewhere on the forums)
  2. make a folder for your mod files to go in.
  3. download these files and put them in your mod folder modinfo.lua modmain.lua
  4. create a scripts folder inside that mod folder
  5. create a prefab folder inside the scripts folder
  6. put the modded wilson.lua file in there
  7. add your mod name, etc to modinfo.lua
  8. (I think) add your postinit code to modmain.lua
  9. use mod tools to upload your mod. if you don't have a mod preview image, put two hyphens in front of the line that asks for mod images.

Code in modmain.lua works, but the game does not use wilson.lua of mod.

Just now, mf99k said:

hm. what changes did you make to it? could be that the game is having trouble recognizing it

I add only:

local start_inv = {"torch"}

and

inst.components.combat.damagemultiplier = 1.25


Full code:

local MakePlayerCharacter = require("prefabs/player_common")

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

local prefabs =
{
    "beardhair",
}

-- Custom starting items
local start_inv = {"torch"}

local function common_postinit(inst)
    --bearded (from beard component) added to pristine state for optimization
    inst:AddTag("bearded")
end

local function OnResetBeard(inst)
    inst.AnimState:ClearOverrideSymbol("beard")
end

--tune the beard economy...
local BEARD_DAYS = { 4, 8, 16 }
local BEARD_BITS = { 1, 3,  9 }

local function OnGrowShortBeard(inst)
    inst.AnimState:OverrideSymbol("beard", "beard", "beard_short")
    inst.components.beard.bits = BEARD_BITS[1]
end

local function OnGrowMediumBeard(inst)
    inst.AnimState:OverrideSymbol("beard", "beard", "beard_medium")
    inst.components.beard.bits = BEARD_BITS[2]
end

local function OnGrowLongBeard(inst)
    inst.AnimState:OverrideSymbol("beard", "beard", "beard_long")
    inst.components.beard.bits = BEARD_BITS[3]
end

local function master_postinit(inst)
    inst:AddComponent("beard")
    inst.components.beard.onreset = OnResetBeard
    inst.components.beard.prize = "beardhair"
    inst.components.beard:AddCallback(BEARD_DAYS[1], OnGrowShortBeard)
    inst.components.beard:AddCallback(BEARD_DAYS[2], OnGrowMediumBeard)
    inst.components.beard:AddCallback(BEARD_DAYS[3], OnGrowLongBeard)
	
    inst.components.combat.damagemultiplier = 1.25
end

return MakePlayerCharacter("wilson", prefabs, assets, common_postinit, master_postinit)

 

2 minutes ago, mf99k said:

not sure exactly what's going on here, but the wilson code looks a bit short to me. I'd take a closer look but I need to get some sleep.

good luck ^^

I fixed)
Forgot to add: return MakePlayerCharacter ( "wilson", prefabs, assets, common_postinit, master_postinit, start_inv)

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

Thank you for your help)

Edited by Tezumoto

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