• Comparing players health to their max?
    5 replies, posted
I cant seem to find the code to see if the players health is less then their max i've tried many things but none seem to work i've tried [CODE]function ITEM:OnHolster(ply) local hp = ply:Health() local maxhp = ply:GetMaxHealth() if hp < maxhp then return false else ply:SetHealth(100) ply:SetMaxHealth(100) end end[/CODE] and many other things but they dont seem to work What i want is that if the player has less than their max health then dont holster the powerup and print a message like "You may only holster if your on full health" or something
No one knows how to do this??
should work ur doing something wrong idk try this at the top [lua] if ( not ply or not ply:IsPlayer() ) then print("i didn't code my weapon base right"); return; end [/lua] in other words is your player object valid is this called on the server only? is the function( OnHolster ) even being called? add a print to the top to see when it's called. does the weapon work when you remove this function from the swep file?
[QUOTE=LauScript;43197688]should work ur doing something wrong idk try this at the top [lua] if ( not ply or not ply:IsPlayer() ) then print("i didn't code my weapon base right"); return; end [/lua] in other words is your player object valid is this called on the server only? is the function( OnHolster ) even being called? add a print to the top to see when it's called. does the weapon work when you remove this function from the swep file?[/QUOTE] Its for a pointshop powerup
[QUOTE=Flavoured;43195454]I cant seem to find the code to see if the players health is less then their max i've tried many things but none seem to work i've tried [CODE]function ITEM:OnHolster(ply) local hp = ply:Health() local maxhp = ply:GetMaxHealth() if hp < maxhp then return false else ply:SetHealth(100) ply:SetMaxHealth(100) end end[/CODE] and many other things but they dont seem to work What i want is that if the player has less than their max health then dont holster the powerup and print a message like "You may only holster if your on full health" or something[/QUOTE] What exactly is the issue your getting? It is saying if your hp is less than max you can't holster it, else, it sets your hp to 100.
[QUOTE=Flavoured;43197834]Its for a pointshop powerup[/QUOTE] well you didn't answer any of the questions i needed in order to debug your script so i guess i'm not helping you
Sorry, you need to Log In to post a reply to this thread.