Compare commits

...

8 Commits

Author SHA1 Message Date
Nereziel
5a5b120674 change knife give handling 2023-11-14 19:54:22 +01:00
Nereziel
5a24f3b9fa bots had no knife 2023-11-14 19:08:17 +01:00
Nereziel
1527eea686 Update README.md 2023-11-14 16:56:18 +01:00
Nereziel
953788c327 Update README.md 2023-11-14 16:52:00 +01:00
Nereziel
837b000126 Merge pull request #24 from daffyyyy/hotfix-1
Update WeaponPaints.cs
2023-11-14 16:42:41 +01:00
Nereziel
87a78b01b4 Merge branch 'main' into hotfix-1 2023-11-14 16:41:06 +01:00
Nereziel
f7c914a267 missing exception 2023-11-14 16:37:47 +01:00
Dawid Bepierszcz
2c0fad230d Update WeaponPaints.cs
Temporary fix for player loading
2023-11-14 15:45:50 +01:00
2 changed files with 33 additions and 16 deletions

View File

@@ -8,11 +8,13 @@
Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin for [CSSharp](https://docs.cssharp.dev/).
### Features
- changes only paint, seed, wear on weapons
- changes only paint, seed and wear on weapons and knives
- mysql based
- data sync on player connect or playe
- data sync on player connect
- Added command `!wp` to refresh skins (with cooldown in second can be configured)
- Added command `!ws` to show website
- Added command `!knife` to show menu with knives
- Knife change is now limited to have these cvars empty `mp_t_default_melee ""` and `mp_ct_default_melee ""`
### CS2 server:
- compile and copy plugin to plugins. Info here [https://docs.cssharp.dev/guides/hello-world-plugin/](https://docs.cssharp.dev/guides/hello-world-plugin/)
@@ -20,6 +22,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
- in `addons/counterstrikesharp/configs/core.json` set **FollowCS2ServerGuidelines** to **false**
### Web install:
- requires PHP (tested on php ver `8.2.3` and nginx webserver)
- copy website to web server
- import `database.sql` to mysql
- get steam api key [https://steamcommunity.com/dev/apikey](https://steamcommunity.com/dev/apikey)

View File

@@ -1,4 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Commands;
@@ -8,6 +8,7 @@ using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using Nexd.MySQL;
using System.Runtime.ExceptionServices;
using static CounterStrikeSharp.API.Core.Listeners;
namespace WeaponPaints;
public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
@@ -67,7 +68,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
SetGlobalExceptionHandler();
MySql = new MySqlDb(Config.DatabaseHost, Config.DatabaseUser, Config.DatabasePassword, Config.DatabaseName!, Config.DatabasePort);
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
RegisterListener<Listeners.OnClientAuthorized>(OnClientAuthorized);
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
@@ -113,7 +114,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
});
}
private void OnClientAuthorized(int playerSlot, SteamID steamId)
private void OnClientPutInServer(int playerSlot)
{
int playerIndex = playerSlot + 1;
Task.Run(async () =>
@@ -130,11 +131,27 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (!player.IsValid || !player.PlayerPawn.IsValid || player.IsBot)
if (!player.IsValid || !player.PlayerPawn.IsValid)
{
return HookResult.Continue;
}
if (!PlayerHasKnife(player)) player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
if (player.IsBot)
{
player.GiveNamedItem("weapon_knife");
return HookResult.Continue;
}
if (!PlayerHasKnife(player))
{
if (g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value))
{
player.GiveNamedItem(g_playersKife[(int)player.EntityIndex!.Value.Value]);
}
else
{
player.GiveNamedItem("weapon_knife");
}
}
return HookResult.Continue;
}
@@ -186,6 +203,7 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
public void RemoveKnifeFromPlayer(CCSPlayerController player)
{
if (!player.PawnIsAlive) return;
if (!g_playersKife.ContainsKey((int)player.EntityIndex!.Value.Value)) return;
var weapons = player.PlayerPawn.Value.WeaponServices!.MyWeapons;
foreach (var weapon in weapons)
{
@@ -301,8 +319,9 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
gPlayerWeaponSeed[steamId.SteamId64][WeaponDefIndex] = Seed;
});
}
catch (Exception)
catch (Exception e)
{
Log(e.Message);
return;
}
}
@@ -323,15 +342,11 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
{
g_playersKife[playerIndex] = knife;
}
else
{
g_playersKife[playerIndex] = "weapon_knife";
}
//Log($"{player.PlayerName} has this knife -> {g_playersKife[playerIndex]}");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Log(e.Message);
return;
}
}
@@ -344,13 +359,12 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
var steamId = new SteamID(player.SteamID);
await MySql!.ExecuteNonQueryAsync($"INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES('{steamId.SteamId64}', '{knife}') ON DUPLICATE KEY UPDATE `knife` = '{knife}';");
}
catch (Exception ex)
catch (Exception e)
{
Log(ex.Message);
Log(e.Message);
return;
}
}
private static void Log(string message)
{
Console.BackgroundColor = ConsoleColor.DarkGray;