Skip to content

Commit

Permalink
swap to ticks over timer
Browse files Browse the repository at this point in the history
  • Loading branch information
jithatsonei committed Mar 25, 2024
1 parent b22791d commit fdc4b7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions WeaponsGiver.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion WeaponsGiver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.175" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.198" />
</ItemGroup>
</Project>

0 comments on commit fdc4b7f

Please sign in to comment.