Jump to content

Alternate ways to update Extended Map Generation to be compatible with RoG?


Recommended Posts

The original mod can be found here:

http://steamcommunity.com/sharedfiles/filedetails/?id=364821573

 

For a while, this mod could not be used with RoG. However, two people on steam (Ozymandias and khirsah) managed to update the mod by doing the following changes:

 

Go to the /Don’t Starve Together Beta/mods folder. Then find the folder representing the extended map generation mod. Go into the scripts folder and change the following:

(1) In “rocky.lua”, change line 170 to
inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })

(2) In “worm.lua“, change line 210 to
inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODGROUP.OMNI })

(3) In “cavespiders.lua”, change line 215 to
inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT })

(4) In “monkey.lua”, change line 366 to
inst.components.eater:SetDiet({ FOODTYPE.VEGGIE }, { FOODTYPE.VEGGIE })

(5) In "slurtle.lua", line 112 needs to be changed to:

inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })

 

(6) Then go to the /Don’t Starve Together Beta/scripts/components folder. Change line 648 of Combat.lua with:

 

or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)

 

(The bolded part is what I'd like an alternative to).

 

I don't mind changing files in the /mods folder. However, is there anyway to update extended map generation by not editing combat.lua in /Don’t Starve Together Beta/scripts/components directly?  If I understand correctly, the original mod replaces "ambientlightning.lua" with it's "ambientlightning_custom.lua". Could something similar be done with a combat_custom.lua file?

 

I have tried to do so by myself (based on what I saw with files related to ambientlightning_custom.lua), and failed miserably.

Edited by Dougles
Link to comment
Share on other sites

I usually do this.

EDIT: In modmain.lua of course.



AddComponentPostInit("combat", function(inst)
local old_GetAttackRange = inst.GetAttackRange
function inst:GetAttackRange()
-- the new function, with as few changes as possible.
end
end)


In the new GetAttackRange function, try to add the line "return old_GetAttackRange()" at the point when your condition is applied correctly, so future updates are less likely to break the mod.

That's what I would try, if I understood the problem correctly. I didn't look at the code, I don't have time right now, sorry.

Edited by Sketchiverse
Link to comment
Share on other sites

I'm sorry. I've read the stickied posts on this forums, but I'm still very clueless with this.

 

I do not know where the condition is being applied. I know the changes to combat.lua were to fix the Splumonkey's poop toss, so I would have to add "return old_GetAttackRange()" somewhere specific in the monkey.lua?

Edited by Dougles
Link to comment
Share on other sites

 

I usually do this.
EDIT: In modmain.lua of course.
AddComponentPostInit("combat", function(inst)   local old_GetAttackRange = inst.GetAttackRange   function inst:GetAttackRange()      -- the new function, with as few changes as possible.   endend)
In the new GetAttackRange function, try to add the line "return old_GetAttackRange()" at the point when your condition is applied correctly, so future updates are less likely to break the mod.
That's what I would try, if I understood the problem correctly. I didn't look at the code, I don't have time right now, sorry.

 

 

This code will be executed for EVERY new prefab with combat component. Better way is to hook function in component code:

local combat_component = GLOBAL.require "components/combat"local old_GetAttackRange = combat_component.GetAttackRangefunction combat_component:GetAttackRange(...)	-- write the new code here	return old_GetAttackRange(self,...)end
Link to comment
Share on other sites

After trying it, I'm having getting crashes.

local combat_component = GLOBAL.require "components/combat"local old_GetAttackRange = combat_component.GetAttackRangefunction combat_component:GetAttackRange(...)or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)return old_GetAttackRange(self,...)end

It says unexpected symbol near "or".

Edited by Dougles
Link to comment
Share on other sites

@Maris If I'm not mistaken, you just did the same thing as I did with AddComponentPostInit. It has barely any difference. The Add___PostInit functions are made for that purpose though, so they should be used. Plus they save you the need to use require so in my opinion it's more efficient, if you're a perfectionist.

 

@Dougles It's not your fault, but if I had to explain your situation I would say you are trying to make an airplane before knowing what air is. (your profile pic represents it quite well too, hehe)

Normally you would have to learn the basics of programming before trying to do this high-level function post init thingamajig I told you about.

 

Just asking, why are you trying to fix this yourself if you're neither the modder, neither the guy who found the fix ? Why don't they do that themselves ? Did you ask whether they were working on it ? If they are, then you're giving yourself a lot of unnecessary trouble, normally it's the modder's role to fix their own mods. If you're doing that because you are trying to learn game programming, then I suggest you learn the basics first. If you're trying to help them, then 1/ same advice, and 2/ I think you already helped them enough by telling them what lines they should change.

Link to comment
Share on other sites

The original author was inactive at the time, and I didn't want to see this mod die. I like playing this mod with a couple of friends, which motivated me to find answers. It gave me a lot of laughs when we encountered an ancient guardian on day 2.

 

