Jump to content

I want to create singing mod


Recommended Posts

Hello, I want to create mod that will let you sing your characters voice with letting you play individual notes of their voice's instrument.

And maybe while youre singing you will get sanity bonus and less hunger drain, but you wont be able to do anything else, and move at a slower rate.

I know lua language and got all flute(Willow) sounds already, but i need to learn DST modding, and maybe some help, so you may write in this thread or send me message if you want to help.

Link to comment
Share on other sites

  • Developer

I suggest you check out some of the tutorials and guides that have been posted at the top of the Mods and Tools forum. They contain a wealth of useful information.

 

Specifically 

rezecib's http://forums.kleientertainment.com/topic/47353-guide-getting-started-with-modding-dst-and-some-general-tips-for-ds-as-well/

and

Kzisor's http://forums.kleientertainment.com/topic/50811-guide-modding-practices-series-index/

 

Good luck!

Link to comment
Share on other sites

I dont quite understand all that keyhandlers and listeners.

So I tried to try this code so if i press any key it is supposed to scale character

But it doesnt - maybe because i shall listen for event in another place?

or maybe i shall make some object of KeyHandler class?

[spoiler]local KEYBOARDTURNONKEY = GetModConfigData("KEYBOARDTURNONKEY")local KeyHandler = Class(function(self, inst)	self.inst = inst	self.handler = TheInput:AddKeyHandler(function(key, down) self:OnRawKey(key, down) end )end)function KeyHandler:OnRawKey(key, down)	local player = ThePlayer  	if (key and not down) and not IsPaused() then      	player:PushEvent("keypressed", {inst = self.inst, player = player, key = key})    elseif key and down and not IsPaused() then      	player:PushEvent("keydown", {inst = self.inst, player = player, key = key})  	endendlocal function OnKeyPressed(inst, data)    if data.inst == ThePlayer then       	local scale = 1.5        data.inst.Transform:SetScale(scale,scale,scale)		    endendlocal function PlayerPostInit(inst)      inst:ListenForEvent("keypressed", OnKeyPressed)    local scale = 0.5    inst.Transform:SetScale(scale,scale,scale)		    if inst.components.freezeable then        inst:RemoveComponent("freezeable")    end         return instend    AddPlayerPostInit(PlayerPostInit) [/spoiler]



			
		
Link to comment
Share on other sites

@Domenje, that is outdated code. I'd recommend you downloading the newest version of that tutorial. I've uploaded it as of right now it should be version 0.0.3. 

 

 

scripts/components/keyhandler.lua

local KeyHandler = Class(function(self, inst)	self.inst = inst	self.handler = TheInput:AddKeyHandler(function(key, down) self:OnRawKey(key, down) end )end)function KeyHandler:OnRawKey(key, down)	local player = ThePlayer  	if (key and not down) and not IsPaused() then      	player:PushEvent("keypressed", {inst = self.inst, player = player, key = key})    elseif key and down and not IsPaused() then      	player:PushEvent("keydown", {inst = self.inst, player = player, key = key})  	endendfunction KeyHandler:AddActionListener(Namespace, Key, Action)	self.inst:ListenForEvent("keypressed", function(inst, data)		if data.inst == ThePlayer then			if data.key == Key then				if TheWorld.ismastersim then					ThePlayer:PushEvent("keyaction"..Namespace..Action, { Namespace = Namespace, Action = Action, Fn = MOD_RPC_HANDLERS[Namespace][MOD_RPC[Namespace][Action].id] })				else					SendModRPCToServer( MOD_RPC[Namespace][Action] )				end			end		end	end)	if TheWorld.ismastersim then      self.inst:ListenForEvent("keyaction"..Namespace..Action, function(inst, data)          if not data.Action == Action and not data.Namespace == Namespace then              return          end                    data.Fn(inst)      end, self.inst)     endendreturn KeyHandler 

 

Here is the newest keyhandler component code that I recommend using. If you use the tutorial you will understand how it functions better.

Edited by Kzisor
Link to comment
Share on other sites

Ok but what if I want to tell function which key was pressed and how do I block keys I use currently from being used elsewhere?

Also i noticed that this code works not when button is pressed, but when it is released.

Link to comment
Share on other sites

