-- DESCRIPTION: smallg thirst script -- DESCRIPTION: Script requires at least image "thirst100.png" -- DESCRIPTION: [ThirstEnabled!=1] if the thirst system is currently active in game or not -- DESCRIPTION: [CurrentThirst=100] starting thirst level (max is always 100) -- DESCRIPTION: [ThirstRate=10] how quickly the thirst bar drops per minute (i.e. 1 = 1 percent every 60s) -- DESCRIPTION: [CanHurtPlayer!=1] if script can also damage the player -- DESCRIPTION: [Damage=1] how much damage to apply if so per tick (or every 0.25s) -- DESCRIPTION: [HurtBelow=0] when the damage should start triggering (i.e. if below 50 percent thirst etc) -- DESCRIPTION: [ThirstImageX=90] x position of image on screen -- DESCRIPTION: [ThirstImageY=1] y position of image on screen -- DESCRIPTION: [ThirstImageWidth=10] how wide the icon is -- DESCRIPTION: [ThirstImageHeight=10] how tall the icon is (200 to keep aspect) -- DESCRIPTION: [ShowThirstText!=1] display the thirst percentage as text -- DESCRIPTION: [ThirstTextX=95] x position of the text -- DESCRIPTION: [ThirstTextY=5] y position of the text -- DESCRIPTION: [ThirstTextSize=3] size of the text U = U or require "scriptbank\\utillib" local thirstimg = {} local thirstspr = nil local timer1 = nil local timer2 = nil local timer3 = nil thirstE = nil g_thirst = {} function thirst_properties(e, thirstenabled, currentthirst, thirstrate, canhurtplayer, damage, hurtbelow, thirstimagex, thirstimagey, thirstimagewidth, thirstimageheight, showthirsttext, thirsttextx, thirsttexty, thirsttextsize) local t = g_thirst[e] t['thirstenabled'] = thirstenabled t['currentthirst'] = currentthirst t['thirstrate'] = thirstrate t['canhurtplayer'] = canhurtplayer t['damage'] = damage t['hurtbelow'] = hurtbelow t['thirstimagex'] = thirstimagex t['thirstimagey'] = thirstimagey t['thirstimagewidth'] = thirstimagewidth if thirstimageheight == 200 then thirstimageheight = -1 end t['thirstimageheight'] = thirstimageheight t['showthirsttext'] = showthirsttext t['thirsttextx'] = thirsttextx t['thirsttexty'] = thirsttexty t['thirsttextsize'] = thirsttextsize end --don't modify init(e) - use the editor properties panel function thirst_init(e) local function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end g_thirst[e] = {} for a = 0, 100 do local img = "scriptbank\\smallg_max\\images\\thirst\\thirst"..a..".png" if file_exists(img) == true then thirstimg[a] = LoadImage(img) end end thirstE = e end function thirst_main(e) local function round(num, numDecimalPlaces) local mult = 10^(numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end local t = g_thirst[e] if thirstspr == nil then thirstspr = CreateSprite(thirstimg[100]) SetSpritePosition(thirstspr,200,200) SetSpriteSize(thirstspr,t['thirstimagewidth'],t['thirstimageheight']) end --check the thirst system is active if t['thirstenabled'] == 1 then --how to deal with player death and thirst levels? --should thirst be restored when player dies? should it only restore if player dies from thirst (i.e. not combat)? if g_PlayerHealth < 1 then if t['currentthirst'] < 1 then t['currentthirst'] = 100 end end --timer stuff for updating the thirst tick if timer1 == nil then timer1 = g_Time timer3 = t['thirstrate'] end timer2 = g_Time-timer1 --get the current thirst as a percentage local thirstperc = (t['currentthirst'] / 100)*100 --thirst levels and damage is updated every 0.25s (to keep the animations smooth and consistent) if timer2 >= 250 then timer1 = g_Time t['currentthirst'] = t['currentthirst']-(t['thirstrate']/240) if t['currentthirst'] < 0 then t['currentthirst'] = 0 end --check if player should also be damaged with each tick if t['canhurtplayer'] == 1 then if thirstperc < t['hurtbelow'] then HurtPlayer(e,t['damage']) end end end --update the thirst icon image to match the new % for a = 100, 0, -1 do if thirstperc <= a then if thirstimg[a] ~= nil then SetSpriteImage(thirstspr, thirstimg[a]) end else break end end PasteSpritePosition(thirstspr,t['thirstimagex'],t['thirstimagey']) --show the thirst as text too if t['showthirsttext'] == 1 then thirstperc = round(thirstperc) TextCenterOnX(t['thirsttextx'],t['thirsttexty'],t['thirsttextsize'],thirstperc.."%") end end end --this function should be called from your collectable items (i.e. drinks etc) function Drink(v) local t = g_thirst[thirstE] t['currentthirst'] = t['currentthirst'] + v if t['currentthirst'] < 0 then t['currentthirst'] = 0 elseif t['currentthirst'] > 100 then t['currentthirst'] = 100 end end