From 3f772a76a32d533e6a53711cf2c6d973136b5691 Mon Sep 17 00:00:00 2001 From: jithatsonei Date: Mon, 25 Mar 2024 04:52:31 +0000 Subject: [PATCH 1/5] ensure weapons are given by waiting for pawn to fully spawn --- .github/workflows/main.yml | 3 ++- WeaponsGiver.cs | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 46c9902..c705578 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,6 @@ name: .NET Build and Release - +permissions: + contents: write on: push jobs: diff --git a/WeaponsGiver.cs b/WeaponsGiver.cs index 0941ec2..230a46a 100644 --- a/WeaponsGiver.cs +++ b/WeaponsGiver.cs @@ -5,7 +5,8 @@ using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Utils; - +using System +using System.Timers namespace WeaponsGiver { [MinimumApiVersion(175)] @@ -21,7 +22,7 @@ public class WeaponsGiver : BasePlugin public override string ModuleName => "WeaponsGiver"; public override string ModuleAuthor => "ji"; public override string ModuleDescription => "Ensures players in custom gamemodes spawn with starting weapons."; - public override string ModuleVersion => "build4"; + public override string ModuleVersion => "build5"; public override void Load(bool hotReload) { @@ -47,6 +48,12 @@ private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo } private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) + { + BasePlugin.AddTimer(1, giveWeapons()) + return HookResult.Continue; + } + + private void giveWeapons() { var player = @event.Userid; @@ -66,8 +73,6 @@ private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info if(!String.IsNullOrEmpty(ctMelee)) player.GiveNamedItem(ctMelee); break; } - - return HookResult.Continue; } } } From 308fd493a5917258f6e38bf6b958cd887db7c9ab Mon Sep 17 00:00:00 2001 From: jithatsonei Date: Sun, 24 Mar 2024 23:58:31 -0500 Subject: [PATCH 2/5] my bosses say im silly for missing this --- WeaponsGiver.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WeaponsGiver.cs b/WeaponsGiver.cs index 230a46a..3c29b6c 100644 --- a/WeaponsGiver.cs +++ b/WeaponsGiver.cs @@ -49,7 +49,7 @@ private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - BasePlugin.AddTimer(1, giveWeapons()) + BasePlugin.AddTimer(1, giveWeapons()); return HookResult.Continue; } From 5edbe75811df90e072f393c521b496ff390153ff Mon Sep 17 00:00:00 2001 From: jithatsonei Date: Mon, 25 Mar 2024 00:00:58 -0500 Subject: [PATCH 3/5] i really should enable c# in my codespace --- WeaponsGiver.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WeaponsGiver.cs b/WeaponsGiver.cs index 3c29b6c..6540a49 100644 --- a/WeaponsGiver.cs +++ b/WeaponsGiver.cs @@ -5,8 +5,9 @@ using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Utils; -using System -using System.Timers +using System; +using System.Timers; + namespace WeaponsGiver { [MinimumApiVersion(175)] From b22791d4c1690312ea7b7d69c0d515e33b710483 Mon Sep 17 00:00:00 2001 From: jii Date: Mon, 25 Mar 2024 00:11:39 -0500 Subject: [PATCH 4/5] fix --- WeaponsGiver.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/WeaponsGiver.cs b/WeaponsGiver.cs index 6540a49..5dd88ef 100644 --- a/WeaponsGiver.cs +++ b/WeaponsGiver.cs @@ -50,15 +50,13 @@ private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - BasePlugin.AddTimer(1, giveWeapons()); + this.AddTimer(1, ()=>GiveWeapons(@event.Userid)); return HookResult.Continue; } - private void giveWeapons() + private void GiveWeapons(CCSPlayerController player) { - var player = @event.Userid; - - if(!player.IsValid || !player.PlayerPawn.IsValid) return HookResult.Continue; + if(!player.IsValid || !player.PlayerPawn.IsValid) return; switch((CsTeam)player.TeamNum) { From fdc4b7fb40589e140281beeedb60773bec1b569f Mon Sep 17 00:00:00 2001 From: jii Date: Mon, 25 Mar 2024 00:48:45 -0500 Subject: [PATCH 5/5] swap to ticks over timer --- WeaponsGiver.cs | 13 +++++-------- WeaponsGiver.csproj | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/WeaponsGiver.cs b/WeaponsGiver.cs index 5dd88ef..ea8af59 100644 --- a/WeaponsGiver.cs +++ b/WeaponsGiver.cs @@ -1,16 +1,12 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Modules.Memory; -using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Utils; -using System; -using System.Timers; namespace WeaponsGiver { - [MinimumApiVersion(175)] + [MinimumApiVersion(198)] public class WeaponsGiver : BasePlugin { private string tPrimary; @@ -23,7 +19,7 @@ public class WeaponsGiver : BasePlugin public override string ModuleName => "WeaponsGiver"; public override string ModuleAuthor => "ji"; public override string ModuleDescription => "Ensures players in custom gamemodes spawn with starting weapons."; - public override string ModuleVersion => "build5"; + public override string ModuleVersion => "build6"; public override void Load(bool hotReload) { @@ -50,13 +46,14 @@ private HookResult Event_RoundPrestart(EventRoundPrestart @event, GameEventInfo private HookResult Event_PlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { - this.AddTimer(1, ()=>GiveWeapons(@event.Userid)); + Server.RunOnTick(Server.TickCount + 1, () => GiveWeapons(@event.Userid)); return HookResult.Continue; } private void GiveWeapons(CCSPlayerController player) { - if(!player.IsValid || !player.PlayerPawn.IsValid) return; + if(!player.IsValid || !player.PlayerPawn.IsValid) return; + if (player.Connected != PlayerConnectedState.PlayerConnected) return; switch((CsTeam)player.TeamNum) { diff --git a/WeaponsGiver.csproj b/WeaponsGiver.csproj index 9f1ee7f..0fd2cd9 100644 --- a/WeaponsGiver.csproj +++ b/WeaponsGiver.csproj @@ -7,6 +7,6 @@ - +