This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Need to help repair the error that cannot be compiled by the plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zfoeyg
New Member
Join Date: May 2024
Old 05-30-2024 , 22:01   Need to help repair the error that cannot be compiled by the plugins
Reply With Quote #1

plugin code
Code:
#pragma newdecls required 
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <multicolors>
#include <clientprefs>
#include <dbi>

#define PLUGIN_VERSION "1.0"

ConVar g_MaxLv_HP;
ConVar g_MaxLv_Atk;
ConVar g_MaxMoney;
ConVar g_UpAtk_Money;
ConVar g_UpHP_Money;
ConVar g_UpHP_Per;

Handle g_hTimer;
Handle g_Database;

public Plugin myinfo = 
{
    name = "CSS ZRiot Human Super", 
    author = "zfoeyg",
    description = "A plugin for human super",
    version = PLUGIN_VERSION,
    url = "www.sourcemod.net" 
};

public void OnPluginStart()
{
 
    RegConsoleCmd("sm_humanup", Command_Upgrade);
 
    
    g_MaxLv_HP = CreateConVar("zs_maxlv_hp", "2000", "Maximum vitality level", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);
    g_MaxLv_Atk = CreateConVar("zs_maxlv_atk", "2000", "Maximum attack power level", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);
    g_MaxMoney = CreateConVar("zs_maxmoney", "99000", "Maximum money limit", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);
    g_UpAtk_Money = CreateConVar("zs_upatk_money", "3000", "Money required to upgrade attack power by one level", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);
    g_UpHP_Money = CreateConVar("zs_uphp_money", "3000", "Money required to upgrade vitality by one level", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);
    g_UpHP_Per = CreateConVar("zs_uphp_per", "20", "Amount of HP increased when upgrading vitality by one level", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED);

    AutoExecConfig(true, "zs_humansuper");

    g_hTimer = CreateTimer(1.0, UpdateHUD, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);

    // Connect to the database
    g_Database = SQL_Connect("zs_humansuper", true, DatabaseConnectCallback, DatabaseConnectErrorCallback);
}

public void OnClientPutInServer(int client)
{
    PrintToChat(client, "{lightgreen}Type !humanup to upgrade human skills.");
}

public void OnClientDisconnect(int client)
{
    SaveClientData(client);
    DeleteClient(client);
}

public void OnClientConnected(int client)
{
    LoadClientData(client);
}

