#include #include #include #include #include #pragma semicolon 1 #define PLUGIN_VERSION "v1.0" #define TIMER_TASKID 1337 #define TIME_DELAY 1.0 #define ADMIN_FLAG ADMIN_KICK new g_eFirstWrite; new g_iTimer; new g_hHudSync; enum _:FWStatus { sOff, sCountDown, sOn } new g_iStatus = sOff; new g_cRatio, g_cMaxRounds; new g_iRounds[MAX_PLAYERS + 1]; new g_szFW[16]; public plugin_init() { register_plugin("First Write",PLUGIN_VERSION,"Hyuna"); RegisterHam(Ham_Think,"info_target","fw_HamEntityThinkPost",1); RegisterHamPlayer(Ham_Spawn,"HamPlayerSpawnPost",1); create_cvar("amx_fwversion",PLUGIN_VERSION,(FCVAR_SERVER | FCVAR_SPONLY | FCVAR_PRINTABLEONLY),"Shows the plugin version."); g_cRatio = create_cvar("amx_fwratio","4",(FCVAR_SERVER | FCVAR_SPONLY | FCVAR_PRINTABLEONLY),"Defines the ratio between the teams.", true, 0.0, true, float(MaxClients)); g_cMaxRounds = create_cvar("amx_maxrounds","10",(FCVAR_SERVER | FCVAR_SPONLY | FCVAR_PRINTABLEONLY),"Defines max CT rounds", true, 1.0); register_clcmd("say","SayHandler"); register_clcmd("say_team","SayHandler"); g_hHudSync = CreateHudSyncObj(); if (!g_hHudSync) set_fail_state("Invaild Hud Sync Object"); } public plugin_cfg() { g_eFirstWrite = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target")); if (!pev_valid(g_eFirstWrite)) set_fail_state("Error creating First Write dummy entity"); // First Write entity Classname set_pev(g_eFirstWrite,pev_classname,"ent_firstwrite"); set_entity_think(g_eFirstWrite,TIME_DELAY); } public fw_HamEntityThinkPost(iEnt) { static players_dummy[32],iCt,iT; if (iEnt != g_eFirstWrite) return; if (g_iStatus != sOff) { set_entity_think(g_eFirstWrite,TIME_DELAY); return; } get_players(players_dummy,iCt,"ce","CT"); get_players(players_dummy,iT,"ce","TERRORIST"); if ((iCt < 1 && iT > 1) || ((iT / get_pcvar_num(g_cRatio)) > iCt)) { g_iTimer = 5; g_iStatus = true; set_task(1.0,"taskCountDown",TIMER_TASKID,.flags="b"); return; } set_entity_think(g_eFirstWrite,TIME_DELAY); } public HamPlayerSpawnPost(client) { static iRounds; if (!is_user_alive(client)) return; if (cs_get_user_team(client) != CS_TEAM_CT) return; iRounds = get_pcvar_num(g_cMaxRounds); if (++g_iRounds[client] > iRounds) { client_print_color(client,print_team_default,"You reached to your rounds limit (^4%d/%d^1)",g_iRounds[client],iRounds); client_print_color(client,print_team_red,"You will be now move to the ^3Terrorist^1 Team"); g_iRounds[client] = 0; cs_set_user_team(client,CS_TEAM_T); cs_reset_user_model(client); ExecuteHamB(Ham_CS_RoundRespawn,client); return; } client_print_color(client,print_team_blue,"This is your ^4%d/%d^1 round as a ^3guard^1.",g_iRounds[client],iRounds); } public SayHandler(client) { static szMsg[32], szName[32], player, iRounds, arg1[16], arg2[16]; read_args(szMsg,charsmax(szMsg)); remove_quotes(szMsg); if (equali(szMsg,"/first") || equali(szMsg,"/fwstart") || equali(szMsg,"/roshem")) { if ((cs_get_user_team(client) == CS_TEAM_CT && is_user_alive(client)) || get_user_flags(client) & ADMIN_FLAG) { if (g_iStatus == sOff) { get_user_name(client,szName,charsmax(szName)); client_print_color(0,client,"^3%s^1 has started ^4First Write^1 game",szName); g_iTimer = 5; g_iStatus = sCountDown; set_task(1.0,"taskCountDown",TIMER_TASKID,.flags="b"); } else client_print_color(client,print_team_default,"The ^4First Write^1 game is already started!"); return PLUGIN_HANDLED; } client_cmd(client,"spk ^"vox/access denied^""); client_print_color(client,print_team_default,"You don't have access to this command!"); return PLUGIN_HANDLED; } else if (equali(szMsg,"/fwstop")) { if ((cs_get_user_team(client) == CS_TEAM_CT && is_user_alive(client)) || get_user_flags(client) & ADMIN_FLAG) { if (g_iStatus == sOn) { get_user_name(client,szName,charsmax(szName)); client_print_color(0,client,"^3%s^1 has stopped ^4First Write^1 game",szName); g_iStatus = sOff; set_entity_think(g_eFirstWrite,TIME_DELAY); remove_task(TIMER_TASKID); } else client_print_color(client,print_team_default,"The ^4First Write^1 didn't started yet."); return PLUGIN_HANDLED; } client_cmd(client,"spk ^"vox/access denied^""); client_print_color(client,print_team_default,"You don't have access to this command!"); return PLUGIN_HANDLED; } else if (szMsg[0] == '/' || szMsg[0] == '!' || szMsg[0] == '.') { parse(szMsg,arg1,charsmax(arg1),arg2,charsmax(arg2)); if (equali(arg1,"/rounds") || equali(arg1,"!rounds") || equali(arg1,".rounds")) { player = cmd_target(client,arg2,(CMDTARGET_NO_BOTS | CMDTARGET_ALLOW_SELF)); iRounds = get_pcvar_num(g_cMaxRounds); if (!player) { client_print_color(client,print_team_default,"Syntex: ^3/rounds "); return PLUGIN_HANDLED; } get_user_name(player,szName,charsmax(szName)); if (cs_get_user_team(client) != CS_TEAM_CT) client_print_color(client,player,"Client ^3%s^1 isn't a ^3guard^1!",szName); else if (client == player) client_print_color(client,print_team_default,"You have ^4%d/%d^1 rounds.",g_iRounds[client],iRounds); else client_print_color(client,player,"^3%s^1 has ^4%d/%d^1 rounds.",szName,g_iRounds[player],iRounds); return PLUGIN_HANDLED; } return PLUGIN_CONTINUE; } else if (g_iStatus == sOn && cs_get_user_team(client) == CS_TEAM_T && is_user_alive(client)) { if (equal(szMsg,g_szFW)) { client_cmd(client,"spk ^"holo/tr_holo_nicejob^""); remove_task(TIMER_TASKID); g_iStatus = sOff; get_user_name(client,szName,charsmax(szName)); client_print_color(client,print_team_blue,"You won the game! You will be now transfred to the ^3Counter-Terrorists^1 team!"); client_print_color(client,print_team_blue,"^3%s^1 won in the ^4First Write^1 game! Good Job!",szName); g_iRounds[client] = 0; cs_set_user_team(client,CS_TEAM_CT); cs_reset_user_model(client); ExecuteHamB(Ham_CS_RoundRespawn,client); } else { client_cmd(client,"spk ^"scientist/completelywrong^""); client_print_color(client,print_team_default,"Sorry, but your answer (^4%s^1) is completely wrong!",szMsg); } } return PLUGIN_CONTINUE; } public taskCountDown(taskid) { static szWord[10]; if (g_iStatus != sCountDown) { remove_task(taskid); return; } if (g_iTimer < 1) { formatex(g_szFW,charsmax(g_szFW),"%c%c%c%c%c%c",chooseRandomChar(),chooseRandomChar(),chooseRandomChar(),chooseRandomChar(),chooseRandomChar(),chooseRandomChar()); set_hudmessage(random(256),random(256),random(256),0.28,0.64,0,6.0,20.0); ShowSyncHudMsg(0,g_hHudSync,"The combination is: %s",g_szFW); client_print_color(0,print_team_default,"The combination is: ^4%s",g_szFW); g_iStatus = sOn; remove_task(taskid); set_task(20.0,"Task_Faild",TIMER_TASKID); return; } num_to_word(g_iTimer,szWord,charsmax(szWord)); set_hudmessage(random(256),random(256),random(256),0.28,0.64,0,6.0,2.0); ShowSyncHudMsg(0,g_hHudSync,"First Write game will start in %d second%s",g_iTimer,(g_iTimer == 1 ? "":"s")); client_cmd(0,"spk ^"vox/%s second%s^"",szWord,(g_iTimer == 1 ? "":"s")); g_iTimer--; } public Task_Faild(taskid){ if (g_iStatus != sOn) { remove_task(taskid); return; } client_print_color(0,print_team_default,"Awwwww... Nobody won! Try again!"); client_cmd(0,"spk ^"holo/tr_holo_tryagain^""); set_entity_think(g_eFirstWrite,TIME_DELAY); g_iStatus = sOff; } stock chooseRandomChar() { switch(random(10)) { case 0..3: return random_num(48,57); // Nubmer (0-9) case 4..6: return random_num(65,90); // Uppercase Letter (A-Z) case 7..9: return random_num(97,122); // Lowercase Letter (a-z) } return 64; // Dummy } stock set_entity_think(iEntity, Float:next) { if (!pev_valid(iEntity)) return 0; set_pev(iEntity,pev_nextthink,get_gametime() + next); return 1; }