Welcome to LegendCS – With grace, in your face !

 
Last Updated: 03-29-2025, 04:06 PM
Name: [Plugin CS2] Economy
Category: Plugins
by: Berserk
Downloads: 0
Views: 4
MD5: 4defcb94e80386694ed923b5f5f83bbf
Your rating: N/A
Average rating: N/A
 
Description:
Description: Core plugin for creating economic relations between players on cs2 servers

Author: gerod220

Installation:

  1. Install https://github.com/roflmuffin/CounterStrikeSharp
  2. Download Economy.zip

  3. Move the Economy folder to addons\counterstrikesharp\plugins\

  4. Done

Usage : On its own, the plugin is nothing of the sort. It does not provide any interface for the player and administration, it is created for developers. 

API:

Best of all, this plugin is built so that its functionality is modules. A module is a plugin from another developer that uses EconomyAPI to create its own economic relationship between players.
  1. Create CSS plugin
  2. Add EconomyAPI.dll your project.
  3. Use Economy.EconomyAPI

PHP Code: 
public override async void Load(bool hotReload)
{
    await EconomyAPI.RegisterModule(this);


As you notice, this is an asynchronous method, which means that the server will not hang if the kernel is not there, and at the same time will not allow an error to be generated because the API functionality will not work. 

Events:

since version 0.2-alpha events have been rewritten to attributes
  • Method Signatures:
ProductPurchasing(iUserId, GuidProductId)
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ProductPurchasing]
public static 
EventResult OnProductPurchasing(int userIdGuid productId)
{
    return EventResult.Continue;

ProductPurchased(iUserId, GuidProductId) 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ProductPurchased]
public static 
void OnProductPurchased(int userIdGuid productId)
{


ItemUsing(iUserId, GuidItemId) 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ItemUsing]
public static 
EventResult OnItemUsing(int userIdGuid itemId)
{
    return EventResult.Continue;

ItemUsed(iUserId, GuidItemId) 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ItemUsed]
public static 
void OnItemUsed(int userIdGuid itemId)
{

MoneyTransfer(dMoney, iFormerUserId, iNewUserId) 

PHP Code: 
[EconomyEvent(EventId EconomyEvents.MoneyTransfer]
public static 
void OnItemUsed(decimal amountint formerUserIdint newUserId)
{

ItemTransfer(GuidItemId, iFormerUserId, iNewUserId) 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ItemTransfer]
public static 
void OnItemUsed(Guid itemIdint formerUserIdint newUserId)
{

Attribute parameters In order to have less code in the handler, the basics have been put into parameters, for example product/item Id should be specified in an attribute. 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ProductPurchasingId "83dba2c3-1f3e-4d8e-9bb4-0070358cf68c"]
public static 
EventResult OnProductPurchasing(int userIdGuid productId// productId = Id
{
    return EventResult.Continue;

As you have noticed, items support custom attributes, you can specify at which item attributes the handler will work 
PHP Code: 
[EconomyEvent(EventId EconomyEvents.ItemUsingHasAttributes = new string[] { "productId" } ]
public static 
EventResult OnItemUsing(int userIdGuid itemId)
{
    var item EconomyAPI.GetItemById(Guid.Parse(itemId))
    var productId item.Attributes["productId"]; // The item will always have the attribute, otherwise the handler will not be called.
    return EventResult.Continue;

What follows is a seemingly complex example of how MedKit can be implemented via API. 
PHP Code: 
private const string MedKitId "4c8ca223-8b28-41b4-8c7d-66b92b7566c8";

[
EconomyEvent(EventId EconomyEvents.ProductPurchasingId MedKitId)]
public static 
EventResult OnMedKitPurchasing(int userIdGuid productId)
{
    var product EconomyAPI.GetProductById(productId);
    var myItemMedKit = new Item(product!.Nameproduct.Description, new Dictionary<stringstring>()
    {
        "view", $"{ChatColors.Red}MedKit" },
        "productId", $"{product.Id}" }
    });

    if(EconomyAPI.TakeMoney(userIdproduct.Money))
    {
        var id EconomyAPI.CreateItem(myItemMedKit);
        EconomyAPI.GiveItem(userIdid);
    }
    return EventResult.Handled;
}

[
EconomyEvent(EventId EconomyEvents.ItemUsingHasAttributes = new string[] { "productId" })]
public static 
EventResult OnItemUsing(int userIdGuid itemId)
{
    var item EconomyAPI.GetItemById(itemId);
    if (item.Attributes["productId"] == MedKitId.ToString())
    {
        var playerController Utilities.GetPlayerFromUserid(userId);
        playerController.PlayerPawn.Value.Health += 50;
        if (playerController.PlayerPawn.Value.Health 100)
            playerController.PlayerPawn.Value.Health 100;
    }
    return EventResult.Continue;


[-]
Leave a comment
To leave a comment you must log in.