AgainstMatter Posted January 29, 2015 Share Posted January 29, 2015 I would like to make a character that is weak to the rain, so if it's raining i want the characters sanity to drop very rapidly.How would i go about doing this? Link to comment Share on other sites More sharing options...
outseeker Posted January 29, 2015 Share Posted January 29, 2015 I found that by using Notepad++ to search files for "IsRaining": TheWorld.state.israining will give you true or false to raining Searching the game files is a sweet way of exposing all this stuff; TheWorld.state also gives you IsDay, IsNight and IsWinter for example Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 29, 2015 Author Share Posted January 29, 2015 I found that by using Notepad++ to search files for "IsRaining":TheWorld.state.israining will give you true or false to raining Searching the game files is a sweet way of exposing all this stuff; TheWorld.state also gives you IsDay, IsNight and IsWinter for exampleThanks! So, onward to problem 2so let's say I have a function like thisif TheWorld.state.israining() == true then [do stuff]else [do stuff]endHow would I make that function run everytime it's raining or stops raining?(sorry for my noobishness I'm kinda new to modding) Link to comment Share on other sites More sharing options...
Blueberrys Posted January 29, 2015 Share Posted January 29, 2015 @AgainstMatter You can use an event listener."inst" is referring to your character, so this would go in your character's create fn.local dapperness_onrain = TUNING.SANITY_SMALL-- You can also use (-TUNING.SANITY_SMALL), or a custom valuelocal function rain_start() inst.components.sanity.dapperness = dapperness_onrainendGetWorld():ListenForEvent("rainstart", rain_start)local function rain_stop() inst.components.sanity.dapperness = 0endGetWorld():ListenForEvent("rainstop", rain_stop)Edit: Fixed the issues listed below.Here's the old (not working) version.inst:AddComponent("dapperness")local dapperness_onrain = TUNING.CRAZINESS_SMALL-- You can also use (-TUNING.SANITY_SMALL), or a custom valuelocal function rain_start() inst.components.dapperness.dapperness = dapperness_onrainendinst:ListenForEvent("rainstart", rain_start)local function rain_stop() inst.components.dapperness.dapperness = 0endinst:ListenForEvent("rainstop", rain_stop) Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 29, 2015 Author Share Posted January 29, 2015 @BlueberrysI am losing sanity but now as fast as I'd like it to be.The rate that i lose sanity doesn't seem to change if i have local dapperness_onrain = -10 or -9999999999 though. Link to comment Share on other sites More sharing options...
Blueberrys Posted January 29, 2015 Share Posted January 29, 2015 @AgainstMatterHmm. Try adding these print statements to see if the code even accesses them.inst:AddComponent("dapperness") local dapperness_onrain = TUNING.CRAZINESS_SMALL-- You can also use (-TUNING.SANITY_SMALL), or a custom value local function rain_start() inst.components.dapperness.dapperness = dapperness_onrain print(inst.components.dapperness.dapperness)endinst:ListenForEvent("rainstart", rain_start) local function rain_stop() inst.components.dapperness.dapperness = 0 print(inst.components.dapperness.dapperness)endinst:ListenForEvent("rainstop", rain_stop)They should print a value to your log.txt file and your console.You can access the console by press the Grave-Accent/Backtick ( ` ) key in-game. Link to comment Share on other sites More sharing options...
outseeker Posted January 29, 2015 Share Posted January 29, 2015 I'm guessing the above would yield some kinda positive result; I've not used any ListenForEvent goodies before, but like the berrys said, if you add in a print or two, you can see if the code is doing its job / how often it runs by looking in the console. I did a quick bit of searching within the .lua files for dapperness and found this function within sanity.lua:function Sanity:Recalc(dt) local total_dapperness = self.dapperness or 0 local mitigates_rain = false for k,v in pairs (self.inst.components.inventory.equipslots) do if v.components.dapperness then total_dapperness = total_dapperness + v.components.dapperness:GetDapperness(self.inst) if v.components.dapperness.mitigates_rain then mitigates_rain = true end end end local dapper_delta = total_dapperness*TUNING.SANITY_DAPPERNESS local light_delta = 0 local lightval = self.inst.LightWatcher:GetLightValue() local day = TheWorld.state.isday and not TheWorld:HasTag("cave") if day then light_delta = TUNING.SANITY_DAY_GAIN else local highval = TUNING.SANITY_HIGH_LIGHT local lowval = TUNING.SANITY_LOW_LIGHT if lightval > highval then light_delta = TUNING.SANITY_NIGHT_LIGHT elseif lightval < lowval then light_delta = TUNING.SANITY_NIGHT_DARK else light_delta = TUNING.SANITY_NIGHT_MID end light_delta = light_delta*self.night_drain_mult end local aura_delta = 0 local x,y,z = self.inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x,y,z, TUNING.SANITY_EFFECT_RANGE, nil, {"FX", "NOCLICK", "DECOR","INLIMBO"} ) for k,v in pairs(ents) do if v.components.sanityaura and v ~= self.inst then local distsq = self.inst:GetDistanceSqToInst(v) local aura_val = v.components.sanityaura:GetAura(self.inst)/math.max(1, distsq) if aura_val < 0 then aura_val = aura_val * self.neg_aura_mult end aura_delta = aura_delta + aura_val end end local rain_delta = not mitigates_rain and TheWorld.state.israining and -1.5 * TUNING.DAPPERNESS_MED * TheWorld.state.precipitationrate or 0 self.ghost_drain_mult = GetNumGhostPlayers() if self.ghost_drain_mult > TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT then self.ghost_drain_mult = TUNING.MAX_SANITY_GHOST_PLAYER_DRAIN_MULT end local ghost_delta = TUNING.SANITY_GHOST_PLAYER_DRAIN * self.ghost_drain_mult self.rate = (dapper_delta + light_delta + aura_delta + rain_delta + ghost_delta) if self.custom_rate_fn then self.rate = self.rate + self.custom_rate_fn(self.inst) end --print (string.format("dapper: %2.2f light: %2.2f TOTAL: %2.2f", dapper_delta, light_delta, self.rate*dt)) self:DoDelta(self.rate*dt, true)endThis explains how dapperness interacts with the player in the context of sanity, so you can consider what you need to do in your code, and what changing dapperness in your code will do Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 29, 2015 Author Share Posted January 29, 2015 @outseekerThanks a bunch! Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 29, 2015 Author Share Posted January 29, 2015 @Blueberrys Im testing it by turning rain on and off using N tools but im guessing that the event won't trigger then. Do you know an another of turning the rain on? Link to comment Share on other sites More sharing options...
Blueberrys Posted January 29, 2015 Share Posted January 29, 2015 @AgainstMatter, Ahh.. nope. That's how I would have done it myself. N-tools calls this functionfunction SeasonManager:StartPrecip() if not self.precip then self.nextlightningtime = GetRandomMinMax(self.lightningdelays.min or 5, self.lightningdelays.max or 15) self.precip = true self.moisture_floor = (.25 + math.random()*.5)*self.atmo_moisture self.peak_precip_intensity = math.random() local snow_thresh = self:IsWinter() and 5 or -5 if self.current_temperature < snow_thresh then self.preciptype = "snow" self.inst:PushEvent("snowstart") else self.preciptype = "rain" self.inst:PushEvent("rainstart") end endendPlease confirm that it's not winter (or close to), as it would push the snowstart event instead. Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 30, 2015 Author Share Posted January 30, 2015 @BlueberrysWell. It seems like the functions are not running.. any idea why? Link to comment Share on other sites More sharing options...
Blueberrys Posted January 30, 2015 Share Posted January 30, 2015 @AgainstMatter The event listener is being set on the player's instance, but it seems the rain events are only being passed to the world's instance. Change bothinst:ListenForEventtoGetWorld():ListenForEventBut I think there may still be a problem with the sanity not going down. Still testing that. Edit:The sanity component does not check for the player's dapperness. Instead, it has it's own dapperness value that is checked when calculating sanity.It can be set through inst.components.sanity.dapperness Working tested codelocal dapperness_onrain = -50-- You can also use (-TUNING.SANITY_SMALL), or a custom valuelocal function rain_start() inst.components.sanity.dapperness = dapperness_onrainendGetWorld():ListenForEvent("rainstart", rain_start)local function rain_stop() inst.components.sanity.dapperness = 0endGetWorld():ListenForEvent("rainstop", rain_stop) Link to comment Share on other sites More sharing options...
seronis Posted January 30, 2015 Share Posted January 30, 2015 Keep in mind the code there is only changing state at the point where the rain itself changes state. Meaning if you load up a game that is already raining you might not receive a 'rainstart' event. This is meant purely as general advice to show you need to think of edge cases. Link to comment Share on other sites More sharing options...
AgainstMatter Posted January 30, 2015 Author Share Posted January 30, 2015 @BlueberrysThanks! It works perfectly now! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.