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

143 lines
6.4 KiB
C#

using GrandTheftMultiplayer.Server.API;
using GrandTheftMultiplayer.Server.Constant;
using GrandTheftMultiplayer.Shared.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrandTheftMultiplayer.Server.Managers;
using GrandTheftMultiplayer.Shared;
using GrandTheftMultiplayer.Server.Elements;
namespace Roleplay.Jobs.Transporter
{
class Transporter : Script
{
public Transporter()
{
Jobmanager.createJobPed(PedHash.Dockwork01SMM, new Vector3(125.4182, -3113.292, 5.95), 0, "", "");
RAPI.Marker.createMarker(1, new Vector3(125.4496, -3112.52, 4.95), 1, 0, 255, 0, "transporter", 0, 185, "Transporter", 0);
API.onEntityEnterColShape += onJobGUI;
API.onClientEventTrigger += onTrigger;
API.onPlayerExitVehicle += onCancel;
populateColShapes();
}
private void onJobGUI(ColShape colshape, NetHandle entity)
{
if (entity != null && colshape != null)
{
if (colshape.getData("transporter") == true)
{
Client player = API.getPlayerFromHandle(entity);
if (player != null)
{
Jobmanager.acceptFenster(player, Jobmanager.Jobnames.transporter, 100);
}
}
else if (colshape.getData("transporter:job:col") == true)
{
Client player = API.getPlayerFromHandle(entity);
if (player != null)
{
if (API.hasEntityData(player, "injob:transporter") == true && API.getEntityData(player, "injob:transporter") == true)
{
if (API.hasEntityData(player, "job:transporter:X") == true && RAPI.MainAPI.getDifference(Convert.ToInt32(API.getEntityData(player, "job:transporter:X")), Convert.ToInt32(colshape.getData("transporter:colshape:loc"))) < 5)
{
int difference = Convert.ToInt32(RAPI.MainAPI.getDistanceBetween2Points(player.position, new Vector3(125.4496, -3112.52, 4.95)));
int calculatedMoney = Convert.ToInt32(difference / 1000 * 50 * 1 * 10);
API.triggerClientEvent(player, "deletelastWaypoint");
Jobmanager.addPayDayMoney(player, calculatedMoney);
Levelsystem.addPlayerLevelFortschritt(player,1,API);
API.triggerClientEvent(player, "transporterstart");
}
else
{
API.sendNotificationToPlayer(player, "~r~ Fehler, dies ist nicht der richtige Wegpunkt!");
}
}
}
}
}
}
public void createColshape(double x, double y, double z, string coldata)
{
ColShape col = API.createCylinderColShape(new Vector3(x, y, z), 2, 5);
col.setData(coldata, true);
col.setData("transporter:colshape:loc", x);
}
private void onTrigger(Client sender, string eventName, object[] arguments)
{
if (eventName == "triggerBackFromClient")
{
string job = (string)arguments[0];
if (job == "job:start:" + Jobmanager.Jobnames.transporter[0])
{
if (Environment.Fahrschule.doesPlayerHaveLKWSchein(sender))
{
if (Jobmanager.getJob(sender) == Jobmanager.Jobnames.transporter[0])
{
API.sendNotificationToPlayer(sender, "~g~Job gestartet!");
API.triggerClientEvent(sender, "transporterstart");
Vehicle veh = RAPI.MainAPI.createRolePlayVehicle(VehicleHash.Mule3, new Vector3(166.3509, -3056.547, 6.129501), new Vector3(0, 0, -90), 50, 50, 50, 50, 50, 50, "System");
API.setVehicleLocked(veh, true);
API.setEntityData(veh, "job:transporter", true);
API.setEntityData(sender, "injob:transporter", true);
API.setPlayerIntoVehicle(sender, veh, -1);
}
else
{
API.sendNotificationToPlayer(sender, "~r~Du musst den Job erstmal annehmen!");
}
} else
{
API.sendNotificationToPlayer(sender, "~r~Du hast kein LKW Schein!");
}
}
} else if(eventName == "colwasselected")
{
double x = (double) Convert.ToDouble(arguments[0]);
API.setEntityData(sender, "job:transporter:X", x);
}
}
private void onCancel(Client player, NetHandle vehicle, int x)
{
if (API.getEntityData(vehicle, "job:transporter") == true)
{
if (API.getEntityData(player, "injob:transporter") == true)
{
Vehicle veh = RAPI.MainAPI.getVehicleFromHandle(API, vehicle);
veh.delete();
API.sendNotificationToPlayer(player, "~r~Job wurde beendet!");
API.triggerClientEvent(player, "transporterCancel");
API.setEntityData(player, "injob:transporter", false);
}
}
}
public void populateColShapes()
{
Blip blip = API.createBlip(new Vector3(125.4496, -3112.52, 4.95), 0);
blip.sprite = 318;
createColshape(-3052.099, 596.9607, 6.44038, "transporter:job:col");
createColshape(-1376.936, -144.8066, 47.484128, "transporter:job:col");
createColshape(-728.4478, -911.282, 18.0139, "transporter:job:col");
createColshape(493.8185, -1002.227, 26.82701, "transporter:job:col");
createColshape(1247.924, -346.1441, 68.0822, "transporter:job:col");
createColshape(2562.558, -319.5804, 91.992, "transporter:job:col");
createColshape(1862.685, 3703.321, 32.49183, "transporter:job:col");
}
}
}