Rakashy Posted October 26, 2020 Share Posted October 26, 2020 Guys I don't know what's wrong, when you completely fill the Hunger bar, even if the thirst is empty, it returns the message that you don't need to eat / drink anything, and sometimes when you fill the thirst bar first, he sets the hunger to 100% ... I'm lost here, can someone help me? the system is integrated with an inventory, you select the food, and click to eat / drink. part of client local s = {guiGetScreenSize()} local box = {36,36} local panel = {s[1]/2 -box[1]/2,s[2]/1.25 - box[2]/1.25} local barItem = 0 local barNum = 0 local barShow = false local barSize = 98 local barHealth = 0 local newAmount = 0 local hasznalhat = false function me(me) triggerServerEvent("chat.me", localPlayer, localPlayer, me) end function itemBar(num,itemID,health) barShow = true barItem = itemID barNum = num barHealth = health newAmount = (barHealth/10) /2 triggerServerEvent("attachItemPlayer",localPlayer,localPlayer,items[itemID].object) end addEventHandler("onClientRender",getRootElement(),function() if barShow == true then dxDrawRectangle(panel[1],panel[2],36+6,36+6,tocolor(0,0,0,140)) dxDrawImage(panel[1] + 3,panel[2] + 3,36,36,getItemImg(barItem)) dxCreateBorder(panel[1]-32,panel[2]+60,100,6,tocolor(0,0,0,180)) dxDrawRectangle(panel[1]-32,panel[2]+60,100,6,tocolor(0,0,0,90)) dxDrawRectangle(panel[1]-30,panel[2]+62,barSize,5,tocolor(208,101,29,250)) end end) function hungBarClick(button, state) cancelEvent() if barShow == true then if button == "right" and state == "down" then if isInSlot(panel[1],panel[2],36,36) then if isTimer(hungTimer) then return end hungTimer = setTimer(function() end, 4000, 1) if getElementData(localPlayer, "hunger") == 100 then exports.vz_info:showBox("Você não precisa comer/beber", "error") return false elseif getElementData(localPlayer, "sede") + newAmount > 100 then setElementData(localPlayer, "sede", 100) return true end barSize = barSize-14 if barNum == 1 then setElementData(localPlayer,"hunger",getElementData(localPlayer,"hunger")+newAmount) triggerServerEvent("itemAnims",localPlayer,localPlayer,1) elseif barNum == 2 then setElementData(localPlayer,"sede",getElementData(localPlayer,"sede")+(newAmount/2)) triggerServerEvent("itemAnims",localPlayer,localPlayer,2) end if barSize <= 1 then triggerServerEvent("detachItemPlayer",localPlayer,localPlayer) barShow = false barSize = 98 end end elseif button == "left" and state == "down" then if isInSlot(panel[1],panel[2],36,36) then barShow = false barSize = 98 triggerServerEvent("detachItemPlayer",localPlayer,localPlayer) end end end end addEventHandler("onClientClick", root, hungBarClick) Link to comment
UndR Posted October 28, 2020 Share Posted October 28, 2020 (edited) `getElementData` will return either 'nil' or 'false' ( not sure about the nil thing ) incase the Element doesn't have the specified data so you need to try something like getElementData(localPlayer, "hunger") or 100 Edited October 28, 2020 by UndR 1 Link to comment
Rakashy Posted October 28, 2020 Author Share Posted October 28, 2020 1 hour ago, UndR said: `getElementData` will return either 'nil' or 'false' ( not sure about the nil thing ) incase the Element doesn't have the specified data so you need to try something like getElementData(localPlayer, "hunger") or 100 I'm also not sure if this will work, but I will test here 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now