Add /goto and /save goto

This commit is contained in:
VegaZ
2018-10-15 18:29:16 +02:00
parent 216bdb4c6c
commit 42e1dc6e07
7 changed files with 84 additions and 81 deletions

View File

@@ -58,6 +58,7 @@ namespace reallife_gamemode.Model
//Saves
public DbSet<Server.Saves.SavedBlip> Blips { get; set; }
public DbSet<Server.Entities.GotoPoint> GotoPoints { get; set; }
public DbSet<Server.Saves.SavedMarker> Markers { get; set; }
public DbSet<Server.Saves.SavedPed> Peds { get; set; }
public DbSet<Server.Saves.SavedPickup> Pickups { get; set; }

View File

@@ -187,6 +187,20 @@ namespace reallife_gamemode.Server.Commands
player.SendChatMessage("Position: X Y Z: " + player.Position);
}
[Command("goto", "~m~Benutzung: ~s~/goto [Ort]")]
public void CmdAdminGotoPoint(Client player, string location)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{
ChatService.NotAuthorized(player);
return;
}
using (var dbContext = new DatabaseContext())
{
Entities.GotoPoint p = dbContext.GotoPoints.FirstOrDefault(x => x.Description == location);
player.MovePosition(new Vector3(p.X, p.Y, p.Z), 0);
}
}
[Command("gotox", "~m~Benutzung: ~s~/gotox [X] [Y] [Z]")]
public void CmdAdminGotoxyz(Client player, float x, float y, float z)
@@ -630,13 +644,25 @@ namespace reallife_gamemode.Server.Commands
target.GetUser().BanPlayer(admin, reason, mins);
}
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle, FVehicle, SVehicle")]
public void CmdAdminSave(Client player, string typ)
[Command("save", "~m~Benutzung: ~s~/save [Typ = ~g~Blip, Goto (X), ~r~Marker, Ped, Pickup, TextLabel, ~g~Vehicle, FVehicle, SVehicle] (Beschreibung) = (X)")]
public void CmdAdminSave(Client player, string typ, string description = null)
{
switch (typ)
{
case "Blip":
player.TriggerEvent("saveBlip");
break;
case "Goto":
if(description == null)
{
player.SendChatMessage("Für Goto musst du einen dritten Parameter angeben. Beispiel: Ort des Goto-Punktes.");
return;
}
else
{
SaveManager.SaveGotoPoint(player, description);
}
break;
case "Vehicle":
if (player.IsInVehicle)

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using reallife_gamemode.Server.Entities;
/**
* @overview Life of German Reallife - Entities GotoPoints (GotoPoints.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
namespace reallife_gamemode.Server.Entities
{
public class GotoPoint
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[StringLength(32)]
public string Description { get; set; }
public float X { get; set; }
public float Y { get; set; }
public float Z { get; set; }
public bool Active { get; set; }
}
}

View File

@@ -86,7 +86,7 @@ namespace reallife_gamemode.Server.Events
}
else
{
loginUser.Bans.Remove(bannedUser);
player.GetUser().BanId = null;
loginUser.SaveChanges();
player.TriggerEvent("showLogin");
}

View File

@@ -1,78 +0,0 @@
using GTANetworkAPI;
using System;
using System.Collections.Generic;
using System.Text;
namespace reallife_gamemode.Server.Events
{
public class SaveData : 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, 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 = false,
Dimension = vehicleDimension,
Active = true
};
saveData.Vehicles.Add(dataSet);
saveData.SaveChanges();
}
}
}
}

View File

@@ -15,10 +15,12 @@ namespace reallife_gamemode.Server.Managers
{
public class LoadManager : Script
{
public static List<GotoPoint> GotoPointList = new List<GotoPoint>();
public static List<Vehicle> FactionVehicleList = new List<Vehicle>();
public static List<Vehicle> ShopVehicleList = new List<Vehicle>();
public static List<Vehicle> UserVehicleList = new List<Vehicle>();
[ServerEvent(Event.ResourceStart)]
public void OnResourceStart()
{
@@ -32,6 +34,13 @@ namespace reallife_gamemode.Server.Managers
b.Color, b.Name, b.Alpha, b.DrawDistance, b.ShortRange, (short) b.Rotation, b.Dimension);
}
}
foreach (Entities.GotoPoint g in loadData.GotoPoints)
{
if (g.Active == true)
{
GotoPointList.Add(g);
}
}
foreach (Saves.SavedVehicle v in loadData.Vehicles)
{
if (v.Active == true)

View File

@@ -124,6 +124,23 @@ namespace reallife_gamemode.Server.Events
saveData.SaveChanges();
}
}
public static void SaveGotoPoint(Client player, string description)
{
using (var saveData = new Model.DatabaseContext())
{
var dataSet = new Entities.GotoPoint
{
Description = description,
X = player.Position.X,
Y = player.Position.Y,
Z = player.Position.Z,
Active = true
};
saveData.GotoPoints.Add(dataSet);
saveData.SaveChanges();
}
}
public static void SaveAllOnSave()
{
using (var saveAll = new Model.DatabaseContext())