fix unknown weapon names (mk 2 weapons)
This commit is contained in:
@@ -110,6 +110,14 @@ namespace ReallifeGamemode.Server.Commands
|
||||
SaveManager.SaveAllOnSave();
|
||||
}
|
||||
|
||||
[Command("hash")]
|
||||
public void CmdHash(Client player, string toHash)
|
||||
{
|
||||
string msg = $"{toHash} => {NAPI.Util.GetHashKey(toHash)}";
|
||||
NAPI.Util.ConsoleOutput(msg);
|
||||
player.SendChatMessage(msg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Support
|
||||
[Command("o", "~m~Benutzung: ~s~/o [Nachricht]", GreedyArg = true)]
|
||||
@@ -989,7 +997,7 @@ namespace ReallifeGamemode.Server.Commands
|
||||
}
|
||||
|
||||
[Command("giveweapon", "~m~Benutzung: ~s~/giveweapon [Spieler] [Waffe] [Munition]")]
|
||||
public void CmdAdminGiveweapon(Client player, string name, string weapon, int ammo)
|
||||
public void CmdAdminGiveweapon(Client player, string name, string hash, int ammo)
|
||||
{
|
||||
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN3) ?? true)
|
||||
{
|
||||
@@ -1003,6 +1011,8 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
hash = hash.ToLower();
|
||||
|
||||
Client target = ClientService.GetClientByNameOrId(name);
|
||||
if (target == null || !target.IsLoggedIn())
|
||||
{
|
||||
@@ -1010,17 +1020,23 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
WeaponHash wHash = NAPI.Util.WeaponNameToModel(weapon);
|
||||
if (!uint.TryParse(hash, out uint uHash))
|
||||
{
|
||||
if (hash.Contains("mk2") && !hash.Contains("_mk2")) hash = hash.Replace("mk2", "_mk2");
|
||||
uHash = NAPI.Util.GetHashKey($"weapon_{hash}");
|
||||
}
|
||||
|
||||
if (wHash == default)
|
||||
if(!WeaponManager.IsValidHash(uHash))
|
||||
{
|
||||
ChatService.Error(player, "Diese Waffe existiert nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
target.GiveWeapon(wHash, ammo);
|
||||
target.SendChatMessage("~b~Du hast von " + player.Name + " eine/n " + wHash + " mit einer Munition von " + ammo + " erhalten.");
|
||||
player.SendChatMessage("~b~Du hast " + target.Name + " eine/n " + wHash + " mit einer Munition von " + ammo + " gegeben.");
|
||||
WeaponHash weaponHash = (WeaponHash)uHash;
|
||||
|
||||
target.GiveWeapon((WeaponHash)uHash, ammo);
|
||||
target.SendChatMessage("~b~Du hast von " + player.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " erhalten.");
|
||||
player.SendChatMessage("~b~Du hast " + target.Name + " eine/n " + hash + " mit einer Munition von " + ammo + " gegeben.");
|
||||
}
|
||||
|
||||
[Command("arevive", "~m~Benutzung: ~s~/arevive [Spieler]")]
|
||||
@@ -1405,20 +1421,28 @@ namespace ReallifeGamemode.Server.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
WeaponHash wHash = NAPI.Util.WeaponNameToModel(weapon);
|
||||
weapon = weapon.ToLower();
|
||||
|
||||
if (wHash == default)
|
||||
if (!uint.TryParse(weapon, out uint uHash))
|
||||
{
|
||||
if (weapon.Contains("mk2") && !weapon.Contains("_mk2")) weapon = weapon.Replace("mk2", "_mk2");
|
||||
uHash = NAPI.Util.GetHashKey($"weapon_{weapon}");
|
||||
}
|
||||
|
||||
if (!WeaponManager.IsValidHash(uHash))
|
||||
{
|
||||
ChatService.Error(player, "Diese Waffe existiert nicht");
|
||||
return;
|
||||
}
|
||||
|
||||
WeaponHash weaponHash = (WeaponHash)uHash;
|
||||
|
||||
var peopleInRange = NAPI.Player.GetPlayersInRadiusOfPlayer(radius, player);
|
||||
|
||||
foreach (var managedClient in peopleInRange)
|
||||
{
|
||||
if (!managedClient.IsLoggedIn()) return;
|
||||
managedClient.GiveWeapon(wHash, munition);
|
||||
managedClient.GiveWeapon(weaponHash, munition);
|
||||
managedClient.SendChatMessage("~b~Admin " + player.Name + " hat im Radius von " + radius + " eine/n " + weapon + " mit " + munition + " Munition vergeben.");
|
||||
}
|
||||
player.SendChatMessage("~b~Du hast " + peopleInRange.Count + " Spielern eine " + weapon + " mit " + munition + " Munition gegeben");
|
||||
|
||||
119
ReallifeGamemode.Server/Managers/WeaponManager.cs
Normal file
119
ReallifeGamemode.Server/Managers/WeaponManager.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
class WeaponManager
|
||||
{
|
||||
private static readonly List<string> _modWeapons = new List<string>()
|
||||
{
|
||||
"dagger",
|
||||
"bat",
|
||||
"bottle",
|
||||
"crowbar",
|
||||
"flashlight",
|
||||
"golfclub",
|
||||
"hammer",
|
||||
"hatchet",
|
||||
"knuckle",
|
||||
"knife",
|
||||
"machete",
|
||||
"switchblade",
|
||||
"nightstick",
|
||||
"wrench",
|
||||
"battleaxe",
|
||||
"poolcue",
|
||||
"stone_hatchet",
|
||||
"pistol",
|
||||
"pistol_mk2",
|
||||
"combatpistol",
|
||||
"appistol",
|
||||
"stungun",
|
||||
"pistol50",
|
||||
"snspistol",
|
||||
"snspistol_mk2",
|
||||
"heavypistol",
|
||||
"vintagepistol",
|
||||
"flaregun",
|
||||
"marksmanpistol",
|
||||
"revolver",
|
||||
"revolver_mk2",
|
||||
"doubleaction",
|
||||
"raypistol",
|
||||
"microsmg",
|
||||
"smg",
|
||||
"smg_mk2",
|
||||
"assaultsmg",
|
||||
"combatpdw",
|
||||
"machinepistol",
|
||||
"raycarbine",
|
||||
"pumpshotgun",
|
||||
"pumpshotgun_mk2",
|
||||
"sawnoffshotgun",
|
||||
"assaultshotgun",
|
||||
"bullpupshotgun",
|
||||
"musket",
|
||||
"heavyshotgun",
|
||||
"dbshotgun",
|
||||
"autoshotgun",
|
||||
"assaultrifle",
|
||||
"assaultrifle_mk2",
|
||||
"carbinerifle",
|
||||
"carbinerifle_mk2",
|
||||
"advancedrifle",
|
||||
"specialcarbine",
|
||||
"specialcarbine_mk2",
|
||||
"bullpuprifle",
|
||||
"bullpuprifle_mk2",
|
||||
"compactrifle",
|
||||
"mg",
|
||||
"combatmg",
|
||||
"combatmg_mk2",
|
||||
"gusenberg",
|
||||
"sniperrifle",
|
||||
"heavysniper",
|
||||
"heavysniper_mk2",
|
||||
"marksmanrifle",
|
||||
"marksmanrifle_mk2",
|
||||
"rpg",
|
||||
"grenadelauncher",
|
||||
"grenadelauncher_smoke",
|
||||
"minigun",
|
||||
"firework",
|
||||
"railgun",
|
||||
"hominglauncher",
|
||||
"compactlauncher",
|
||||
"rayminigun",
|
||||
"grenade",
|
||||
"bzgas",
|
||||
"molotov",
|
||||
"stickybomb",
|
||||
"proxmine",
|
||||
"snowball",
|
||||
"pipebomb",
|
||||
"ball",
|
||||
"smokegrenade",
|
||||
"flare",
|
||||
"petrolcan",
|
||||
"parachute",
|
||||
"fireextinguisher"
|
||||
};
|
||||
|
||||
public static bool IsValidHash(uint hash)
|
||||
{
|
||||
foreach (WeaponHash vh in Enum.GetValues(typeof(WeaponHash)))
|
||||
{
|
||||
if ((uint)vh == hash) return true;
|
||||
}
|
||||
|
||||
foreach (string mod in _modWeapons)
|
||||
{
|
||||
if (NAPI.Util.GetHashKey($"weapon_{mod}") == hash) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user