Jump to content

Recommended Posts

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.

2. I need him to slowly regain HP while it's raining

You 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)end

As 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 Crazyfear

Obviously, change the health value and speed multipliers as you see fit. I set the speed to what you'd get from a walking cane.

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 by Electroflux

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 by Electroflux

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 by Electroflux

@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

 

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

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 by Electroflux
Guest
This topic is now closed to further replies.
×
  • Create New...