[+] Add Gangwar System (bugs incl.)

This commit is contained in:
Lukas Moungos
2020-01-13 21:43:55 +01:00
parent 3b0189807e
commit e8321e3ec3
10 changed files with 246 additions and 85 deletions

View File

@@ -240,7 +240,7 @@ export default function (globalData: GlobalData): void {
})
if (jailTime > 0) {
mp.game.graphics.drawText("~y~Knastzeit: " + jailTime + " Minuten", [0.92, 0.52],
mp.game.graphics.drawText("~y~Knastzeit: ~ " + jailTime + " Minuten", [0.92, 0.52],
{
font: 4,
color: [255, 255, 255, 255],
@@ -251,7 +251,7 @@ export default function (globalData: GlobalData): void {
}
if (att_score > 0 && def_score > 0) {
mp.game.graphics.drawText("~y~" + def + " " + def_score + " : " + att_score + " " + att, [0.1, 0.416],
mp.game.graphics.drawText("~y~" + def + " " + def_score + " : " + att_score + " " + att, [0.07, 0.55],
{
font: 4,
color: [255, 255, 255, 255],
@@ -259,6 +259,15 @@ export default function (globalData: GlobalData): void {
outline: true,
centre: false
})
mp.game.graphics.drawText("~w~Gangwar", [0.07, 0.514],
{
font: 1,
color: [255, 255, 255, 255],
scale: [0.5, 0.5],
outline: true,
centre: false
})
mp.game.graphics.drawRect(0.0, 0.555, 0.3, 0.08, 0, 0, 0, 70)
}
}

View File

@@ -76,7 +76,7 @@ export default function keys(globalData: GlobalData) {
//E
mp.keys.bind(0x45, false, function () {
if (!globalData.InChat) {
if (!globalData.InChat && !globalData.InMenu) {
mp.events.callRemote("keyPress:E");
}
});
@@ -95,8 +95,8 @@ export default function keys(globalData: GlobalData) {
});
//O //Spielerliste
mp.keys.bind(0x4F, false, function () {
if (!globalData.InChat && !globalData.InMenu) {
mp.keys.bind(0x4F, true, function () {
if (!globalData.InChat && !globalData.InMenu && !globalData.InTuning && !showInv) {
mp.events.callRemote("keyPress:O");
//mp.events.call("showPlayerlist");
}

View File

@@ -56,12 +56,15 @@
_timerCheck;
edit: boolean;
attackBlip: BlipMp;
leaderBlip: BlipMp;
leaderBlipVector: Vector3Mp;
leaderColShape: MarkerMp;
constructor(name, id, x, y, range, color, rot, owner, edit) {
this._setup(name, id, x, y, range, color, rot, owner, edit);
constructor(name, id, x, y, range, color, rot, owner, edit, vector) {
this._setup(name, id, x, y, range, color, rot, owner, edit, vector);
}
_setup(name, id, x, y, range, color, rot, owner, edit) {
_setup(name, id, x, y, range, color, rot, owner, edit, vector) {
var self = this;
self.name = name;
@@ -82,6 +85,14 @@
self.edit = edit;
self.loadArea();
self.attackBlip = null;
self.leaderBlip = null;
if (vector != null) {
self.leaderBlipVector = JSON.parse(vector);
} else {
self.leaderBlipVector = null;
}
self.leaderColShape = null;
}
setColor(owner) {
@@ -133,6 +144,8 @@
}
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) {
@@ -182,6 +195,8 @@
}
}
if (self.isInsideArea()) {
mp.game.graphics.drawText(self.name, [self.x, self.y, mp.players.local.position.z + 20], {
font: 7,
@@ -190,14 +205,49 @@
outline: true,
centre: true
});
}
}
}
if (self.leaderBlipVector != null) {
let dist = mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, mp.players.local.position.z, self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z, false);
if (self.isInsideArea() && self._status != "attack" && dist <= 3) {
if (self.leaderBlipVector != null) {
mp.game.graphics.drawText(self.name + "\n~y~Gang: ~s~" + self.owner + "\n~y~Wert: ~s~$~g~187", [self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z], {
font: 7,
color: [255, 255, 255, 185],
scale: [0.4, 0.4],
outline: true,
centre: true
});
}
}
}
}
private delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async startGangWar() {
var self = this;
await this.delay(1000);
if (self._status == "normal") {
let dist = mp.game.gameplay.getDistanceBetweenCoords(mp.players.local.position.x, mp.players.local.position.y, 0, self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z, false);
if (dist <= 3) {
mp.events.callRemote("SERVER:StartGangwar");
}
}
}
updateArea(status, ...args) {
var self = this;
if (status == "attack") {
if (self.leaderColShape != null) {
self.leaderColShape.destroy();
self.leaderColShape = null;
}
self._status = "attack";
self.attacker = args[1];
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, true);
@@ -216,6 +266,7 @@
mp.game.invoke(Natives.SET_BLIP_FLASHES, self.blip, false);
self.setColor(self.owner)
mp.game.invoke(Natives.SET_BLIP_COLOUR, self.blip, self.color);
self.setLeaderColShape();
return;
}
}
@@ -223,7 +274,7 @@
setAttackBlip(bool) {
var self = this;
if (bool) {
self.attackBlip = mp.game.ui.addBlipForRadius(self.x, self.y, 1, 60);
self.attackBlip = mp.game.ui.addBlipForCoord(self.x, self.y, 0);
mp.game.invoke(Natives.SET_BLIP_SPRITE, self.attackBlip, 378);
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, self.attackBlip, false);
@@ -232,6 +283,36 @@
}
}
setLeaderBlip(bool) {
var self = this;
if (bool) {
self.leaderBlipVector = mp.players.local.position;
mp.events.callRemote("SERVER:Turf_SetNewLeaderPoint", JSON.stringify(self.leaderBlipVector), JSON.stringify(self.id));
self.setLeaderColShape();
return;
}
if (self.leaderBlipVector != null) {
self.leaderBlip = mp.game.ui.addBlipForRadius(self.leaderBlipVector.x, self.leaderBlipVector.y, 1, 60);
self.setLeaderColShape();
mp.game.invoke(Natives.SET_BLIP_SPRITE, self.leaderBlip, 437);
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, self.leaderBlip, false);
}
}
setLeaderColShape() {
var self = this;
let newVector = new mp.Vector3(self.leaderBlipVector.x, self.leaderBlipVector.y, self.leaderBlipVector.z - 2)
self.leaderColShape = mp.markers.new(1, newVector, 2, {
color: [255, 255, 255, 150],
visible: true,
dimension: 0
});
}
isTurfArea(shape) {
return (shape == this._colshape)
}
@@ -384,6 +465,11 @@
last_attackBlip = mp.game.invoke(Natives.GET_NEXT_BLIP_INFO_ID, 378);
}
let last_leaderBlip = mp.game.invoke(Natives.GET_FIRST_BLIP_INFO_ID, 437);
while (mp.game.invoke(Natives.DOES_BLIP_EXIST, last_leaderBlip)) {
mp.game.ui.removeBlip(last_leaderBlip);
last_leaderBlip = mp.game.invoke(Natives.GET_NEXT_BLIP_INFO_ID, 437);
}
}
mp.events.add('GangAreas:Create', (turfsJSON) => {
@@ -396,7 +482,7 @@
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, false);
gangturfs[gangturfs.length] = new Gangturf(turf.Name, turf.Id, turf.X, turf.Y, turf.Range, turf.Color, turf.Rotation, turf.Owner, false, turf.Vector);
}
});
}
@@ -404,7 +490,7 @@
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);
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, null);
});
mp.events.add('ADMIN:SetTurf', (name) => {
@@ -446,5 +532,31 @@
});
});
mp.events.add('CLIENT:Turf_LoadLeaderBlip', () => {
gangturfs.forEach(function (turf) {
if (turf.Id != undefined) {
turf.setLeaderBlip(false);
}
});
});
mp.events.add('ADMIN:Turf_CreateLeaderBlip', () => {
gangturfs.forEach(function (turf) {
if (turf._entered == true) {
if (turf.leaderColShape != null) {
turf.leaderColShape.destroy();
turf.leaderColShape = null;
}
turf.setLeaderBlip(true);
}
});
});
mp.events.add('CLIENT:StartGangwar', () => {
gangturfs.forEach(function (turf) {
if (turf._entered == true) {
turf.startGangWar();
}
});
});
}

