Jump to content

Need help for a character perk.


Recommended Posts

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

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

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)    endend

Then 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

 
 

 

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)    endend

Then 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

 

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)	endend

And 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

 
 

 

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)	endend

And 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

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

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

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

Turns out the stuff in the link I posted doesn't work for DST.

 

I got it working with this...

 

Add this function

local function managenightvision(inst)	if inst.components.playervision:HasNightVision() then		inst.components.playervision:ForceNightVision(false)	else		inst.components.playervision:ForceNightVision(true)	endend

and this in either master_postinit or common_postinit

inst:WatchWorldState("startnight", managenightvision)inst:WatchWorldState("startday", managenightvision)
Edited by whatsmynameagain
Link to comment
Share on other sites

 
 

 

 

Turns out the stuff in the link I posted doesn't work for DST.

 

I got it working with this...

 

Add this function

local function managenightvision(inst)	if inst.components.playervision:HasNightVision() then		inst.components.playervision:ForceNightVision(false)	else		inst.components.playervision:ForceNightVision(true)	endend

and this in either master_postinit or common_postinit

inst: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

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	endend
inst:WatchWorldState("isnight", managenightvision)inst:WatchWorldState("isday", managenightvision)inst:WatchWorldState("isfullmoon", managenightvision)managenightvision(inst) --check when connecting

Works on all the cases I've tried.

Link to comment
Share on other sites

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

@rons0n:

 

If a piece of equipment has nightvision, then

inst:AddTag("nightvision")

If it's on the character on certain circumstances, you need to trigger the nightvision on the client, like

AddPrefabPostInit("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

@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):

 

9hsGysT.jpg

 

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

@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

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

 

27xJM2G.jpg

 

Picture taken on a dedicated server. Heavily modded server. Client:

 

%7Boption%7DqnE9iwK.jpg

 

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 by rons0n
Link to comment
Share on other sites

@rons0n, alright then, try this.

 

Add

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

so the molevision gets set up.

Link to comment
Share on other sites

@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 by rons0n
Link to comment
Share on other sites

 
 

 

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	endend
inst:WatchWorldState("isnight", managenightvision)inst:WatchWorldState("isday", managenightvision)inst:WatchWorldState("isfullmoon", managenightvision)managenightvision(inst) --check when connecting

Works 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...