Naplez Posted February 17, 2015 Share Posted February 17, 2015 I want to make my DST mod character can transform if you press Z key. (anim/zim.zip -> anim/zim_disguised.zip) And turn back if you press Z key again. I've found this forum - Creating a character that can transform? by ZackOcs and It's helping me a lot, but how do you can set the trigger to press Z key? I can't find out for DST code ;~; Can you please help me? Link to comment Share on other sites More sharing options...
rezecib Posted February 17, 2015 Share Posted February 17, 2015 (edited) @Naplez, This is a little bit difficult right now, because client -> server networking would be required, which occurs only by RPC (remote procedure call). Currently there's only a very... unseemly way to do custom RPCs (this involve making a fake action, then using the RPC for that action), but very soon we will have a proper mod API for it. But you can look at the GestureWheel mod to see how to map a function to be run when a key is pressed, and then what you'll need to do is have it do a custom RPC to transform (or on the server just execute transformation directly). Edited February 17, 2015 by rezecib Link to comment Share on other sites More sharing options...
Naplez Posted February 17, 2015 Author Share Posted February 17, 2015 @Naplez, This is a little bit difficult right now, because client -> server networking would be required, which occurs only by RPC (remote procedure call). Currently there's only a very... unseemly way to do custom RPCs (this involve making a fake action, then using the RPC for that action), but very soon we will have a proper mod API for it. But you can look at the GestureWheel mod to see how to map a function to be run when a key is pressed, and then what you'll need to do is have it do a custom RPC to transform (or on the server just execute transformation directly). Thank you so much to letting me know it! S2 Link to comment Share on other sites More sharing options...
Jjmarco Posted February 17, 2015 Share Posted February 17, 2015 @rezecib, what about using TheNet:SendSlashCmdToServer?On the client, you could send a command through that function when the player presses the key, and on the server, through a overriden Networking_SlashCmd, if it detects that command, you could push an event that triggers the transformation (as the function also provides the GUID of the player) if the player can indeed transform.It's still hackish, but less than a custom RPC and much easier to implement.It's like sending a command for an emote, but instead of doing a simple animation, do a full transformation. Link to comment Share on other sites More sharing options...
Kzisor Posted February 17, 2015 Share Posted February 17, 2015 I want to make my DST mod character can transform if you press Z key. (anim/zim.zip -> anim/zim_disguised.zip) And turn back if you press Z key again. I've found this forum - Creating a character that can transform? by ZackOcs and It's helping me a lot, but how do you can set the trigger to press Z key? I can't find out for DST code ;~; Can you please help me? I don't want to devalue what rezecib said, but you can also take a look at the Gir mod by Purswader as it does exactly what you want it to do with transforming your character. Link to comment Share on other sites More sharing options...
Naplez Posted February 18, 2015 Author Share Posted February 18, 2015 I don't want to devalue what rezecib said, but you can also take a look at the Gir mod by Purswader as it does exactly what you want it to do with transforming your character. @Kzisor Thank you! I read the post you said, It was very good example to me. But would you help me little more if you're okay? I'm very new at moding Don't starve. The Gir mod has kind of power function with transform and It seems to very delicate to me. I tried but really can't what lines should I take for just transform by a key. I made components folder and create keyhandler.lua that you posted but can't go to the next step. And sorry for my bad English. I hope you can understand what I'm meaning ;~; Link to comment Share on other sites More sharing options...
Kzisor Posted February 18, 2015 Share Posted February 18, 2015 @Naplez, the following code is what you need to look at. scritps/components/keyhandler.lualocal 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}) endendreturn KeyHandler modmain.lualocal SETDOG = GLOBAL.Action()SETDOG.str = "SetDog"SETDOG.id = "SETDOG"SETDOG.fn = function(act) local silent = true if (act.target.strength=="normal" or act.target.strength=="mighty") then local damage_mult = 0.9 local health_max = 150 local hunger_rate = 1.7 local scale = 0.9 local speed = 1.1 act.target.AnimState:SetBuild("gir_dog") act.target.strength="dog" act.target.Transform:SetScale(scale,scale,scale) act.target.components.hunger:SetRate(hunger_rate*TUNING.WILSON_HUNGER_RATE) act.target.components.combat.damagemultiplier = damage_mult act.target.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * speed) act.target.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * speed) act.target.components.sanity.dapperness = 0 local health_percent = act.target.components.health:GetPercent() act.target.components.health:SetMaxHealth(health_max) act.target.components.health:SetPercent(health_percent, true) elseif act.target.components.sanity.current < (85) then act.target.strength="mighty" elseif act.target.components.sanity.current > (85) then act.target.strength="normal" end -- act.target.components.health:SetCurrentHealth(1) -- act.target.components.health:DoDelta(0) return trueend AddAction(SETDOG) characterprefab.lualocal function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_T then print("KEY_T has been pressed.") if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SETDOG):Do() -- Since we are the server, do the action on the server. else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SETDOG.code, inst, ACTIONS.SETDOG.mod_name) end end endendlocal function common_postinit(inst) inst:AddComponent("keyhandler") inst:ListenForEvent("keypressed", OnKeyPressed)end Link to comment Share on other sites More sharing options...
Naplez Posted February 18, 2015 Author Share Posted February 18, 2015 (edited) @Naplez, the following code is what you need to look at. scritps/components/keyhandler.lualocal 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}) endendreturn KeyHandler modmain.lualocal SETDOG = GLOBAL.Action()SETDOG.str = "SetDog"SETDOG.id = "SETDOG"SETDOG.fn = function(act) local silent = true if (act.target.strength=="normal" or act.target.strength=="mighty") then local damage_mult = 0.9 local health_max = 150 local hunger_rate = 1.7 local scale = 0.9 local speed = 1.1 act.target.AnimState:SetBuild("gir_dog") act.target.strength="dog" act.target.Transform:SetScale(scale,scale,scale) act.target.components.hunger:SetRate(hunger_rate*TUNING.WILSON_HUNGER_RATE) act.target.components.combat.damagemultiplier = damage_mult act.target.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * speed) act.target.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * speed) act.target.components.sanity.dapperness = 0 local health_percent = act.target.components.health:GetPercent() act.target.components.health:SetMaxHealth(health_max) act.target.components.health:SetPercent(health_percent, true) elseif act.target.components.sanity.current < (85) then act.target.strength="mighty" elseif act.target.components.sanity.current > (85) then act.target.strength="normal" end -- act.target.components.health:SetCurrentHealth(1) -- act.target.components.health:DoDelta(0) return trueend AddAction(SETDOG) characterprefab.lualocal function OnKeyPressed(inst, data) if data.inst == ThePlayer then if data.key == KEY_T then print("KEY_T has been pressed.") if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SETDOG):Do() -- Since we are the server, do the action on the server. else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SETDOG.code, inst, ACTIONS.SETDOG.mod_name) end end endendlocal function common_postinit(inst) inst:AddComponent("keyhandler") inst:ListenForEvent("keypressed", OnKeyPressed)end @Kzisor, Thank you so much!I added your codes and set the key Z. And edited modmain.lua like this. local DISGUISED = GLOBAL.Action()DISGUISED.str = "Disguised"DISGUISED.id = "DISGUISED"DISGUISED.fn = function(act) local silent = true if act.target.components.sanity.current < (85) then act.target.AnimState:SetBuild("zim") elseif act.target.components.sanity.current > (85) then act.target.AnimState:SetBuild("zim_disguised") end -- act.target.components.health:SetCurrentHealth(1) -- act.target.components.health:DoDelta(0) return trueend AddAction(DISGUISED) It kind of work. When I press Z and while his sanity is more than 85. he turn into "zim_disguised" anim. But he can't come back to "zim" anim unless I exit the game. Can I change the "if he has more or less sanity than 85 then" like-if his current AnimState is "zim", press Z makes it "zim_disguised"and if his current AnimState is "zim_disguised", Z makes it "zim"so I can switch him whenever I want, no matter of his sanity? Edited February 18, 2015 by Naplez Link to comment Share on other sites More sharing options...
Kzisor Posted February 18, 2015 Share Posted February 18, 2015 @Naplez, you need a boolean to denote that he is transformed or not. -- In your DISGUISED function.if act.target.transformed then act.target.AnimState:SetBuild("zim")else act.target.AnimState:SetBuild("zim_disguised")end-- Reverses the boolean.act.target.transformed = not act.target.transformed-- In your CHARACTER PREFAB common function.local inst.transformed = false Link to comment Share on other sites More sharing options...
Naplez Posted February 18, 2015 Author Share Posted February 18, 2015 (edited) @Naplez, you need a boolean to denote that he is transformed or not. -- In your DISGUISED function.if act.target.transformed then act.target.AnimState:SetBuild("zim")else act.target.AnimState:SetBuild("zim_disguised")end-- Reverses the boolean.act.target.transformed = not act.target.transformed-- In your CHARACTER PREFAB common function.local inst.transformed = false @Kzisor, Thank you! It works just perfectly! I haven't tested it with multiplayers yet but it's good on my online server! XDI'm also making same one for single Don't starve mod. Do you think these codes are works on it?Oh, and if you don't mind, can I credit you when I update the mod on workshop for the coding? Edited February 18, 2015 by Naplez Link to comment Share on other sites More sharing options...
Kzisor Posted February 18, 2015 Share Posted February 18, 2015 @Naplez, please do give credit where it is due. Also this code might work on single player, but you'd need to do further testing. I don't really do mods for single player anymore unless someone specifically asks for a mod to be ported to single player. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now