Skip to content

Commit

Permalink
0.1.8
Browse files Browse the repository at this point in the history
- Fixed the issue of direct equip when you buy the item.
- Fixed a few issues with the Customweapon item.
- Added FollowCS2ServerGuidelines control for customweapon
- Added precache for default models
  • Loading branch information
schwarper authored Apr 29, 2024
2 parents 27b89df + 4592101 commit 6a6edb2
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Store/src/cs2-store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Store;
public class Store : BasePlugin, IPluginConfig<StoreConfig>
{
public override string ModuleName => "Store";
public override string ModuleVersion => "0.1.7";
public override string ModuleVersion => "0.1.8";
public override string ModuleAuthor => "schwarper & xshadowbringer";

public StoreConfig Config { get; set; } = new StoreConfig();
Expand Down
234 changes: 123 additions & 111 deletions Store/src/event/event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,117 +26,9 @@ public static void Load()
Instance.RegisterListener<OnTick>(OnTick);
Instance.RegisterListener<OnEntityCreated>(OnEntityCreated);

Instance.RegisterEventHandler<EventPlayerConnectFull>((@event, info) =>
{
CCSPlayerController? player = @event.Userid;

if (player == null || !player.Valid())
{
return HookResult.Continue;
}

Task.Run(() => Database.LoadPlayer(player));

if (!Instance.GlobalDictionaryPlayer.TryGetValue(player, out Player? value))
{
value = new Player();
Instance.GlobalDictionaryPlayer.Add(player, value);
}

value.CreditIntervalTimer = Instance.AddTimer(Instance.Config.Credits["interval_active_inactive"], () =>
{
if (GameRules.IgnoreWarmUp())
{
return;
}

CsTeam Team = player.Team;

switch (Team)
{
case CsTeam.Terrorist:
case CsTeam.CounterTerrorist:
{
if (Instance.Config.Credits["amount_active"] > 0)
{
Credits.Give(player, Instance.Config.Credits["amount_active"]);

player.PrintToChatMessage("credits_earned<active>", Instance.Config.Credits["amount_active"]);
}

break;
}
case CsTeam.Spectator:
{
if (Instance.Config.Credits["amount_inactive"] > 0)
{
Credits.Give(player, Instance.Config.Credits["amount_inactive"]);

player.PrintToChatMessage("credits_earned<inactive>", Instance.Config.Credits["amount_inactive"]);
}

break;
}
}
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);

return HookResult.Continue;
});

Instance.RegisterEventHandler<EventPlayerDisconnect>((@event, info) =>
{
CCSPlayerController? player = @event.Userid;

if (player == null || !player.Valid())
{
return HookResult.Continue;
}

if (!Instance.GlobalDictionaryPlayer.TryGetValue(player, out Player? value))
{
return HookResult.Continue;
}

value?.CreditIntervalTimer?.Kill();

Database.SavePlayer(player);

Instance.GlobalStorePlayers.RemoveAll(p => p.SteamID == player.SteamID);
Instance.GlobalStorePlayerItems.RemoveAll(i => i.SteamID == player.SteamID);
Instance.GlobalStorePlayerEquipments.RemoveAll(e => e.SteamID == player.SteamID);

return HookResult.Continue;
});

Instance.RegisterEventHandler<EventPlayerDeath>((@event, info) =>
{
if (GameRules.IgnoreWarmUp())
{
return HookResult.Continue;
}

CCSPlayerController victim = @event.Userid;
CCSPlayerController attacker = @event.Attacker;

if (victim == null || attacker == null || !victim.Valid() || !attacker.Valid() || victim == attacker)
{
return HookResult.Continue;
}

Server.NextFrame(() =>
{
Database.SavePlayer(victim);
});

if (Instance.Config.Credits["amount_kill"] > 0)
{
Credits.Give(attacker, Instance.Config.Credits["amount_kill"]);

attacker.PrintToChat(Instance.Config.Tag + Instance.Localizer["credits_earned<kill>", Instance.Config.Credits["amount_kill"]]);
}

return HookResult.Continue;
});
Instance.RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
Instance.RegisterEventHandler<EventPlayerDisconnect>(OnPlayerDisconnect);
Instance.RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
}

public static void OnMapStart(string mapname)
Expand All @@ -163,6 +55,14 @@ public static void OnMapStart(string mapname)

public static void OnServerPrecacheResources(ResourceManifest manifest)
{
foreach (string[] models in Instance.Config.DefaultModels.Values)
{
foreach (string model in models)
{
manifest.AddResource(model);
}
}

Instance.GlobalStoreItemTypes.ForEach((type) =>
{
type.ServerPrecacheResources(manifest);
Expand Down Expand Up @@ -197,4 +97,116 @@ public static void OnEntityCreated(CEntityInstance entity)
Item_GrenadeTrail.OnEntityCreated(entity);
Item_CustomWeapon.OnEntityCreated(entity);
}

public static HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;

if (player == null || !player.Valid())
{
return HookResult.Continue;
}

Task.Run(() => Database.LoadPlayer(player));

if (!Instance.GlobalDictionaryPlayer.TryGetValue(player, out Player? value))
{
value = new Player();
Instance.GlobalDictionaryPlayer.Add(player, value);
}

value.CreditIntervalTimer = Instance.AddTimer(Instance.Config.Credits["interval_active_inactive"], () =>
{
if (GameRules.IgnoreWarmUp())
{
return;
}

CsTeam Team = player.Team;

switch (Team)
{
case CsTeam.Terrorist:
case CsTeam.CounterTerrorist:
{
if (Instance.Config.Credits["amount_active"] > 0)
{
Credits.Give(player, Instance.Config.Credits["amount_active"]);

player.PrintToChatMessage("credits_earned<active>", Instance.Config.Credits["amount_active"]);
}

break;
}
case CsTeam.Spectator:
{
if (Instance.Config.Credits["amount_inactive"] > 0)
{
Credits.Give(player, Instance.Config.Credits["amount_inactive"]);

player.PrintToChatMessage("credits_earned<inactive>", Instance.Config.Credits["amount_inactive"]);
}

break;
}
}
}, TimerFlags.REPEAT | TimerFlags.STOP_ON_MAPCHANGE);

return HookResult.Continue;
}

public static HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
CCSPlayerController? player = @event.Userid;

if (player == null || !player.Valid())
{
return HookResult.Continue;
}

if (!Instance.GlobalDictionaryPlayer.TryGetValue(player, out Player? value))
{
return HookResult.Continue;
}

value?.CreditIntervalTimer?.Kill();

Database.SavePlayer(player);

Instance.GlobalStorePlayers.RemoveAll(p => p.SteamID == player.SteamID);
Instance.GlobalStorePlayerItems.RemoveAll(i => i.SteamID == player.SteamID);
Instance.GlobalStorePlayerEquipments.RemoveAll(e => e.SteamID == player.SteamID);

return HookResult.Continue;
}

public static HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
if (GameRules.IgnoreWarmUp())
{
return HookResult.Continue;
}

CCSPlayerController victim = @event.Userid;
CCSPlayerController attacker = @event.Attacker;

if (victim == null || attacker == null || !victim.Valid() || !attacker.Valid() || victim == attacker)
{
return HookResult.Continue;
}

Server.NextFrame(() =>
{
Database.SavePlayer(victim);
});

if (Instance.Config.Credits["amount_kill"] > 0)
{
Credits.Give(attacker, Instance.Config.Credits["amount_kill"]);

attacker.PrintToChat(Instance.Config.Tag + Instance.Localizer["credits_earned<kill>", Instance.Config.Credits["amount_kill"]]);
}

return HookResult.Continue;
}
}
2 changes: 1 addition & 1 deletion Store/src/item/item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static bool Purchase(CCSPlayerController player, Dictionary<string, strin
return false;
}

