Add VehicleShop, SaveManager, Edit LoadManager amm...
This commit is contained in:
156
Server/Managers/SaveManager.cs
Normal file
156
Server/Managers/SaveManager.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace reallife_gamemode.Server.Events
|
||||
{
|
||||
public class SaveManager : Script
|
||||
{
|
||||
[RemoteEvent("OnSaveBlipData")]
|
||||
public void OnSaveBlipData(Client player, string blipSprite, string blipName, string blipScale, string blipColor,
|
||||
string blipAlpha, string blipDrawDistance, string blipShortRange, string blipRotation, string blipDimension)
|
||||
{
|
||||
float x = player.Position.X;
|
||||
float y = player.Position.Y;
|
||||
float z = player.Position.Z;
|
||||
short sprite = short.Parse(blipSprite);
|
||||
string name = blipName;
|
||||
float scale = float.Parse(blipScale);
|
||||
byte color = Convert.ToByte(blipColor);
|
||||
byte alpha = Convert.ToByte(blipAlpha);
|
||||
float drawDistance = float.Parse(blipDrawDistance);
|
||||
bool shortRange = bool.Parse(blipShortRange);
|
||||
float rotation = float.Parse(blipRotation);
|
||||
byte dimension = Convert.ToByte(blipDimension);
|
||||
|
||||
NAPI.Blip.CreateBlip(uint.Parse(blipSprite), new Vector3(x,y,z), scale, color, name, alpha, drawDistance, shortRange, short.Parse(blipRotation), dimension);
|
||||
|
||||
using (var saveData = new Model.DatabaseContext())
|
||||
{
|
||||
var dataSet = new Server.Saves.SavedBlip
|
||||
{
|
||||
Sprite = sprite,
|
||||
PositionX = x,
|
||||
PositionY = y,
|
||||
PositionZ = z,
|
||||
Name = blipName,
|
||||
Scale = scale,
|
||||
Color = color,
|
||||
Alpha = alpha,
|
||||
DrawDistance = drawDistance,
|
||||
ShortRange = shortRange,
|
||||
Rotation = rotation,
|
||||
Dimension = dimension,
|
||||
Active = true
|
||||
};
|
||||
saveData.Blips.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveVehicleData(VehicleHash vehicleModel, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, byte vehiclePrimaryColor, byte vehicleSecondaryColor, bool vehicleLocked, bool vehicleEngine, byte vehicleDimension)
|
||||
{
|
||||
using (var saveData = new Model.DatabaseContext())
|
||||
{
|
||||
var dataSet = new Server.Saves.SavedVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Locked = vehicleLocked,
|
||||
Engine = vehicleEngine,
|
||||
Dimension = vehicleDimension,
|
||||
Active = true
|
||||
};
|
||||
saveData.Vehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
public static void SaveFactionVehicleData(VehicleHash vehicleModel, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, byte vehiclePrimaryColor, byte vehicleSecondaryColor, bool vehicleLocked, bool vehicleEngine, byte vehicleDimension, int? factionId)
|
||||
{
|
||||
using (var saveData = new Model.DatabaseContext())
|
||||
{
|
||||
var dataSet = new Entities.FactionVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
FactionId = factionId,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Locked = vehicleLocked,
|
||||
Engine = vehicleEngine,
|
||||
Dimension = vehicleDimension,
|
||||
Active = true
|
||||
};
|
||||
saveData.FactionVehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
public static void SaveShopVehicleData(VehicleHash vehicleModel, string vehicleModelName, Vector3 vehiclePosition, float vehicleHeading,
|
||||
string vehicleNumberPlate, byte vehiclePrimaryColor, byte vehicleSecondaryColor, byte vehicleDimension, int? factionId)
|
||||
{
|
||||
using (var saveData = new Model.DatabaseContext())
|
||||
{
|
||||
var dataSet = new Entities.ShopVehicle
|
||||
{
|
||||
Model = vehicleModel,
|
||||
ModelName = vehicleModelName,
|
||||
PositionX = vehiclePosition.X,
|
||||
PositionY = vehiclePosition.Y,
|
||||
PositionZ = vehiclePosition.Z,
|
||||
Heading = vehicleHeading,
|
||||
NumberPlate = vehicleNumberPlate,
|
||||
PrimaryColor = vehiclePrimaryColor,
|
||||
SecondaryColor = vehicleSecondaryColor,
|
||||
Dimension = vehicleDimension,
|
||||
Active = true
|
||||
};
|
||||
saveData.ShopVehicles.Add(dataSet);
|
||||
saveData.SaveChanges();
|
||||
}
|
||||
}
|
||||
public static void SaveAllOnSave()
|
||||
{
|
||||
using (var saveAll = new Model.DatabaseContext())
|
||||
{
|
||||
//Alle User Vehicle
|
||||
foreach (Vehicle v in LoadManager.UserVehicleList)
|
||||
{
|
||||
int ownerId = v.GetData("ownerId");
|
||||
Entities.UserVehicle userVehicle = saveAll.UserVehicles.FirstOrDefault(u => u.UserId == ownerId);
|
||||
userVehicle.PositionX = v.Position.X;
|
||||
userVehicle.PositionY = v.Position.Y;
|
||||
userVehicle.PositionZ = v.Position.Z;
|
||||
userVehicle.Heading = v.Heading;
|
||||
}
|
||||
|
||||
//Alle Spieler
|
||||
foreach (Client player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
int userId = player.GetUser().Id;
|
||||
Entities.User user = saveAll.Users.FirstOrDefault(u => u.Id == userId);
|
||||
user.PositionX = player.Position.X;
|
||||
user.PositionY = player.Position.Y;
|
||||
user.PositionZ = player.Position.Z;
|
||||
}
|
||||
|
||||
saveAll.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user