Jump to content

[SOLVED] unable to get my mod to work


Recommended Posts

hello!

im currently making my first mod and am trying to make it so that when my character's sanity reaches a certain point, his damage multiplier will go down.  ive been trying to make it work for a couple hours and have looked at people trying to do similar things, but i still cant quite figure out what im doing wrong.  so if anyone could help me out thatd be cool!!  thanks a bunch in advance!

heres the code that i have so far in the prefabs folder file that doesnt end in _none:

local MakePlayerCharacter = require "prefabs/player_common"


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

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

-- When the character is revived from human
local function onbecamehuman(inst)
	-- Set speed when reviving from ghost (optional)
	inst.components.locomotor:SetExternalSpeedMultiplier(inst, "jonathan_speed_mod", 1)
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "jonathan_speed_mod")
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


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

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
	function sanitydelta (inst)
	inst=80
	-- choose which sounds this character will play
	inst.soundsname = "wickerbottom"
	
	-- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
	
	-- Stats	
	inst.components.health:SetMaxHealth(200)
	inst.components.hunger:SetMax(150)
	inst.components.sanity:SetMax(130)
	
	-- Damage multiplier (optional)
    if inst.components.sanity.current >=80 then inst.components.combat.damagemultiplier = "1.6"
	elseif inst.components.sanity.current <=79 then inst.components.combat.damagemuliplier= "1"
	end
	end
	
	-- Hunger rate (optional)
	inst.components.hunger.hungerrate = 1.3 * TUNING.WILSON_HUNGER_RATE
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload
	inst:ListenForEvent("sanitydelta", sanitydelta)
	
end

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

 

Link to comment
Share on other sites

9 hours ago, ZupaleX said:

Hi,

does this even compile and run?

it seems to compile, and when i run the game i can select my character.  however, once i press the "go" button on the screen where you can customize the character, this error message pops up:

errormessage.PNG

Link to comment
Share on other sites

It seems that you're trying to set your character to a value of 80! In line 47 in your code "inst = 80" 

In this case, "inst" is the reference to your entire character. If you were maybe trying to change the current sanity of you character, "inst.components.sanity.current = 80" would do the trick!

But that might not have been what you were trying to do, since putting that there would basically make his sanity 80 at all times, since every time his sanity changes, it would change back to 80

Link to comment
Share on other sites

This is the code from a  character who gets stronger as her sanity gets lower the code is pretty old and is from a the custom Character Lyss whom I had made for a friend. it may help you figure out what you did wrong in your master_postinit.

 

local function sanitydelta(inst)
   if inst.components.sanity.current >= 100 then
      inst.components.combat.damagemultiplier = 1.5
   elseif inst.components.sanity.current >= 50 then
      inst.components.combat.damagemultiplier = 2
   elseif inst.components.sanity.current <= 50 then
      inst.components.combat.damagemultiplier = 4
   end
end

This will go under master_postinit. I'm not completely sure if it will still work, I haven't used Lyss for a while... Any way you can change it to where the numbers go down as the character gets closer to insanity.

Edited by Andreasgamming
Link to comment
Share on other sites

Well to be fair you need to say more about what you want to achieve because currently you are setting stuffs for hunger and health inside this function sanitidelta which is a callback for the event "sanitydelta". I'm not sure that was intended.

Link to comment
Share on other sites

22 minutes ago, Andreasgamming said:

This is the code from a  character who gets stronger as her sanity gets lower the code is pretty old and is from a the custom Character Lyss whom I had made for a friend. it may help you figure out what you did wrong in your master_postinit.

 


local function sanitydelta(inst)
   if inst.components.sanity.current >= 100 then
      inst.components.combat.damagemultiplier = 1.5
   elseif inst.components.sanity.current >= 50 then
      inst.components.combat.damagemultiplier = 2
   elseif inst.components.sanity.current <= 50 then
      inst.components.combat.damagemultiplier = 4
   end
end

This will go under master_postinit. I'm not completely sure if it will still work, I haven't used Lyss for a while... Any way you can change it to where the numbers go down as the character gets closer to insanity.

WOW yeah that really helped!!!!!!  i think i solved the issue (i had some lines of code that i shouldnt have had and local function sanitydelta was in the wrong place i think).  thank you so much for your help!!

Link to comment
Share on other sites

2 hours ago, pickleplayer said:

It seems that you're trying to set your character to a value of 80! In line 47 in your code "inst = 80" 

In this case, "inst" is the reference to your entire character. If you were maybe trying to change the current sanity of you character, "inst.components.sanity.current = 80" would do the trick!

But that might not have been what you were trying to do, since putting that there would basically make his sanity 80 at all times, since every time his sanity changes, it would change back to 80

ah that makes sense!!  im gonna be honest i didnt 100% know what inst meant (im..........  super super new to coding haha) so thats really helpful to know!!  luckily i think i solved the issue!!  thank you very much for your help

Link to comment
Share on other sites

23 minutes ago, ZupaleX said:

Well to be fair you need to say more about what you want to achieve because currently you are setting stuffs for hunger and health inside this function sanitidelta which is a callback for the event "sanitydelta". I'm not sure that was intended.

it wasnt intended haha..  i think i got the issue solved though!!  thank you for your replies/input!

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