if (!type.Equip(player, item))
if (!type.Equipable && !type.Equip(player, item))
{
return false;
}
Expand Down
16 changes: 11 additions & 5 deletions Store/src/item/items/customweapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public static void OnPluginStart()
{
Item.RegisterType("customweapon", OnMapStart, OnServerPrecacheResources, OnEquip, OnUnequip, true, null);

Instance.RegisterEventHandler<EventItemEquip>(OnItemEquip);
if (Item.GetItemsByType("customweapon").Count > 0)
{
if (CoreConfig.FollowCS2ServerGuidelines)
{
throw new Exception($"Cannot set or get 'CEconEntity::m_OriginalOwnerXuidLow' with \"FollowCS2ServerGuidelines\" option enabled.");
}

Instance.RegisterEventHandler<EventItemEquip>(OnItemEquip);
}
}
public static void OnMapStart()
{
Expand Down Expand Up @@ -65,11 +73,9 @@ public static void OnEntityCreated(CEntityInstance entity)

CBasePlayerWeapon weapon = entity.As<CBasePlayerWeapon>();

Server.RunOnTick((int)(Server.TickedTime + 10.0f), () =>
Server.NextWorldUpdate(() =>
{
CHandle<CBaseEntity> ownerentity = weapon.OwnerEntity;

if (!ownerentity.IsValid)
if (weapon.OriginalOwnerXuidLow == 0)
{
return;
}
Expand Down

0 comments on commit 6a6edb2

Please sign in to comment.