Defranco Posted February 18, 2017 Share Posted February 18, 2017 Script.thirst = 100 --float "Thirst" Script.maxThirst = 200 --float "Max Thirst" Script.thirst_time = 0 --time to keep track of thirst Script.location_rate_thirst = -0.00000008 Script.healthLocation_ratethirst = .12 --(this part is inside the script: start area)-- --Activate Thirst self.thirst_time = Time:Millisecs() --(this controls using items that give thirst back to player)-- Not really relevant to the timer function. function Script:ReceiveThirst(thirstPoints) --Increase thirst self.thirst = self.thirst + thirstPoints; if self.thirst > self.maxThirst then self.thirst = self.maxThirst end self.component:CallOutputs("ThirstReceived") end --(this part is inside the script: Update World area)-- -- Update Thirst if self.thirst > 0 then self.thirst=self.thirst-self.location_rate_thirst*(self.thirst_time-Time:Millisecs()) end if self.health > 0 then if self.thirst < 5 then self.health=self.health-self.healthLocation_ratethirst; end end if self.thirst > self.maxThirst then self.thirst = self.maxThirst end What I am trying to do: Have thirst decrease at a steady rate that keeps the same forever. Then if it hits lower than 5, it starts damaging the player over time until the player drinks to get thirst back. So what this script seems to be doing is increasing over-time. The first 20 seconds seems normal. But as time increases, so does the rate of decrease. Just an Example: First 1-20 seconds it decreases at 0.5 per second, then 21-40 it decreases at 0.8 per second, then at 41-60 seconds it decreases at 1.2 per second. It seems to be adding on extra time as time goes on and increases the rate. Not sure what I'm missing. Quote Link to comment Share on other sites More sharing options...
macklebee Posted February 18, 2017 Share Posted February 18, 2017 Its because the value that you keep subtracting from 'self.thirst' is constantly getting larger. self.thirst=self.thirst-self.location_rate_thirst*(self.thirst_time-Time:Millisecs()) Time:Millisecs() returns the system time in milliseconds. if you want a constant rate of decrease then do something like: function Script:UpdateWorld() if self.thirst > 0 then self.currenttime = Time:Millisecs() if self.currenttime>self.thirst_time+2000 then -- 2000 = 2 seconds self.thirst = self.thirst - 0.5 --- or however much you want to descrease but should be a constant if thats what you want self.thirst_time = self.currenttime end end ... end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Defranco Posted February 18, 2017 Author Share Posted February 18, 2017 Thanks, that worked perfect. I didn't think it would constantly get larger in the one I was using previous. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.