Author Topic: Simple hunger mod w/ food items  (Read 1111 times)

I tried to make this myself but I'm utter stuff at coding. Basic premise is that it uses a modified version of the LL Food Pack items, and a simple hunger system. Every player starts out with 100 food and it slowly ticks down at a variable rate. When it reaches 0, the player dies.

The food items, when consumed, makes the food go up, with a variable hunger cap that can be set over 100.

just drafting out a setup here:

package gameconnection::spawnplayer to start a hunger tick + bottomprint on the player. store schedule in %client.hungerTick
every tick increase %client.hunger. if hunger > 100 kill, or start a hurting loop. for any bottomprint, floor the value to remove decimals
if we want to increase hunger growth based on certain actions package that and add hunger for those actions
for each item, make the function onFire remove the item and reduceHunger from the player. in reduceHunger do a check for %client.hunger being below 0 or whatever limit is set.

just drafting out a setup here:

package gameconnection::spawnplayer to start a hunger tick + bottomprint on the player. store schedule in %client.hungerTick
every tick increase %client.hunger. if hunger > 100 kill, or start a hurting loop. for any bottomprint, floor the value to remove decimals
if we want to increase hunger growth based on certain actions package that and add hunger for those actions
for each item, make the function onFire remove the item and reduceHunger from the player. in reduceHunger do a check for %client.hunger being below 0 or whatever limit is set.

Maybe instead of the bottomprint for the hunger, have it so every time hunger decreases past an interval of 20, it will display variable "You've gotten hungrier" to "You're starving" messages in chat

Bottomprint is probably too intrusive for what should definitely be single messages

I'm bumping this cause I still need this

Well, I made an edit of those food items. Not sure how balanced this is. There is 3 preferences, one being $Pref::Server::MaxHunger which stands for the max hunger default being 100 (decay and food consumption adjusts accordingly) as for $Pref::Server::HungerLoopTime it's default is 90; which means every 90 seconds hunger will increase. Done very little testing. Plus I added some events that let you add a player variable "Food" /eatfood <amount> is how you consume it. Use $Pref::Server::HungerRate to increase the rate of hunger increasing, default being 1 multiplies the rate by 1.

$Pref::Server::MaxHunger (Default; 100)
$Pref::Server::HungerRate (Default; 1)
$Pref::Server::HungerLoopTime (Default; 90)

(Editted Food Items + Mod)

Link:  http://www.mediafire.com/download/8nykcbfuyd9kwdx/Hunger_Mod.zip

Edit: FIXED
« Last Edit: July 20, 2016, 01:20:26 PM by Soretooth »

I'll check it out, thanks!

Well, I tried out Soretooth's mod, but as soon as my hunger reaches 100/100, I do not die or my health does not slowly lower?

Well, I tried out Soretooth's mod, but as soon as my hunger reaches 100/100, I do not die or my health does not slowly lower?

I don't think he tested it completely because he's missed out a looping schedule responsible for calling the hunger effects function he's created. He has the cancel function line there but has forgotten about the actual schedule itself, so this should fix it:

Code: [Select]
%player.StatusEffectLoop = %player.schedule($Pref::Server::HungerLoopTime * 1000, StatusEffects);
Put the above under line 71 in the server.cs of Server_Hunger.

I appreciate it, Paperwork.

Edit: Okay, after I added that in under line 71, the mod is broken and I cannot get it to work. Here's the code from the console.

Code: [Select]
Loading Add-On: Server_Hunger (CRC:1298818730)
Add-Ons/Server_Hunger/server.cs Line: 72 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^    else if(%player.Hunger >= ($Pref::Server::MaxHunger * 0.95) && %player.Hunger < $Pref::Server::MaxHunger)

^    {

^^  %player.addHealth(-0.3);

^    }

^    else if(%player.Hunger >= $Pref::Server::MaxHunger)

^    {

^^  %player.kill();

^    }

        % ##p##layer.StatusEffectLoop = % player.schedule($Pref::Server::HungerLoopTime * 1000, StatusEffects);

    }

}



function Player::HudDisplay(%player)

{

 if(%player.getClassName() $= "Player")

 {

^cancel(%player.HudDisplayLoop);

^if(isObject(%player))

^{
>>> Error report complete.

ADD-ON "Server_Hunger" CONTAINS SYNTAX ERRORS
« Last Edit: July 19, 2016, 04:06:37 PM by Spartan224 »

I appreciate it, Paperwork.

Edit: Okay, after I added that in under line 71, the mod is broken and I cannot get it to work. Here's the code from the console.

There shouldn't be any spaces between the % symbol and player on the code you added, it should just be %player.

Ah, that did the trick. Thank you for spotting that.

Sorry guys about not testing at all. I knew it'd at least be mostly functional, thanks for fixing it. I'll update that link so people don't need to add crap in themselves.

Link:  http://www.mediafire.com/download/8nykcbfuyd9kwdx/Hunger_Mod.zip
« Last Edit: July 20, 2016, 01:21:10 PM by Soretooth »