• Gmod DarkRP No Health Above 100!!!
    9 replies, posted
Ok basically I got this food mod with food but you can eat it and your health can go past 100 so I need someone to make me a small bit of code that makes it so if you have 100 health your health can no go above that
1 minute code right here, not sure about GetHealth(): [lua] function HealthBelow100() for k,v in pairs( player.GetAll() ) do if ply:Health() > 100 then ply:SetHealth( 100 ) end end end hook.Add( "Think", "HpBelow100", HealthBelow100 ) [/lua] Try that. EDIT: Thanks, Willox
[QUOTE=HumbleTH;43368963]Now, can some of you lua pros tell me if it's SetHealth() or just Health() ??[/QUOTE] SetHealth is right, GetHealth should just be Health
Rather than using a Think hook in Humble's example, if you can find the code where the health is added when you eat the food just add a simple check to make sure it doesn't go over 100.
@Willox Your code does not work
If you want it to be automated for you, when you eat; make a helper function. Clamp the value: Player:SetHealth( math.Clamp( Player:Health( ) + foodHealthValue, 0, 100 ) );
@Acecool I added that to the code and it didn't work :(
Food Mod on github has the [url=https://github.com/dkoz/foodmod/blob/master/lua/entities/food_base/init.lua#L30]limits[/url] you want. Github: [url]https://github.com/dkoz/foodmod[/url]
This has been solved by OasisRP
Then maybe setting the thread to 'solved' would be a good idea?
Sorry, you need to Log In to post a reply to this thread.