View Single Post
kikifrh
Senior Member
Join Date: May 2009
Old 06-17-2010 , 13:12   Re: Plugin value 3 selected, bug!
Reply With Quote #3

Code:
/*

Advanced Donation
v1.1
by Wrecked

Changelog:
    v1.0 - Private
    v1.1 - is_str_num and fixed abuse of negative donations
*/

#include <amxmodx>
#include <cstrike>

new const VERSION[] = "1.1"

#define MAX_PLAYERS 32

new const prefix[] = "!g[DONATE]!y"

new const MONEYINTERVALS[] =
{
    500,
    1000,
    2000,
    3000,
    4000,
    5000,
    10000,
    15000
}

new bool:b_TypeAmount[MAX_PLAYERS+1]
new bool:b_Donating[MAX_PLAYERS+1][MAX_PLAYERS+1]

new iAmount[MAX_PLAYERS+1]

public plugin_init()
{
    register_plugin( "Money Donation", VERSION, "Wrecked" ) // :avast:
    
    register_clcmd( "say donate", "CMD_PlayerMenu" )
    register_clcmd( "say_team donate", "CMD_PlayerMenu" )
    register_clcmd( "say /donate", "CMD_PlayerMenu" )
    register_clcmd( "say_team /donate", "CMD_PlayerMenu" )

    register_clcmd("Donate_Amount", "CMD_Say", -1);
    
    register_logevent( "LEV_RoundStart", 2, "1=Round_Start" )
}

public client_connect( id )
{
    iAmount[id] = 0
}

public client_disconnect( id )
{
    iAmount[id] = 0
}

public LEV_RoundStart( id )
{
    new iPlayers[32]
    new iNum
    
    get_players( iPlayers, iNum, "c" )
    
    new tempid
    
    for( new i = 0; i < iNum; i++ )
    {
        tempid = iPlayers[i]
        
        if( !is_user_connected( tempid ) )
            continue;
            
        RESET_Donations( tempid )
    }
}

public CMD_Say( id )
{
    if( b_TypeAmount[id] )
    {
        b_TypeAmount[id] = false
        
        new said[128]
        read_argv( 1, said, 127 )
        remove_quotes( said )
        trim( said )
        if( !is_str_num( said ) )
        {
            ChatColor( id, "%s Invalid value!", prefix )
            
            return PLUGIN_HANDLED_MAIN;
        }
        
        new iDonation = str_to_num( said )
        
        if( iDonation <= 0 )
        {            
            return PLUGIN_HANDLED_MAIN;
        }
        
        new iMoney = cs_get_user_money( id )
        
        if( iMoney < iDonation )
        {
            ChatColor( id, "%s You don't have $%i!", prefix, iDonation )
            
            return PLUGIN_HANDLED_MAIN;
        }
        
        new idname[64]
        get_user_name( id, idname, 63 )
        
        new donatename[64]
        new donateid
        GET_Donation_Info( id, donatename, charsmax( donatename ), donateid ) // whut?! byref!?
        
        cs_set_user_money( id, iMoney - iDonation )
        cs_set_user_money( donateid, cs_get_user_money( donateid ) + iDonation )
        
        ChatColor( id, "%s You have just donated $%i to %s!", prefix, iDonation, donatename )
        ChatColor( donateid, "%s You just received a donation of $%i from %s!", prefix, iDonation, idname )
        
        RESET_Donations( id )
        RESET_Donations( donateid )
        
        return PLUGIN_HANDLED_MAIN;
    }
    
    return PLUGIN_CONTINUE;
}

public CMD_PlayerMenu( id )
{
    RESET_Donations( id )
    
    new iPlayers[32]
    new iNum
    
    get_players( iPlayers, iNum, "c" )
    
    if( iNum < 2 )
    {
        ChatColor( id, "%s No one else is in the server!", prefix )
        
        return PLUGIN_HANDLED;
    }
    
    new pmenu = menu_create( "\rDonate To:", "PMENU_Handler" )
    
    new tempid
    
    new szTempid[10]
    new szName[32]
    
    for( new i = 0; i < iNum; i++ )
    {
        tempid = iPlayers[i]
        
        if( id == tempid )
        {
            continue;
        }
        
        get_user_name( tempid, szName, 31 )
        num_to_str( tempid, szTempid, 9 )
        
        menu_additem( pmenu, szName, szTempid, 0 )
    }
    
    menu_setprop( pmenu, MPROP_EXIT, MEXIT_ALL )
    
    menu_display( id, pmenu, 0 )
    
    return PLUGIN_CONTINUE;
}

public PMENU_Handler( id, pmenu, item )
{
    if( item == MENU_EXIT )
    {
        menu_destroy( pmenu )
        
        return PLUGIN_HANDLED;
    }
    
    new access
    new callback
    new name[64]
    new data[10]
    
    menu_item_getinfo( pmenu, item, access, data, 9, name, 63, callback )
    
    new tempid = str_to_num( data )
    
    if( is_user_connected( tempid ) )
    {
        b_Donating[id][tempid] = true
        
        CMD_Donate( id )
        
        return PLUGIN_HANDLED;
    }
    
    menu_destroy( pmenu )
    
    return PLUGIN_HANDLED;
}

