Raised This Month: $51 Target: $400
 12% 

Jackpot game


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-28-2017 , 09:55   Jackpot game
Reply With Quote #1

This is how it should work:

1. Player's put amount of money to jackpot, more money = better chances to win.
i.e.
Player1 puts 800, Player2 - 400, Player3 - 700.
800 + 400 + 700 = 1900

Percent of winning for each player:
Player1: 800/1900*100= 42,1052...
Player2: 400/1900*100= 21...
Player3: 700/1900*100= 36,84...

2. When there's 2 or more players who placed money the countdown starts (60seconds so other players could join)
3. Winner announced in chat and receives whole Jackpot money.

I imagine menu something similar to coinflip, just show the percent of winning in menu title and update it every time someone places money?

Jackpot | Chance [42%]^n
Rolling in 34 seconds...

1. Player2 - $400 - [21%]
2. Player3 - $700 - [37%]

Thanks
__________________
Airkish is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-28-2017 , 14:06   Re: Jackpot game
Reply With Quote #2

I was improving my "CS1.6Bet.com" plugin with jackpot too, I'm gonna share a half, you might like:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN            "New Plug-In"
#define VERSION            "1.0"
#define AUTHOR            "author"

#if AMXX_VERSION_NUM < 183
#define MAX_PLAYERS        32
#endif

#define TASK_LIST        21233112

new const g_szPrefix[] =        "[Jackpot]:"

const MAX_MONEY =        16000

new bool:g_bIsBetting[MAX_PLAYERS 1], g_iUserValueBetted[MAX_PLAYERS 1], g_iGamblers[MAX_PLAYERS 1]
new 
g_iValueBettedbool:g_bIsRollingg_iCount
new g_cVarMinPlayersToStartg_cVarMinBetg_cVarMaxBet

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_cVarMinPlayersToStart register_cvar("jp_minplayers_to_roll""15")
    
g_cVarMinBet register_cvar("jp_minbet""1000")
    
g_cVarMaxBet register_cvar("jp_maxbet""16000")
    
    
register_clcmd("say /jackpot""cmdJackpot")
    
register_clcmd("jackpot_bet""cmdBetValue")
}

