PHP Code:
#include <sourcemod>
#include <csgo_colors>
#include <sdktools>
#include <store>
#pragma semicolon 1
ConVar gc_iMinPlayer;
ConVar gc_sTag;
char g_sTag[32];
public Plugin myinfo = {
name = "zGiveaway",
author = "Black Flash, fix by shanapu",
description = "Giveaway plugin compatible with zephyrus store.",
version = "2.1",
url = "www.terra2.forumeiros.com"
}
public void OnPluginStart()
{
gc_iMinPlayer = CreateConVar("sm_giveaway_minplayers", "1", "Minimum players required in the server for the giveaway.");
RegAdminCmd("sm_giveaway", CommandGiveawayCredits, ADMFLAG_ROOT, "Start store credits giveaway");
}
public void OnConfigsExecuted()
{
gc_sTag = FindConVar("sm_store_chat_tag");
gc_sTag.GetString(g_sTag, sizeof(g_sTag));
}
public Action CommandGiveawayCredits(int client, int args)
{
if(!IsValidClient(client) || !IsClientInGame(client))
{
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "%s Usage: \x04sm_giveaway \x02<amount>", g_sTag);
return Plugin_Handled;
}
if(GetClientCount() > gc_iMinPlayer.IntValue)
{
char buffer[512];
GetCmdArg(1, buffer, sizeof(buffer));
int gStoreCreds = StringToInt(buffer);
int random = GetRandomPlayer();
if (IsValidClient(random))
{
Store_SetClientCredits(random, Store_GetClientCredits(random) + gStoreCreds);
}
CPrintToChatAll("%s Player: {green}%L {default}won %L credits in the the giveaway!", g_sTag, random, gStoreCreds);
}
else
{
CPrintToChat(client, "%s To do a giveaway, the server must contain at least {green}%s {default}players.", g_sTag, gc_iMinPlayer.IntValue);
}
return Plugin_Handled;
}
stock int GetRandomPlayer()
{
int[] clients = new int[MaxClients];
int clientCount;
for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i))
{
if (IsPlayerAlive(i))
{
clients[clientCount++] = i;
}
}
return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)];
}
bool IsValidClient(client, bool bAllowBots = true, bool bAllowDead = true)
{
if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (!IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}
Help please
__________________