View File

@@ -21,6 +21,7 @@ namespace ReallifeGamemode.Database.Entities
public float Rotation { get; set; }
public float Range { get; set; }
public int Color { get; set; }
public string Vector { get; set; } = null;
}
}

View File

@@ -16,8 +16,8 @@ namespace ReallifeGamemode.Database.Migrations
FactionId = table.Column<int>(nullable: true),
Owner = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
X = table.Column<int>(nullable: false),
Y = table.Column<int>(nullable: false),
X = table.Column<float>(nullable: false),
Y = table.Column<float>(nullable: false),
Rotation = table.Column<float>(nullable: false),
Range = table.Column<float>(nullable: false),
Color = table.Column<int>(nullable: false)

View File

@@ -907,9 +907,11 @@ namespace ReallifeGamemode.Database.Migrations
b.Property<float>("Rotation");
b.Property<int>("X");
b.Property<string>("Vector");
b.Property<int>("Y");
b.Property<float>("X");
b.Property<float>("Y");
b.HasKey("Id");

View File

@@ -1767,7 +1767,6 @@ namespace ReallifeGamemode.Server.Commands
ChatService.SendMessage(player, "~b~[ADMIN]~s~ Du hast hast den Spieler ~y~" + target.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
ChatService.SendMessage(target, "~b~[ADMIN]~s~ Du wurdest von ~y~" + player.Name + "~s~ zum Leader der Fraktion ~o~" + f.Name + "~s~ ernannt.");
u.FactionLeader = false;
switch (u.FactionId)
{
case null:
@@ -3056,7 +3055,7 @@ namespace ReallifeGamemode.Server.Commands
Gangwar.Gangwar.loadClient(player);
}
[Command("reloadturfs", "~m~Benutzung:~s~ /reloadturfs")]
[Command("reloadturfs", "~m~Benutzung:~s~ /ReloadTurfs")]
public void CmdAdmReloadTurf(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
@@ -3067,7 +3066,7 @@ namespace ReallifeGamemode.Server.Commands
Gangwar.Gangwar.loadTurfs();
Gangwar.Gangwar.loadTurfs_ToAllClients();
}
[Command("deleteturf", "~m~Benutzung:~s~ /reloadturfs")]
[Command("deleteturf", "~m~Benutzung:~s~ /DeleteTurfs")]
public void CmdAdmDeleteTurf(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
@@ -3077,7 +3076,16 @@ namespace ReallifeGamemode.Server.Commands
}
player.TriggerEvent("ADMIN:DeleteTurf");
}
[Command("setturfpoint", "~m~Benutzung:~s~ /setturfpoint")]
public void CmdAdmSetTurfPoint(Client player)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.HEADADMIN) ?? true)
{
ChatService.NotAuthorized(player);
return;
}
player.TriggerEvent("ADMIN:Turf_CreateLeaderBlip");
}
#endregion
#region ALevel1338