@Domenje, as I stated, you should look at the tutorial to get the full details of how it works. It's very straight forward just look in the modmain.lua file there should be comments to tell you how it works. If you're still having issues of how it works, I will break it down further. However, I implore you to look at the tutorial because me simply telling you how to get it to work will not actually help you understand how it works. While I have made it easier to use for beginners, this is still very much intermediate/advanced level lua programming because it uses network data to work across all clients.

Link to comment
Share on other sites

This is strange - I dont find comments in modmain, except the ones that tell what are imports for. So questions i posted above still remain unclear to me.

 

Strange it seems they have gotten deleted when I was rewriting that to work with the new version. Thanks for pointing that out.

 

Basically this is the code you need to understand:

--  Function to be called on the server.local function FreezeImmuntyFn(inst)		if inst.components.freezable then		inst:RemoveComponent("freezable")	else		inst:AddComponent("freezable")	endend--  Add the MODRPC Handler on the server and client. Allows communication with the server.AddModRPCHandler(modname, "FreezeImmunity", FreezeImmuntyFn)local function PlayerPostInit(inst)        --  Ensures only one keyhandler component is ever added to our player.	if not inst.components.keyhandler then		inst:AddComponent("keyhandler")	end        --  Add action listener to player.        --  First Parameter: modname or the name we want to reference when looking for this MODRPC Handler.        --  Second Parameter: The key we will use to "activate" to send the data to the server.        --  Third Parameter: The function we want to call on the server.	inst.components.keyhandler:AddActionListener(modname, KEY_Z, "FreezeImmunity")	return instendAddPlayerPostInit(PlayerPostInit) 

 

Basically because you're wanting to make a singing mod that send the data across all clients you will need to use MODRPC Handlers; I've integrated the MODRPC handlers into the Keyhandler functionality which means you only need to use a very small amount of code; I will eventually make it even more simpler to use and give more options. However, for now this should give you enough to get you started.

Link to comment
Share on other sites

Thank you - with your mod i managed to make game respond to a key press.

Now I probably would need to edit your mod abit if i am allowed to, because there I need in my mod:

-a switch that will turn on and off key handling of 36 keys

-36 action listeners - maybe that would be easier if i could pack them into one which is passed key that was pressed as an agrument

-currently in your code OnRawKey() sends event at the end of key press, not at the beginning - I need it at beginning

-to block keys like Y chat key from working as intended when switch is turned on

Or maybe you could give me an advice - that would be appreciated

Link to comment
Share on other sites

Thank you - with your mod i managed to make game respond to a key press.

Now I probably would need to edit your mod abit if i am allowed to, because there I need in my mod:

-a switch that will turn on and off key handling of 36 keys

-36 action listeners - maybe that would be easier if i could pack them into one which is passed key that was pressed as an agrument

-currently in your code OnRawKey() sends event at the end of key press, not at the beginning - I need it at beginning

-to block keys like Y chat key from working as intended when switch is turned on

Or maybe you could give me an advice - that would be appreciated

 

Some of the changes you are wanting to do is actually complicated. Adding the switch and the 36 action listeners would be simple, however, in order to make the chat not show you'd have to modify the chat screen. This is already being done in the tutorial to not pick up keystrokes, so look at it and modify it to not show period.

 

Depending on how you set up the 36 different action listeners you wouldn't need to modify the actual code I provided at all. You'd simply need to set up different MODRPC Handlers to handle each action appropriately.

 

I'd say start small. Start with the activation switch and getting it to disable both chat screen. Afterwards, move onto adding a single action listener which is only players while the switch is active. After that set up you can easily move forward to adding the other 35 action listeners.

Link to comment
Share on other sites

Thank you

from what I have gathered:
in your code HUD is being toggled with H, and prevents chat, ESC menu and map from appearing, but doesnt prevent other keys from working
and chat and console are preventing Z key from working by toggling pause
but I dont understand how can I reproduce HUD toggling effect of blocking keys from working, and make it cover more keys - like Q and E keys.

Link to comment
Share on other sites

@Domenje, some keys might not be able to be blocked by modders as not everything is completely modder friendly. The only way to completely figure it out which keys can be blocked is to simply test each one and see what they all do. It will take a lot of time and effort to figure out what can and cannot be done.

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