How could I get a working hunger system c#?
-
I saw how in simple zombies by @Sollaholla he did it. I'd need this for the working drive thru mod
-
@NotCrunchyTaco I used native UI, and created a dummy class that holds data about the stat, then I made new copys of each of the dummy classes and stored them in a list.
When I loop through the list I draw the data from the class on screen and do something like this:
stats[i].Value -= Game.LastFrameTime * someModifierValue;
I also had a public function like "Eat(float amount)" and looped again and just did
stats[i].Value += amount;
That's the basic synopsis of my code.
-
@sollaholla Ah, I see thanks man hopefully this will help!
-
@sollaholla I know this may be a big favor but do you happen to have a sample?
-
Well, a simple way to set it up would be setting a hunger variable to 100, then substracting X each Y seconds.
Then you would have the base hunger, you would then just need to increase the variable's value when you eat.
Voilá
-
@NotCrunchyTaco Not invited to the thread, still crashing the party and sharing some info as I had this included in one of my mods.
Its simple, as @Eddlm said, set your float value to 100 and then check the value when you want it to decrease. Anyways, here is how I did it, I get the in game minute from the Get_Clock/Get_Min Native. If number of mins have passed from base time, decrease the value by certain %, then get the current time and set it to base time, so your script will add the mins interval and wait till then.
P.S. I am unsure, but if I remember it correctly, I referenced this to Player Sprint as well. If he sprints for longer, the hunger bar and sleep bar goes down equally.
-
float hunger = 100; public MyScript() { Tick += OnTick; } private void OnTick(object sender, EventArgs e) { if (Game.Player.Character.IsDead) { hunger = 100; return; } // 0.05 might be too low, because the calculator tells me that'll take 33.33333 minutes to run out. (0.05 a second) hunger -= Game.LastFrameTime * 0.05f; if (hunger <= 0) { Game.Player.Character.Kill(); UI.Notify("You ~r~died~s~ of starvation!", true); } }
-
@sollaholla I can't express how helpful this is! Thank you man!!
-
@sollaholla Also, one last thing small thing. Would I have to set the OnTick Interval to any specific value?
-
@NotCrunchyTaco No, if you're using
Game.LastFrameTime
it shouldn't be dependent on any interval. (LastFrameTime, believe, is calculated every 1 millisecond by the game. I could be wrong.)
-
@sollaholla alright