Jump to content

Recommended Posts

Hello Don't Starve modding community! 

 

Late last year, I had started working on a new project, an item mod, which I had already asked some help for. I was having troubles with the animation, thankfully this was fixed (thanks to you). Since then, I worked a little more on the mod, but decided to take a short break, which turned into a very long break ( several months). But now I am back, to finish my mod once and for all.

 

The problem I am having this time is this:

 

The item is supposed to be edible, and comes with certain side effects when consumed. When I don't declare this item's foodtype, it can be consumed, but does not provide the effects. When I do declare the foodtype ( which I saw in plenty of working mods), I come across an issue. The item only shows an "examine" option in game, and does not allow me to eat it.

 

What I'm looking to do, is to make the item edible, AND to provide the side effects. I looked a lot at wx78.lua, gears.lua, and some random mods ( since the item is similar to these), and have tried nearly everything. With no success.

 

Help would be much appreciated!

 

Thanks,

 

jimmeh57

 

 

levelups.zip

My guess is you've defined a foodtype, "Xptoken" but, by default none of the characters can eat it, WX is able to eat gears, because it's defined in his code that he can eat that food-type, but since xptoken isnt a native foodtype, none of the characters can eat it, and, as far as i've seen, you've made it to where upon eating the foodtype Xptoken, then you get the upgrades, perhaps making it where it gives the stats upon eating the item instead of the foodtype, or making the foodtype edible by all characters.

My guess is you've defined a foodtype, "Xptoken" but, by default none of the characters can eat it, WX is able to eat gears, because it's defined in his code that he can eat that food-type, but since xptoken isnt a native foodtype, none of the characters can eat it, and, as far as i've seen, you've made it to where upon eating the foodtype Xptoken, then you get the upgrades, perhaps making it where it gives the stats upon eating the item instead of the foodtype, or making the foodtype edible by all characters.

 

Thanks for responding so quickly!

 

I think that I could try both options, but I would like to attempt the latter first(making the foodtype edible to all characters). I have an idea on how to go about doing this, but I'll need a bit more help:

 

I found this line in wx78.lua -- table.insert(inst.components.eater.foodprefs, "GEARS")

 

...I'm guessing this is what I should do, but for "xptoken" instead?

 

If so, I have no idea where to put this line in the code.

 

 

Thanks for responding so quickly!

 

I think that I could try both options, but I would like to attempt the latter first(making the foodtype edible to all characters). I have an idea on how to go about doing this, but I'll need a bit more help:

 

I found this line in wx78.lua -- table.insert(inst.components.eater.foodprefs, "GEARS")

 

...I'm guessing this is what I should do, but for "xptoken" instead?

 

If so, I have no idea where to put this line in the code.

 

Remember, whenever two prefabs have the same name in modding (e.g. base file name == sword and mod file name is sword, then the game uses the mod sword)

 

So, logical fix is this = Copy the .lua files and locations of the characters .lua files, add that line (replacing with XPTOKEN) to all of them, stick 'em in your mod folder, and test, if it doesn't work let me know, most of what im saying is theoretical since i havent got DS on my comp atm.

Remember, whenever two prefabs have the same name in modding (e.g. base file name == sword and mod file name is sword, then the game uses the mod sword)

 

So, logical fix is this = Copy the .lua files and locations of the characters .lua files, add that line (replacing with XPTOKEN) to all of them, stick 'em in your mod folder, and test, if it doesn't work let me know, most of what im saying is theoretical since i havent got DS on my comp atm.

 

I'm not sure if I understood this correctly, but this is what I did (inside modmain.lua):

 

local function eatxptokens(inst)
 
table.insert(inst.components.eater.foodprefs, "XPTOKEN")
end
 
...
 
AddPrefabPostInit( ??? , eatxptokens)
 
I'm not sure if this is right at all, but I'm hoping that all I have to do is replace ??? with something. Just I don't know what.

Remember, whenever two prefabs have the same name in modding (e.g. base file name == sword and mod file name is sword, then the game uses the mod sword)

 

