AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [CSGO/ANY?] Zephyrus Store Daily Credits [1.0] [25 Aug 20] (https://forums.alliedmods.net/showthread.php?t=326958)

kratoss1812 08-25-2020 09:18

[CSGO/ANY?] Zephyrus Store Daily Credits [1.0] [25 Aug 20]
 
2 Attachment(s)
Description: Players are able to collect 50 Credits every 24 hours through !daily Command

Requirements: MySql Database

Instalation:
Put store_daily.smx in addons/sourcemod/plugins/ folder
Add "skins_shop" configuration in addons/sourcemod/configs/database.cfg file

This Plugin Is fully tested and working in CS:GO

Sourcecode:
PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <store>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[Store] Daily Credits",
    
author "kRatoss"
};

Handle g_hDataBase;

public 
void OnPluginStart()
{
    
SQL_TConnect(OnDBConnected"skins_shop");
    
RegConsoleCmd("sm_daily"Command_Daily);
}

public 
Action Command_Daily(int Clientint Args)
{
    if(
IsValidClient(Client) && g_hDataBase != INVALID_HANDLE)
    {
        
char Steam[32], Buffer[128];
        if(
GetClientAuthId(ClientAuthId_SteamID64Steamsizeof(Steam)))
        {
            
Format(Buffersizeof(Buffer), "SELECT reward_time FROM skins_daily WHERE steamid = '%s';"Steam);
            
SQL_TQuery(g_hDataBaseSQLT_LoadDailyBufferClient);
        }
    }
}

public 
void SQLT_LoadDaily(Handle DataBaseHandle Results, const char[] sErrorany Client)
{
    if(
strlen(sError))
    {
        
LogError("Error: %s"sError);
        return;
    }
        
    if(
DataBase == INVALID_HANDLE)
    {
        
SetFailState("Databases Error( %s )"sError);
        return;
    }
    
    if(
IsValidClient(Client))
    {
        
SQL_FetchRow(Results);
        if(
SQL_GetRowCount(Results) == 0)
        {
            
char Steam[32], Buffer[128];
            
GetClientAuthId(ClientAuthId_SteamID64Steamsizeof(Steam));
            
            
Format(Buffersizeof(Buffer), "\
            INSERT INTO skins_daily \
                (steamid, reward_time) \
            VALUES \
                ('%s', '%i'); "
SteamGetTime() + 86400);
            
kQuery(g_hDataBaseBuffer"SQLT_LoadDaily");
        }
        else
        {
            
Menu Daily = new Menu(DailyMenuHandler);
            
char Title[128], Time[32];
            
int Hours 0Minutes 0Seconds SQL_FetchInt(Results0); 
            
            if (
GetTime() > Seconds)
            {
                
PrintToChat(Client"test");
                    
                
Format(Titlesizeof(Title), "\
                Daily Bonus\n\
                --------------------------- \n\
                You can colect your bonus now \n\
                ---------------------------\n"
);
                
Daily.AddItem("1""Get 50 Credits"ITEMDRAW_DEFAULT);
            }
            else
            {
                
Seconds Seconds GetTime();
                while(
Seconds 3600)
                {
                    
Hours++;
                    
Seconds -= 3600;
                }
                while(
Seconds 60)
                {
                    
Minutes++;
                    
Seconds -= 60;
                }
                
                if(
Hours >= 1)
                    
Format(Timesizeof(Time), "%d Hrs %d Mins %d Secs"HoursMinutesSeconds );
                else if(
Minutes >= 1)
                    
Format(Timesizeof(Time), "%d Mins %d Secs"MinutesSeconds );
                else
                    
Format(Timesizeof(Time), "%d Secs"Seconds );
                
                
PrintToChat(Client"test 2");
                
Format(Titlesizeof(Title), "\
                Daily Bonus\n\
                --------------------------- \n\
                You will be able to collect in %s\n\
                ---------------------------\n"
Time);        
                
Daily.AddItem("1""Get 50 Credits"ITEMDRAW_DISABLED);
            }
            
Daily.SetTitle(Title);
            
Daily.Display(ClientMENU_TIME_FOREVER);
        }
    }
}

public 
int DailyMenuHandler(Handle hMenuMenuAction pActionint Clientint Selection)
{
    if (
pAction == MenuAction_Select)
    {
        if(
g_hDataBase != INVALID_HANDLE)
        {
            
char Steam[32], sQuery[128];
            if(
GetClientAuthId(ClientAuthId_SteamID64Steamsizeof(Steam)))
            {
                
PrintToChat(Client"[\x04SHOP\x01] You've Collected\x04 50\x01 Credits!");
                
Format(sQuerysizeof(sQuery), "UPDATE skins_daily SET reward_time = '%i' WHERE steamid = '%s';"GetTime() + 86400Steam);
                
kQuery(g_hDataBasesQuery"DailyMenuHandler");
                
//SS_SetTokens(Client, SS_GetTokens(Client) + 50);
                
Store_SetClientCredits(ClientStore_GetClientCredits(Client) + 50);
            }
        }
    }
}

public 
int OnDBConnected(Handle hOwnerHandle hHandlechar [] sErrorany Data)
{
    if(
hHandle == INVALID_HANDLE)
    {
        
SetFailState("Databases does not work. Error: %s"sError);
    }
    else
    {
        
g_hDataBase hHandle;
        
kQuery(g_hDataBase"\
        CREATE TABLE IF NOT EXISTS `skins_daily` (`steamid` varchar(32) PRIMARY KEY NOT NULL, `reward_time` int(16) NOT NULL); "
"OnDBConnected(1)");
    }
}

stock void kQuery(Handle pDatabasechar[] szQuery, const char[] sFunction)
{
    if (!
SQL_FastQuery(pDatabaseszQuery))
    {
        
char szError[255];
        
SQL_GetError(pDatabaseszErrorsizeof(szError));
        
//SetFailState("MySQL Error @%s : %s", sFunction, szError);
        
LogError("MySQL Error @%s : %s"sFunctionszError);
    }
}

stock bool IsValidClient(int client)

    if (
client <= || client MaxClients || !IsClientConnected(client) || client 0)
    {
        return 
false
    }
    return 
IsClientInGame(client); 



Nanochip 08-25-2020 19:09

Re: [CSGO/ANY?] Zephyrus Store Daily Credits [1.0] [25 Aug 20]
 
Please also upload a compiled version since it has a custom include & won't compile through the forum.


All times are GMT -4. The time now is 20:12.

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