Jump to content

Some coding questions


Recommended Posts

I'm making some custom characters, and I had a few questions about how to do certain things with them.

 

One of the characters is really airheaded, so I thought that making her sanity loss AND sanity regain lowered would be interesting. I know how to do the sanity loss thing, thanks to Wendy, but I'm not so sure about the sanity regain. Does anyone know how to make her regain sanity 25% slower?

 

Another thing is that I want the character to be a friend to tentacles. Looking at Webber, I see that they just did inst:AddTag("monster") and in the spider code they changed it to not attack him if he has the monster tag. If I did inst:AddTag("tentaclewhisperer") and changed line 27 in the tentacles prefab to say

return (guy.components.combat.target == inst or guy:HasTag("character") or guy:HasTag("monster") or guy:HasTag("animal")) and not guy:HasTag("prey") and not guy:HasTag("tentaclewhisperer") and not (guy.prefab == inst.prefab)

Would that work? I intend on testing it out when I get home later, but I wanted to post it up here to just double check.

Link to comment
Share on other sites

This is an example of where I insert some code before the health:DoDelta function to filter a scenario out. You could use a method like this to alter the sanity delta values depending on what character owns the component.

function modhealthdelta(inst)	oldhealthdelta = inst.DoDelta	inst.DoDelta = function(self, amount, overtime, cause, ignore_invincible)		if cause == "rain" then			local x,y,z = self.inst.Transform:GetWorldPosition()			local ents = TheSim:FindEntities(x,y,z, 4, {'sheltercarrier'} )			for k,v in pairs(ents) do 				if v.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.HANDS) and v.components.inventory:GetEquippedItem( GLOBAL.EQUIPSLOTS.HANDS).prefab == "umbrella" then					return				end			end		end		oldhealthdelta(self, amount, overtime, cause, ignore_invincible)	endendAddComponentPostInit("health", modhealthdelta)
Link to comment
Share on other sites

Hm... I'm still learning, and I don't really know lua that well. What is delta? The change in that value?

 

I'm looking at some tutorials and the like, but I have a feeling that there are some things Don't Starve-specific that I don't know where to find

Link to comment
Share on other sites

Hm... I'm still learning, and I don't really know lua that well. What is delta? The change in that value?

 

I'm looking at some tutorials and the like, but I have a feeling that there are some things Don't Starve-specific that I don't know where to find

 

"doDelta" is in general a function to change a value, just like you said. You can find the exact way these work by looking into the respective files.

In the above example, you see a new delta function which uses "health" (it's replacing "inst" because of the last line).

Having said that, I don't understand the function at all myself... :confused:

EDIT: I asume it's incomplete and just looks wether you're standing in rain without doing anything? Oh lord, don't listen to me, that's the best for yourself.

Link to comment
Share on other sites

The function replaces the standard health:DoDelta function with a nearly identical copy of itself. The difference being that if the damage is coming from rain (which happens only for WX78) it performs some additional checks. If anyone takes damage and it's not from rain, it will just run the standard function.

 

If you did something like this instead

function modhealthdelta(inst)    oldhealthdelta = inst.DoDelta    inst.DoDelta = function(self, amount, overtime, cause, ignore_invincible)        if self.inst.prefab == "webber" then           amount = amount * 0.75        end        oldhealthdelta(self, amount, overtime, cause, ignore_invincible)    endendAddComponentPostInit("health", modhealthdelta)

you would have a function that made Webber take 25% less damage from all sources.

 

The benefit of doing it like this is that it will be compatible with other mods seeking to alter the same functions.

Link to comment
Share on other sites

The function replaces the standard health:DoDelta function with a nearly identical copy of itself. The difference being that if the damage is coming from rain (which happens only for WX78) it performs some additional checks. If anyone takes damage and it's not from rain, it will just run the standard function.

 

If you did something like this instead

[...]

you would have a function that made Webber take 25% less damage from all sources.

 

The benefit of doing it like this is that it will be compatible with other mods seeking to alter the same functions.

 

Ah, that makes sense! :D This way, one can also change sanity:doDelta to achieve the 25% weakening mentioned above. And that without overriding any files! *mind blown*

Excuse me for asking silly questions about what is none of my business, and thank you for kindly clearing things up for me.

Link to comment
Share on other sites

The function replaces the standard health:DoDelta function with a nearly identical copy of itself. The difference being that if the damage is coming from rain (which happens only for WX78) it performs some additional checks. If anyone takes damage and it's not from rain, it will just run the standard function.

 

If you did something like this instead

function modhealthdelta(inst)    oldhealthdelta = inst.DoDelta    inst.DoDelta = function(self, amount, overtime, cause, ignore_invincible)        if self.inst.prefab == "webber" then           amount = amount * 0.75        end        oldhealthdelta(self, amount, overtime, cause, ignore_invincible)    endendAddComponentPostInit("health", modhealthdelta)

you would have a function that made Webber take 25% less damage from all sources.

 

The benefit of doing it like this is that it will be compatible with other mods seeking to alter the same functions.

 

It helped me out greatly as well! Is there a chat room or something that I could go into and ask questions? I kind of jumped into this not knowing anything about lua, so I've been making a lot of assumptions.

 

I'm not sure exactly what the "inst" and such are, so if someone could explain that to me, I'd appreciate it. I've noticed that it's used as a (parameter? argument? I'm not quite sure what the word for it is) for a lot of functions. Owner is sort of self-explanatory. 

 

Also, it seems that there are a lot of functions that are inherent to Don't Starve, so I haven't been able to find any sort of documentation on them; doDelta is a good example of this.

 

If someone doesn't mind answering these and other silly questions from a newbie (either here on the forums, or in a chatroom or something), let me know. I'd really appreciate it :3

Link to comment
Share on other sites

There is no documentation for such functions, but they are generally written in such a way that you should be able to understand them just by looking at the code.

 

In the base code for the game (not in my examples above), an "inst" is a variable that generally refers to an instance of a prefab (a prefab being an entity - a tree, a badger, or sometimes more esotheric stuff like a dungeon). When you add a component to a prefab, you pass the name of the inst along to the component. In all components you will find close to the top the code "self.inst = inst" which is, for the component class, storing what inst the component belongs to. Therefore whenever you see a "self.inst" inside a component, it is referring to the prefab that uses the component.

Link to comment
Share on other sites

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.

×
  • Create New...