Just recently, Sarcen showed he/she was still alive, so I guess it's not necessary now. However, I'm already this far. I may as well get something easy to distribute to my friends via skype right now, since they like me, are not at all tech savvy. I fear asking them to find the mods folder is already going to be a huge pain, let alone the components folder. You could just say I'm impatient.

 

If this is rather a complicated task, than I understand. If not, then I hope it's not too much trouble.

Edited by Dougles
Link to comment
Share on other sites

The original author was inactive at the time

I was trying to add author as a friend too, but there is an error. I wanted to help him with Endia mod to make it compatible with RoG. I hope he will be active before RoG will be released.

Link to comment
Share on other sites

@Dougles I understand. I'll try to help, as you said we're already this far. But as always with mods, I don't know how complicated this can become yet, we'll see.

 

Let's say, if it works, how about you guys invite me to play ? I'm jealous of other people having friends.

Heh. You don't have to.

 

Fortunately he didn't add the combat.lua file as he did for every single prefab while it was probably useless to do so. I suppose he didn't aim to bother too much with the coding, which I understand. He may just have used a shortcut that was actually even longer...

Do not make a custom combat.lua file or the mod will break whenever Klei makes an update.

 

Now we have two choices. First, do it properly... Second, write crappy dirty code that will probably break if there's an update and that the modder should not use if he wants to have a polished mod, but it's already so ducktaped anyway, I think we'll just do that. Especially since it's an emergency solution that won't be published for everyone on the Steam Workshop so it's useless to do polished work.

 

The code that you will add will be put in the modmain.lua file, preferably at the bottom. I changed the line as you said, but I believe you were mistaken on the line number because line 648 is completely unrelated. I'm just assuming that the function you wanna change is that one.

 

Note for every modder who wants to learn, don't do this, it's disgusting.

AddComponentPostInit("combat", function(inst)	--local old_GetAttackRange = inst.GetAttackRange --lol I don't even care	function inst:GetAttackRange()		local range = self.attackrange		local weapon = self:GetWeapon()		if weapon and weapon.components.weapon.variedmodefn		or (weapon.components.weapon.variedmodefn ~= nil		and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange) then			local weaponrange = weapon.components.weapon.variedmodefn(weapon)			range = range + weaponrange.attackrange		elseif weapon and weapon.components.weapon.attackrange then			range = range + weapon.components.weapon.attackrange		end		return range	endend)

Since I can't be sure which is the line you wanted to change, you can also try this if it doesn't work, but I'm pretty sure the former is the right one :

AddComponentPostInit("combat", function(inst)	local old_GetAttackRange = inst.GetAttackRange	function inst:GetAttackRange()		local range = self.attackrange		local weapon = self:GetWeapon()		if weapon and weapon.components.weapon.variedmodefn then			local weaponrange = weapon.components.weapon.variedmodefn(weapon)			range = range + weaponrange.attackrange		elseif weapon and weapon.components.weapon.attackrange                or (weapon.components.weapon.variedmodefn ~= nil		and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange) then			range = range + weapon.components.weapon.attackrange		end		return range	endend)

Link to comment
Share on other sites

I appreciate your effort to help.

 

Sure, I don't see why not. I'll add you. Steam is http://steamcommunity.com/id/lagstabcoming .

 

I tried both codes, copying and pasting them both exactly into the bottom of modmain.lua. However, the splumonkey poop toss crash still causes the game to crash with errors both related to the same line in combat.lua.

 

Here's the error:

http://imgur.com/U9jMUV2

 

If it helps, according to khirsah (the steam user who fixed the error via combat.lua changes), he/she stated that:

 

[Line 648 of combat.lua in Don't Starve Together Beta/data/scripts/components:]

or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weaponrange.components.weapon.variedmodefn(weapon).hitrange)

So yea an error here, as it confirms [weaponrange] exists then checks something else. Weaponrange should not exist, it's not declared anywhere else in any lua file i can see. So I assume changing it to read

 

or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)

 

would be correct.

 

 

 

 
Edited by Dougles
Link to comment
Share on other sites

@Maris This is only a temporary solution, it wouldn't be published, that's why I didn't care that much. And I can't find a way to add the change and still return the old function. Maybe you can, I don't know.

 

@Dougles The function causing the error is CalcAttackRangeSq, which calls GetAttackRange. I am really stupid for not seeing that.

 

I edited the mod and did this, just for me, and it seems to work. I had a monkey throw poop at me three times and it didn't crash.

AddComponentPostInit("combat", function(inst)	local old_CalcAttackRangeSq = inst.CalcAttackRangeSq	function inst:CalcAttackRangeSq(target)		target = target or self.target or (weapon.components.weapon.variedmodefn ~= nil	        and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)	    local range = self:GetAttackRange() + (target.Physics and target.Physics:GetRadius() or 0)	    return range*range	endend)

