diff --git a/ReallifeGamemode.Client/util/Gangwar.ts b/ReallifeGamemode.Client/util/Gangwar.ts index a917301c..ec8690f8 100644 --- a/ReallifeGamemode.Client/util/Gangwar.ts +++ b/ReallifeGamemode.Client/util/Gangwar.ts @@ -28,7 +28,8 @@ SET_BLIP_FLASHES: "0xB14552383D39CE3E", GET_FIRST_BLIP_INFO_ID: "0x1BEDE233E6CD2A1F", GET_NEXT_BLIP_INFO_ID: "0x14F96AA50D6FBEA7", - DOES_BLIP_EXIST: "0xA6DB27D19ECBB7DA" + DOES_BLIP_EXIST: "0xA6DB27D19ECBB7DA", + SET_BLIP_COORDS: "0xAE2AF67E9D9AF65D" }; var Gangturf = class { @@ -59,27 +60,30 @@ } _setup(name, id, x, y, range, color, rot, owner, edit) { + var self = this; self.name = name; self.id = id; self.range = range; - if (owner = "Ballas") { + if (owner === "Ballas") { + self.color = 83; self.colorZone_r = 143; self.colorZone_g = 0; self.colorZone_b = 199; - } else if (owner = "GroveStreet") { + } else if (owner === "GroveStreet") { + self.color = 2; self.colorZone_r = 22; self.colorZone_g = 87; self.colorZone_b = 0; - } else if (owner = "Neutral") { + } else if (owner === "Neutral") { + self.color = 0; self.colorZone_r = 255; self.colorZone_g = 255; self.colorZone_b = 255; } - self.color = color; + self.x = x; self.y = y; - self.rotation = rot; self._colshape = null; self._status = "normal"; @@ -97,20 +101,31 @@ loadArea() { var self = this; - self.blip = mp.game.ui.addBlipForRadius(self.x, self.y, 1, self.range); - mp.game.invoke(Natives.SET_BLIP_SPRITE, self.blip, 5); - mp.game.invoke(Natives.SET_BLIP_ALPHA, self.blip, 70); - mp.game.invoke(Natives.SET_BLIP_COLOUR, self.blip, self.color); + + self.blip = mp.game.ui.addBlipForRadius(self.x, self.y, 1, self.range); + mp.game.invoke(Natives.SET_BLIP_SPRITE, self.blip, 5); + mp.game.invoke(Natives.SET_BLIP_ALPHA, self.blip, 70); + mp.game.invoke(Natives.SET_BLIP_COLOUR, self.blip, self.color); + self._colshape = mp.colshapes.newCircle(self.x, self.y, self.range * 1.5); } render() { var self = this; - if (self.blip) { - mp.game.invoke(Natives.SET_BLIP_ROTATION, self.blip, self.rotation); + if (self._colshape) { + if (self.edit == true) { + let vector3 = mp.players.local.getRotation(2); + self.rotation = Math.round(vector3.z); + mp.game.invoke(Natives.SET_BLIP_COORDS, self.blip, mp.players.local.position.x, mp.players.local.position.y, 1); + self.x = mp.players.local.position.x; + self.y = mp.players.local.position.y; + } + mp.game.invoke(Natives.SET_BLIP_ROTATION, self.blip, self.rotation); + } - if (self._status == "attack") { - if (self.blip) { + + if (self._status == "attack" || self.edit == true) { + if (self._colshape) { if (mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, 0, self.x, self.y, 0, true) < self.range * 1.5) { var range = Math.sqrt(((self.range * 1.2) * (self.range * 1.2)) + (((self.range * 1.2) / 2) * ((self.range * 1.2) / 2))); let degrees = (self.rotation + 45) * (Math.PI / 180); @@ -310,15 +325,33 @@ mp.events.add('GangAreas:Create', (turfsJSON) => { var turfs = JSON.parse(turfsJSON); + if (gangturfs.length > 0) { + gangturfs[gangturfs.length - 1].edit = false; + } clearBlips(); if (turfs.length > 0) { gangturfs = []; turfs.forEach(function (turf) { if (turf.Id != undefined) { - gangturfs[gangturfs.length] = new Gangturf(turf.Name, turf.Id, turf.X, turf.Y, turf.Range, turf.Color, turf.Rotation, turf.Owner); + mp.gui.chat.push(turf.Owner); + gangturfs[gangturfs.length] = new Gangturf(turf.Name, turf.Id, turf.X, turf.Y, turf.Range, turf.Color, turf.Rotation, turf.Owner, false); } }); } }); + mp.events.add('ADMIN:CreateTurf', (rangeJSON) => { + var range = JSON.parse(rangeJSON); + gangturfs[gangturfs.length] = new Gangturf("Reload For Name", -1, mp.players.local.position.x, mp.players.local.position.y, range, 0, mp.players.local.getHeading(), "Neutral", true); + }); + + mp.events.add('ADMIN:SetTurf', (name) => { + gangturfs[gangturfs.length - 1].edit = false; + if (gangturfs[gangturfs.length - 1].id == -1) { + + mp.events.callRemote("SERVER:SetTurf", JSON.stringify(gangturfs[gangturfs.length - 1].x), JSON.stringify(gangturfs[gangturfs.length - 1].y), JSON.stringify(gangturfs[gangturfs.length - 1].rotation), JSON.stringify(gangturfs[gangturfs.length - 1].range), name); + } + }); + + } \ No newline at end of file diff --git a/ReallifeGamemode.Database/Entities/Turfs.cs b/ReallifeGamemode.Database/Entities/Turfs.cs index d7829c56..fcfcf87d 100644 --- a/ReallifeGamemode.Database/Entities/Turfs.cs +++ b/ReallifeGamemode.Database/Entities/Turfs.cs @@ -21,10 +21,10 @@ namespace ReallifeGamemode.Database.Entities public string Owner { get; set; } public string Name { get; set; } - public int X { get; set; } - public int Y { get; set; } - public int Rotation { get; set; } - public int Range { get; set; } + public float X { get; set; } + public float Y { get; set; } + public float Rotation { get; set; } + public float Range { get; set; } public int Color { get; set; } } diff --git a/ReallifeGamemode.Server/Commands/AdminCommands.cs b/ReallifeGamemode.Server/Commands/AdminCommands.cs index 88db8863..d5d2062c 100644 --- a/ReallifeGamemode.Server/Commands/AdminCommands.cs +++ b/ReallifeGamemode.Server/Commands/AdminCommands.cs @@ -2986,6 +2986,39 @@ namespace ReallifeGamemode.Server.Commands player.SendChatMessage("~m~Benutzung:~s~ /business [price] [Option]"); } + [Command("createturf", "~m~Benutzung:~s~ /createturf [radius]")] + public void CmdAdmCreateTurf(Client player, float option) + { + if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true) + { + ChatService.NotAuthorized(player); + return; + } + player.TriggerEvent("ADMIN:CreateTurf", JsonConvert.SerializeObject(option)); + } + + [Command("setturf", "~m~Benutzung:~s~ /setturf (Name)")] + public void CmdAdmSetTurf(Client player, string name) + { + if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true) + { + ChatService.NotAuthorized(player); + return; + } + player.TriggerEvent("ADMIN:SetTurf", name); + } + + [Command("cancleturf", "~m~Benutzung:~s~ /cancleturf")] + public void CmdAdmCancleTurf(Client player) + { + if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true) + { + ChatService.NotAuthorized(player); + return; + } + Gangwar.Gangwar.loadClient(player); + } + #endregion #region ALevel1338 diff --git a/ReallifeGamemode.Server/Gangwar/Gangwar.cs b/ReallifeGamemode.Server/Gangwar/Gangwar.cs index f614bcc5..d7781523 100644 --- a/ReallifeGamemode.Server/Gangwar/Gangwar.cs +++ b/ReallifeGamemode.Server/Gangwar/Gangwar.cs @@ -9,7 +9,7 @@ using Newtonsoft.Json; namespace ReallifeGamemode.Server.Gangwar { - public class Gangwar + public class Gangwar : Script { public static Turf[] _loadedTurfs; private static List turfs; @@ -40,5 +40,33 @@ namespace ReallifeGamemode.Server.Gangwar return _loadedTurfs; } + + [RemoteEvent("SERVER:SetTurf")] + public void RmtEvent_SetTurf(Client client, string jsonX, string jsonY, string jsonRot, string jsonRange, string Name) + { + float pX = JsonConvert.DeserializeObject(jsonX); + float pY = (float)JsonConvert.DeserializeObject(jsonY); + float Rot = (float)JsonConvert.DeserializeObject(jsonRot); + float Range = (float)JsonConvert.DeserializeObject(jsonRange); + + var newTurf = new Turfs + { + Name = Name, + X = pX, + Y = pY, + Rotation = client.Heading, + Range = Range, + Owner = "Neutral", + Color = 0 + }; + using(var dbContext = new DatabaseContext()) + { + dbContext.Turfs.Add(newTurf); + dbContext.SaveChanges(); + } + loadTurfs(); + NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray())); + } + } }