Jump to content

Raw Meat/ Monster Meat Eating Code?


Recommended Posts

Hey-o so I barely use forums buuuut- 

I'm trying to make a personal custom modded character for well, myself; and one of his traits is that he can eat basically any food without problems (example- Raw meat, I'd expect raw/cooked Monster meat wouldn't effect him too.) but with the code I've tried nothing seems to give him either health / sanity back from eating the items or at least preventing the loss of health / sanity in the first place. Can anyone help me out? 

I'm able to post pictures of what I have if that would help too, I tried to modify some code from another mod that allowed the eating thing that would perfectly fit him if it actually worked. 

Edit: Tried also copied over  the code from Webber (strong stomach) but not seeing any difference too.

Edited by Judathian
Link to comment
Share on other sites

On 11/19/2017 at 4:42 AM, Lumina said:

The code for webber will allows to eat monster meat without penalty, not classic raw meat.

Right, but I've tried that as well but yet I still get a penalty (the normal health and sanity loss); I honestly don't know why it's not working unless I've messed something up, tho thankfully it's not crashing me if I have messed up.

It's acting like the code in it isn't there I guess? 

(I've made character mods before, I've just never tried making one that had "buffs" I guess? At least when it comes to eating n stuff) 

Edited by Judathian
Link to comment
Share on other sites

7 hours ago, DarkKingBoo said:

You are putting it in the master_postinit right? Share your mod.

Ohhh! I didn't know I had to put it there, I was putting it as just another common_postinit / local_postinit; that could be the problem

-

Edit: Yea that fixed it! Thank you so much!!

Edited by Judathian
Link to comment
Share on other sites

12 minutes ago, DarkKingBoo said:

Just for clearing things up, common_postinit is clientside code, while master_postinit is serverside.

Ohhh makes sense okay, thank you so much again on clearing that part up for me! ;v;

Tho does anyone know any code for eating raw meat w/o penalty?

Link to comment
Share on other sites

I dealt with sanity losses kinda unconventional way. Code from .../mods/modname/scripts/prefabs/character.lua:
 

--where to add it
local function fn(inst)
  --prevent setting sanity value to nil
  inst.components.sanity.lastvalue = inst.components.sanity.current
  --Override sanity.doDelta
  inst.components.sanity.DoDeltaX = inst.components.sanity.DoDelta
  inst.components.sanity.DoDelta = function(self, delta, overtime)
    self.lastvalue = self.current
    self:DoDeltaX(delta, overtime)
  end
  --Event and conditions could differ
  inst:ListenForEvent("oneatsomething", function(inst, data)
    if data.food.components.edible.foodtype == "MEAT"
    and data.food.components.edible.sanityvalue < 0
    then
      --revert last sanity change
      inst.components.sanity.current = inst.components.sanity.lastvalue
    end
  end)

This method has a little flaw: there is still sound and HUD animation which signals about sanity loss. Of course, you can tweak health and hunger same way.

Link to comment
Share on other sites

9 hours ago, staeros said:

I dealt with sanity losses kinda unconventional way. Code from .../mods/modname/scripts/prefabs/character.lua:
 


--where to add it
local function fn(inst)
  --prevent setting sanity value to nil
  inst.components.sanity.lastvalue = inst.components.sanity.current
  --Override sanity.doDelta
  inst.components.sanity.DoDeltaX = inst.components.sanity.DoDelta
  inst.components.sanity.DoDelta = function(self, delta, overtime)
    self.lastvalue = self.current
    self:DoDeltaX(delta, overtime)
  end
  --Event and conditions could differ
  inst:ListenForEvent("oneatsomething", function(inst, data)
    if data.food.components.edible.foodtype == "MEAT"
    and data.food.components.edible.sanityvalue < 0
    then
      --revert last sanity change
      inst.components.sanity.current = inst.components.sanity.lastvalue
    end
  end)

This method has a little flaw: there is still sound and HUD animation which signals about sanity loss. Of course, you can tweak health and hunger same way.

I'm not seeing a "Local function fn(inst)" ; Would it hurt if I just popped it in under the other local functions? 

Link to comment
Share on other sites

2 hours ago, staeros said:

Oh, that's a code for DS, not DST. Needed fuction is master_postinit, code for components should be there.

Ohhh! Yea I prob should have said this was ganna be a dst mod, it completely slipped my mind. I'll try it out really quick n' see if it works! 

Edit- Still seeming to drop in sanity, does this all look right?

e1c0771367.png

Edited by Judathian
Link to comment
Share on other sites

I only started with modding, dunno how API changed between DS and DST. However, I found "monsterimune"  property of "eater" component (check it in ../data/scripts/components/eater.lua), so instead of my code you better try "inst.components.eater.monsterimmune = true". I hope that will help.

