Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as alt from "alt";
  2. function updateFoodThirst(){
  3.     setInterval(function (){
  4.             alt.Player.all.forEach(player => {
  5.                 if(player.getSyncedMeta("gamestatus") === "playing"){
  6.                     var food = player.getSyncedMeta("food");
  7.                     var thirst = player.getSyncedMeta("thirst");
  8.                     var thirstLoss = 2;
  9.                     var foodLoss = 1;
  10.                     let newThirst = thirst - thirstLoss;
  11.                     let newFood = food - foodLoss;
  12.                     setTimeout(() => {
  13.                        
  14.                         if(newFood < 0){
  15.                             newFood = 0;
  16.                            
  17.                             gm.mysql.DBcon().query("UPDATE account SET food = ? WHERE id = ?", [newFood, player.getSyncedMeta("uniqueId")], function (err, res){
  18.                                 player.setSyncedMeta("food", newFood);
  19.                                 alt.emitClient(player, 'updateFood', newFood);
  20.                             });
  21.                         }
  22.  
  23.                         if(newFood > 100){
  24.                             newFood = 100;
  25.  
  26.                             gm.mysql.DBcon().query("UPDATE account SET food = ? WHERE id = ?", [newFood, player.getSyncedMeta("uniqueId")], function (err, res){
  27.                                 player.setSyncedMeta("food", newFood);
  28.                                 alt.emitClient(player, 'updateFood', newFood);
  29.                             });
  30.                         }
  31.  
  32.                         if(newThirst < 0){
  33.                             newThirst = 0;
  34.  
  35.                             gm.mysql.DBcon().query("UPDATE account SET thirst = ? WHERE id = ?", [newThirst, player.getSyncedMeta("uniqueId")], function (err, res){
  36.                                 player.setSyncedMeta("thirst", newThirst);
  37.                                 alt.emitClient(player, 'updateThirst', newThirst);
  38.                             });
  39.                         }
  40.  
  41.                         if(newThirst > 100){
  42.                             newThirst = 100;
  43.  
  44.                             gm.mysql.DBcon().query("UPDATE account SET thirst = ? WHERE id = ?", [newThirst, player.getSyncedMeta("uniqueId")], function (err, res){
  45.                                 player.setSyncedMeta("thirst", newThirst);
  46.                                 alt.emitClient(player, 'updateThirst', newThirst);
  47.                             });
  48.                         }
  49.  
  50.                         gm.mysql.DBcon().query("UPDATE account SET thirst = ?, food = ? WHERE id = ?", [newThirst, newFood, player.getSyncedMeta("uniqueId")], function (err, res){
  51.                             player.setSyncedMeta("thirst", newThirst);
  52.                             alt.emitClient(player, 'updateThirst', newThirst);
  53.                             player.setSyncedMeta("food", newFood);
  54.                             alt.emitClient(player, 'updateFood', newFood);
  55.                         });
  56.  
  57.                     }, 50);
  58.                 }
  59.             });  
  60.     }, 180000);
  61. }
  62.  
  63. updateFoodThirst();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement