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

172 lines
7.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrandTheftMultiplayer.Server;
using GrandTheftMultiplayer.Shared;
using GrandTheftMultiplayer.Server.API;
using GrandTheftMultiplayer.Shared.Math;
using GrandTheftMultiplayer.Server.Elements;
using GrandTheftMultiplayer.Server.Constant;
using GrandTheftMultiplayer.Server.Managers;
namespace Roleplay.Environment
{
class vehicle : Script
{
public const int VEHICLE_CALLBACKID = -5566163;
public vehicle()
{
API.onEntityEnterColShape += RollerAusleih;
API.onClientEventTrigger += onAusleih;
//NOOBSPAWN
API.createPed(PedHash.ChiGoon02GMM, new Vector3(-1047.322,-2727.229,20.16928), -36, 0);
RAPI.Marker.createMarker(21, new Vector3(-1046.052, -2726.443, 20.16928), 1, 0, 255, 0, "ausleih", 0, 50, "~b~ Rollerverleih");
loadAusleihe();
loadtimer();
API.onEntityEnterColShape += onColHandler;
}
private void onAusleih(Client sender, string eventName, object[] arguments)
{
if (eventName == "menu_handler_select_item")
{
var callbackId = (int)arguments[0];
var index = (int)arguments[1];
if (callbackId == VEHICLE_CALLBACKID)
{
if(index == 0)
{
if(API.getEntityData(sender,"ausleih") == false)
{
if(Environment.MONEY.Money.hasBarMoney(sender,50))
{
Vehicle veh = RAPI.MainAPI.createRolePlayVehicle(VehicleHash.Faggio, new Vector3(-1046.036, -2723.229, 20.07), new Vector3(0, 0, -119), 0, 255, 255);
API.setPlayerIntoVehicle(sender, veh, -1);
API.setEntityData(sender, "ausleih", true);
Environment.MONEY.Money.giveBarMoney(sender, -50, API);
}
}
else
{
API.sendPictureNotificationToPlayer(sender, "Du hast schon ein Faggio ausgeliehen!", "CHAR_BLOCKED", 1, 0, "Faggio Ausleih", "");
}
}
else
{
API.triggerClientEvent(sender, "menu_handler_close_menu");
}
} else if(callbackId == AUSLEIH_CB){
if(index == 0){
//PANTO
Vehicle panto = API.createVehicle(VehicleHash.Panto,sender.position, sender.rotation,new Random().Next(0,100),new Random().Next(0,100),0);
panto.numberPlate = "84D6A54D";
panto.setData("owner",sender);
panto.setData("remainingtime",45);
} else if(index == 1){
Vehicle panto = API.createVehicle(VehicleHash.Issi2,sender.position, sender.rotation,new Random().Next(0,100),new Random().Next(0,100),0);
panto.numberPlate = "84D6A54F";
panto.setData("owner",sender);
panto.setData("remainingtime",45);
} else if(index == 2){
Vehicle panto = API.createVehicle(VehicleHash.Blista,sender.position, sender.rotation,new Random().Next(0,100),new Random().Next(0,100),0);
panto.numberPlate = "84D6A54G";
panto.setData("owner",sender);
panto.setData("remainingtime",45);
}
}
}
}
public void loadtimer(){
API.delay(1000*60,false, () => {
foreach(NetHandle nh in API.getAllVehicles()){
if(API.getEntityType(nh) == EntityType.Vehicle){
Vehicle veh = API.getEntityFromHandle<Vehicle>(nh);
if(veh != null){
if(veh.hasData("remainingtime") == true){
int remainingtime = veh.getData("remainingtime");
if(remainingtime != 0){
veh.setData("remainingtime", remainingtime -1);
} else {
veh.delete();
}
}
}
}
}
});
}
private void RollerAusleih(ColShape colshape, NetHandle entity)
{
if (colshape.getData("ausleih") == true)
{
if(API.getEntityType(entity) == EntityType.Player)
{
Client player = API.getPlayerFromHandle(entity);
object[] argumentList = new object[13];
argumentList[0] = VEHICLE_CALLBACKID;
argumentList[1] = "Rollerverleih";
argumentList[2] = "Optionen:";
argumentList[3] = false;
int itemlength = 2;
argumentList[4] = itemlength;
argumentList[5] = "Ausleihen";
argumentList[6] = "Schliessen";
for (var i = 0; i < itemlength; i++)
{
argumentList[9 + i] = "";
}
API.triggerClientEvent(player, "menu_handler_create_menu", argumentList);
}
}
}
public const int AUSLEIH_CB = 4168561;
private void onColHandler(ColShape colshape, NetHandle entity)
{
if(colshape != null && entity != null)
{
if(colshape.hasData("wagenausleih") == true && colshape.getData("wagenausleih") == true)
{
Client player = API.getPlayerFromHandle(entity);
if(player != null)
{
object[] argumentList = new object[14];
argumentList[0] = AUSLEIH_CB;
argumentList[1] = "Autoverleih";
argumentList[2] = "Optionen:";
argumentList[3] = false;
int itemlength = 3;
argumentList[4] = itemlength;
argumentList[5] = "Panto";
argumentList[6] = "Issi";
argumentList[7] = "Blista";
argumentList[8] = "~y~ 45min ~c~| ~g~$500";
argumentList[9] = "~y~ 45min ~c~| ~g~$750";
argumentList[10] = "~y~ 45min ~c~| ~g~$1000";
API.triggerClientEvent(player, "menu_handler_create_menu", argumentList);
}
}
}
}
public void loadAusleihe()
{
}
public static void createAusleih(Vector3 npc, float npcrotation, Vector3 markerpos)
{
API.shared.createPed(PedHash.TaosTranslator,npc,npcrotation,0);
RAPI.Marker.createMarker(0,markerpos,1,255,255,255,"wagenausleih",0,150,"Autoverleih",0);
}
}
}