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

193 lines
No EOL
10 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 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.Shared;
using GrandTheftMultiplayer.Shared.Math;
using GrandTheftMultiplayer.Server.Elements;
using GrandTheftMultiplayer.Server.Constant;
using GrandTheftMultiplayer.Server.Managers;
namespace Roleplay.Vehiclesystem
{
class Garagen : Script
{
public Garagen()
{
loadGaragen();
API.onEntityEnterColShape += onCol;
API.onPlayerEnterVehicle += onVehenter;
}
public void loadGaragen()
{
createGaragen();
initfahrzeugplaetze();
}
public static Dictionary<Vector3,Vector3> fahrzeugplatzcoordinaten = new Dictionary<Vector3, Vector3>();
public void createGaragen()
{
// no need to subtract 1 from vector.z
RAPI.Marker.createMarker(1, new Vector3(224.4718,-1006.159,-100),1,255,255,255,"garageausgang",0,150,"Ausgang",0);
createGarage(new Vector3(-286.1883,-993.951,24.18966), new Vector3(-245.013,-1008.895,29));
createGarage(new Vector3(1410.2960,3620.221,34.89), new Vector3(1420.203,3623.018,34.43812));
createGarage(new Vector3(-83.86467,6497.647,31.49), new Vector3(-76.0,6488.279,31.06));
createGarage(new Vector3(-201.8927,192.3173,79.56), new Vector3(-218.6985,192.3184,80.300));
createGarage(new Vector3(186.4626,2786.7,45.95), new Vector3(198.9884,2789.475,45.23163));
createGarage(new Vector3(-1203.929,-1489.616,4.35), new Vector3(-1178.401,-1488.99,3.9));
createGarage(new Vector3(416.9065,-1168.525,28.72203), new Vector3(433.3928,-1156.188,28.72));
createGarage(new Vector3(-70.19,-1822.766,26.37), new Vector3(-58.65803,-1835.294,26.11637));
createGarage(new Vector3(1196.69,-1768.275,38.93857), new Vector3(1205.433,-1764.278,39.11811));
createGarage(new Vector3(900.7571,-145.7877,76.04), new Vector3(902.8272,-136.9632,76.09794));
createGarage(new Vector3(-875.2408,-2735.09,13.3113), new Vector3(-887.381,-2728.418,13.25815));
createGarage(new Vector3(-1370.086,-473.0449,31.025), new Vector3(-1388.501,-473.0952,31.01838));
}
public void createGarage(Vector3 marker, Vector3 fahrzeugeouput)
{
Marker m = RAPI.Marker.createMarkerWithReturnType(1,marker.Subtract(new Vector3(0,0,1)),2,255,255,255,"Garageeingang",0,185,"Garage",0);
ColShape col = m.getData("colshape");
col.setData("output",fahrzeugeouput);
Blip blip = API.createBlip(marker);
blip.sprite = 50;
API.setBlipName(blip, "Garage");
}
public void initfahrzeugplaetze(){
fahrzeugplatzcoordinaten.Add(new Vector3(223.41, -999.54, -99.37), new Vector3(0,0,-117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(223.08, -994.45, -99.37), new Vector3(0,0,-117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(223.47, -989.82, -99.38), new Vector3(0,0,-117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(223.27, -985.14, -99.38), new Vector3(0,0,-117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(223.50, -980.24, -99.38), new Vector3(0,0,-117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(233.42, -901.83, -99.37), new Vector3(0,0,117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(233.31, -985.86, -99.38), new Vector3(0,0,117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(233.40, -990.01, -99.38), new Vector3(0,0,117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(233.59, -994.54, -99.38), new Vector3(0,0,117.75));
fahrzeugplatzcoordinaten.Add(new Vector3(233.74, -999.71, -99.38), new Vector3(0,0,117.75));
}
public void onCol(ColShape col, NetHandle entity)
{
if(col != null && entity != null){
if(col.hasData("Garageeingang") == true && col.getData("Garageeingang") == true && col.hasData("output") == true){
if(API.getEntityType(entity) == EntityType.Player){
Client player = API.getPlayerFromHandle(entity);
if(player.isInVehicle != true){
ClientAPI.loadingScreen(player,5);
ClientAPI.playSound(player,"OPENING","DOOR_GARAGE");
Vehiclesystem.VehicleMain.deletePersonalVehicle(player);
Vector3 ouput = col.getData("output");
int privateDimension = API.getEntityData(player,"ID");
API.setEntityData(player,"output",ouput);
API.setEntityPosition(player,new Vector3(241.5012,-1004.756,-98.9));
API.setEntityDimension(player,privateDimension);
Vehiclesystem.VehicleMain.loadPrivateVehicles(player,API);
List<Vehicle> vehiclelist = Vehiclesystem.VehicleMain.getPrivateVehicles(player);
int fahrzeugplatzid = 0;
foreach(Vehicle veh in vehiclelist){
if(veh != null){
veh.position = fahrzeugplatzcoordinaten.Keys.ElementAt(fahrzeugplatzid);
veh.rotation = fahrzeugplatzcoordinaten.Values.ElementAt(fahrzeugplatzid);
API.setEntityDimension(veh,privateDimension);
API.setEntityData(veh,"eingelagert",true);
veh.repair();
fahrzeugplatzid++;
}
}
}
} else if(API.getEntityType(entity) == EntityType.Vehicle){
Vehicle vehs = API.getEntityFromHandle<Vehicle>(entity);
if(vehs != null && vehs.occupants[0] != null){
Client player = vehs.occupants[0];
if(API.getEntityData(vehs,"besitzer") == player.name){
ClientAPI.loadingScreen(player,5);
ClientAPI.playSound(player,"OPENING","DOOR_GARAGE");
Vehiclesystem.VehicleMain.deletePersonalVehicle(player);
if(vehs != null){
vehs.delete();
}
Vector3 ouput = col.getData("output");
API.setEntityData(player,"output",ouput);
int privateDimension = API.getEntityData(player,"ID");
API.setEntityPosition(player,new Vector3(231.2288,-1006.435,-98.99));
API.setEntityDimension(player,privateDimension);
Vehiclesystem.VehicleMain.loadPrivateVehicles(player,API);
List<Vehicle> vehiclelist = Vehiclesystem.VehicleMain.getPrivateVehicles(player);
int fahrzeugplatzid = 0;
foreach(Vehicle veh in vehiclelist){
if(veh != null){
veh.position = fahrzeugplatzcoordinaten.Keys.ElementAt(fahrzeugplatzid);
veh.rotation = fahrzeugplatzcoordinaten.Values.ElementAt(fahrzeugplatzid);
API.setEntityDimension(veh,privateDimension);
API.setEntityData(veh,"eingelagert",true);
veh.repair();
fahrzeugplatzid++;
}
}
} else {
API.sendNotificationToPlayer(player,"Das ist nicht dein Fahrzeug!");
}
}
}
} else if(col.hasData("garageausgang") == true && col.getData("garageausgang") == true){
if(API.getEntityType(entity) == EntityType.Player){
Client player = API.getPlayerFromHandle(entity);
if(player.isInVehicle != true){
if(player != null && player.hasData("output") == true){
ClientAPI.loadingScreen(player,5);
ClientAPI.playSound(player,"GARAGE_DOOR_SCRIPTED_CLOSE","0");
player.position = player.getData("output");
player.resetData("output");
player.dimension = 0;
Vehiclesystem.VehicleMain.deletePersonalVehicle(player);
} else {
API.sendNotificationToPlayer(player,"Du bist in einer falschen Garage!",true);
}
}
}
}
}
}
public void onVehenter(Client sender, NetHandle veh, int x)
{
if(sender != null && veh != null){
Vehicle vehs = API.getEntityFromHandle<Vehicle>(veh);
if(vehs.hasData("eingelagert") == true && vehs.getData("eingelagert") == true && sender.hasData("output") == true){
ClientAPI.loadingScreen(sender,5);
Vector3 output = sender.getData("output");
vehs.resetData("eingelagert");
vehs.dimension = 0;
sender.dimension = 0;
API.setEntityPosition(vehs,output);
sender.resetData("output");
List<Vehicle> privates = Vehiclesystem.VehicleMain.getPrivateVehicles(sender);
foreach(Vehicle pri in privates){
if(pri != null){
if(pri.hasData("eingelagert") == true){
pri.delete();
Vehiclesystem.VehicleMain.privates.Remove(sender);
}
}
}
}
}
}
}
}