Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as alt from "alt";
- function updateFoodThirst(){
- setInterval(function (){
- alt.Player.all.forEach(player => {
- if(player.getSyncedMeta("gamestatus") === "playing"){
- var food = player.getSyncedMeta("food");
- var thirst = player.getSyncedMeta("thirst");
- var thirstLoss = 2;
- var foodLoss = 1;
- let newThirst = thirst - thirstLoss;
- let newFood = food - foodLoss;
- setTimeout(() => {
- if(newFood < 0){
- newFood = 0;
- gm.mysql.DBcon().query("UPDATE account SET food = ? WHERE id = ?", [newFood, player.getSyncedMeta("uniqueId")], function (err, res){
- player.setSyncedMeta("food", newFood);
- alt.emitClient(player, 'updateFood', newFood);
- });
- }
- if(newFood > 100){
- newFood = 100;
- gm.mysql.DBcon().query("UPDATE account SET food = ? WHERE id = ?", [newFood, player.getSyncedMeta("uniqueId")], function (err, res){
- player.setSyncedMeta("food", newFood);
- alt.emitClient(player, 'updateFood', newFood);
- });
- }
- if(newThirst < 0){
- newThirst = 0;
- gm.mysql.DBcon().query("UPDATE account SET thirst = ? WHERE id = ?", [newThirst, player.getSyncedMeta("uniqueId")], function (err, res){
- player.setSyncedMeta("thirst", newThirst);
- alt.emitClient(player, 'updateThirst', newThirst);
- });
- }
- if(newThirst > 100){
- newThirst = 100;
- gm.mysql.DBcon().query("UPDATE account SET thirst = ? WHERE id = ?", [newThirst, player.getSyncedMeta("uniqueId")], function (err, res){
- player.setSyncedMeta("thirst", newThirst);
- alt.emitClient(player, 'updateThirst', newThirst);
- });
- }
- gm.mysql.DBcon().query("UPDATE account SET thirst = ?, food = ? WHERE id = ?", [newThirst, newFood, player.getSyncedMeta("uniqueId")], function (err, res){
- player.setSyncedMeta("thirst", newThirst);
- alt.emitClient(player, 'updateThirst', newThirst);
- player.setSyncedMeta("food", newFood);
- alt.emitClient(player, 'updateFood', newFood);
- });
- }, 50);
- }
- });
- }, 180000);
- }
- updateFoodThirst();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement