Kelly003 Posted July 1, 2021 Share Posted July 1, 2021 I do a healing system and I checked the amount of cash with me and when you have a certain amount, it takes it from us and gives you hp. The problem is how to check the amount of hp so that it does not take cash unnecessarily when someone has 100% hp. addEventHandler("onClientClick", root, function(btn, state) if btn == 'left' and state == 'down' then if data.open == true then if isMouseInPosition(screenW * 0.4081, screenH * 0.3932, screenW * 0.1846, screenH * 0.0560) then if getElementHealth(localPlayer) ~= 100 then outputChatBox("Your hp is full!") end if getPlayerMoney(localPlayer)<500 then outputChatBox("No money") else takePlayerMoney(500) setElementHealth(localPlayer, 100) outputChatBox("Transaction completed") end end if isMouseInPosition(screenW * 0.6007, screenH * 0.2943, screenW * 0.0176, screenH * 0.0352) then showGUI() end end end Link to comment
βurak Posted July 2, 2021 Share Posted July 2, 2021 (edited) use getPedMaxHealth function to find player's max health also use server side to set player's money I'm not sure but it could be like this client: function getPedMaxHealth(ped) -- Output an error and stop executing the function if the argument is not valid assert(isElement(ped) and (getElementType(ped) == "ped" or getElementType(ped) == "player"), "Bad argument @ 'getPedMaxHealth' [Expected ped/player at argument 1, got " .. tostring(ped) .. "]") -- Grab his player health stat. local stat = getPedStat(ped, 24) -- Do a linear interpolation to get how many health a ped can have. -- Assumes: 100 health = 569 stat, 200 health = 1000 stat. local maxhealth = 100 + (stat - 569) / 4.31 -- Return the max health. Make sure it can't be below 1 return math.max(1, maxhealth) end addEventHandler("onClientClick", root, function(btn, state) if btn == 'left' and state == 'down' then if data.open == true then if isMouseInPosition(screenW * 0.4081, screenH * 0.3932, screenW * 0.1846, screenH * 0.0560) then if (getElementHealth(localPlayer) >= getPedMaxHealth(localPlayer)) then outputChatBox("Your hp is full!") return end if (getPlayerMoney(localPlayer) < 500) then outputChatBox("No money") return else if(getPlayerMoney(localPlayer) > 500 and getElementHealth(localPlayer) < getPedMaxHealth(localPlayer)) then triggerServerEvent("takeMoneyFromPlayer", localPlayer, 500) setElementHealth(localPlayer, getPedMaxHealth(localPlayer)) outputChatBox("Transaction completed") end end end if isMouseInPosition(screenW * 0.6007, screenH * 0.2943, screenW * 0.0176, screenH * 0.0352) then showGUI() end end end server: addEvent("takeMoneyFromPlayer", true) addEventHandler("takeMoneyFromPlayer", root, function(amount) local theAmount = tonumber(amount) takePlayerMoney(source, theAmount) end ) Edited July 2, 2021 by Burak5312 1 Link to comment
Kelly003 Posted July 2, 2021 Author Share Posted July 2, 2021 I already did it myself, but thanks for the answer anyway 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