Cześć,
Mam taki oto kod:
using System;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Events;
using CounterStrikeSharp.API.Modules.Utils;
public class tDeagleOnly : BasePlugin
{
public override string ModuleName => "tDeagleOnly";
public override string ModuleVersion => "1.0.0";
public override void Load(bool hotReload)
{
RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
}
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
{
var victim = @event.Userid;
if (victim == null || !victim.IsValid || victim.IsBot)
return HookResult.Continue;
// If the hit is not a headshot, cancel damage
if (@event.Hitgroup != 1) // Hitgroup 1 = headshot
{
@event.DmgHealth = 0;
Server.PrintToConsole("[DEBUG] Non-headshot damage cancelled");
}
return HookResult.Continue;
}
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
{
var player = @event.Userid;
if (player == null || !player.IsValid)
return HookResult.Continue;
// Remove all weapons and give the Deagle
player.RemoveWeapons();
player.GiveNamedItem("weapon_deagle");
Server.PrintToConsole("[DEBUG] Deagle given to player on spawn");
return HookResult.Continue;
}
}
Z założenia ma ograniczać broń tylko do deagla i headshotów, niestety, ale ani jedna z funkcji nie działa mimo, że kompiluje się normalnie.
Gdzie jest błąd gdybym mógł prosić o pomoc.