Jump to content

Recommended Posts

I apologize for someone has asked a similar question but I am stuck in a rut. I'm working on a character mod that has a function similar to Wickerbottom's books, but with music instead. (They're a violinist) I was wondering if a way to make music sheets, and have them play it? Is it too much for a a 1st time modder such as myself? 

Link to comment
https://forums.kleientertainment.com/forums/topic/146685-a-little-help-please/
Share on other sites

Its a bit more on the complicated side for someone just starting because it will require using a lot of different things to make work, but if you can start to understand how to do it then there's a lot that opens up for modding. I don't think its too much but it can get overwhelming to understand.

 There are probably a few ways to make something similar to Wicker's books, the best would probably be to emulate the code that's already there for her books. The books have a prefab file and a component they use, found at scripts/prefabs/books and scripts/components/book. The books prefab uses a table of definitions to hold all the information (including the function done on use) of each different book, then the book component is what actually does most of the book's stuff, like consuming a use or sanity loss. You could potentially just copy the whole component and rewrite the parts you need to change (changing the name to whatever you want too)

For all of this you'll need to know how the book's code works, how to make custom items, and most importantly how to make a custom action so the music sheets are actually usable. There are a plethora of guides/questions on these topics you can search through on the forums but I can try and help as much as you need too. Custom Actions mostly consist of using "AddAction", "AddComponentAction", and "AddStategraphActionHandler" in tandem. An example of these used in modmain :

Spoiler
-- All of this would go in your modmain.lua

AddAction("ACTION_NAME", "Action", function(act) -- "ACTION_NAME" would be the unique identifier of the action, "Action" is what shows up in-game
	if act.doer~=nil and act.invobject ~= nil then -- There are a number of different things you can check for in the if statement, it would be hard to go over them all but act has a few things attached depending on the type of action. In this case "doer" is the one doing the action and "invobject" is the target of the action.
		return act.invobject.components.component_name:DoAction(act.invobject, act.doer) -- This starts the function that does the action, the function should return a true or false so this return also returns that, as thats what decides if an action succeeds or fails.
	end
end)

AddComponentAction("INVENTORY", "component_name", function(inst, doer, actions, right) -- "INVENTORY" is the type of action, there are a few options but you will probably want to use this one as its for using an item in your inventory, same as Wicker's books or eating food. "component_name" is the custom component you'd be adding to your custom item that this action is getting attached to. (inst, doer, actions, right) are the arguments for this specific type of action. It may be different for the others. Inst is the item being used, doer is the one doing it, actions is a table of actions, and right is whether the button used was a right click or not.
	if doer~=nil and doer.prefab=="yourcharactername" and inst~=nil and inst:HasTag("custom_tag") then -- If statement for deciding if the action should be present in-game, as with the other if statement there are a number of things you can do. Just keep in mind this is client-side and needs to use only what a client knows
		table.insert(actions, GLOBAL.ACTIONS.ACTION_NAME) -- Adds the action to the table, GLOBAL is required since this is in modmain, but putting 'local Action = GLOBAL.Action' somewhere above these functions allows you to trim it off.
	end
end)
AddStategraphActionHandler("wilson", ActionHandler(GLOBAL.ACTIONS.ACTION_NAME, "domediumaction"))
AddStategraphActionHandler("wilson_client", ActionHandler(GLOBAL.ACTIONS.ACTION_NAME, "domediumaction")) -- These handle making your character go into a "state" in their Stategraph, aka it decides what animation they play when you do the Action. There's a bunch of these that can be put in place of "domediumaction", I don't know what you'd wanna use for playing a music sheet.

 

For actual tutorials, either of these might be helpful :

 

This should at least help get you started with figuring things out. If you need further help or specific instructions I'm more than willing to continue helping

1 hour ago, Merkyrrie said:

Its a bit more on the complicated side for someone just starting because it will require using a lot of different things to make work, but if you can start to understand how to do it then there's a lot that opens up for modding. I don't think its too much but it can get overwhelming to understand.

 There are probably a few ways to make something similar to Wicker's books, the best would probably be to emulate the code that's already there for her books. The books have a prefab file and a component they use, found at scripts/prefabs/books and scripts/components/book. The books prefab uses a table of definitions to hold all the information (including the function done on use) of each different book, then the book component is what actually does most of the book's stuff, like consuming a use or sanity loss. You could potentially just copy the whole component and rewrite the parts you need to change (changing the name to whatever you want too)

For all of this you'll need to know how the book's code works, how to make custom items, and most importantly how to make a custom action so the music sheets are actually usable. There are a plethora of guides/questions on these topics you can search through on the forums but I can try and help as much as you need too. Custom Actions mostly consist of using "AddAction", "AddComponentAction", and "AddStategraphActionHandler" in tandem. An example of these used in modmain :

  Reveal hidden contents
-- All of this would go in your modmain.lua

AddAction("ACTION_NAME", "Action", function(act) -- "ACTION_NAME" would be the unique identifier of the action, "Action" is what shows up in-game
	if act.doer~=nil and act.invobject ~= nil then -- There are a number of different things you can check for in the if statement, it would be hard to go over them all but act has a few things attached depending on the type of action. In this case "doer" is the one doing the action and "invobject" is the target of the action.
		return act.invobject.components.component_name:DoAction(act.invobject, act.doer) -- This starts the function that does the action, the function should return a true or false so this return also returns that, as thats what decides if an action succeeds or fails.
	end
end)

AddComponentAction("INVENTORY", "component_name", function(inst, doer, actions, right) -- "INVENTORY" is the type of action, there are a few options but you will probably want to use this one as its for using an item in your inventory, same as Wicker's books or eating food. "component_name" is the custom component you'd be adding to your custom item that this action is getting attached to. (inst, doer, actions, right) are the arguments for this specific type of action. It may be different for the others. Inst is the item being used, doer is the one doing it, actions is a table of actions, and right is whether the button used was a right click or not.
	if doer~=nil and doer.prefab=="yourcharactername" and inst~=nil and inst:HasTag("custom_tag") then -- If statement for deciding if the action should be present in-game, as with the other if statement there are a number of things you can do. Just keep in mind this is client-side and needs to use only what a client knows
		table.insert(actions, GLOBAL.ACTIONS.ACTION_NAME) -- Adds the action to the table, GLOBAL is required since this is in modmain, but putting 'local Action = GLOBAL.Action' somewhere above these functions allows you to trim it off.
	end
end)
AddStategraphActionHandler("wilson", ActionHandler(GLOBAL.ACTIONS.ACTION_NAME, "domediumaction"))
AddStategraphActionHandler("wilson_client", ActionHandler(GLOBAL.ACTIONS.ACTION_NAME, "domediumaction")) -- These handle making your character go into a "state" in their Stategraph, aka it decides what animation they play when you do the Action. There's a bunch of these that can be put in place of "domediumaction", I don't know what you'd wanna use for playing a music sheet.

 

For actual tutorials, either of these might be helpful :

 

This should at least help get you started with figuring things out. If you need further help or specific instructions I'm more than willing to continue helping

Thank you so much! I'm just testing the waters with coding, I have a test mod I have for practice so Ill start using that!

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