Provably fair [Raffle system code]

Discussion in 'General server discussion' started by Ant, Nov 14, 2017.

  1. Ant

    Ant Staff Member Owner

    Deagle: Rank#6508
    Multi1v1: Rank#184
    AWP: Rank#7
    Below is the code for the raffle system. In case anyone wants to complain the admins have some sort of edge.



    PHP:
    #pragma semicolon 1

    #define PLUGIN_VERSION "Private"

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

    #define MIN_CREDITS 10
    #define MAX_CREDITS 5000

    #define CHAT_PREFIX "[Raffle]"

    #define LoopClients(%1) for(int %1 = 1; %1 <= MaxClients; %1++)

    bool g_bUsed[MAXPLAYERS 1] = {false, ...};
    int g_iSpend[MAXPLAYERS 1] = {0, ...};

    int g_iAccountID[MAXPLAYERS 1] = {-1, ...};

    Handle g_hJackpot null;

    public 
    Plugin myinfo =
    {
        
    name "Zephyrus-Store: Raffle",
        
    author ".#Zipcore & Simon",
        
    description "Round based raffle system for Zephyrus Store credits",
        
    version PLUGIN_VERSION,
        
    url "[email protected]"
    };

    public 
    void OnPluginStart()
    {
        
    RegConsoleCmd("sm_raffle"Cmd_Raffle);
        
        
    g_hJackpot CreateArray(1);
        
        
    HookEvent("round_end"Event_OnRoundEnd);
    }

    public 
    void OnClientDisconnect(int client)
    {
        
    g_iAccountID[client] = -1;
    }

    int GetClientOfAccountId(int accountID)
    {
        
    char buffer1[32];
        
    Format(buffer132"%d"accountID);
        
    LoopClients(i)
        {
            
    char buffer2[32];
            
    Format(buffer232"%d"g_iAccountID[i]);
            if(
    StrEqual(buffer1buffer2))
            {
                return 
    i;
            }
        }
        
        return -
    1;
    }

    public 
    Action Event_OnRoundEnd(Handle event, const char[] namebool dontBroadcast)
    {
        
    int jackpot GetArraySize(g_hJackpot);
        
        if (
    jackpot <= 0)
            return 
    Plugin_Continue;
            
        
    int winner_account GetArrayCell(g_hJackpotGetRandomInt(0jackpot-1));
        
    int winner GetClientOfAccountId(winner_account);
        
        
    // Winner is not in game, try to find another winner
        
    if (winner <= || !IsClientInGame(winner))
        {
            
    CPrintToChatAll("%s Winner is not in game anymore, trying to find a new winner."CHAT_PREFIX);
            
            for (
    int i 0jackpot 1i++)
            {
                
    winner_account GetArrayCell(g_hJackpotGetRandomInt(0jackpot-1));
                
    winner GetClientOfAccountId(winner_account);
                
                if(
    winner && IsClientInGame(winner))
                    break;
            }
        }
        
        
    // All players disconnect, nobody get his credits back, lol
        
    if (winner <= || !IsClientInGame(winner))
        {
            
    CPrintToChatAll("%s All players disconnect, nobody get his credits back, lol. Jackpot was %d credits!"CHAT_PREFIXjackpot);
            return 
    Plugin_Continue;
        }
        
        
    //Store_GiveCredits(winner_account, jackpot, EmptyStoreCreditsCallback, winner_account);
        
    Store_SetClientCredits(winner_accountStore_GetClientCredits(winner_account) + jackpot);
        
        if(
    winner == -|| !IsClientInGame(winner))
            
    CPrintToChatAll("%s Winner has left the game but won %d credits."CHAT_PREFIXjackpot);
        else 
    CPrintToChatAll("%s %N has won %d credits."CHAT_PREFIXwinnerjackpot);
        
        
    // Reset
        
    LoopClients(i)
        {
            
    g_bUsed[i] = false;
            
    g_iSpend[i] = 0;
        }
            
        
    ClearArray(g_hJackpot);
        
        return 
    Plugin_Continue;
    }

    public 
    Action Cmd_Raffle(int clientint args)
    {
        if(
    client == 0)
        {
            
    ReplyToCommand(client"%s This command is only for players"CHAT_PREFIX);
            return 
    Plugin_Handled;
        }
        
        if(
    g_bUsed[client])
        {
            
    CPrintToChat(client"%s You already spend %d credits this game. Current win chance: %.2f% Jackpot: %d credits"CHAT_PREFIXg_iSpend[client], float(g_iSpend[client])/float(GetArraySize(g_hJackpot))*100.0GetArraySize(g_hJackpot));
            return 
    Plugin_Handled;
        }
        
        if(
    args == 0)
        {
            
    CPrintToChat(client"%s Jackpot: %d credits"CHAT_PREFIXGetArraySize(g_hJackpot));
            return 
    Plugin_Handled;
        }
        
        if(
    args != 1)
        {
            
    CPrintToChat(client"%s Usage: sm_raffle <credits>"CHAT_PREFIX);
            return 
    Plugin_Handled;
        }
        
        
    char buffer[32];
        
    GetCmdArg(1buffer32);
        
        
    int credits StringToInt(buffer);
        
        if(
    credits MIN_CREDITS)
        {
            
    CPrintToChat(client"%s You have to spend at least %d credits."CHAT_PREFIXMIN_CREDITS);
            return 
    Plugin_Handled;
        }
        else if(
    credits MAX_CREDITS)
        {
            
    CPrintToChat(client"%s You can't spend that much credits (Max: %d)."CHAT_PREFIXMAX_CREDITS);
            return 
    Plugin_Handled;
        }
        
        
    //int storeAccountID = Store_GetClientTarget(client);
        
    g_iAccountID[client] = client;
        
        
    //Store_GetCredits(storeAccountID, GetCreditsCallback, pack);
        
    int test Store_GetClientCredits(client);
        if(
    credits test)
        {
            
    CPrintToChat(client"%s You don't have enough credits. (Spend: %d Current: %d)"CHAT_PREFIXcreditstest);
            return 
    Plugin_Handled;
        }
        
        
    g_bUsed[client] = true;
        
    g_iSpend[client] = credits;
        
        
    // Remove credits
        //Store_GiveCredits(storeAccountID, -credits_spend, EmptyStoreCreditsCallback, client);
        
    Store_SetClientCredits(clienttest credits);
        
        
    // Add his credits too the jackpot "pool"
        
    for (int i 0creditsi++)
            
    PushArrayCell(g_hJackpotclient); //Use store account id in case player left game or rejoined
        
        
    CPrintToChatAll("%s %N has spend %d credits, his current winning chance is: %.2f% (Jackpot: %d credits)"CHAT_PREFIXclientcreditsfloat(credits)/float(GetArraySize(g_hJackpot))*100.0GetArraySize(g_hJackpot));
        
        return 
    Plugin_Handled;
    }
    //Empty callback
    //public int EmptyStoreCreditsCallback(int accountId, any pack){}
     
    • Like Like x 3
  2. plat

    plat

    Deagle: Rank#6508
    AWP: Rank#22114
    gonna steal this code and make my own raffle thing on my own private server harharhar
     
    • Like Like x 5