So, logical fix is this = Copy the .lua files and locations of the characters .lua files, add that line (replacing with XPTOKEN) to all of them, stick 'em in your mod folder, and test, if it doesn't work let me know, most of what im saying is theoretical since i havent got DS on my comp atm.

So I replaced ??? with 'wilson', and now I am able to eat the xptokens only on wilson. My question is, what do I put so that it automatically works on all characters ( including mod characters).

 

Note: The side effects still don't work when the token is eaten.

So I replaced ??? with 'wilson', and now I am able to eat the xptokens only on wilson. My question is, what do I put so that it automatically works on all characters ( including mod characters).

 

Note: The side effects still don't work when the token is eaten.

Not entirely sure what you did here, can you send me a download link for the new mod? i'd like to take a look at it

Remember, whenever two prefabs have the same name in modding (e.g. base file name == sword and mod file name is sword, then the game uses the mod sword)

 

So, logical fix is this = Copy the .lua files and locations of the characters .lua files, add that line (replacing with XPTOKEN) to all of them, stick 'em in your mod folder, and test, if it doesn't work let me know, most of what im saying is theoretical since i havent got DS on my comp atm.

While this would "work," it's the worst possible solution in terms of compatibility with other mods (and compatibility with game updates). Overwriting game files should only be used as an absolute last resort and should be avoided whenever possible.

So I replaced ??? with 'wilson', and now I am able to eat the xptokens only on wilson. My question is, what do I put so that it automatically works on all characters ( including mod characters).

 

Note: The side effects still don't work when the token is eaten.

Use AddSimPostInit. It gives you whatever player is currently being played as the parameter.

AddSimPostInit(eatxptokens)

While this would "work," it's the worst possible solution in terms of compatibility with other mods (and compatibility with game updates). Overwriting game files should only be used as an absolute last resort and should be avoided whenever possible.

Use AddSimPostInit. It gives you whatever player is currently being played as the parameter.

 

AddSimPostInit(eatxptokens)

Thank you! I tested this with multiple characters and now all of them can eat the item.

 

I only need help with one more thing now: getting the effects to work. I basically copied some lines off of wx78.lua ( with some minor changes), since he gets upgraded when eating gears. The code looks alright to me, yet it still won't work. Would you happen to know what's wrong?

Thank you! I tested this with multiple characters and now all of them can eat the item.

 

I only need help with one more thing now: getting the effects to work. I basically copied some lines off of wx78.lua ( with some minor changes), since he gets upgraded when eating gears. The code looks alright to me, yet it still won't work. Would you happen to know what's wrong?

You have some code in weird places. There's no reason to ever use a PrefabPostInit on a custom prefab, all that stuff should just go in your prefab's file.

A bunch of the local functions in modmain.lua are never used for anything. All those should presumably be used in a character prefab, but if the goal is to make the XP Token work on all characters, you probably want to take a different approach (make the level up code into a component that gets added to all players using a PostInit [see this thread for information about adding a component with save data to all players], and then make the XP Token have an oneat callback function to do the leveling).

Edited by squeek

You have some code in weird places. There's no reason to ever use a PrefabPostInit on a custom prefab, all that stuff should just go in your prefab's file.

A bunch of the local functions in modmain.lua are never used for anything. All those should presumably be used in a character prefab, but if the goal is to make the XP Token work on all characters, you probably want to take a different approach (make the level up code into a component that gets added to all players using a PostInit [see this thread for information about adding a component with save data to all players], and then make the XP Token have an oneat callback function to do the leveling).

 

Hi, sorry for the late response, but I'm a bit confused about what to do here. I think I know what you mean by the oneat callback function, but making the level up code into a component, I don't.

 

Here is what I tried doing after reading your comment, but it didn't really get anywhere:

 

levelups.zip

 

Do I need to make a new file along with modmain and the prefab is my main question, and also, how would i get to "oneat" from xptoken.lua if this is the case?

Here's what I was talking about:

attachicon.giflevelups.zip

 

Wow, thank you so much! I tested it, and it works great!

 

Now all I have to do is look through the code and try to understand it, for I would have never came up with the solution. I guess it's all a learning experience.

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
×
  • Create New...