View File

@@ -53,6 +53,10 @@ namespace ReallifeGamemode.Server.Events
player.SetData("duty", false);
player.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney, 0);
Gangwar.Gangwar.loadClient(player);
if (player.GetUser().FactionLeader)
{
player.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
}
if (user.IsAdmin(AdminLevel.HEADADMIN) == true)
{
player.SetData("editmode", false);

View File

@@ -40,6 +40,14 @@ namespace ReallifeGamemode.Server.Gangwar
public static void loadTurfs_ToAllClients()
{
NAPI.ClientEvent.TriggerClientEventForAll("GangAreas:Create", JsonConvert.SerializeObject(turfs.ToArray()));
foreach(var l in NAPI.Pools.GetAllPlayers())
{
if (!l.IsLoggedIn() && !l.GetUser().FactionLeader)
return;
l.TriggerEvent("CLIENT:Turf_LoadLeaderBlip");
}
}
public static void GangwarKill(Client killer, Client victim)
@@ -108,7 +116,8 @@ namespace ReallifeGamemode.Server.Gangwar
Rotation = Rot,
Range = Range,
Owner = "Neutral",
Color = 0
Color = 0,
Vector = null
};
using (var dbContext = new DatabaseContext())
{
@@ -141,8 +150,30 @@ namespace ReallifeGamemode.Server.Gangwar
}
}
[Command("/gwstart")]
public void StartGangwar(Client client)
[RemoteEvent("SERVER:Turf_SetNewLeaderPoint")]
public void RmtEvent_SetNewLeaderPoint(Client client, string vector, string jsonId) {
int id = JsonConvert.DeserializeObject<int>(jsonId);
if (id == -1)
{
ChatService.ErrorMessage(client, "Du befindest dich in keinem Gebiet");
return;
}
using (var dbContext = new DatabaseContext())
{
Turfs dturf = dbContext.Turfs.Where(t => t.Id == id).FirstOrDefault();
if (dturf != null)
{
dturf.Vector = vector;
dbContext.SaveChanges();
loadTurfs();
loadTurfs_ToAllClients();
}
}
}
[RemoteEvent("SERVER:StartGangwar")]
public void RmtEvent_StartGangwar(Client client)
{
if (!client.GetUser().FactionLeader)
return;
@@ -151,7 +182,7 @@ namespace ReallifeGamemode.Server.Gangwar
{
if (turf.status == "attack")
{
client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG
client.SendChatMessage("Ein GW läuft grad bruder"); // DEBUG //change to smth more serious
return;
}
}

View File

@@ -36,8 +36,8 @@ namespace ReallifeGamemode.Server.Gangwar
this.Color = color;
this.Owner = Owner;
this.Attacker = null;
this.Att_Score = 5;
this.Def_Score = 5;
this.Att_Score = 50;
this.Def_Score = 50;
this.status = "normal";
this.timer = null;
this.playerInside = new List<Client>();
@@ -81,7 +81,7 @@ namespace ReallifeGamemode.Server.Gangwar
private void Tick(object sender, System.Timers.ElapsedEventArgs e)
{
if (this.status == "attack")
if(this.status == "attack")
{
update();
}
@@ -91,6 +91,7 @@ namespace ReallifeGamemode.Server.Gangwar
private void update()
{
#region Ticket system
/*
try
{
@@ -113,6 +114,7 @@ namespace ReallifeGamemode.Server.Gangwar
if(owners.Length < attackers.Length)
this.Def_Score -= attackers.Length - owners.Length;
*/
#endregion
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
@@ -120,43 +122,40 @@ namespace ReallifeGamemode.Server.Gangwar
if (this.Def_Score <= 0)
{
this.takeOver(this.Attacker);
}
else if (this.Att_Score <= 0)
} else if (this.Att_Score <= 0)
{
this.takeOver(this.Owner);
}
timerCount += 1;
if (timerCount >= 60) //change to 900 before release
if(timerCount >= 900) //change to 900 (seconds) before release for testing reasons change to whatever you like
{
this.timer.Stop();
this.timer = null;
if (this.Def_Score > this.Att_Score)
if(this.Def_Score > this.Att_Score)
{
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
this.takeOver(this.Owner);
this.Att_Score = 0;
}else if(this.Def_Score < this.Att_Score)
{
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
}
else if (this.Def_Score < this.Att_Score)
{
this.takeOver(this.Attacker);
this.Def_Score = 0;
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
return;
}
else if (this.Def_Score == this.Att_Score)
else if(this.Def_Score == this.Att_Score)
{
this.takeOver(this.Attacker);
this.Def_Score = 0;
foreach (Client gangwarPlayer in this.playerInGangwar)
{
gangwarPlayer.TriggerEvent("GangwarScore", this.Attacker, this.Owner, 0, 0);
}
this.takeOver(this.Attacker);
this.Def_Score = 0;
return;
}
}
@@ -180,8 +179,7 @@ namespace ReallifeGamemode.Server.Gangwar
}
}
if (playerInside.Find(c => c == client) == null)
{
if(playerInside.Find(c => c == client) == null) {
playerInside.Add(client);
client.SetData("GotInsideOfTurf", true);
}
@@ -189,10 +187,10 @@ namespace ReallifeGamemode.Server.Gangwar
public void leave(Client client)
{
if (playerInside.Find(c => c == client) != null)
if(playerInside.Find(c => c == client) != null)
{
this.playerInside = this.playerInside.Where(c => c != client).ToList();
if (this.status != "attack")
if(this.status != "attack")
client.ResetData("GotInsideOfTurf");
}
}
@@ -220,10 +218,6 @@ namespace ReallifeGamemode.Server.Gangwar
}
else if (getOwner() != FactionName)
{
foreach (var c in playerInGangwar)
{
}
ChatService.BroadcastFaction("~y~[GANGWAR] ~w~Deine Fraktion konnte das Gebiet ~r~" + getName() + "~w~ nicht verteidigen.", dbContext.Factions.Where(f => f.Name == getOwner()).FirstOrDefault());
Client[] owners = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Owner).ToArray();
Client[] attackers = NAPI.Pools.GetAllPlayers().Where(c => c.IsLoggedIn() && c.GetUser().Faction.Name == this.Attacker).ToArray();
@@ -245,7 +239,7 @@ namespace ReallifeGamemode.Server.Gangwar
}
this.Attacker = null;
foreach (var c in playerInGangwar)
foreach(var c in playerInGangwar)
{
c.TriggerEvent("CLIENT:setAttackBlip", false, TurfID);
c.ResetData("inGangWar");
@@ -258,9 +252,9 @@ namespace ReallifeGamemode.Server.Gangwar
public void attack(string attacker)
{
if (this.status == "normal")
if(this.status == "normal")
{
if (this.timer != null)
if(this.timer != null)
{
this.timer.Stop();
this.timer = null;
@@ -277,7 +271,7 @@ namespace ReallifeGamemode.Server.Gangwar
u.TriggerEvent("CLIENT:setAttackBlip", true, TurfID);
u.TriggerEvent("GangwarScore", this.Attacker, this.Owner, this.Att_Score, this.Def_Score);
u.SetData("inGangWar", getId());
ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " hat das Gebiet ~y~" + TurfName + "~w~ der " + getOwner() + " angegriffen.");
ChatService.SendMessage(u, "~y~[GANGWAR]~w~ Die " + getAttacker() + " haben das Gebiet ~y~"+ TurfName +"~w~ der "+ getOwner() +" angegriffen.");
clientsInGangwar.Add(u);
}
playerInGangwar = clientsInGangwar.ToArray();