AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
|
01-09-2021
, 10:45
Re: random_num
|
#7
|
Quote:
Originally Posted by lexzor
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <amxmisc> #include <ColorChat> #include <nvault>
#define PLUGIN "giveaway" #define VERSION "1.0" #define AUTHOR "lexzor"
#define YT_FLAG ADMIN_LEVEL_F
new key = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0;
new const tag[] = "JoiNET"
new bool:g_bGwJoined[MAX_PLAYERS + 1] new bool:g_bGwStarted
new g_bCount = 0 new g_bPlayerCount[MAX_PLAYERS +1]
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_menu("gwmenu", key, "gwmenu_handler") register_menu("gwstart", key, "gwstart_handler") }
public gwmenu(id){ static szMenu[650], ilen ilen += formatex(szMenu[ilen], charsmax(szMenu), "\y[%s]\w YouTube Giveaway", tag) if (get_user_flags(id) & YT_FLAG) ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r1.\w Start giveaway", tag) else ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r1.\w Start a giveaway - \d [YT ONLY]") ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r2.\w Join giveaway") ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r0.\y Exit") }
public gwmenu_handler(id, key){ switch(key){ case 1:{ if(get_user_flags(id) & YT_FLAG) gwstart(id) else ColorChat(id, GREEN, "[^4%s^3]^1 You have to be an^4 YouTuber to start a giveaway^1!", tag) } case 2:{ if(g_bGwStarted) gwjoin(id) else if (!g_bGwStarted) ColorChat(id, GREEN, "[^4%s^3]^1 There doesn't exist^4 an started giveaway^1!", tag) } case 0:{ return } } }
public gwstart(id){ new szMenu[650], ilen ilen = 0 ilen += formatex(szMenu[ilen], charsmax(szMenu), "\y[%s]\w YouTube Giveaway", tag) if(!g_bGwStarted) ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r1.\w Start a giveaway") else if (g_bGwStarted) ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r1.\d Giveaway running") if (g_bGwStarted) ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r2.\y Choose a random player") else if (!g_bGwStarted) ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r2.\d Choose a random player") ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r0.\y Exit") }
public gwstart_handler(id, key){ switch(key){ case 1:{ g_bGwStarted = true } case 2:{ randomchooser(id) } } }
public gwjoin(id){ g_bCount++ g_bPlayerCount[id] = g_bCount }
public randomchooser(id){ static winner new players[MAX_PLAYERS + 1], inum, iPlayer winner = random_num(1, g_bCount) get_players(players, inum) for ( new i = 0; i<=inum; i++){ iPlayer = players[i] if (g_bPlayerCount[iPlayer] == winner){ new name[MAX_NAME_LENGTH] get_user_name(iPlayer, name, charsmax(name)) ColorChat(0, GREEN, "[^4%s^3]^1 The winner of giveaway is^3 %s^1!", tag, name) ColorChat(0, GREEN, "[^4%s^3]^1 Congratulations!", tag) } } }
this is what i did until now.
i don't understand what this is:
PHP Code:
if ( g_JoinedGiveaway & ( 1 << ( id & 31 ) ) )
|
View it as if(g_JoinedGiveaway[id]) where g_JoinedGiveaway is declared as: new g_JoinedGiveaway[33].
If you want to understand how it works, read about bits & bitsums.
If you are wondering if you need to do the same and replace boolean arrays, then the answer is no. It's a cool trick and it might be fun to learn more about it, but don't worry if you don't understand it.
__________________
Last edited by HamletEagle; 01-09-2021 at 10:46.
|
|