Devorer Posted August 1, 2015 Share Posted August 1, 2015 I basically no experience at coding. Everything I've done on my own character was from tutorials and copy/pasting. So I would require some help please.The thing I want is quite simple, but I dunno if it is when coding.I want my character to gain sanity when eating a specific food (cave bananas precisely). And also get a damage multiplier bonus for a certain amount of time after eating it.Thanks in advance. Link to comment Share on other sites More sharing options...
StarmanUltra Posted August 1, 2015 Share Posted August 1, 2015 Make a function in character.lua somewhere above master_postinit: local function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) endend then within master_postinit include the line inst.components.eater:SetOnEatFn(bananas)That'll give you the initial sanity boost, anyway. I'm pretty bad with timers, so I might leave that to someone else. Basically though, you'd have it call another function in that if statement and have it create a time variable, call inst.components.combat.damagemultiplier = 1.5 or something, and keep checking back to that function using that variable until the time is up. Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 1, 2015 Share Posted August 1, 2015 Using both the above code and adapting wx78's lightning boost thingy... Add these three functions to your char's prefab above master_postinit:local function onupdate(inst, dt) inst.boost_time = inst.boost_time - dt --reduce dt from the charge if inst.boost_time <= 0 then --if the boost time is over inst.boost_time = 0 if inst.boost_task ~= nil then --stop the task inst.boost_task:Cancel() inst.boost_task = nil end --and restore the multiplier inst.components.combat.damagemultiplier = TUNING.WILSON_COMBAT_MULT --change this to your char's default multiplier end endlocal function startbananaboost(inst, duration) inst.boost_time = duration if inst.boost_task == nil then --if the task is not running inst.boost_task = inst:DoPeriodicTask(1, onupdate, nil, 1) --create a new task inst.components.combat.damagemultiplier = inst.boost_mult --increase the multiplier endendlocal function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) startbananaboost(inst, inst.boost_time) endendThen add this inside master_postinit:inst.boost_time = 10 --boost duration in secondsinst.boost_task = nil --leave this nil inst.boost_mult = 2 --change this to the desired multiplier after eating the bananasinst.components.eater:SetOnEatFn(bananas)I haven't tested it too much, let me know if it something doesn't work. Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 Using both the above code and adapting wx78's lightning boost thingy... Add these three functions to your char's prefab above master_postinit:local function onupdate(inst, dt) inst.boost_time = inst.boost_time - dt --reduce dt from the charge if inst.boost_time <= 0 then --if the boost time is over inst.boost_time = 0 if inst.boost_task ~= nil then --stop the task inst.boost_task:Cancel() inst.boost_task = nil end --and restore the multiplier inst.components.combat.damagemultiplier = TUNING.WILSON_COMBAT_MULT --change this to your char's default multiplier end endlocal function startbananaboost(inst, duration) inst.boost_time = duration if inst.boost_task == nil then --if the task is not running inst.boost_task = inst:DoPeriodicTask(1, onupdate, nil, 1) --create a new task inst.components.combat.damagemultiplier = inst.boost_mult --increase the multiplier endendlocal function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) startbananaboost(inst, inst.boost_time) endendThen add this inside master_postinit:inst.boost_time = 10 --boost duration in secondsinst.boost_task = nil --leave this nil inst.boost_mult = 2 --change this to the desired multiplier after eating the bananasinst.components.eater:SetOnEatFn(bananas)I haven't tested it too much, let me know if it something doesn't work. I just tested it and it works perfectly with no bugs. The notes you left in it so I don't search the values are just perfect too. Thanks a lot captain. Do you want to share your steam name so I can give you credits in my char description for the help you provided. Aslo, would you be able to help me even more by giving me the script to : The char get a buff animation once he consumes the bananas (like Wolfang energy boosts animation).And, he is able to ''see'' in the dark via a classic glow arround him. But i dont really like the fact that other players can see via this light though. Is it possible to make this light reserved for him only too? Thanks a bunch for the script again! Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 2, 2015 Share Posted August 2, 2015 I just tested it and it works perfectly with no bugs. The notes you left in it so I don't search the values are just perfect too. Thanks a lot captain. Do you want to share your steam name so I can give you credits in my char description for the help you provided. Aslo, would you be able to help me even more by giving me the script to : The char get a buff animation once he consumes the bananas (like Wolfang energy boosts animation).And, he is able to ''see'' in the dark via a classic glow arround him. But i dont really like the fact that other players can see via this light though. Is it possible to make this light reserved for him only too? Thanks a bunch for the script again! Actually, I had time to test it a bit more and it had a couple issues, particularly not being able to get more than one boost. This should work better... Same deal, this goes above master_init:local function onupdate(inst, dt) inst.boost_time = inst.boost_time - dt if inst.boost_time <= 0 then if inst.boost_task ~= nil then inst.boost_task:Cancel() inst.boost_task = nil end inst.components.combat.damagemultiplier = TUNING.WILSON_DAMAGE_MULT --change this to your char's default multiplier endendlocal function startbananaboost(inst, duration) inst.boost_time = 10 --boost duration in seconds, change it to whatever you want if inst.boost_task == nil then inst.boost_task = inst:DoPeriodicTask(1, onupdate, nil, 1)--arguments:(time, fn, delay, fnArguments) inst.components.combat.damagemultiplier = inst.boost_mult onupdate(inst, 0)--for avoiding a 1 second delay endendlocal function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) startbananaboost(inst) endendAnd this in master_prefab:--remove inst.boost_time from here if you have itinst.boost_task = nil --leave this nil inst.boost_mult = 2 --change this to the desired multiplier after eating the bananasinst.components.eater:SetOnEatFn(bananas)About the boost animation, is it exactly the same as wolfgang's or do you want to make a custom one? And I don't know about the light thing. Oh and my steam name is the same as here, add me if you want. Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 Actually, I had time to test it a bit more and it had a couple issues, particularly not being able to get more than one boost. This should work better... Same deal, this goes above master_init:local function onupdate(inst, dt) inst.boost_time = inst.boost_time - dt if inst.boost_time <= 0 then if inst.boost_task ~= nil then inst.boost_task:Cancel() inst.boost_task = nil end inst.components.combat.damagemultiplier = TUNING.WILSON_DAMAGE_MULT --change this to your char's default multiplier endendlocal function startbananaboost(inst, duration) inst.boost_time = 10 --boost duration in seconds, change it to whatever you want if inst.boost_task == nil then inst.boost_task = inst:DoPeriodicTask(1, onupdate, nil, 1)--arguments:(time, fn, delay, fnArguments) inst.components.combat.damagemultiplier = inst.boost_mult onupdate(inst, 0)--for avoiding a 1 second delay endendlocal function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) startbananaboost(inst) endendAnd this in master_prefab:--remove inst.boost_time from here if you have itinst.boost_task = nil --leave this nil inst.boost_mult = 2 --change this to the desired multiplier after eating the bananasinst.components.eater:SetOnEatFn(bananas)About the boost animation, is it exactly the same as wolfgang's or do you want to make a custom one? And I don't know about the light thing. Oh and my steam name is the same as here, add me if you want. Yes it can be the same animation. Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 Also too bad for the light thing. It would have been preferable that he could see in the dark without making the others see too. Thanks anyway. Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 2, 2015 Share Posted August 2, 2015 Also too bad for the light thing. It would have been preferable that he could see in the dark without making the others see too. Thanks anyway. You can probably combine this...inst.components.playervision:ForceNightVision(true)...with this http://forums.kleientertainment.com/topic/27642-night-vision/#entry507803 Link to comment Share on other sites More sharing options...
UnionGaming Posted August 2, 2015 Share Posted August 2, 2015 inst:ListenForEvent( "nighttime", function() inst.components.playervision:ForceNightVision(true)end, GetWorld() ) inst:ListenForEvent( "daytime", function() inst.components.playervision:ForceNightVision(false)end, GetWorld() ) Don't quote me on that, I just put it together for you.Don't know how it will work in Dusk and certainly not in Dawn if you have that. Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 2, 2015 Share Posted August 2, 2015 For Wolfgang's mighty animation add this to your char prefab's assets table:Asset( "ANIM", "anim/player_wolfgang.zip")And modify the function bananas:local function bananas(inst, food) if inst.components.eater and food.prefab == "cave_banana" then inst.components.sanity:DoDelta(5) if inst.boost_time == nil or inst.boost_time == 0 then inst.AnimState:PlayAnimation("powerup") end startbananaboost(inst) endend Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 inst:ListenForEvent( "nighttime", function() inst.components.playervision:ForceNightVision(true)end, GetWorld() ) inst:ListenForEvent( "daytime", function() inst.components.playervision:ForceNightVision(false)end, GetWorld() ) Don't quote me on that, I just put it together for you.Don't know how it will work in Dusk and certainly not in Dawn if you have that. It doens't work. Nothing happens when the night comes. Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 2, 2015 Share Posted August 2, 2015 (edited) Turns out the stuff in the link I posted doesn't work for DST. I got it working with this... Add this functionlocal function managenightvision(inst) if inst.components.playervision:HasNightVision() then inst.components.playervision:ForceNightVision(false) else inst.components.playervision:ForceNightVision(true) endendand this in either master_postinit or common_postinitinst:WatchWorldState("startnight", managenightvision)inst:WatchWorldState("startday", managenightvision) Edited August 2, 2015 by whatsmynameagain Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 Turns out the stuff in the link I posted doesn't work for DST. I got it working with this... Add this functionlocal function managenightvision(inst) if inst.components.playervision:HasNightVision() then inst.components.playervision:ForceNightVision(false) else inst.components.playervision:ForceNightVision(true) endendand this in either master_postinit or common_postinitinst:WatchWorldState("startnight", managenightvision)inst:WatchWorldState("startday", managenightvision) Once again sir, you nailed it. Everything works properly within my tests. So a big thank you again. And I'll keep you in touch if something comes out. Link to comment Share on other sites More sharing options...
Devorer Posted August 2, 2015 Author Share Posted August 2, 2015 There is an issue. If I connect/respawn during night time, it switch the rotation (night vision during daytime, worn off during nighttime). I have to reconnect during day to restart the cycle. Link to comment Share on other sites More sharing options...
whatsmynameagain Posted August 3, 2015 Share Posted August 3, 2015 local function managenightvision(inst) if inst.components.playervision:HasNightVision() then if TheWorld.state.isday or TheWorld.state.isfullmoon or TheWorld.state.isdusk then inst.components.playervision:ForceNightVision(false) end else if TheWorld.state.isnight and not TheWorld.state.isfullmoon then inst.components.playervision:ForceNightVision(true) end endendinst:WatchWorldState("isnight", managenightvision)inst:WatchWorldState("isday", managenightvision)inst:WatchWorldState("isfullmoon", managenightvision)managenightvision(inst) --check when connectingWorks on all the cases I've tried. Link to comment Share on other sites More sharing options...
rons0n Posted August 9, 2015 Share Posted August 9, 2015 The above post works well as the host, but as the client nothing visually changes. You'll still be in the dark but you'll be completely immune to charlie. How would you adjust that so nightvision also works for clients? Link to comment Share on other sites More sharing options...
DarkXero Posted August 9, 2015 Share Posted August 9, 2015 @rons0n: If a piece of equipment has nightvision, theninst:AddTag("nightvision")If it's on the character on certain circumstances, you need to trigger the nightvision on the client, likeAddPrefabPostInit("wilson", function(inst) inst.nightvision = GLOBAL.net_bool(inst.GUID, "player.customvision", "flipvision") inst.nightvision:set_local(false) local function FlipFn(inst) inst.components.playervision:ForceNightVision(inst.nightvision:value()) end inst:ListenForEvent("flipvision", FlipFn) if GLOBAL.TheWorld.ismastersim then local function OnPhaseChange(inst, phase) inst.nightvision:set(phase == "night") end inst:WatchWorldState("phase", OnPhaseChange) OnPhaseChange(inst, GLOBAL.TheWorld.state.phase) endend)Both host and client flip the nightvision, so the host can calculate the immunities, and the client can see.Only the host flips the net variable. Link to comment Share on other sites More sharing options...
rons0n Posted August 9, 2015 Share Posted August 9, 2015 @DarkXero, Thanks again but whats up with hosts having everything looked inverse while the client has standard night vision? I'd rather much like have the inverse night vision the host has rather than the standard. Is there a way to do that or is it just a glitch? Inverse NightVision(Host Only): And then standard nightvision just looks like day but with a lighter blue tint to it. Client side. Link to comment Share on other sites More sharing options...
DarkXero Posted August 10, 2015 Share Posted August 10, 2015 @rons0n:Inverse nightvision? That's the RoG nightvision of the moggles, the molehat.Clients should also have the "inverse nightvision" by default.I used my code and hosted a game as Wilson, and joined a game as Wilson, and I got the mole vision on both. Could you post more screenshots? Link to comment Share on other sites More sharing options...
rons0n Posted August 10, 2015 Share Posted August 10, 2015 (edited) @DarkXero, Apologies for the late reply, but if what you say is true then its probably just a mod conflict I guess. Here are some screenshots with the non-moggle vision and moggle-vision: Picture taken on a non-dedicated server. I'm Host: Picture taken on a dedicated server. Heavily modded server. Client: Could possibly be something with my character? Shes already on the workshop called Sakura if you want to take a look If it is a mod conflict then it really isn't really to be fussed over, I can deal with non-moggle vision. Edited August 10, 2015 by rons0n Link to comment Share on other sites More sharing options...
DarkXero Posted August 10, 2015 Share Posted August 10, 2015 @rons0n, alright then, try this. Addlocal NIGHTVISION_COLOURCUBES ={ day = "images/colour_cubes/mole_vision_off_cc.tex", dusk = "images/colour_cubes/mole_vision_on_cc.tex", night = "images/colour_cubes/mole_vision_on_cc.tex", full_moon = "images/colour_cubes/mole_vision_off_cc.tex",}in scope and put the FlipFn like local function FlipFn(inst) local val = inst.nightvision:value() inst.components.playervision:ForceNightVision(val) inst.components.playervision:SetCustomCCTable(val and NIGHTVISION_COLOURCUBES or nil) endso the molevision gets set up. Link to comment Share on other sites More sharing options...
rons0n Posted August 10, 2015 Share Posted August 10, 2015 (edited) @DarkXero, It's still the same as it was before but I'm no longer gotta make a big deal out of it. I'll try a vanilla Dedicated Server with just my Sakura mod and edit this post later to see if anything changes. Regardless if it changes or not I'm content with the outcome anyway. I just wanted night vision and I got night vision so I'm okay as is. So as always, thanks for the help! Update: I know you're probably not going to look at this now but the culprit was the Dawn mod. Removed that and her moggle version has returned. Woot Edited September 18, 2015 by rons0n Link to comment Share on other sites More sharing options...
Randy Boggs Posted September 5, 2015 Share Posted September 5, 2015 Hey captain, do you think you could make another code for me.I would like something about hoarding to gain sanity.Precisely, gain sanity while you hoard nitre, gold nuggets and gems around the character.Thanks in advance. Link to comment Share on other sites More sharing options...
Devorer Posted September 12, 2015 Author Share Posted September 12, 2015 local function managenightvision(inst) if inst.components.playervision:HasNightVision() then if TheWorld.state.isday or TheWorld.state.isfullmoon or TheWorld.state.isdusk then inst.components.playervision:ForceNightVision(false) end else if TheWorld.state.isnight and not TheWorld.state.isfullmoon then inst.components.playervision:ForceNightVision(true) end endendinst:WatchWorldState("isnight", managenightvision)inst:WatchWorldState("isday", managenightvision)inst:WatchWorldState("isfullmoon", managenightvision)managenightvision(inst) --check when connectingWorks on all the cases I've tried. Yes, It seems to have an issue when it comes to the clients. As a host, the night vision works properly, but as a client, it doesn't trigger. Simply stays pitch black. 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