public CMD_Donate( id )
{
    new donationname[64]
    new donateid
    GET_Donation_Info( id, donationname, charsmax( donationname ), donateid )
    
    new menutitle[64]
    formatex( menutitle, 63, "\rDonate To: \y%s", donationname )
    new menu = menu_create( menutitle, "DMENU_Handler" )
    
    new donatemsg[64]
    formatex( donatemsg, 63, "\wFinalize Donatation", donationname )
    menu_additem( menu, donatemsg, "1", 0 )
    
    new message[64]
    formatex( message, 63, "\wDonation Amount: %s%d", ( cs_get_user_money( id ) >= MONEYINTERVALS[iAmount[id]] ) ? "\y" : "\d", MONEYINTERVALS[iAmount[id]] )
    menu_additem( menu, message, "2", 0 )
    
    menu_additem( menu, "\wType A Custom Amount", "3", 0 )
    
    menu_setprop( menu, MPROP_EXIT, MEXIT_ALL )
    menu_setprop( menu, MPROP_EXITNAME, "Back to Player Menu" )
    
    menu_display( id, menu, 0 )
    
    return PLUGIN_CONTINUE;
}

public DMENU_Handler( id, menu, item )
{
    if( item == MENU_EXIT )
    {
        RESET_Donations( id )
        
        CMD_PlayerMenu( id )
        
        return PLUGIN_HANDLED;
    }
    
    new access
    new callback
    new name[64]
    new data[10]
    
    menu_item_getinfo( menu, item, access, data, 9, name, 63, callback )
    
    new choice = str_to_num( data )
    
    switch( choice )
    {
        case 1:
        {
            new iMoney = cs_get_user_money( id )
            
            if( iMoney < MONEYINTERVALS[iAmount[id]] )
            {
                CMD_Donate( id )
                
                return PLUGIN_HANDLED;
            }
            
            new donateid
            new donatename[64]
            
            GET_Donation_Info( id, donatename, charsmax( donatename ), donateid )
            
            new idname[64]
            get_user_name( id, idname, charsmax( idname ) )
            
            cs_set_user_money( id, iMoney - MONEYINTERVALS[iAmount[id]] )
            cs_set_user_money( donateid, cs_get_user_money( donateid ) + MONEYINTERVALS[iAmount[id]] )
            
            ChatColor( id, "%s You have just donated $%i to %s!", prefix, MONEYINTERVALS[iAmount[id]], donatename )
            ChatColor( donateid, "%s You just received a donation of $%i from %s!", prefix, MONEYINTERVALS[iAmount[id]], idname )
            
            RESET_Donations( id )
            RESET_Donations( donateid )
            
            return PLUGIN_HANDLED;
        }
        
        case 2:
        {
            if( iAmount[id] == sizeof( MONEYINTERVALS ) - 1 )
            {
                iAmount[id] = 0
            }
            else
            {
                iAmount[id]++
            }
            
            CMD_Donate( id )
            
            return PLUGIN_HANDLED;
        }
        
        case 3:
        {
            b_TypeAmount[id] = true
            
            client_cmd(id, "messagemode Donate_Amount");

            ChatColor( id, "%s Please type your amount to donate. It MUST be an !ginteger!y!", prefix )

            CMD_Say( id )

            return PLUGIN_HANDLED;
        }
    }
    
    menu_destroy( menu )
    
    return PLUGIN_HANDLED;
}

stock RESET_Donations( id ) // so the game doesn't have you donate to the wrong person. fix from beta testing
{
    b_TypeAmount[id] = false
    
    new iPlayers[32]
    new iNum
    
    get_players( iPlayers, iNum, "c" )
    
    new tempid
    
    for( new i = 0; i < iNum; i++ )
    {
        tempid = iPlayers[i]
        
        if( !is_user_connected( tempid ) )
            continue;
        
        b_Donating[id][tempid] = false
    }
}

stock GET_Donation_Info( id, name[], iLen, &donationid ) // yay byref
{
    new iPlayers[32]
    new iNum
    
    get_players( iPlayers, iNum, "c" )
    
    new tempid
    
    for( new i = 0; i < iNum; i++ )
    {
        tempid = iPlayers[i]
        
        if( b_Donating[id][tempid] )
        {
            get_user_name( tempid, name, iLen )
            donationid = tempid
            
            break;
        }
    }
}

stock ChatColor(const id, const input[], any:...) // i think this was cuchii's
{
    new count = 1, players[32]
    static msg[191]
    vformat(msg, 190, input, 3)
    
    replace_all(msg, 190, "!g", "^4") // Green Color
    replace_all(msg, 190, "!y", "^1") // Default Color
    replace_all(msg, 190, "!team", "^3") // Team Color
    replace_all(msg, 190, "!team2", "^0") // Team2 Color
    
    if (id) players[0] = id; else get_players(players, count, "ch")
    {
        for (new i = 0; i < count; i++)
        {
            if (is_user_connected(players[i]))
            {
                message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
                write_byte(players[i]);
                write_string(msg);
                message_end();
            }
        }
    }
}
kikifrh is offline