Jump to content

How to make a character glow in the dark?


Recommended Posts

For the first time ever im trying to get in to modding so I can make a custom character of my very own. Im not familiar with coding stuff, or any of the functions used in Don't Starve togehter.

Currently, I'm trying to get my character to glow in the dark while above 70% hunger.  Any help would be appreciated. Thank you.

Edited by GrumbleGrits
Link to comment
Share on other sites

First of all, welcome to the wonderful world of modding! :D Strap in. You may feel copious amounts of rage at times and may never be satisfied, but gosh darn it, it's somehow worth it in the end xD

I would strongly recommend that you take a thorough look through the newcomer post, since it will ease your entry into this crazy world of modding for DS/DST. It will tell you where the most used files are located and how to debug your mod. There are also two simple example mods.

Now for your query. I'm not entirely sure how to actually do the glow, but if you just want there to be light around your character in the dark, then this post does just that. In your case you have two conditions, so simply listening for the event "hungerdelta" may not be good enough. If (for some weird reason) your hunger doesn't change while it's dark, then you also have to listen for the world event telling you when it gets dark. You also have to take care of what happens when the player joins the server during the night or is resurrected during the night (since resurrection resets the Light component). Then it might not be triggering either of the events.

I would probably go with this type of structure, using a simple periodic check. This code will make your character light up whenever they are in total darkness, but not otherwise. I thought this might make sense, since you said "glow in the dark". It'll work for caves out of the box. Otherwise, you'd also have to check whether you're in a cave and check the current phase of the world ("day", "dusk", "night"), in addition to the other things mentioned in the last paragraph.

Spoiler

local function turnOnLight(inst)
	-- Set these to whatever you like, as long as "Enable" is true.
	-- Intensity should be between 0.0 and 1.0, 0.0 being no light.
	inst.Light:SetIntensity(0.7)
	inst.Light:SetRadius(4)
	-- Falloff determines how quickly the light fades from the emitter to the radius.
	inst.Light:SetFalloff(0.75)
	-- The color actually takes values of 0.0 to 1.0 as well,
	-- but since we usually use RGB values of 0-255, we replace
	-- all the values with divisions, so for red, here 255 / 255,
	-- we are giving it the maximum amount.
	inst.Light:SetColour(255 / 255, 207 / 255, 98 / 255)
	inst.Light:Enable(true)
end

local function turnOffLight(inst)
	--Default to electrocute light values (taken from player_common.lua)
	inst.Light:SetIntensity(0.8)
	inst.Light:SetRadius(0.5)
	inst.Light:SetFalloff(0.65)
	inst.Light:SetColour(255 / 255, 255 / 255, 236 / 255)
	inst.Light:Enable(false)
end

local function checkLight(inst)
	if not inst.LightWatcher:IsInLight() and inst.components.hunger:GetPercent() >= 0.7
	and not inst:HasTag("playerghost") and not inst.components.health:IsDead()
	then
		turnOnLight(inst)
	else
		turnOffLight(inst)
	end
end

local common_postinit = function(inst)
	-- whatever you have in your common_postinit already.
	
	inst:DoPeriodicTask(1.0, checkLight)
end

 

 

Edited by Ultroman
Link to comment
Share on other sites

Hooooo boy, i've got a lot to dig through before i can get any decent understanding of how to properly make things work, lmao. Otherwise i may just manage to make my computer explode, or give rise to the first decepticon or some crap. Thank you though for the help though, I'll try to take some time to scour through things and see if i can get a handle on it.

If not, I'll surely come crying for help lmao. Thanks again though <3.

 

Link to comment
Share on other sites

Well, you have a running start now, and some (hopefully) running code :) Just take it slow at the beginning. Make some small test-mods first to get the hang of it. Perhaps try to alter the example mods and look at code from existing mods doing things similar to what you want to end up doing (character mod, world generation mod, new items, altering existing items, etc.), and ask your questions on the forum. We're here to help, but the journey starts with a bit of studying.

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