public Action UpdateHUD(Handle timer, any data)
{
    for (int client = 1; client <= MaxClients; client++)
    {
        if (IsClientInGame(client) && IsPlayerAlive(client) && GetClientTeam(client) == 3)
        {
            int hp = GetClientHealth(client);
            int armor = GetClientArmor(client);
            int vitality = GetClientData(client, "vitality", 0);
            int attackPower = GetClientData(client, "attackpower", 0);

            char buffer[256];
            Format(buffer, sizeof(buffer), "HP: {green}%d{default} Armor: {blue}%d{default} Vitality
LVL: {red}%d{default} Attack LVL: {yellow}%d{default}", hp, armor, vitality, attackPower);
            ShowHudText(client, 1, buffer);
        }
    }
    return Plugin_Continue;
}

public Action Command_Upgrade(int client, int args)
{
    int money = GetEntProp(client, Prop_Send, "m_iAccount");

    char arg1[64];
    GetCmdArgString(arg1, sizeof(arg1));

    if (StrEqual(arg1, "hp"))
    {
        int vitality = GetClientData(client, "vitality", 0);
        if (vitality >= g_MaxLv_HP.IntValue)
        {
            PrintToChat(client, "{red}Vitality has reached the maximum level!");
            return Plugin_Handled;
        }

        if (money < g_UpHP_Money.IntValue)
        {
            PrintToChat(client, "{red}Not enough money to upgrade vitality!");
            return Plugin_Handled;
        }

        SetClientData(client, "vitality", vitality + 1);
        SetEntProp(client, Prop_Send, "m_iAccount", money - g_UpHP_Money.IntValue);
        SetEntProp(client, Prop_Send, "m_iMaxHealth", GetEntProp(client, Prop_Send, "m_iMaxHealth") + g_UpHP_Per.IntValue);
        PrintToChat(client, "{green}Vitality level upgraded!");
    }
    else if (StrEqual(arg1, "atk"))
    {
        int attackPower = GetClientData(client, "attackpower", 0);
        if (attackPower >= g_MaxLv_Atk.IntValue)
        {
            PrintToChat(client, "{red}Attack power has reached the maximum level!");
            return Plugin_Handled;
        }

        if (money < g_UpAtk_Money.IntValue)
        {
            PrintToChat(client, "{red}Not enough money to upgrade attack power!");
            return Plugin_Handled;
        }

        SetClientData(client, "attackpower", attackPower + 1);
        SetEntProp(client, Prop_Send, "m_iAccount", money - g_UpAtk_Money.IntValue);
        PrintToChat(client, "{green}Attack power level upgraded!");
    }
    return Plugin_Handled;
}

void LoadClientData(int client)
{
    char query[256];
    Format(query, sizeof(query), "SELECT vitality, attackpower FROM HumanSuper WHERE client = %d", client);
    SQL_TQuery(g_Database, SQL_QueryCallback, query, client);
}

public void SQL_QueryCallback(Handle owner, Handle hndl, const char[] error, any client)
{
    if (hndl == INVALID_HANDLE)
    {
        PrintToServer("Failed to execute query: %s", error);
        return;
    }

    if (SQL_FetchRow(hndl))
    {
        SetClientData(client, "vitality", SQL_FetchInt(hndl, 0));
        SetClientData(client, "attackpower", SQL_FetchInt(hndl, 1));
    }
    else
    {
        char query[256];
        Format(query, sizeof(query), "INSERT INTO HumanSuper (client, vitality, attackpower) VALUES (%d, 0, 0)", client);
        SQL_TQuery(g_Database, null, query);
    }
    SQL_FreeResult(hndl);
}

void SaveClientData(int client)
{
    int vitality = GetClientData(client, "vitality", 0);
    int attackPower = GetClientData(client, "attackpower", 0);

    char query[256];
    Format(query, sizeof(query), "UPDATE HumanSuper SET vitality = %d, attackpower = %d WHERE client = %d", vitality, attackPower, client);
    SQL_TQuery(g_Database, null, query);
}

void DeleteClient(int client)
{
    char query[256];
    Format(query, sizeof(query), "DELETE FROM HumanSuper WHERE client = %d", client);
    SQL_TQuery(g_Database, null, query);
}

void SetClientData(int client, const char[] key, int value)
{
    SetEntDataEnt(client, key, value);
}

int GetClientData(int client, const char[] key, int defaultValue)
{
    return GetEntDataEnt(client, key, defaultValue);
}

public void OnPluginEnd()
{
    CloseHandle(g_hTimer);
    if (g_Database != INVALID_HANDLE)
    {
        SQL_Disconnect(g_Database);
        SQL_FreeResult(g_Database);
    }
}

public void DatabaseConnectCallback(Handle owner, Handle hndl, const char[] error, any data)
{
    if (hndl == INVALID_HANDLE)
    {
        PrintToServer("Database connection failed: %s", error);
    }
    else
    {
        g_Database = hndl;
        PrintToServer("Database connected successfully.");
    }
}

public void DatabaseConnectErrorCallback(Handle owner, Handle hndl, const char[] error, any data)
{
    PrintToServer("Database connection error: %s", error);
}
How to modify if the hud needs to be displayed in the image like this?
Attached Thumbnails
Click image for larger version

Name:	IMG_20240531_095416.jpg
Views:	13
Size:	64.5 KB
ID:	204491  

Last edited by zfoeyg; Yesterday at 06:11.
zfoeyg is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode