1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Other Primary Needs Question

Discussion in 'Development' started by NoahtheBoah36™, May 8, 2018.

  1. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

  2. MiliViu

    MiliViu Clockwork Customer

    Its working for you? that plugin?
     
  3. Viz

    Viz Legend Clockwork Customer

    Code:
    -- Called when a player uses an item.
    function PLUGIN:PlayerUseItem(player, itemTable, itemEntity)
       if itemTable.hunger then
         player:SetCharacterData( "hunger", math.Clamp(player:GetCharacterData("hunger") - itemTable.hunger, 0, 100) );
       end;
       
       if itemTable.thirst then
         player:SetCharacterData( "thirst", math.Clamp(player:GetCharacterData("thirst") - itemTable.thirst, 0, 100) );
       end;
       
       if itemTable.sleep then
         player:SetCharacterData( "sleep", math.Clamp(player:GetCharacterData("sleep") - itemTable.sleep, 0, 100) );
       end;
    end;
    
    It clamps the value between 0 and 100, so no, negative values do not increase the player's hunger/thirst/sleep.
     
  4. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer

    @Viz I see, thank you.
    @MiliViu It's working fine for me yeah, I was just wondering if it were possible to increase thirst/hunger/sleep by means of setting negative values.
     
  5. Viz

    Viz Legend Clockwork Customer

    @NoahtheBoah36™
    My bad, I didn't look at the code correctly.
    Using a negative value will increase the player's hunger/thirst/sleep, as it's clamping the player's actual hunger/thirst/sleep level between 0 and 100, not the item value.

    Thanks @robot for pointing this out.
     
    • Like Like x 1
    • Good Coder Good Coder x 1

Previous Readers (Total: 0)