Я попросил бота написать плагин внутриигровой валюты
Насколько хорошо он справился?
Плагин игровой валюты:
#include <sourcemod>
enum CurrencyType
{
CASH,
COINS
}
new Handle:g_hTimer;
public Plugin myPlugin;
public Dictionary g_PlayerCurrency;
public void OnPluginStart()
{
myPlugin = Plugin();
myPlugin.SetAuthor("Your Name");
myPlugin.SetVersion("1.0");
myPlugin.SetDescription("Currency system example");
g_PlayerCurrency = CreateDictionary();
RegisterEvent("player_spawn", "OnPlayerSpawn", EventPriority_Normal);
RegisterCommand("givecurrency", "cmdGiveCurrency", ADMFLAG_GENERIC, "Give currency to a player", FCVAR_NONE);
RegisterCommand("checkcurrency", "cmdCheckCurrency", ADMFLAG_GENERIC, "Check a player's currency balance", FCVAR_NONE);
g_hTimer = CreateTimer(60.0, Timer_UpdateCurrency, _, TIMER_FLAG_RECURRING);
}
public Action OnPlayerSpawn(int client)
{
DisplayCurrencyMessage(client);
return Plugin_Handled;
}
public void DisplayCurrencyMessage(int client)
{
int cash = GetPlayerCurrency(client, CASH);
int coins = GetPlayerCurrency(client, COINS);
PrintToChat(client, "Your currency balance: Cash - %d, Coins - %d", cash, coins);
}
public int GetPlayerCurrency(int client, CurrencyType type)
{
if (!g_PlayerCurrency.Contains(client))
{
g_PlayerCurrency[client] = CreateDictionary();
}
int currency = 0;
g_PlayerCurrency[client].GetValue(type, currency);
return currency;
}
public void SetPlayerCurrency(int client, CurrencyType type, int value)
{
if (!g_PlayerCurrency.Contains(client))
{
g_PlayerCurrency[client] = CreateDictionary();
}
g_PlayerCurrency[client][type] = value;
}
public void AddPlayerCurrency(int client, CurrencyType type, int amount)
{
int currentBalance = GetPlayerCurrency(client, type);
SetPlayerCurrency(client, type, currentBalance + amount);
}
public void cmdGiveCurrency(int client, const char[] args)
{
if (args.ArgC() < 3)
{
PrintToChat(client, "Usage: sm_givecurrency <target> <amount>");
return;
}
int targetClient = FindTargetClient(args.Arg(1));
if (targetClient == -1)
{
PrintToChat(client, "Player not found!");
return;
}
int amount = StrToInt(args.Arg(2));
AddPlayerCurrency(targetClient, CASH, amount);
DisplayCurrencyMessage(targetClient);
}
public void cmdCheckCurrency(int client, const char[] args)
{
DisplayCurrencyMessage(client);
}
public void Timer_UpdateCurrency(Handle hTimer)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
AddPlayerCurrency(i, COINS, 1);
}
}
}