Ragemp-roleplay-skript/EssenTrinken.cs
2019-04-16 13:59:07 +02:00

109 lines
No EOL
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrandTheftMultiplayer.Server.API;
using GrandTheftMultiplayer.Server.Constant;
using GrandTheftMultiplayer.Server.Elements;
using GrandTheftMultiplayer.Server.Managers;
using GrandTheftMultiplayer.Shared;
using GrandTheftMultiplayer.Shared.Math;
namespace Roleplay.Environment.EssenTrinken
{
class EssenTrinken : Script
{
public EssenTrinken()
{
essentrinkentimer();
API.onPlayerRespawn += oNDead;
API.onPlayerDeath += Death;
}
public void essentrinkentimer()
{
API.delay(1000*60,false, ()=> {
foreach(Client player in API.getAllPlayers())
{
if(player != null && API.hasEntityData(player,"Adminmode") == false)
{
if(player.getData("loggedin") == true){
float trinken = player.getSyncedData("trinken");
float essen = player.getSyncedData("essen");
if(trinken != 0 && essen != 0)
{
API.setEntitySyncedData(player,"trinken",trinken - 1);
API.setEntitySyncedData(player,"essen",essen - 1);
updateEssenTrinkenDisplay(player);
}
else if(trinken == 0 || essen == 0)
{
API.sendNotificationToPlayer(player,"Du verlierst Leben!");
API.setPlayerHealth(player,API.getPlayerHealth(player) - 10);
}
}
}
}
});
}
public void Death(Client player, NetHandle entityKiller, int weapon){
if(API.getEntityType(entityKiller) == EntityType.Player){
Client killer = API.getPlayerFromHandle(entityKiller);
API.consoleOutput("Player: " + player.name + " died by " + killer.name + " by weaponid: " + weapon);
}
API.consoleOutput("Player: " + player.name + " died!");
}
public void oNDead(Client player)
{
addTrinken(player,100);
addEssen(player,100);
}
public static void updateEssenTrinkenDisplay(Client player){
API.shared.triggerClientEvent(player,"update_essentrinken_display", getEssen(player), getTrinken(player));
}
public static void addTrinken(Client player, float trinkentoadd)
{
float current = API.shared.getEntitySyncedData(player,"trinken");
if((trinkentoadd + current) > 100){
API.shared.setEntitySyncedData(player,"trinken",100);
updateEssenTrinkenDisplay(player);
} else {
API.shared.setEntitySyncedData(player,"trinken",current + trinkentoadd);
updateEssenTrinkenDisplay(player);
}
}
public static float getTrinken(Client player)
{
return API.shared.getEntitySyncedData(player,"trinken");
}
public static void addEssen(Client player, float essentoadd)
{
float current = API.shared.getEntitySyncedData(player,"essen");
if((essentoadd + current) > 100){
API.shared.setEntitySyncedData(player,"essen",100);
updateEssenTrinkenDisplay(player);
} else {
API.shared.setEntitySyncedData(player,"essen",current + essentoadd);
updateEssenTrinkenDisplay(player);
}
}
public static float getEssen(Client player)
{
return API.shared.getEntitySyncedData(player,"essen");
}
}
}