Electroflux Posted January 9, 2015 Share Posted January 9, 2015 Hello, I'm a terrible coder, but I'm looking for scripts to create some relatively basic perks. 1. I need my character to increase speed and health when he's scared (implying the same thing as Willow). 2. I need him to slowly regain HP while it's raining 3. I need him to play the /sad animation randomly, not too often and not too long of a duration when he's below 50 sanity. I honestly have no idea where to start but these are the last things I need done on my character. I appreciate any help I can get. Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/ Share on other sites More sharing options...
rezecib Posted January 9, 2015 Share Posted January 9, 2015 2. I need him to slowly regain HP while it's rainingYou can appropriate WX's code for this, although this actually has a number of different steps. In the master_postinit (this makes sure it isn't trying to do it while he's a ghost): inst:ListenForEvent("ms_respawnedfromghost", onbecamealive) inst:ListenForEvent("ms_becameghost", onbecameghost) onrespawned(inst)Then above that in the prefab file, you need to add these functions:local function onisraining(inst, israining) if israining then inst.rain_task = inst.rain_task or inst:DoPeriodicTask(1, function(inst) inst.components.health:DoDelta(0.5) end) else if inst.rain_task ~= nil then inst.rain_task:Cancel() end endendlocal function onbecamealive(inst) inst:WatchWorldState("israining", onisraining)endlocal function onbecameghost(inst) inst:StopWatchingWorldState("israining", onisraining)endAs for the other two... You're probably best-off stealing Willow's firebug component and rewriting it a little. I didn't change the timing of anything, so he'll emote /sad whenever Willow would've made a fire.local Crazyfear = Class(function(self, inst) self.inst = inst self.time_to_sad = 60 self.inst:StartUpdatingComponent(self) self.sademote = nil self.isspeedy = false for k,v in pairs(EMOTES) do if v.command == "/bye" then self.sademote = v end endend)function Crazyfear:OnUpdate(dt) if self.inst.components.sanity and self.inst.components.sanity:GetPercent() < TUNING.WILLOW_LIGHTFIRE_SANITY_THRESH then if not self.isspeedy then self.isspeedy = true self.inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*1.25 self.inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*1.25 self.inst.components.health:SetMaxHealth(200) end self.time_to_sad = self.time_to_sad - dt if self.time_to_sad <= 0 then self.inst:PushEvent("emote", self.sademote) self.time_to_sad = 120*math.random()+120 end else if self.isspeedy then self.isspeedy = false self.inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED self.inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED self.inst.components.health:SetMaxHealth(100) end endendreturn CrazyfearObviously, change the health value and speed multipliers as you see fit. I set the speed to what you'd get from a walking cane. Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599190 Share on other sites More sharing options...
Electroflux Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) So, I'm not exactly sure what to do. I go to prefabs > waxwell.lua and put in your code or do I have to replace code or what? There's other lines of code in there that I don't want, like those starting items. I'm just not sure where I'm supposed to be putting these lines. The other code, should I just make a whole new .lua and place it into my mods scripts folder and name it "crazyfear.lua"? It says WILSON and WILLOW on some of the lines, should I rename those to my characters name? Also does it announce when he's scared, so at least I'll know in-game when it's happening? Sorry, I'm just not sure what I'm supposed to be doing with this code exactly. Edited January 9, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599278 Share on other sites More sharing options...
rezecib Posted January 9, 2015 Share Posted January 9, 2015 @Electroflux, Crazyfear you should put in your_mod/scripts/components/crazyfear.lua But... why are you adding it to waxwell.lua? Maxwell is a character in the game files already. Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599319 Share on other sites More sharing options...
Electroflux Posted January 9, 2015 Author Share Posted January 9, 2015 (edited) I have no clue. You said WX, so for some reason I found waxwell and it kind of had stuff related to that. So, I copy your code for crazyfear.lua, put it where you said and it should work. However, still confused about the first one. What exactly am i supposed to be editting or creating? master_postinit and "above that in prefab" file? I really don't know what I'm looking for. I sound retarded, but I'm confused by the sentence structure here. EDIT: Okay, I am clearly retarded. In the prefabs folder of MY character...I see it added there. Let me see if I can make it work. Either way, thanks for the help, I very much appreciate it. In response to my other post, does this announce when he's scared (I need him to have a custom phrase), like Willow does and do I have to change the names listed (Wilson/Willow) in the code? Edited January 9, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599327 Share on other sites More sharing options...
rezecib Posted January 10, 2015 Share Posted January 10, 2015 @Electroflux, No, I took that out, but you can look at Willow's code and add it back in the appropriate place. It should be something like this, right above the emote event being pushed:self.inst.components.talker:Say("I'M SO SCAREDDD!") Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599649 Share on other sites More sharing options...
Electroflux Posted January 10, 2015 Author Share Posted January 10, 2015 (edited) Okay, awesome. This should work. Thanks for the help, I really appreciate it. Edited January 10, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599845 Share on other sites More sharing options...
Electroflux Posted January 10, 2015 Author Share Posted January 10, 2015 (edited) Actually, I"m missing one thing. @rezecib How do you reference crazyfear.lua in the prefab script? I tried: inst.AddComponent("crazyfear") in master_postinit but just crashes in-game Edited January 10, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599919 Share on other sites More sharing options...
rezecib Posted January 10, 2015 Share Posted January 10, 2015 inst.AddComponent("crazyfear") You want inst:AddComponent("crazyfear"). If that still crashes, I don't know what's going on without seeing the error screen/log. Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-599985 Share on other sites More sharing options...
Electroflux Posted January 10, 2015 Author Share Posted January 10, 2015 @rezecib Okay, almost worked. Here's the error now: attempt to perform arithmetic on field 'ISAAC_WALK_SPEED' (a nil value) The line was this when you provided it, I just renamed Wilson to my characters name:self.inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*1.25self.inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*1.25 Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-600020 Share on other sites More sharing options...
Aquaterion Posted January 10, 2015 Share Posted January 10, 2015 @rezecib Okay, almost worked. Here's the error now: attempt to perform arithmetic on field 'ISAAC_WALK_SPEED' (a nil value) The line was this when you provided it, I just renamed Wilson to my characters name:self.inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*1.25self.inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*1.25 keep it as wilson, you can't rename it to isaac, because "TUNING.WILSON_WALK/RUN_SPEED" are variables that are declared somewhere else, should work if you keep it at wilson. Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-600022 Share on other sites More sharing options...
Electroflux Posted January 10, 2015 Author Share Posted January 10, 2015 (edited) Okay, Wilson worked. Now that I finally can see the results of the code, it presents more problems.-Removed huge paragraph Edited January 11, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-600028 Share on other sites More sharing options...
Electroflux Posted January 11, 2015 Author Share Posted January 11, 2015 (edited) If anyone out there knows how we can modify his code to do this, I'd really appreciate it. I'm more angry at myself everyday for not knowing how to code but it's just not my forte...and I have to rely on others which is both good and bad... I just want to get it done at this point. I've editted the above post so I can make this more clear on what I'm asking exactly. Perk 1: Activate below 75 sanity, increase speed to 2 and health to 300. Only activates at random intervals of 5-10 minutes (while still below 75 sanity). Duration of perk, 10-20 second intervals, all random between those seconds. Perk 2: /cry randomly below 100 sanity. Only cries every 60 seconds. Each of these perks reset when he's back above 100 sanity. @rezecib@Aquaterion Here's the updated code: http://pastebin.com/qWwZtKgV Edited January 11, 2015 by Electroflux Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-600070 Share on other sites More sharing options...
Electroflux Posted January 11, 2015 Author Share Posted January 11, 2015 Anyone? Link to comment https://forums.kleientertainment.com/forums/topic/48744-need-help-with-coding-perks/#findComment-600295 Share on other sites More sharing options...
Recommended Posts