Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.24 KB | None | 0 0
  1. local PLUGIN = PLUGIN;
  2.  
  3. -- Called when a player's character data should be restored.
  4. function PLUGIN:PlayerRestoreCharacterData(player, data)
  5.     if ( !data["hunger"] ) then
  6.         data["hunger"] = 0;
  7.     end;
  8.     if ( !data["thirst"] ) then
  9.         data["thirst"] = 0;
  10.     end;
  11.     if ( !data["sleep"] ) then
  12.         data["sleep"] = 0
  13.     end;
  14. end;
  15.  
  16. -- Called when a player's shared variables should be set.
  17. function PLUGIN:PlayerSetSharedVars(player, curTime)
  18.     player:SetSharedVar( "hunger", math.Round( player:GetCharacterData("hunger") ) );
  19.     player:SetSharedVar( "thirst", math.Round( player:GetCharacterData("thirst") ) );
  20.     player:SetSharedVar( "sleep", math.Round( player:GetCharacterData("sleep") ) );
  21.     local position = player:GetPos();
  22.    
  23.     if (player:Alive() and !player:IsRagdolled() and player:GetVelocity():Length() > 0) then
  24.         if (player:GetCharacterData("thirst") == 100) then
  25.             player:BoostAttribute("Thirst", ATB_ACROBATICS, -50);
  26.             player:BoostAttribute("Thirst", ATB_ENDURANCE, -50);
  27.             player:BoostAttribute("Thirst", ATB_STRENGTH, -50);
  28.             player:BoostAttribute("Thirst", ATB_AGILITY, -50);
  29.             player:BoostAttribute("Thirst", ATB_DEXTERITY, -50);
  30.             player:BoostAttribute("Thirst", ATB_MEDICAL, -50);
  31.         else
  32.             player:BoostAttribute("Thirst", ATB_ACROBATICS, false);
  33.             player:BoostAttribute("Thirst", ATB_ENDURANCE, false);
  34.             player:BoostAttribute("Thirst", ATB_STRENGTH, false);
  35.             player:BoostAttribute("Thirst", ATB_AGILITY, false);
  36.             player:BoostAttribute("Thirst", ATB_DEXTERITY, false);
  37.             player:BoostAttribute("Thirst", ATB_MEDICAL, false);
  38.         end;
  39.     end;
  40.     if (player:Alive() and !player:IsRagdolled() and player:GetVelocity():Length() > 0) then
  41.         if (tonumber(player:GetCharacterData("hunger")) >= 70) then
  42.             player:BoostAttribute("Hunger", ATB_ACROBATICS, -10);
  43.             player:BoostAttribute("Hunger", ATB_ENDURANCE, -10);
  44.             player:BoostAttribute("Hunger", ATB_STRENGTH, -10);
  45.             player:BoostAttribute("Hunger", ATB_AGILITY, -10);
  46.             player:BoostAttribute("Hunger", ATB_DEXTERITY, -10);
  47.             player:BoostAttribute("Hunger", ATB_MEDICAL, -10);
  48.         elseif (tonumber(player:GetCharacterData("hunger")) >= 80) then
  49.             player:BoostAttribute("Hunger", ATB_ACROBATICS, -25);
  50.             player:BoostAttribute("Hunger", ATB_ENDURANCE, -25);
  51.             player:BoostAttribute("Hunger", ATB_STRENGTH, -25);
  52.             player:BoostAttribute("Hunger", ATB_AGILITY, -25);
  53.             player:BoostAttribute("Hunger", ATB_DEXTERITY, -25);
  54.             player:BoostAttribute("Hunger", ATB_MEDICAL, -25);
  55.         elseif (tonumber(player:GetCharacterData("hunger")) >= 90) then
  56.             player:BoostAttribute("Hunger", ATB_ACROBATICS, -30);
  57.             player:BoostAttribute("Hunger", ATB_ENDURANCE, -30);
  58.             player:BoostAttribute("Hunger", ATB_STRENGTH, -30);
  59.             player:BoostAttribute("Hunger", ATB_AGILITY, -30);
  60.             player:BoostAttribute("Hunger", ATB_DEXTERITY, -30);
  61.             player:BoostAttribute("Hunger", ATB_MEDICAL, -30);
  62.         else
  63.             player:BoostAttribute("Hunger", ATB_ACROBATICS, false);
  64.             player:BoostAttribute("Hunger", ATB_ENDURANCE, false);
  65.             player:BoostAttribute("Hunger", ATB_STRENGTH, false);
  66.             player:BoostAttribute("Hunger", ATB_AGILITY, false);
  67.             player:BoostAttribute("Hunger", ATB_DEXTERITY, false);
  68.             player:BoostAttribute("Hunger", ATB_MEDICAL, false);
  69.         end;
  70.     end;
  71. end;
  72.  
  73. -- Called at an interval while a player is connected.
  74. function PLUGIN:PlayerThink(player, curTime, infoTable)
  75.     local alive = player:Alive();
  76.     local faction = player:GetFaction();
  77.     local curTime = CurTime();
  78.    
  79. if ( player:Alive() )  then
  80.         if (tonumber(player:GetCharacterData("sleep")) >= 95) then
  81.             if (!player:IsRagdolled() and !player:IsNoClipping()) then
  82.                 if (!player.nextSleepKO or curTime >= player.nextSleepKO) then
  83.                     if (math.random(1, 100) == 100) then
  84.                         Clockwork.player:SetRagdollState(player, RAGDOLL_KNOCKEDOUT, math.random(5, 15));
  85.                         Clockwork.chatBox:Add(player, nil, "sleep", "** Вы так долго не спали, что попросту потеряли сознание. **");
  86.                         player.nextSleepKO = curTime + 25;
  87.                     end;
  88.                 end;
  89.             end;
  90.         end;
  91.         if (!player.nextHunger or curTime >= player.nextHunger) then
  92.             if (tonumber(player:GetCharacterData("hunger")) != -1) then
  93.                 player:SetCharacterData( "hunger", math.Clamp(player:GetCharacterData("hunger") + 1, 0, 100) );
  94.                 player.nextHunger = curTime + 206;
  95.                 if player:GetCharacterData("hunger") == 31 then
  96.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вам хочется перекусить. **");
  97.                 elseif player:GetCharacterData("hunger") == 51 then
  98.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы проголодались. **");
  99.                 elseif player:GetCharacterData("hunger") == 71 then
  100.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы очень хотите есть. **");
  101.                 elseif player:GetCharacterData("hunger") == 81 then
  102.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы сильно голодны и очень ослабли. **");
  103.                 end;
  104.             end;
  105.         end;
  106.         if (!player.nextThirst or curTime >= player.nextThirst) then
  107.             if (tonumber(player:GetCharacterData("thirst")) != -1) then
  108.                 player:SetCharacterData( "thirst", math.Clamp(player:GetCharacterData("thirst") + 1, 0, 100) );
  109.                 player.nextThirst = curTime + 103;
  110.                 if player:GetCharacterData("thirst") == 31 then
  111.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вам хочется чего-то выпить. **");
  112.                 elseif player:GetCharacterData("thirst") == 51 then
  113.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы чувствуете жажду. **");
  114.                 elseif player:GetCharacterData("thirst") == 71 then
  115.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы очень хотите пить. **");
  116.                 elseif player:GetCharacterData("thirst") == 81 then
  117.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы обезвожены и очень слабы. **");
  118.                 end;
  119.             end;
  120.         end;
  121.         if (!player.nextSleep or curTime >= player.nextSleep) then
  122.             if (tonumber(player:GetCharacterData("sleep")) != -1) then
  123.                 player:SetCharacterData( "sleep", math.Clamp(player:GetCharacterData("sleep") + 1, 0, 100) );
  124.                 player.nextSleep = curTime + 411;
  125.                 if player:GetCharacterData("sleep") == 51 then
  126.                     Clockwork.chatBox:Add(player, nil, "sleep", "** В чувствуете усталость, стоит немного вздремнуть. **");
  127.                 elseif player:GetCharacterData("sleep") == 81 then
  128.                     Clockwork.chatBox:Add(player, nil, "sleep", "** Вы очень хотите спать, стоит хорошо выспаться. **");
  129.                 end;
  130.             end;
  131.         end;
  132.     end;
  133. end;
  134.  
  135. function PLUGIN:PlayerShouldStaminaRegenerate(player)
  136.     local faction = player:GetFaction();
  137.     if ( tonumber(player:GetCharacterData("hunger")) >= 70 ) then
  138.         return false;
  139.     end;
  140. end;
  141.  
  142. -- Called when a player uses an item.
  143. function PLUGIN:PlayerUseItem(player, itemTable, itemEntity)
  144.     if itemTable.hunger then
  145.         player:SetCharacterData( "hunger", math.Clamp(player:GetCharacterData("hunger") - itemTable.hunger, 0, 100) );
  146.     end;
  147.    
  148.     if itemTable.thirst then
  149.         player:SetCharacterData( "thirst", math.Clamp(player:GetCharacterData("thirst") - itemTable.thirst, 0, 100) );
  150.     end;
  151.    
  152.     if itemTable.sleep then
  153.         player:SetCharacterData( "sleep", math.Clamp(player:GetCharacterData("sleep") - itemTable.sleep, 0, 100) );
  154.     end;
  155. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement