Skip to content

Commit

Permalink
Added link item
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarper committed Oct 22, 2024
1 parent f769683 commit 7c8c11b
Show file tree
Hide file tree
Showing 21 changed files with 433 additions and 70 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vs/
**/obj
**/bin
**/bin

# Ignore everything in BuildOutput directory
BuildOutput/
Binary file added Dapper.dll
Binary file not shown.
Binary file added MySqlConnector.dll
Binary file not shown.
66 changes: 43 additions & 23 deletions Store/cs2-store.csproj
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.279" />
<PackageReference Include="Daffer" Version="1.0.3" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="Tomlyn" Version="0.17.0" />
</ItemGroup>

<ItemGroup>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StoreApi\StoreApi.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>$(ProjectDir)..\BuildOutput\plugins\cs2-store\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.279" />
<PackageReference Include="Daffer" Version="1.0.3" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="Tomlyn" Version="0.17.0" />
</ItemGroup>

<ItemGroup>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StoreApi\StoreApi.csproj" />
</ItemGroup>

<Target Name="ExcludeStoreApiFiles" AfterTargets="Build">
<Delete Files="$(OutputPath)StoreApi.dll" />
<Delete Files="$(OutputPath)StoreApi.pdb" />
</Target>

<Target Name="CopyConfigFiles" AfterTargets="Build">
<ItemGroup>
<FilesToCopy Include="$(ProjectDir)..\config.toml" />
<FilesToCopy Include="$(ProjectDir)..\cs2-store.json" />
</ItemGroup>
<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(ProjectDir)..\BuildOutput\configs\plugins\cs2-store\" />
</Target>

<Target Name="CopyNuGetAssemblies" AfterTargets="Build">
<Copy SourceFiles="../MySqlConnector.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
<Copy SourceFiles="../Dapper.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
<Copy SourceFiles="../Tomlyn.dll" DestinationFolder="$(OutputPath)" SkipUnchangedFiles="true" />
</Target>

</Project>
1 change: 1 addition & 0 deletions Store/lang/ch.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "T阵营模型",
"menu_store<ct_title>": "CT阵营模型",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "装备",
"menu_store<unequip>": "脱下",
"menu_store<sell>": "出售 [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "T Models",
"menu_store<ct_title>": "CT Models",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "EQUIP",
"menu_store<unequip>": "UNEQUIP",
"menu_store<sell>": "SELL [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "Modelos T",
"menu_store<ct_title>": "Modelos CT",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "EQUIPAR",
"menu_store<unequip>": "DESEQUIPAR",
"menu_store<sell>": "VENDER [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "Modele T",
"menu_store<ct_title>": "Modele CT",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "ECHIPEAZĂ",
"menu_store<unequip>": "DEZ-ECHIPEAZĂ",
"menu_store<sell>": "VINDE [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "Модели t",
"menu_store<ct_title>": "Модели ct",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "ЭКИПИРОВАТЬ",
"menu_store<unequip>": "СНЯТЬ",
"menu_store<sell>": "ПРОДАТЬ [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/sl.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "T Modeli",
"menu_store<ct_title>": "CT Modeli",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "AKTIVIRAJ",
"menu_store<unequip>": "DEAKTIVIRAJ",
"menu_store<sell>": "PRODAJ [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "T Modelleri",
"menu_store<ct_title>": "CT Modelleri",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "KUŞAN",
"menu_store<unequip>": "BIRAK",
"menu_store<sell>": "SAT [{0}]",
Expand Down
1 change: 1 addition & 0 deletions Store/lang/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"menu_store<t_title>": "Моделі t",
"menu_store<ct_title>": "Моделі ct",
"menu_store<purchase>": "{0} - [{1}]",
"menu_store<purchase1>": "{0}",
"menu_store<equip>": "ЕКІПІРОВАТИ",
"menu_store<unequip>": "ЗНЯТИ",
"menu_store<sell>": "ПРОДАТИ [{0}]",
Expand Down
3 changes: 2 additions & 1 deletion Store/src/cs2-store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Store;
public class Store : BasePlugin, IPluginConfig<Item_Config>
{
public override string ModuleName => "Store";
public override string ModuleVersion => "1.5";
public override string ModuleVersion => "1.6";
public override string ModuleAuthor => "schwarper";

public Item_Config Config { get; set; } = new Item_Config();
Expand Down Expand Up @@ -41,6 +41,7 @@ public override void Load(bool hotReload)
Item_Gravity.OnPluginStart();
Item_GrenadeTrail.OnPluginStart();
Item_Health.OnPluginStart();
Item_Link.OnPluginStart();
Item_Open.OnPluginStart();
Item_PlayerSkin.OnPluginStart();
Item_Respawn.OnPluginStart();
Expand Down
9 changes: 7 additions & 2 deletions Store/src/item/item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ public static bool Purchase(CCSPlayerController player, Dictionary<string, strin
return false;
}

Credits.Give(player, -int.Parse(item["price"]));
var price = int.Parse(item["price"]);

player.PrintToChatMessage("Purchase Succeeded", item["name"]);
if (price > 0)
{
Credits.Give(player, -int.Parse(item["price"]));

player.PrintToChatMessage("Purchase Succeeded", item["name"]);
}

if (type.Equipable)
{
Expand Down
1 change: 0 additions & 1 deletion Store/src/item/items/link.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

Expand Down
50 changes: 29 additions & 21 deletions Store/src/menu/menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,42 @@ public static void DisplayItem(CCSPlayerController player, bool inventory, strin
}
else if (!inventory && !isHidden)
{
AddMenuOption(player, menu, (player, option) =>
if (int.Parse(item["price"]) <= 0)
{
if (Config.Menu.EnableConfirmMenu)
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayConfirmationMenu(player, item, option);
}
else
{
if (Item.Purchase(player, item))
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayItemOption(player, item, option);
}
else
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundNo}");
WasdManager.CloseMenu(player);
}
}

}, "menu_store<purchase>", item["name"], item["price"]);
AddMenuOption(player, menu, (player, option) => SelectPurchase(player, item, option, false), "menu_store<purchase1>", item["name"]);
}
else
{
AddMenuOption(player, menu, (player, option) => SelectPurchase(player, item, option, true), "menu_store<purchase>", item["name"], item["price"]);
}
}
}

WasdManager.OpenSubMenu(player, menu);
}

private static void SelectPurchase(CCSPlayerController player, Dictionary<string, string> item, IWasdMenuOption option, bool confirm)
{
if (confirm && Config.Menu.EnableConfirmMenu)
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayConfirmationMenu(player, item, option);
}
else
{
if (Item.Purchase(player, item))
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayItemOption(player, item, option);
}
else
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundNo}");
WasdManager.CloseMenu(player);
}
}
}

public static void DisplayItemOption(CCSPlayerController player, Dictionary<string, string> item, IWasdMenuOption? prev = null)
{
IWasdMenu menu = WasdManager.CreateMenu(item["name"]);
Expand Down
51 changes: 30 additions & 21 deletions Store/src/menu/oldmenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public static void DisplayItem(CCSPlayerController player, bool inventory, strin
}

bool isHidden = item.ContainsKey("hide") && item["hide"] == "true";

if (Item.PlayerHas(player, item["type"], item["uniqueid"], false))
{
AddMenuOption(player, menu, (player, option) =>
Expand All @@ -117,34 +118,42 @@ public static void DisplayItem(CCSPlayerController player, bool inventory, strin
}
else if (!inventory && !isHidden)
{
AddMenuOption(player, menu, (player, option) =>
if (int.Parse(item["price"]) <= 0)
{
if (Config.Menu.EnableConfirmMenu)
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayConfirmationMenu(player, item);
}
else
{
if (Item.Purchase(player, item))
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayItemOption(player, item);
}
else
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundNo}");
WasdManager.CloseMenu(player);
}
}

}, false, "menu_store<purchase>", item["name"], item["price"]);
AddMenuOption(player, menu, (player, option) => SelectPurchase(player, item, false), false, "menu_store<purchase1>", item["name"]);
}
else
{
AddMenuOption(player, menu, (player, option) => SelectPurchase(player, item, true), true, "menu_store<purchase>", item["name"], item["price"]);
}
}
}

MenuManager.OpenCenterHtmlMenu(Instance, player, menu);
}

private static void SelectPurchase(CCSPlayerController player, Dictionary<string, string> item, bool confirm)
{
if (confirm && Config.Menu.EnableConfirmMenu)
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayConfirmationMenu(player, item);
}
else
{
if (Item.Purchase(player, item))
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundYes}");
DisplayItemOption(player, item);
}
else
{
player.ExecuteClientCommand($"play {Config.Menu.MenuPressSoundNo}");
WasdManager.CloseMenu(player);
}
}
}

public static void DisplayItemOption(CCSPlayerController player, Dictionary<string, string> item)
{
CenterHtmlMenu menu = new(item["name"], Instance);
Expand Down
2 changes: 2 additions & 0 deletions StoreApi/StoreApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputPath>$(ProjectDir)..\BuildOutput\shared\StoreApi\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file added Tomlyn.dll
Binary file not shown.
49 changes: 49 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[Tag]
Tag = "{red}[Store] "

[DatabaseConnection]
Host = ""
Port = 3306
User = ""
Password = ""
Name = ""
DatabaseEquipTableName = "store_equipments"

[Commands]
Credits = [ "credits", "tl" ]
Store = [ "store", "shop", "market" ]
Inventory = [ "inv", "inventory" ]
GiveCredits = [ "givecredits" ]
Gift = [ "gift" ]
ResetPlayer = [ "resetplayer" ]
ResetDatabase = [ "resetdatabase" ]

# Should you not wish to utilise the default model, you are free to leave the list blank.
[DefaultModels]
Terrorist = [ "characters/models/ctm_fbi/ctm_fbi_variantb.vmdl" ]
CounterTerrorist = [ "characters/models/tm_leet/tm_leet_variantj.vmdl" ]

[Credits]
Start = 0
IntervalActiveInActive = 60
AmountActive = 10
AmountInActive = 1
AmountKill = 1
IgnoreWarmup = true

[Menu]
EnableSelling = true
EnableConfirmMenu = true
UseWASDMenu = true # If you mark it as false, it will be used as CentreHtmlMenu.
VipFlag = "@css/root" # Individuals in possession of the requisite authorisation shall be entitled to utilise equipable items free of charge. Making this field empty will result in the cancellation of Vip.
MenuPressSoundYes = ""
MenuPressSoundNo = ""

[Settings]
MaxHealth = 0
MaxArmor = 0
SellRatio = 0.6 # This setting determines the ratio of money you will receive when you sell the item.
ApplyPlayerskinDelay = 0.6
SellUsePurchaseCredit = false # If true, the selling ratio is calculated based on the price at which you bought the item. If false, it is calculated based on the current store price.
DefaultModelDisableLeg = false
Model0Model1Flag = "@css/root"
Loading

0 comments on commit 7c8c11b

Please sign in to comment.