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

176 lines
7.2 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.Jobs.Greenkeeper
{
class Greenkeeper : Script
{
public Greenkeeper()
{
API.onEntityEnterColShape += onColShapeHandler;
API.onClientEventTrigger += onTrigger;
API.onPlayerExitVehicle += oNCancel;
setupJob();
}
List<ColShape> colshapes = new List<ColShape>();
public const int totalmarkers = 4;
public void setupJob()
{
API.createPed(PedHash.GarbageSMY, new Vector3(-1349.198, 23.55496, 53.450), 180, 0);
RAPI.Marker.createMarker(1, new Vector3(-1349.115, 22.5, 52.45), 1, 0, 255, 0, "job:greenkeeper", 0, 185, "Greenkeeper", 0);
colshapes.Add(API.createCylinderColShape(new Vector3(-1288.488, 53.28987, 50.44), 1, 2));
colshapes.Add(API.createCylinderColShape(new Vector3(-1206.227, 23.28249, 48.25), 1, 2));
colshapes.Add(API.createCylinderColShape(new Vector3(-1188.594, -29.88, 44.61), 1, 2));
colshapes.Add(API.createCylinderColShape(new Vector3(-1139.745, -61.15126, 43.03), 1, 2));
Blip blip = API.createBlip(new Vector3(-1349.198, 23.55496, 53.450), 0);
blip.sprite = 109;
blip.name = "Greenkeeper";
foreach(ColShape col in colshapes)
{
col.setData("ID", colshapes.IndexOf(col) + 1);
}
}
public void startMarker(Client player)
{
API.triggerClientEvent(player, "job:generate:marker", 1);
API.setEntityData(player, "job:greenkeeper:next", 1);
}
public int getCurrentId(Client player)
{
if (API.hasEntityData(player, "job:greenkeeper:next") == true && API.getEntityData(player, "job:greenkeeper:next") != null)
{
return API.getEntityData(player, "job:greenkeeper:next");
} else
{
return 0;
}
}
public void nextMarker(Client player)
{
if (API.hasEntityData(player, "job:greenkeeper:next") == true)
{
int current = API.getEntityData(player, "job:greenkeeper:next");
if (current >= 4)
{
API.triggerClientEvent(player, "destroyMarker");
API.triggerClientEvent(player, "job:generate:marker", 1);
API.setEntityData(player, "job:greenkeeper:next", 1);
}
else
{
API.triggerClientEvent(player, "destroyMarker");
API.triggerClientEvent(player, "job:generate:marker", current + 1);
API.setEntityData(player, "job:greenkeeper:next", current + 1);
}
} else
{
API.triggerClientEvent(player, "destroyMarker");
API.triggerClientEvent(player, "job:generate:marker", 1);
API.setEntityData(player, "job:greenkeeper:next", 1);
}
}
private void onTrigger(Client sender, string eventName, object[] arguments)
{
if (eventName == "triggerBackFromClient")
{
string job = (string)arguments[0];
if (job == "job:start:" + Jobmanager.Jobnames.greenkeeper[0])
{
if (Jobmanager.getJob(sender) == Jobmanager.Jobnames.greenkeeper[0])
{
API.sendNotificationToPlayer(sender, "~g~Job gestartet!");
Vehicle veh = RAPI.MainAPI.createRolePlayVehicle(VehicleHash.Mower, new Vector3(-1328.324, 26.21, 53.0396), new Vector3(0, 0, -80), 0, 100, 0, 0, 255, 0, "System");
API.setPlayerIntoVehicle(sender, veh, -1);
API.setVehicleLocked(veh, true);
API.setEntityData(veh, "job:greenkeeper:mower", true);
API.setEntityData(sender,"job:greenkeeper",true);
API.setEntityData(sender, "job:greenkeeper:next", 1);
API.triggerClientEvent(sender, "job:generate:marker", 1);
}
else
{
API.sendNotificationToPlayer(sender, "~r~Du musst den Job erstmal annehmen!");
}
}
}
}
private void onColShapeHandler(ColShape colshape, NetHandle entity)
{
if (entity != null && colshape != null)
{
if (colshape.hasData("job:greenkeeper") == true && colshape.getData("job:greenkeeper") == true)
{
Client player = API.getPlayerFromHandle(entity);
if (player != null)
{
Jobmanager.acceptFenster(player, Jobmanager.Jobnames.greenkeeper, 0);
}
}
else if (colshape.hasData("ID") == true)
{
Client player = API.getPlayerFromHandle(entity);
if (player != null)
{
if (player.isInVehicle != true)
{
int colshapeid = colshape.getData("ID");
if (colshapeid == getCurrentId(player))
{
if (colshapeid == 4)
{
API.triggerClientEvent(player, "destroyMarker");
}
nextMarker(player);
API.playPlayerScenario(player, "WORLD_HUMAN_GARDENER_PLANT");
API.delay(1000 * 10, true, () =>
{
API.stopPlayerAnimation(player);
Jobmanager.addPayDayMoney(player, 400);
Levelsystem.addPlayerLevelFortschritt(player,1,API);
});
}
}
else
{
API.sendNotificationToPlayer(player, "Du musst absteigen!");
}
}
}
}
}
private void oNCancel(Client player, NetHandle vehicle, int x)
{
if (API.getEntityData(vehicle, "job:greenkeeper:mower") == true)
{
//API.delay(1000 * 60, true, () =>
//{
// if(player.isInVehicle != true)
// {
// API.deleteEntity(vehicle);
// API.triggerClientEvent(player, "destroyMarker");
// }
//});
}
}
}
}