To be honest I'm not that good and I don't understand how the new line fixes it but yeah, it works.

Link to comment
Share on other sites

 
After placing the new code at the bottom of the modmain.lua, it seems the game still crashes after when poop toss is used (unless the edited combat.lua is used). I still receive the same error message.

 

Here's what the modmain.lua currently looks like. The only difference from the original modmain.lua is the very last part of the text.

PrefabFiles = {"minotaur","slurper","slurtle","cavespiders","worm","monkey","rocky","dropperweb","slurtlehole","monkeybarrel","cave_banana_tree","nightmarecreature",}GLOBAL.TUNING.MINOTAUR_DAMAGE = 200GLOBAL.TUNING.MINOTAUR_HEALTH = 5000GLOBAL.TUNING.MINOTAUR_TARGET_DIST = 15GLOBAL.GetNightmareClock = function () return nil end--local function AddAmbientLight(inst)--print("replacing ambientlightning")--inst:AddComponent("ambientlightning_custom")--inst:RemoveComponent("ambientlightning")--inst.components.ambientlightning = inst.components.ambientlightning_custom--end--AddPrefabPostInit("world", AddAmbientLight)-- ONLY EDIT PART DOWN BELOWAddComponentPostInit("combat", function(inst)local old_CalcAttackRangeSq = inst.CalcAttackRangeSqfunction inst:CalcAttackRangeSq(target)target = target or self.target or (weapon.components.weapon.variedmodefn ~= niland self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)local range = self:GetAttackRange() + (target.Physics and target.Physics:GetRadius() or 0)return range*rangeendend)

 

(I appreciate the help. However, if this is not something simple, I wouldn't stress over it. I only made this thread because I was assuming it would be).

Edited by Dougles
Link to comment
Share on other sites

So it turns out after extensive research, the problem was that we had was that different "combat.lua"'s. I have the DST RoG version of combat.lua, and he has the vanilla one.

 

With that said, the above code does not work for RoG DST. I should have clarified that:

  1. This mod did work in Vanilla, but no longer works with the RoG version of DST.
  2. The method in the opening post allows the mod to be compatible with RoG. However, requires you to edit a file (combat.lua) that is outside of the folder. 
  3. I was wondering if there was any alternatives to that (I wouldn't mind a whole-file replacement of combat.lua with a combat_cumstom.lua - the custom file simply being combat.lua with the line 648 edit).

Due to not being able to find any decent examples of whole file replacement, and me being inexperienced, I am having difficulties doing so. Any help with be appreciated. 

Edited by Dougles
Link to comment
Share on other sites

Hm, I'm not sure what's going on. You just want to port this mod for DST RoG? Or something else?

I could help, but better and faster way for me is to download the mod and do all job by myself.

Link to comment
Share on other sites

I didn't think it would be this confusing. Allow me to clarify the situation.

 

There is already a method to make the mod work with RoG, as shown here:

 

 

Go to the /Don’t Starve Together Beta/mods folder. Then find the folder representing the extended map generation mod. Go into the scripts folder and change the following:

(1) In “rocky.lua”, change line 170 to
inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })

(2) In “worm.lua“, change line 210 to
inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODGROUP.OMNI })

(3) In “cavespiders.lua”, change line 215 to
inst.components.eater:SetDiet({ FOODTYPE.MEAT }, { FOODTYPE.MEAT })

(4) In “monkey.lua”, change line 366 to
inst.components.eater:SetDiet({ FOODTYPE.VEGGIE }, { FOODTYPE.VEGGIE })

(5) In "slurtle.lua", line 112 needs to be changed to:

inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })

 

(6) Then go to the /Don’t Starve Together Beta/scripts/components folder. Change line 648 of Combat.lua with:

 

or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)

 

(The bolded part is what I'd like an alternative to).

 

However, the last step involves editing the combat.lua found in /Don’t Starve Together Beta/scripts/components folder. That's outside the mod's folder. I was just wondering if there was an alternative to that, such as having a combat_custom.lua that replaces the combat.lua, but is still within the mod's folder. (Every other change involves changing files within the mod. That I don't mind.)

 

To fix the error caused by combat.lua, line 648 must be replaced with:

 

or (weapon.components.weapon.variedmodefn ~= nil and self.hitrange + weapon.components.weapon.variedmodefn(weapon).hitrange)

 

I figure I'd just be easier to make a duplicate combat.lua called combat_custom.lua that has the fix, and replaces the original combat.lua, but still remains in the mod folder. Basically, the combat_custom.lua would potentially be the attached file. I just have no idea how to actually make the the combat_custom.lua replace the original combat.lua.

combat_custom.lua

Edited by Dougles
Link to comment
Share on other sites

We don't really use any mods anyway, and this is only meant to be a band-aid solution until the original mod author updates anyway.

 

Thanks for all the help Morris. Also, this thread can be closed.

Edited by Dougles
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...