1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
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 Customer Active Member

  2. MiliViu

    MiliViu Clockwork Customer Active Member

    Its working for you? that plugin?
     
  3. Viz

    Viz Legend Clockwork Customer Active Member

    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 Customer Active Member

    @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 Active Member

    @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