Jump to content

Decreasing Food / Thirst - Chopping Tree's


CoolBeans
 Share

Recommended Posts

Decreasing Food / Thirst.

 

Hello,

 

Trying to figure out how to have a calorie and thirst system. Ive already cheated and copied

the health system twice and renamed both of them. Ive also set up 3 meters on screen

health, hunger and thirst. Eventually I want to use calories and dehydration when my charater

walks, chops, crafts, or any kind of activity for the most part. For now Id settle for a timed

system first. I just want the food and thirst levels to decrease as time goes on in game.

--float so i can adjust the speeds individually on the fly wink.png

 

Thirst script on bottle of water or what ever fluids.

 

Script.thirst = 15.0 --float "Thirst"

Script.useOnce = true --bool "Use once"

 

function Script:Start()

if self.thirst < 0 then

error("Thirst can't be a negative value.")

end

end

 

function Script:Use(player)

if player.script.thirst < player.script.maxThirst then

player.script:ReceiveThirst(self.thirst)

if self.useOnce then

self.entity:Release()

end

end

end

 

 

FPSPlayer Script

 

Script.thirst = 100 --float "Thirst"

Script.maxThirst = 100 --float "Max Thirst"

 

**

 

function Script:Thirst(Thirsty,distributorOfThirst)

if self.thirst>0 then

self.sound.damage[math.random(#self.sound.damage)]:Play()

self.thirst = self.thirst - damage

if self.thirst<=0 then

self:Kill()

end

end

end

 

 

**

 

 

 

 

--If thirst lower or equal to zero, the player is dead

if self.thirst <= 0 then

self.alive = false

--Call the OnDead output

self:OnDead()

end

end

 

--Increase thirst

function Script:ReceiveThirst(thirstPoints)--in

--Increase thirst

self.thirst = self.thirst + thirstPoints;

 

--Thirst can not be more then maximum thurst

if self.thirst > self.maxThirst then

self.thirst = self.maxThirst

end

 

--Call Thurst received output

self.component:CallOutputs("ThirstReceived")

end

 

--when thirst is zero or lower, an output call is made

function Script:OnDead()--out

--Extra check to make sure that the player is no longer alive

if not(self:IsAlive()) then

self.component:CallOutputs("Ondead")

end

 

 

Any help on the timed decrease would be awesome!

 

If you can help with other details like faster decrease of thirst in different environments like desert

or when chopping a tree etc would be a plus wink.png At least point me the direction. Further If I could have

it start to decrease your health after a certain point I just thought of! Please O' man help an amateur out!

 

Sneaking one in...

Another question. Best way to have a map full of different trees and have it to where I can chop them

down and convert them to wood. Maybe play the tree falls over animation. I found one topic

in here on this matter and it fizzled out. Need some detailed help / direction if possible. Thank you!

 

CB!

Link to comment
Share on other sites

  • 1 month later...

I think the best way to approach this is to start with one of these problems, preferably the simplest, and read the Lua tutorials with that in mind. It's very difficult if you try to do everything at once:

http://www.leadwerks.com/werkspace/page/tutorials/_/lua-scripting-r12

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

The two health bars idea is good. All you need to do for the decreasing time for thirst is something like this:

 

At the top of your code:

Script.thrist_time=0 --time to keep track of thirst
Script.thirst_max=150
Script.thirst_original=150
Script.location_rate=.0001

 

Put in Start():

self.thirst_time=Time:Millisecs()

 

Put in UpdateWorld():

self.thirst=self.thirst_original-self.location_rate*(self.thirst_time-Time:Millisecs())

 

Then, if you pick up a water bottle, then you would increase self.original by a certain amount (check to make sure it isn't over the max). Change the self.location_rate variable to change the speed at which dehydration occurs.

 

For decreasing health, you could attach it to the self.thirst level (in UpdateWorld()):

if self.thirst<10 then
 --Same logic for decreasing the thirst level (use different variables for health)
end

 

The tree question is a totally separately question though, and can be a bit more involved. I would try getting the first stuff above to work as it might give you more insight into how to do this.

Link to comment
Share on other sites

In Dead Anyway we have a bunch of stats that are all 0 - 100 like thirst, hunger, sleep, temp, etc and we use a weighted average from those to make the overall health value. Thirst is the highest weighted followed by sleep/rest, hunger, temp etc. This tries to mimic real life in terms of how long you can survive in real life converted to game days.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...