Code: Select all
#include <amxmodx> #include <fakemeta> #include <fun> #include <hamsandwich> new const VERSION[] = "1.0" new g_iRounds, g_pDelay, g_pVoteTime new gszMenu[100] new const gsz_Commands[][] = { "free", "/free", "fr", "/fr", "freeround", "/freeround" } new gKeys = ( MENU_KEY_0 | MENU_KEY_2 | MENU_KEY_3 ) new g_iYes, g_iNo new g_iMaxPlayers new gbFreeRound, gbVoteRunning #define TASKID 92182141827161 public plugin_init() { register_plugin("[DeathRun] Free round", VERSION, "Khalid :)") // Taken from xPaw's free round plugin RegisterHam(Ham_Use, "func_rot_button", "FwdHamUse_Button") RegisterHam(Ham_Use, "func_button", "FwdHamUse_Button") RegisterHam(Ham_Use, "button_target", "FwdHamUse_Button") // Exolent RegisterHam(Ham_Touch, "weaponbox", "FwdHamTouch_Weapon") RegisterHam(Ham_Touch, "armoury_entity", "FwdHamTouch_Weapon") g_iMaxPlayers = get_maxplayers() register_event("HLTV", "eNewRound", "a", "1=0", "2=0") register_clcmd("say", "HookSaid") g_pDelay = register_cvar("dr_free_rounds_between_one_vote", "4") g_pVoteTime = register_cvar("dr_free_vote_time", "15") register_menucmd(register_menuid("\rDo you want this round to be a free round?"), gKeys, "VoteHandler") formatex(gszMenu, charsmax(gszMenu), "\rDo you want this round to be a free round?^n 1.\w Yes^n\r2. \wNo^n^n\r0. \wExit") } // Exolent public FwdHamTouch_Weapon( iEntity, id ) return ( 1 <= id <= g_iMaxPlayers && gbFreeRound ) ? HAM_SUPERCEDE : HAM_IGNORED // From xPaw's free round plugin public FwdHamUse_Button( iEntity, id, iActivator, iUseType, Float:flValue ) { if( gbFreeRound && iUseType == 2 && flValue == 1.0 && is_user_alive( id ) && get_user_team( id ) == 1 && get_pdata_int( iEntity, 41, 4 ) == 1 ) { set_hudmessage( 0, 100, 255, -1.0, 0.25, 0, 2.0, 2.0, 0.2, 0.2, 3 ); show_hudmessage( id, "It is free round!^nYou can't use buttons!" ); return HAM_SUPERCEDE; } return HAM_IGNORED; } bool:AllowVoteStart() { if(g_iRounds >= get_pcvar_num(g_pDelay)) return true return false } public eNewRound() { if(gbFreeRound) gbFreeRound = false g_iRounds++ } public HookSaid(id) { new szSaid[25] read_argv(1, szSaid, charsmax(szSaid)) new j = sizeof(gsz_Commands), iTeam for(new i; i < j; i++) { if(equali(szSaid, gsz_Commands[i])) { if( ( iTeam = get_user_team(id) ) == 1) { if(!gbFreeRound && !gbVoteRunning) StartFreeRun() else client_print(id, print_chat, "[DeathRun] Free round is already running") } else if(iTeam == 2 && !gbFreeRound && !gbVoteRunning && AllowVoteStart()) StartVote() break; } } return PLUGIN_CONTINUE } StartVote() { new Float:flTime = get_pcvar_float(g_pVoteTime) if(!flTime) return; gbVoteRunning = true g_iRounds = 0 show_menu(0, gKeys, gszMenu) client_print(0, print_chat, "[DeathRun] Free round vote has been started.") new data[1]; data[0] = floatround(flTime) set_task(1.0, "CountVotes", TASKID, data, 1, "b") } public CountVotes(data[]) { static iNum ++iNum if(iNum != data[0]) client_print(0, print_center, "%d minutes left for voting", data[0] - iNum) else { remove_task(TASKID) gbVoteRunning = false; iNum = 0 if(g_iYes > g_iNo) { client_print(0, print_chat, "[DeathRun] This round will be a free round! TotalVotes: %d (Yes: %d : No: %d)", g_iYes + g_iNo, g_iYes, g_iNo) StartFreeRun() } else if(g_iYes < g_iNo || g_iYes == g_iNo) client_print(0, print_chat, "[DeathRun] Vote has ended. This round WON'T be a free round. TotalVotes: %d (Yes: %d : No: %d)", g_iYes + g_iNo, g_iYes, g_iNo) g_iYes = 0; g_iNo = 0 } } StartFreeRun() { new iPlayers[32], iNum, iPlayer get_players(iPlayers, iNum, "b") for(new i; i < iNum; i++) { iPlayer = iPlayers[i] strip_user_weapons(iPlayer) give_item(iPlayer, "weapon_knife") } gbFreeRound = true } public VoteHandler(id, key) { new szName[32]; get_user_name(id, szName, 31) if(gbVoteRunning) { switch(key) { case 0: { client_print(0, print_chat, "%s chose Yes", szName) g_iYes++ } case 1: { client_print(0, print_chat, "%s chose No", szName) g_iNo++ } case 3: client_print(0, print_chat, "%s chose not to take part in vote", szName) } } }