public 
cmdJackpot(id)
{    
    new 
szFormat[75]
    
formatex(szFormatcharsmax(szFormat), "Jackpot Menu^n\d - Current jackpot: %d"g_iValueBetted)
    new 
iMenu menu_create(szFormat"jackpot_handler")
    
    
menu_additem(iMenu"Join Jackpot^n\d - After join, you can't get out!")
    
menu_additem(iMenu"Gamblers' Chance^n\d - Check gamblers' chance!")
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
jackpot_handler(idiMenuiItem)
{
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
iItem)
    {
        case 
0:
        {
            if(
g_bIsBetting[id])
            {
                
client_print(idprint_chat"%s You have already joined!"g_szPrefix)
                return 
PLUGIN_HANDLED
            
}
            else if(
g_bIsRolling)
            {
                
client_print(idprint_chat"%s The gaming is rolling, you cannot now."g_szPrefix)
                return 
PLUGIN_HANDLED
            
}
            
client_cmd(id"messagemode jackpot_bet")
            
client_print(idprint_center"Type the value that you wanna bet!")
        }
        case 
1:
        {
            if(!
g_iCount)
            {
                
client_print(idprint_chat"%s There's no bets!"g_szPrefix)
                
menu_display(idiMenu)
                return 
PLUGIN_HANDLED
            
}
            
showPlayersChanceMenu(id)
        }
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
showPlayersChanceMenu(id)
{
    new 
szFormat[100], iMenu menu_create("Players Chance""chance_handler")
    
    new 
iPlayers[MAX_PLAYERS], iNumtempid
    get_players
(iPlayersiNum)
    for(new 
iszName[MAX_PLAYERS];iNumi++)
    {
        
tempid iPlayers[i]
    
        if(
g_iUserValueBetted[tempid])
        {
            
get_user_name(tempidszNamecharsmax(szName))
            
formatex(szFormatcharsmax(szFormat), "\r%s\w with\y %.1f%%"szNamegetChance(tempid))
        
            
menu_additem(iMenuszFormat)
        }
    }
    
menu_display(idiMenu)
}

public 
chance_handler(idiMenu)
{
    
menu_destroy(iMenu)
}

public 
cmdBetValue(id)
{
    new 
szValue[6]
    
read_argv(1szValuecharsmax(szValue))
    new 
iValue str_to_num(szValue), iUserMoney cs_get_user_money(id)
    
    new 
iMinBet get_pcvar_num(g_cVarMinBet)
    new 
iMaxBet get_pcvar_num(g_cVarMaxBet)
    
    if(
iValue <= 0)
    {
        
client_print(idprint_chat"%s You must use a value that's more than 0"g_szPrefix)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue iUserMoney)
    {
        
client_print(idprint_chat"%s You do not have enough money!"g_szPrefix)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue iMinBet)
    {
        
client_print(idprint_chat"%s You must use a value that's more than %d"g_szPrefixiMinBet)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue iMaxBet)
    {
        
client_print(idprint_chat"%s You must use a value that's more than %d"g_szPrefixiMaxBet)
        return 
PLUGIN_HANDLED
    
}
    else
    {
        
cs_set_user_money(id, (iUserMoney iValue))
        
        
g_iGamblers[g_iCount] = id
        g_iCount
++
        
        
g_bIsBetting[id] = true
        g_iUserValueBetted
[id] = iValue
        g_iValueBetted 
+= iValue
        
        
if(checkPlayersInJackpot() == 1)
        {
            if(!
task_exists(TASK_LIST))
            {
                
set_task(1.0"showPlayersList"TASK_LIST, .flags "b")
            }
        }
        
        new 
szName[MAX_PLAYERS]
        
get_user_name(idszNamecharsmax(szName))
        
        
client_print(idprint_chat"%s %s has joined the jackpot betting %d$ with %.1f%% chance!"g_szPrefixszNameiValuegetChance(id))
    }
    return 
PLUGIN_HANDLED
}

public 
showPlayersList()
{
    new 
szHud[75], iPlayersNeeded get_pcvar_num(g_cVarMinPlayersToStart)
    if(
checkPlayersInJackpot() >= iPlayersNeeded)
    {
        static 
iTime
        
if(!iTime)
        {
            
iTime 4
            g_bIsRolling 
true
            
            client_print
(0print_chat"%s Rolling..."g_szPrefix)
            
set_task(3.8"roll")
        }
        
formatex(szHudcharsmax(szHud), "Rolling in %d..."iTime--)
    }
    else
    {
        
formatex(szHudcharsmax(szHud), "%d of %d players needed^n to roll!"checkPlayersInJackpot(), iPlayersNeeded)
    }
    
    
set_hudmessage(020000.750.1001.01.0)
    
show_hudmessage(0szHud)
}

public 
roll()
{
    new 
iRandomPlayer
    
for(new iiPlayerFloat:iRandomValue;g_iCount;i++)
    {
        
iRandomValue random_float(0.1100.0), iPlayer getBestChance()
        if(
iRandomValue >= getChance(iPlayer))
        {
            
iRandomPlayer iPlayer
        
}
        else
        {
            
iRandomPlayer g_iGamblers[random(g_iCount)] 
        }
    }

    if(!
is_user_connected(iRandomPlayer))
    {
        
roll()
        return
    }

    
remove_task(TASK_LIST)
    
cs_set_user_money(iRandomPlayerclamp(cs_get_user_money(iRandomPlayer) + g_iValueBetted0MAX_MONEY))
    
    new 
szWinnerName[MAX_PLAYERS]
    
get_user_name(iRandomPlayerszWinnerNamecharsmax(szWinnerName))
    
client_print(0print_chat"%s %s won %d$ with %.1f%% chance!"g_szPrefixszWinnerNameg_iValueBettedgetChance(iRandomPlayer))
    
    
g_bIsRolling false
    g_iValueBetted 
0
    g_iCount 
0
    
    
new iPlayers[MAX_PLAYERS], iNumid
    get_players
(iPlayersiNum)
    for(new 
i;iNumi++)
    {
        
id iPlayers[i]
        
        
g_bIsBetting[id] = false
        g_iUserValueBetted
[id] = 0
    
}
    
    
arrayset(g_iGamblers0sizeof g_iGamblers)
}

getBestChance()
{
    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum)
    
SortCustom1D(iPlayersiNum"get_best_chance")
    
    return 
iPlayers[0]
}

public 
get_best_chance(id1id2)
{
    if(
getChance(id1) > getChance(id2))  
        return -
1
        
    
else if(getChance(id1) < getChance(id2))  
        return 
1  

    
return 0
}

Float:getChance(id)
{
    return (
100.0 g_iUserValueBetted[id] / g_iValueBetted)
}

checkPlayersInJackpot()
{
    new 
iPlayers[MAX_PLAYERS], iNumiPlayersNum 0
    get_players
(iPlayersiNum)
    for(new 
i;iNumi++)
    {
        if(
g_bIsBetting[iPlayers[i]])
        {
            
iPlayersNum++
        }
    }
    return 
iPlayersNum

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 09-29-2017 at 14:35.
EFFx is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-29-2017 , 02:53   Re: Jackpot game
Reply With Quote #3

Quote:
Originally Posted by EFFx View Post
I was improving my "CS1.6Bet.com" plugin with jackpot too, I'm gonna share a half, you might like:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN            "New Plug-In"
#define VERSION            "1.0"
#define AUTHOR            "author"

#if AMXX_VERSION_NUM < 183
#define MAX_PLAYERS        32
#endif

#define TASK_LIST        21233112

new const g_szPrefix[] =        "[Jackpot]:"

const MAX_MONEY =        16000

new bool:g_bIsBetting[MAX_PLAYERS 1], g_iUserValueBetted[MAX_PLAYERS 1], g_iGamblers[MAX_PLAYERS 1]
new 
g_iValueBettedbool:g_bIsRollingg_iCount
new g_cVarMinPlayersToStartg_cVarMinBetg_cVarMaxBet

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_cVarMinPlayersToStart register_cvar("jp_minplayers_to_roll""15")
    
g_cVarMinBet register_cvar("jp_minbet""1000")
    
g_cVarMaxBet register_cvar("jp_maxbet""16000")
    
    
register_clcmd("say /jackpot""cmdJackpot")
    
register_clcmd("jackpot_bet""cmdBetValue")
}

public 
cmdJackpot(id)
{    
    new 
szFormat[75]
    
formatex(szFormatcharsmax(szFormat), "Jackpot Menu^n\d - Current jackpot: %d"g_iValueBetted)
    new 
iMenu menu_create(szFormat"jackpot_handler")
    
    
menu_additem(iMenu"Join Jackpot^n\d - After join, you can't get out!")
    
menu_additem(iMenu"Gamblers' Chance^n\d - Check gamblers' chance!")
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED
}

public 
jackpot_handler(idiMenuiItem)
{
    if(
iItem == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
iItem)
    {
        case 
0:
        {
            if(
g_bIsBetting[id])
            {
                
client_print(idprint_chat"%s You have already joined!"g_szPrefix)
                return 
PLUGIN_HANDLED
            
}
            else if(
g_bIsRolling)
            {
                
client_print(idprint_chat"%s The gaming is rolling, you cannot now."g_szPrefix)
                return 
PLUGIN_HANDLED
            
}
            
client_cmd(id"messagemode jackpot_bet")
            
client_print(idprint_center"Type the value that you wanna bet!")
        }
        case 
1:
        {
            if(!
g_iCount)
            {
                
client_print(idprint_chat"%s There's no bets!"g_szPrefix)
                
menu_display(idiMenu)
                return 
PLUGIN_HANDLED
            
}
            
showPlayersChanceMenu(id)
        }
    }
    
menu_destroy(iMenu)
    return 
PLUGIN_HANDLED
}

public 
showPlayersChanceMenu(id)
{
    new 
szFormat[100], iMenu menu_create("Players Chance""chance_handler")
    
    new 
iPlayers[MAX_PLAYERS], iNumtempid
    get_players
(iPlayersiNum)
    for(new 
iszName[MAX_PLAYERS];iNumi++)
    {
        
tempid iPlayers[i]
    
        if(
g_iUserValueBetted[tempid])
        {
            
get_user_name(tempidszNamecharsmax(szName))
            
formatex(szFormatcharsmax(szFormat), "\r%s\w with\y %.1f%%"szNamegetChance(tempid))
        
            
menu_additem(iMenuszFormat)
        }
    }
    
menu_display(idiMenu)
}

public 
chance_handler(idiMenu)
{
    
menu_destroy(iMenu)
}

public 
cmdBetValue(id)
{
    new 
szValue[6]
    
read_argv(1szValuecharsmax(szValue))
    new 
iValue str_to_num(szValue), iUserMoney cs_get_user_money(id)
    
    new 
iMinBet get_pcvar_num(g_cVarMinBet)
    new 
iMaxBet get_pcvar_num(g_cVarMaxBet)
    
    if(
iValue <= 0)
    {
        
client_print(idprint_chat"%s You must use a value that's more than 0"g_szPrefix)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue iUserMoney)
    {
        
client_print(idprint_chat"%s You do not have enough money!"g_szPrefix)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue iMinBet)
    {
        
client_print(idprint_chat"%s You must use a value that's more than %d"g_szPrefixiMinBet)
        return 
PLUGIN_HANDLED
    
}
    else if(
iValue get_pcvar_num(g_cVarMaxBet))
    {
        
client_print(idprint_chat"%s You must use a value that's more than %d"g_szPrefixiMaxBet)
        return 
PLUGIN_HANDLED
    
}
    else
    {
        
cs_set_user_money(id, (iUserMoney iValue))
        
        
g_iGamblers[g_iCount] = id
        g_iCount
++
        
        
g_bIsBetting[id] = true
        g_iUserValueBetted
[id] = iValue
        g_iValueBetted 
+= iValue
        
        
if(checkPlayersInJackpot() == 1)
        {
            if(!
task_exists(TASK_LIST))
            {
                
set_task(1.0"showPlayersList"TASK_LIST, .flags "b")
            }
        }
        
        new 
szName[MAX_PLAYERS]
        
get_user_name(idszNamecharsmax(szName))
        
        
client_print(idprint_chat"%s %s has joined the jackpot betting %d$ with %.1f%% chance!"g_szPrefixszNameiValuegetChance(id))
    }
    return 
PLUGIN_HANDLED
}

public 
showPlayersList()
{
    new 
szHud[75], iPlayersNeeded get_pcvar_num(g_cVarMinPlayersToStart)
    if(
checkPlayersInJackpot() >= iPlayersNeeded)
    {
        static 
iTime
        
if(!iTime)
        {
            
iTime 4
            g_bIsRolling 
true
            
            client_print
(0print_chat"%s Rolling..."g_szPrefix)
            
set_task(3.8"roll")
        }
        
formatex(szHudcharsmax(szHud), "Rolling in %d..."iTime--)
    }
    else
    {
        
formatex(szHudcharsmax(szHud), "%d of %d players needed^n to roll!"checkPlayersInJackpot(), iPlayersNeeded)
    }
    
    
set_hudmessage(020000.750.1001.01.0)
    
show_hudmessage(0szHud)
}

public 
roll()
{
    new 
iRandomPlayer g_iGamblers[random(g_iCount)]
    if(!
is_user_connected(iRandomPlayer))
    {
        
roll()
        return
    }

    
remove_task(TASK_LIST)
    
cs_set_user_money(iRandomPlayerclamp(cs_get_user_money(iRandomPlayer) + g_iValueBetted0MAX_MONEY))
    
    new 
szWinnerName[MAX_PLAYERS]
    
get_user_name(iRandomPlayerszWinnerNamecharsmax(szWinnerName))
    
client_print(0print_chat"%s %s won %d$ with %.1f%% chance!"g_szPrefixszWinnerNameg_iValueBettedgetChance(iRandomPlayer))
    
    
g_bIsRolling false
    g_iValueBetted 
0
    g_iCount 
0
    
    
new iPlayers[MAX_PLAYERS], iNumid
    get_players
(iPlayersiNum)
    for(new 
i;iNumi++)
    {
        
id iPlayers[i]
        
        
g_bIsBetting[id] = false
        g_iUserValueBetted
[id] = 0
    
}
    
    
arrayset(g_iGamblers0sizeof g_iGamblers)
}

Float:getChance(id)
{
    return (
g_iUserValueBetted[id] / g_iValueBetted 100.0)
}

checkPlayersInJackpot()
{
    new 
iPlayers[MAX_PLAYERS], iNumiPlayersNum 0
    get_players
(iPlayersiNum)
    for(new 
i;iNumi++)
    {
        if(
g_bIsBetting[iPlayers[i]])
        {
            
iPlayersNum++
        }
    }
    return 
iPlayersNum

This looks nice, however there is a bug.
First player 100% chance of winning (it's ok).
But when others join everyone gets 0.0% and even the first player.

Airkish has joined the jackpot betting 100$ with 0.0% chance!

When jackpot rolls out in message I get also 0.0%

[Jackpot]: Airkish won 3500$ with 0.0% chance!

And Im pretty sure it affects who wins (because I bet $100 and other player $16000, and I won. Not sure if I am that lucky or it's related to 0% chance)
__________________
Airkish is offline
Old 09-29-2017, 12:09
EFFx
This message has been deleted by EFFx.
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-29-2017 , 12:26   Re: Jackpot game
Reply With Quote #4

Fixed.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-29-2017 , 12:46   Re: Jackpot game
Reply With Quote #5

Quote:
Originally Posted by EFFx View Post
Fixed.
Seems fine now.

Other question. I looked through the code and it seems that "chance" has no influence to win, am I right?

Because you simply choose a random player from the player list who bet
PHP Code:
new iRandomPlayer g_iGamblers[random(g_iCount)] 
Correct me if I am wrong.
__________________
Airkish is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-29-2017 , 13:16   Re: Jackpot game
Reply With Quote #6

You're right.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-29-2017 , 13:17   Re: Jackpot game
Reply With Quote #7

Quote:
Originally Posted by EFFx View Post
You're right.
Is there anything you could do so chance would have effect?
__________________
Airkish is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-29-2017 , 13:23   Re: Jackpot game
Reply With Quote #8

I'm actually thinking something to do this, gimme a time...
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-29-2017 , 13:31   Re: Jackpot game
Reply With Quote #9

Quote:
Originally Posted by EFFx View Post
I'm actually thinking something to do this, gimme a time...
Okay, I'll think with you xD
Take your time.
__________________
Airkish is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 09-29-2017 , 14:23   Re: Jackpot game
Reply With Quote #10

I have updated the roll system:

The function will pick a random float number between 0.1 (min chance) and 100.0 ( max ), if the random be equal to or more than the best chance, the player that got that chance will be the winner, otherwise, a random gambler will be the winner.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
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 03:06.


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