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_iValueBetted, bool:g_bIsRolling, g_iCount
new g_cVarMinPlayersToStart, g_cVarMinBet, g_cVarMaxBet
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
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(szFormat, charsmax(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(id, iMenu)
return PLUGIN_HANDLED
}
public jackpot_handler(id, iMenu, iItem)
{
if(iItem == MENU_EXIT)
{
menu_destroy(iMenu)
return PLUGIN_HANDLED
}
switch(iItem)
{
case 0:
{
if(g_bIsBetting[id])
{
client_print(id, print_chat, "%s You have already joined!", g_szPrefix)
return PLUGIN_HANDLED
}
else if(g_bIsRolling)
{
client_print(id, print_chat, "%s The gaming is rolling, you cannot now.", g_szPrefix)
return PLUGIN_HANDLED
}
client_cmd(id, "messagemode jackpot_bet")
client_print(id, print_center, "Type the value that you wanna bet!")
}
case 1:
{
if(!g_iCount)
{
client_print(id, print_chat, "%s There's no bets!", g_szPrefix)
menu_display(id, iMenu)
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], iNum, tempid
get_players(iPlayers, iNum)
for(new i, szName[MAX_PLAYERS];i < iNum; i++)
{
tempid = iPlayers[i]
if(g_iUserValueBetted[tempid])
{
get_user_name(tempid, szName, charsmax(szName))
formatex(szFormat, charsmax(szFormat), "\r%s\w with\y %.1f%%", szName, getChance(tempid))
menu_additem(iMenu, szFormat)
}
}
menu_display(id, iMenu)
}
public chance_handler(id, iMenu)
{
menu_destroy(iMenu)
}
public cmdBetValue(id)
{
new szValue[6]
read_argv(1, szValue, charsmax(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(id, print_chat, "%s You must use a value that's more than 0", g_szPrefix)
return PLUGIN_HANDLED
}
else if(iValue > iUserMoney)
{
client_print(id, print_chat, "%s You do not have enough money!", g_szPrefix)
return PLUGIN_HANDLED
}
else if(iValue < iMinBet)
{
client_print(id, print_chat, "%s You must use a value that's more than %d", g_szPrefix, iMinBet)
return PLUGIN_HANDLED
}
else if(iValue > iMaxBet)
{
client_print(id, print_chat, "%s You must use a value that's more than %d", g_szPrefix, iMaxBet)
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(id, szName, charsmax(szName))
client_print(id, print_chat, "%s %s has joined the jackpot betting %d$ with %.1f%% chance!", g_szPrefix, szName, iValue, getChance(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(0, print_chat, "%s Rolling...", g_szPrefix)
set_task(3.8, "roll")
}
formatex(szHud, charsmax(szHud), "Rolling in %d...", iTime--)
}
else
{
formatex(szHud, charsmax(szHud), "%d of %d players needed^n to roll!", checkPlayersInJackpot(), iPlayersNeeded)
}
set_hudmessage(0, 200, 0, 0.75, 0.10, 0, 1.0, 1.0)
show_hudmessage(0, szHud)
}
public roll()
{
new iRandomPlayer
for(new i, iPlayer, Float:iRandomValue;i < g_iCount;i++)
{
iRandomValue = random_float(0.1, 100.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(iRandomPlayer, clamp(cs_get_user_money(iRandomPlayer) + g_iValueBetted, 0, MAX_MONEY))
new szWinnerName[MAX_PLAYERS]
get_user_name(iRandomPlayer, szWinnerName, charsmax(szWinnerName))
client_print(0, print_chat, "%s %s won %d$ with %.1f%% chance!", g_szPrefix, szWinnerName, g_iValueBetted, getChance(iRandomPlayer))
g_bIsRolling = false
g_iValueBetted = 0
g_iCount = 0
new iPlayers[MAX_PLAYERS], iNum, id
get_players(iPlayers, iNum)
for(new i;i < iNum; i++)
{
id = iPlayers[i]
g_bIsBetting[id] = false
g_iUserValueBetted[id] = 0
}
arrayset(g_iGamblers, 0, sizeof g_iGamblers)
}
getBestChance()
{
new iPlayers[MAX_PLAYERS], iNum
get_players(iPlayers, iNum)
SortCustom1D(iPlayers, iNum, "get_best_chance")
return iPlayers[0]
}
public get_best_chance(id1, id2)
{
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], iNum, iPlayersNum = 0
get_players(iPlayers, iNum)
for(new i;i < iNum; i++)
{
if(g_bIsBetting[iPlayers[i]])
{
iPlayersNum++
}
}
return iPlayersNum
}