Files
reallife-gamemode/Server/Managers/LoadManager.cs
2018-11-28 19:36:46 +01:00

80 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using GTANetworkAPI;
using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities;
/**
* @overview Life of German Reallife - Managers LoadManager (LoadManager.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/
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()
{
using (var loadData = new DatabaseContext())
{
foreach (Saves.SavedBlip b in loadData.Blips)
{
if(b.Active == true)
{
NAPI.Blip.CreateBlip((uint) b.Sprite, new Vector3(b.PositionX, b.PositionY, b.PositionZ), b.Scale,
b.Color, b.Name, b.Alpha, b.DrawDistance, b.ShortRange, (short) b.Rotation, b.Dimension);
}
}
foreach (GotoPoint g in loadData.GotoPoints)
{
if (g.Active == true)
{
GotoPointList.Add(g);
}
}
foreach(ServerVehicle veh in loadData.ServerVehicles)
{
if (!veh.Active) continue;
Vehicle current = veh.Spawn();
if (veh is Saves.SavedVehicle savedV)
{
NAPI.Vehicle.CreateVehicle((uint)savedV.Model, new Vector3(savedV.PositionX, savedV.PositionY, savedV.PositionZ), savedV.Heading, savedV.PrimaryColor,
savedV.SecondaryColor, savedV.NumberPlate, 255, savedV.Locked);
}
if (veh is FactionVehicle factionV)
{
current.SetData("factionId", factionV.FactionId);
FactionVehicleList.Add(current);
}
if (veh is ShopVehicle shopV)
{
string displayName = NAPI.Vehicle.GetVehicleDisplayName(shopV.Model);
ShopVehicleList.Add(current);
NAPI.Vehicle.SetVehicleEngineHealth(current, 0);
var tLabel = NAPI.TextLabel.CreateTextLabel(displayName + " | " + shopV.Price + "~g~$", new Vector3(shopV.PositionX, shopV.PositionY, shopV.PositionZ + 1.5), 10, 1, 0, new Color(255, 255, 255), false);
current.SetData("shopVehicleId", shopV.Id);
tLabel.AttachTo(current, "chassis", new Vector3(0, 0, 1.5), new Vector3(0, 0, 0));
}
if (veh is UserVehicle userV)
{
UserVehicleList.Add(current);
}
}
}
}
}
}