Raised This Month: $ Target: $400
 0% 

random_num


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-08-2021 , 21:04   Re: random_num
Reply With Quote #4

Here's a basic method of doing it. You will need more code so more than 1 player can run a giveaway at a time.
PHP Code:

#include <amxmodx>
#include <amxmisc>

new const Version[] = "0.1";

const 
GiveawayTaskID 9312434;

new 
bool:g_bActiveGiveaway;
new 
g_JoinedGiveaway;

public 
plugin_init() 
{
    
register_plugin"Giveaway Plugin" Version "bugsy" );
    
    
register_concmd"start_giveaway" "StartGiveaway" ADMIN_KICK );
    
register_clcmd"say /join" "JoinGiveaway" );
}

#if AMXX_VERSION_NUM < 190
public client_disconnectid 
#else
public client_disconnectedid 
#endif
{
    
g_JoinedGiveaway &= ~( << ( id 31 ) );
}

public 
StartGiveawayid iAccess iCid )
{
    if ( 
cmd_accessid iAccess iCid ) )
    {
        
g_JoinedGiveaway 0;
        
g_bActiveGiveaway true;
        
set_task6.0 "EndGiveaway" GiveawayTaskID );
        
client_printprint_chat "* Say '/join' to join the giveaway!" );
    }
    
    return 
PLUGIN_HANDLED;
}

public 
JoinGiveawayid )
{
    if ( 
g_bActiveGiveaway )
    {
        if ( !( 
g_JoinedGiveaway & ( << ( id 31 ) ) ) )
        {
            
client_printid print_chat "* You have joined the giveaway!" );
            
g_JoinedGiveaway |= ( << ( id 31 ) );
        }
        else
        {
            
client_printid print_chat "* You have already joined the giveaway." );
        }
    }
    else
    {
        
client_printid print_chat "* There is no active giveaway." );
    }

    return 
PLUGIN_HANDLED;
}

public 
EndGiveaway()
{
    if ( !
g_JoinedGiveaway )
    {
        
client_printprint_chat "* Giveaway has ended. No players joined the giveaway!" );
    }
    else
    {
        new 
iPlayersMAX_PLAYERS ] , szName32 ] , iRandomPlayer;
        
        for ( new 
id id <= MAX_PLAYERS id++ )
        {
            if ( 
g_JoinedGiveaway & ( << ( id 31 ) ) )
            {
                
iPlayersi++ ] = id;
            }
        }
        
        
iRandomPlayer iPlayersrandom) ];
        
get_user_nameiRandomPlayer szName charsmaxszName ) );
        
client_printprint_chat "* Giveaway has ended. Winning player is %s!" szName );
    }
    
    
g_bActiveGiveaway false;

__________________

Last edited by Bugsy; 01-08-2021 at 22:10.
Bugsy is offline
 



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 14:09.


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