Link to comment
Share on other sites

5 hours ago, staeros said:

I only started with modding, dunno how API changed between DS and DST. However, I found "monsterimune"  property of "eater" component (check it in ../data/scripts/components/eater.lua), so instead of my code you better try "inst.components.eater.monsterimmune = true". I hope that will help.

You're being a super big help for sure, I'll test it out n' see what happens (I'll just edit this in a bit with the result) 

Edit: Still losing sanity, man this is driving me crazy LOL! 

Edited by Judathian
Link to comment
Share on other sites

Remembered conventional way to do it. In Masteer_postinit()

inst.components.eater:SetOnEatFn(function(inst, food)
  if food:HasTag("meat") and food.sanityvalue < 0 then --or whatever conditions you want
    inst.sanity.DoDelta(- food.sanityvalue)
  end
end)

I wrote that code with overriding because i wanted to prevent any sanity regain except one chosen way. No need to to use elsewhere.

Link to comment
Share on other sites

6 hours ago, staeros said:

Remembered conventional way to do it. In Masteer_postinit()


inst.components.eater:SetOnEatFn(function(inst, food)
  if food:HasTag("meat") and food.sanityvalue < 0 then --or whatever conditions you want
    inst.sanity.DoDelta(- food.sanityvalue)
  end
end)

I wrote that code with overriding because i wanted to prevent any sanity regain except one chosen way. No need to to use elsewhere.

Alright so I tried to match the code as much as I could since copy pasting it would mess it up, here's what I got-

084b024360.png

99cd74700a.png

Link to comment
Share on other sites

tl;dr Change "food.sanityvalue" to "food.edible.sanityvalue". Non-tl;dr is about black magic, you'we been warned.
Typical crash log. It says that food.sanityvalue is nil and can't be compared with 0. Geing further: food is not nil, else there would be error like "trying to get property of non-object" (in lua it's tables, not objects, but whatever). There is no property called sanityvalue ("is nil" equals to "not exists"), so food is not instance of Edible. But wait, Edible is a component, not a prefab...
BTW: it's common way among modders to tweak sanity/health/hunger, but there is "near zero" bug because of it. 5 sanity + tweaked monster meat (0 sanity) = 10 sanity. How? Thing is in two inst.sanity:DoDelta() calls. First call with -10 as argument reduses 5 to 0, because there is no negative sanity in game logic. The second call (argument is 10) meant to mitigate effects of the first, adds more than was deducted before. With health it's even more funny: "non damaging" monster meat will kill character with low health. That's why "strong belly" was added into Edible.lua, while most tweaks can be written in character prefab file. Same thing with mod to cancel restoring effect and near-maximum values. That was one of reasons why I started shaman's dance with overriding. And even there I left a bug, which understood only now.

Link to comment
Share on other sites

1 hour ago, staeros said:

tl;dr Change "food.sanityvalue" to "food.edible.sanityvalue". Non-tl;dr is about black magic, you'we been warned.
Typical crash log. It says that food.sanityvalue is nil and can't be compared with 0. Geing further: food is not nil, else there would be error like "trying to get property of non-object" (in lua it's tables, not objects, but whatever). There is no property called sanityvalue ("is nil" equals to "not exists"), so food is not instance of Edible. But wait, Edible is a component, not a prefab...
BTW: it's common way among modders to tweak sanity/health/hunger, but there is "near zero" bug because of it. 5 sanity + tweaked monster meat (0 sanity) = 10 sanity. How? Thing is in two inst.sanity:DoDelta() calls. First call with -10 as argument reduses 5 to 0, because there is no negative sanity in game logic. The second call (argument is 10) meant to mitigate effects of the first, adds more than was deducted before. With health it's even more funny: "non damaging" monster meat will kill character with low health. That's why "strong belly" was added into Edible.lua, while most tweaks can be written in character prefab file. Same thing with mod to cancel restoring effect and near-maximum values. That was one of reasons why I started shaman's dance with overriding. And even there I left a bug, which understood only now.

Still gettin' errors, am I suppose to change both of them or just one? I tried changing both to it, got a error on line 72 which is 

" if food:HasTag("meat") and food.editble.sanityvalue < 0 then " (with editble added)

Then changed it to just the bottom one and got I think 73 or 72 but I can't remember exactly which it was.

Link to comment
Share on other sites

On 11/25/2017 at 7:51 AM, Lumina said:

Try removing the t in "editble", is it better ?

why was,,,a T there,,, ommmg I never even noticed alright hold on I'll check if that was the problem

- Nah, still getting errors

3ab461f116.png

I think I'm just ganna give up on the meat eating code, thanks though for everyone who tried to help!

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