Guest User

Script_hunger/hunger.cs

a guest
Dec 23rd, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. //====================
  2. //Hunger Part
  3. //====================
  4.  
  5. //Register Events
  6. registerOutputEvent(GameConnection,"setFood", "int 1 100 50");
  7. registerOutputEvent(GameConnection,"addFood", "int 1 100 50");
  8. registerOutputEvent(GameConnection,"setHunger", "int 1 100 50");
  9.  
  10. //Main CMD's
  11. package HungerMain
  12. {
  13. function serverCmdCheckFood(%client)
  14. {
  15. if(isObject(%client.player))
  16. {
  17. if(%client.food > 1)
  18. {
  19. messageClient(%client,'',"\c6You have \c3" @ %client.food @ "\c6 food.");
  20. }
  21. else
  22. {
  23. messageClient(%client,'',"\c6You have \c3no\c6 food!");
  24. }
  25. }
  26. else
  27. {
  28. messageClient(%client,'',"\c6Please wait until you spawn.");
  29. }
  30. }
  31.  
  32. function serverCmdEatFood(%client, %input)
  33. {
  34. if(isObject(%client.player))
  35. {
  36. if(%client.food > 5)
  37. {
  38. %changefood = %client.food - %input;
  39. %client.food = %changefood;
  40. %addfoodvar = %client.hunger + %input;
  41. %v = (%addfoodvar >= $HungerMod::pref::MaxHunger);
  42. if(%v $= 1)
  43. {
  44. %client.hunger = $HungerMod::pref::MaxHunger;
  45. }
  46. else
  47. {
  48. %client.hunger = %addfoodvar;
  49. }
  50. messageClient(%client,'',"\c6Current Hunger: \c3" @ %client.hunger);
  51. }
  52. else
  53. {
  54. messageClient(%client,'',"\c6You don't have that much food!");
  55. }
  56. }
  57. else
  58. {
  59. messageClient(%client,'',"\c6Please wait until you spawn.");
  60. }
  61. }
  62.  
  63. function serverCmdStartHunger(%client)
  64. {
  65. if(%client.isSuperAdmin || %client.isHost || %client.isAdmin)
  66. {
  67. messageAll('',"\c6Hunger\c2 Started.");
  68. $HungerMod::pref::HungerActive = true;
  69. HungerTick();
  70. }
  71. else
  72. {
  73. messageClient(%client,'',"\c6You're not an admin!");
  74. }
  75. }
  76.  
  77. function serverCmdStopHunger(%client)
  78. {
  79. if(%client.isSuperAdmin || %client.isHost || %client.isAdmin)
  80. {
  81. messageAll('',"\c6Hunger\c2 Stopped.");
  82. $HungerMod::pref::HungerActive = false;
  83. }
  84. else
  85. {
  86. messageClient(%client,'',"\c6You're not an admin!");
  87. }
  88. }
  89. };
  90. activatePackage(HungerMain);
  91.  
  92. //Looping system
  93. function HungerTick()
  94. {
  95. if($HungerMod::pref::HungerActive)
  96. {
  97. deductHunger();
  98. schedule($HungerMod::pref::TickTime,0,HungerTick);
  99. }
  100. }
  101.  
  102. function deductHunger()
  103. {
  104. %count = clientGroup.getCount();
  105. for(%i=0;%i<%count;%i++)
  106. {
  107. %client = clientGroup.getObject(%i);
  108. if(isObject(%client.player))
  109. {
  110. %hungeredit = %client.hunger;
  111. %client.hunger = %hungeredit - $HungerMod::pref::HungerDecriment;
  112. if(%client.hunger <= 0)
  113. {
  114. %client.player.kill();
  115. %replacehunger = $HungerMod::pref::MaxHunger / 2;
  116. %client.hunger = %replacehunger;
  117. messageAll('',"\c3" @ %client.name @ " \c6has died of hunger.");
  118. messageClient(%client,'',"\c6Hunger reset to\c3 " @ %replacehunger);
  119. }
  120. else
  121. {
  122. messageClient(%client,'',"\c6Hunger status:\c3 " @ %client.hunger @ "\c6/\c3" @ $HungerMod::pref::MaxHunger);
  123. }
  124. if($HungerMod::pref::Hydration)
  125. {
  126. %hydrationedit = %client.hydration;
  127. %client.hydration = %hydrationedit - $HungerMod::pref::HydrationDecriment;
  128. if(%client.hydration <= 0)
  129. {
  130. %client.player.kill();
  131. %replacehydration = $HungerMod::pref::MaxHydration / 2;
  132. %client.hydration = %replacehunger;
  133. messageAll('',"\c3" @ %client.name @ " \c6has died of hydration.");
  134. messageClient(%client,'',"\c6Hydration reset to\c3 " @ %replacehydration);
  135. }
  136. else
  137. {
  138. messageClient(%client,'',"\c6Hydration status:\c3 " @ %client.hydration @ "\c6/\c3" @ $HungerMod::pref::MaxHydration);
  139. }
  140. }
  141. }
  142. }
  143. }
  144.  
  145. //Events
  146. function GameConnection::setFood(%client, %input)
  147. {
  148. %client.food = %input;
  149. }
  150.  
  151. function GameConnection::addFood(%client, %input)
  152. {
  153. %client.food = %client.food + %input;
  154. }
  155.  
  156. function GameConnection::setHunger(%client, %input)
  157. {
  158. %ifhunger = %client.hunger + %input;
  159. if(%ifhunger >= $HungerMod::pref::MaxHunger)
  160. {
  161. %client.hunger = $HungerMod::pref::MaxHunger;
  162. }
  163. else
  164. {
  165. %client.hunger = %client.hunger + %input;
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment