Raised This Month: $ Target: $400
 0% 

AMXX Lottery (Plugin/API)


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
Mario AR.
Senior Member
Join Date: May 2011
Location: Lima, Perú
Old 07-09-2014 , 16:36   AMXX Lottery (Plugin/API)
Reply With Quote #1

AMXX Lottery


Description
  • This plugin enables a "lottery" in your server. Every <x> seconds (cvar) a menu will be displayed to all players to let then choose if they want to participate in the lottery.
  • The user can choose if he wants to participate (Must pay the cost), don't participate at the time or reject all the lottery invitations.

How does the lottery works?
  • Players who accepted to participate will have to pay the cost; if they can't pay, they will not enter to the lottery. If can participate, will enter a number from 1 to <x> (cvar). Then wait until the lottery time ends and see if they won.
  • Cost for participate in the lottery is <x> $ (cvar).
  • Reward for winning is <x> $ (cvar).

CVARs
  • lottery_enable <1|0> - Enables/Disables the lottery.
  • lottery_interval <#> - The interval in seconds between lotteries. (Default: 300.0 = 5 minutes)
  • lottery_duration <#> - Duration of the lottery in seconds. (Default: 20.0)
  • lottery_min_players <#> - How many players should be playing to start a lottery. (Default: 5)
  • lottery_min_participants <#> - Minimal ammount of players that must participate in the lottery to proceed. (Default: 3)
  • lottery_options <#> - How many numbers will be able to be chosed in the lottery. (Default: 0 (Auto). Higher = Harder to win)
  • lottery_cost <#> - The cost in $ to participate in the lottery. (Default: 100)
  • lottery_reward <#> - Reward in $ for winners. (Default: 500)
  • lottery_fixed_reward <0|1> - If 0, the reward will be multiplied by the ammount of participants in the lottery. If 1, the reward will always be the same (lottery_reward cvar). (Default: 0)

Plugin installation
  • Download the plugin and paste the .amxx file in the addons/amxmodx/plugins folder.
  • Download the multilang file (.txt) and paste it in the addons/amxmodx/data/lang folder.

Do you want your own costs/rewards?
  • Ignore this part if you don't know how to create/edit AMXX plugins.
  • You can use this plugin as an API, then you can take control of the lotteries!
  • The API does not require the cstrike module, so you'll be able to use the lottery in (almost) any HL mod.
  • Look at this post: AMXX Lottery API

Credits
  • Alphad (Plugin request)
  • Backstabnoob (Good ideas)
  • KliPPy (Suggested the API, Serbian translation)
  • OciXCrom (Macedonian translation)
  • Belo95135 (Slovak translation)
  • get_tn & ANTICHRISTUS (French translation)
  • suie (Romanian translation)
  • LoRikU (Dutch translation)

Translations
  • Available languages: EN, ES, FR, RO, SR, MK, SK, NL.
  • Any help with translations will be greatly appreciated.
  • Translations thread: Here.
Attached Files
File Type: sma Get Plugin or Get Source (amx_lottery.sma - 1867 views - 12.9 KB)
File Type: txt amx_lottery.txt (9.1 KB, 576 views)
File Type: inc lottery_api.inc (1.8 KB, 623 views)

Last edited by Mario AR.; 08-09-2014 at 23:53. Reason: Update: Available languages.
Mario AR. is offline
Freezo Begin
BANNED
Join Date: Mar 2014
Location: Morocco
Old 07-09-2014 , 16:52   Re: AMXX Lottery
Reply With Quote #2

Aha i like it ^^' GJ !
Freezo Begin is offline
Alphad
Senior Member
Join Date: Jun 2014
Old 07-09-2014 , 17:00   Re: AMXX Lottery
Reply With Quote #3

Thank you so much!
Alphad is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 07-09-2014 , 17:54   Re: AMXX Lottery
Reply With Quote #4

This is really not that interesting or original, but it's at least somewhat new so I'll let it pass.

The code is good, you seem to know what you're doing.

If I may suggest something, a cvar to set a price for participating in the lottery would be welcome, as there's really no reason for players to hit that No button.

Another suggestion would be to change the reward (and possibly the price) to a define:
PHP Code:
#define give_reward(%1,%2)   cs_set_user_money(%1,cs_get_user_money(%1)+%2) 
That way it could be easier for people to change the reward to work with their system.

If people confirm this works fine, I have no reason to not approve this.
Backstabnoob is offline
Mario AR.
Senior Member
Join Date: May 2011
Location: Lima, Perú
Old 07-10-2014 , 01:38   Re: AMXX Lottery
Reply With Quote #5

Quote:
Originally Posted by Backstabnoob View Post
This is really not that interesting or original, but it's at least somewhat new so I'll let it pass.

The code is good, you seem to know what you're doing.

If I may suggest something, a cvar to set a price for participating in the lottery would be welcome, as there's really no reason for players to hit that No button.

Another suggestion would be to change the reward (and possibly the price) to a define:
PHP Code:
#define give_reward(%1,%2)   cs_set_user_money(%1,cs_get_user_money(%1)+%2) 
That way it could be easier for people to change the reward to work with their system.

If people confirm this works fine, I have no reason to not approve this.
The main idea is not mine but personally I like the concept.
You're totally right about the cost; without it the No button is somewhat useless; so i've implemented functions to customize the costs and prices, and let cvars for those who don't want to edit the source (Or don't know how to?). I would like to use multiline macros but they're harder to understand and they can't return a value (for checking if the player can pay the lottery cost).
Thank you for your comments

Quote:
Originally Posted by jingojang View Post
Make it with tickets instead, so the players buys a ticket to enter the lottery, let the player be given a ticket with a number instead of them choosing

Just an idea, but good job, mate
Thank you for your suggest, but that system might look somewhat "unfair". In fact, I've never seen real lottos where you can't choose your numbers.
Mario AR. is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 07-11-2014 , 20:20   Re: AMXX Lottery
Reply With Quote #6

Quote:
Originally Posted by Mario AR. View Post
In fact, I've never seen real lottos where you can't choose your numbers.
In fact, the lottery works in some countries like that.
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
jingojang
Senior Member
Join Date: Feb 2010
Location: The Moon
Old 07-09-2014 , 17:56   Re: AMXX Lottery
Reply With Quote #7

Make it with tickets instead, so the players buys a ticket to enter the lottery, let the player be given a ticket with a number instead of them choosing

Just an idea, but good job, mate
__________________
jingojang is offline
Mario AR.
Senior Member
Join Date: May 2011
Location: Lima, Perú
Old 07-10-2014 , 02:29   Re: AMXX Lottery
Reply With Quote #8

AMXX Lottery API


Installing the API
  • To use the API, the first step is to download the source code, edit one line and then compile.
    PHP Code:
    /*================================================================================================

     Uncomment the next line if you want to use the API. Read the .inc file for instructions.
     Using the API will disable the following cvars:
     lottery_options, lottery_min_participants, lottery_cost, lottery_reward, lottery_fixed_reward.
     The API does not require the cstrike module.                            */


    // #define EXTERNAL_MANAGEMENT

    /*==============================================================================================*/ 
  • We should get:
    PHP Code:
    #define EXTERNAL_MANAGEMENT 
  • After uncommenting that line and compiling, we should be able to use the API.
  • Now, we have to download the .inc file from the main post (Were we downloaded the source code) and paste it in our addons/amxmodx/scripting/include folder (Or wherever is located our compiler).

Configuring our plugins to work with the lottery API
  • First of all: The lottery will NOT work properly if we don't have plugins communicating with the API.
  • This is part of the .inc file:
    PHP Code:
    // Set the description of the cost or reward.
    native lottery_set_description(const What LOTTERY_COST, const Description[] = ""any:...);

    // Set the number of options for the players to choose.
    native lottery_set_options_num(const OptionsNum);

    // Sets the minimun number of participants for the lottery.
    native lottery_set_min_participants(const MinParticipants)

    // Forces a lottery to start. Returns true on success, false if the lottery couldn't begin.
    native bool:lottery_force_start();

    // Returns the seconds (float with ms) remaining for the next lottery, 0.0 if a lottery is in progress.
    // Returns < 0 if there is not a next lottery.
    native Float:lottery_time_remaining();

    // Called when a lottery is ready to start.
    // This is the correct place to call the natives lottery_set_*
    // Return PLUGIN_HANDLED to stop the lottery from beginning.
    forward lottery_start();

    // Called when someone wants to participate. Here we must check if the player can pay.
    // Return PLUGIN_HANDLED if the player can't pay.
    forward lottery_check(id);

    // After checking that the player can pay the lottery, this is called.
    // Here we collect the cost from the player.
    forward lottery_pay(id);

    // This forward is called if someone payed to play but the lottery didn't start because of not enought participants.
    // Here we refund the cost to the player.
    forward lottery_refund(id);

    // This forward is called when a player won the lottery. Here we give the reward to the player.
    forward lottery_give_reward(id); 
  • Here's a sample plugin to work with the API:
    PHP Code:
    #include <amxmodx>
    #include <cstrike>
    #include <fun>
    #include <lottery_api>    // MUST have.

    new cvar_cost;

    public 
    plugin_init()
    {
        
    register_plugin("Testing Lottery API""0.1""Mario AR.");
        
    cvar_cost register_cvar("test_lottery_cost""100");
    }

    // Forward called when a lottery is ready to start.
    public lottery_start()
    {
        
    // Let's set the description of the cost
        
    lottery_set_description(LOTTERY_COST"%d Dollars"get_pcvar_num(cvar_cost));
        
    lottery_set_description(LOTTERY_REWARD"Godmode for 60 seconds.");
        
        
    // Here, we set the maximun ammount of options to choose.
        
    lottery_set_options_num(50); // The reward is godmode! Win must be hard.
        
        // In this lottery, I want at least 10 participants.
        
    lottery_set_min_participants(10);
        
        
    // The lottery will start.
        
    return PLUGIN_CONTINUE;
    }

    // Forward called when someone wants to participate. Here we must check if he/she can pay.
    public lottery_check(id)
    {
        if (
    cs_get_user_money(id) < get_pcvar_num(cvar_cost))
            return 
    PLUGIN_HANDLED;    // Return PLUGIN_HANDLED if he/she can't.
        
        
    return PLUGIN_CONTINUE// If he/she can pay, return PLUGIN_CONTINUE.
    }

    // Forward called after checkings are done. The player can pay, so let's take the money!
    public lottery_pay(id)
    {
        
    cs_set_user_money(idcs_get_user_money(id) - get_pcvar_num(cvar_cost));
    }

    // This forward is called IF someone payed but the lottery was cancelled.
    public lottery_refund(id)
    {
        
    // I'm sorry, Take your money back.
        
    cs_set_user_money(idcs_get_user_money(id) + get_pcvar_num(cvar_cost));
    }

    // This forward is called when someone won the lottery.
    public lottery_give_reward(id)
    {
        
    // Ok, you won. As I promised, godmode for 60 seconds.
        
    set_user_godmode(id1);
        
        
    set_task(60.0"remove_godmode"id);
    }

    public 
    remove_godmode(id)
    {
        if (!
    is_user_connected(id))
            return;
        
        
    set_user_godmode(id0);

  • With these plugin running along with the API, I've got:
    [IMG]http://s11.************/b241f605v/test1.jpg[/IMG]
  • This plugin will allow admins to start a lottery, and add a command for users to know when the next lottery will start.
    PHP Code:
    #include <amxmodx>
    #include <amxmisc>
    #include <lottery_api>

    public plugin_init()
    {
        
    register_plugin("Lottery Test""0.1""Mario AR.");
        
        
    register_clcmd("say /lotterystart""clcmd_lotterystart"ADMIN_KICK);
        
    register_clcmd("say /nextlottery""clcmd_nextlottery");
    }

    public 
    clcmd_lotterystart(idlevelcid)
    {
        if (!
    cmd_access(idlevelcid0))
            return 
    PLUGIN_HANDLED;
        
        if (
    lottery_force_start())
        {
            new 
    szName[32];
            
    get_user_name(idszName31);
            
    client_print(0print_chat"Admin %s - Start a lottery!"szName);
        }
        else
        {
            
    client_print(idprint_chat"Lottery could not start.");
        }
        
        return 
    PLUGIN_HANDLED;
    }

    public 
    clcmd_nextlottery(id)
    {
        new 
    Float:nexttime lottery_time_remaining();
        
        if (
    nexttime 0.0)
        {
            
    client_print(idprint_chat"Next lottery in %.f seconds."nexttime);
        }
        else if (
    nexttime == 0.0)
        {
            
    client_print(idprint_chat"The lottery is in progress right now.");
        }
        else
        {
            
    client_print(idprint_chat"There's no time for the next lottery.");
        }
        
        return 
    PLUGIN_HANDLED;

  • Now, I want to do something different. I want 3 different lotteries! Let's go!
    PHP Code:
    #include <amxmodx>
    #include <cstrike>
    #include <fun>
    #include <zombieplague>
    #include <lottery_api>    // MUST have.

    new g_lottery;

    public 
    plugin_init()
    {
        
    register_plugin("Testing Lottery API""0.1""Mario AR.");
    }

    // Forward called when a lottery is ready to start.
    public lottery_start()
    {
        
    g_lottery++;
        
        
    // Just a check to avoid problems.
        
    if (g_lottery 3)
            
    g_lottery 1;
        
        switch (
    g_lottery)
        {
            case 
    1:
            {
                
    lottery_set_description(LOTTERY_COST"100 Dollars.");
                
    lottery_set_description(LOTTERY_REWARD"Godmode for 60 seconds.");
                
                
    lottery_set_options_num(10);
                
                
    lottery_set_min_participants(5);
            }
            case 
    2:
            {
                
    lottery_set_description(LOTTERY_COST"200 Ammo packs.");
                
    lottery_set_description(LOTTERY_REWARD"You'll be turned into a Survivor/Nemesis.");
                
                
    lottery_set_options_num(50);
                
                
    lottery_set_min_participants(2);
            }
            case 
    3:
            {
                
    lottery_set_description(LOTTERY_COST"500 HP.");
                
    lottery_set_description(LOTTERY_REWARD"5000 Ammo Packs.");
                
                
    lottery_set_options_num(20);
                
                
    lottery_set_min_participants(5);
            }
        }
                
        
    // The lottery will start.
        
    return PLUGIN_CONTINUE;
    }

    // Forward called when someone wants to participate. Here we must check if he/she can pay.
    public lottery_check(id)
    {
        switch (
    g_lottery)
        {
            case 
    1:
            {
                if (
    cs_get_user_money(id) < 100)
                    return 
    PLUGIN_HANDLED;
            }
            case 
    2:
            {
                if (
    zp_get_user_ammo_packs(id) < 200)
                    return 
    PLUGIN_HANDLED;
            }
            case 
    3:
            {
                if (
    get_user_health(id) <= 500// He/she MUST have at least 501 HP, so will not die.
                    
    return PLUGIN_HANDLED;
            }
        }
        
        return 
    PLUGIN_CONTINUE// If he/she can pay, return PLUGIN_CONTINUE.
    }

    // Forward called after checkings are done. The player can pay, so let's take the money!
    public lottery_pay(id)
    {
        switch (
    g_lottery)
        {
            case 
    1:
            {
                
    cs_set_user_money(idcs_get_user_money(id) - 100);
            }
            case 
    2:
            {
                
    zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) - 200);
            }
            case 
    3:
            {
                
    set_user_health(idget_user_health(id) - 500);
            }
        }
    }

    // This forward is called IF someone payed but the lottery was cancelled.
    public lottery_refund(id)
    {
        switch (
    g_lottery)
        {
            case 
    1:
            {
                
    cs_set_user_money(idcs_get_user_money(id) + 100);
            }
            case 
    2:
            {
                
    zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 200);
            }
            case 
    3:
            {
                
    set_user_health(idget_user_health(id) + 500);
            }
        }
    }

    // This forward is called when someone won the lottery.
    public lottery_give_reward(id)
    {
        switch (
    g_lottery)
        {
            case 
    1:
            {
                
    set_user_godmode(id1);
                
    set_task(60.0"remove_godmode"id);
            }
            case 
    2:
            {
                if (
    is_user_alive(id))
                {
                    if (
    zp_get_user_zombie(id))
                        
    zp_make_user_nemesis(id);
                    else
                        
    zp_make_user_survivor(id);
                }
            }
            case 
    3:
            {
                
    zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + 5000);
            }
        }
    }

    public 
    remove_godmode(id)
    {
        if (!
    is_user_connected(id))
            return;
        
        
    set_user_godmode(id0);

  • The results:
    [IMG]http://s29.************/gxkf1a7xz/test2.jpg[/IMG]
    [IMG]http://s12.************/mdhtbqr5p/test3.jpg[/IMG]
  • That's it. You can do a lot of things with the API. Just use your imagination.

Last edited by Mario AR.; 08-09-2014 at 23:47. Reason: API v0.6
Mario AR. is offline
Alphad
Senior Member
Join Date: Jun 2014
Old 07-10-2014 , 02:42   Re: AMXX Lottery
Reply With Quote #9

Hey, How can I do that there is no messagemode? And any number you type in chat will be your Lottery number?
The first one you type.
Alphad is offline
Old 07-10-2014, 03:31
GamblerP
This message has been deleted by GamblerP. Reason: Stupid message, Sorry for spam.
Reply



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 15:56.


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