Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdkhooks>
- #include <sdktools>
- #include <readyup>
- #include <colors>
- #include <l4d2_direct>
- #define IS_VALID_CLIENT(%1) (%1 > 0 && %1 <= MaxClients)
- #define IS_VALID_INGAME(%1) (IS_VALID_CLIENT(%1) && IsClientInGame(%1) && !IsFakeClient(%1))
- #define IS_INFECTED(%1) (GetClientTeam(%1) == 3)
- bool alltalk = false;
- bool scores_fixed = false;
- new Handle:gConf = INVALID_HANDLE;
- new Handle:fSetCampaignScores = INVALID_HANDLE;
- Menu g_hVoteMenu = null;
- public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) {
- MarkNativeAsOptional("IsInReady");
- return APLRes_Success;
- }
- public OnPluginStart() {
- gConf = LoadGameConfigFile("left4downtown.l4d2");
- if(gConf == INVALID_HANDLE)
- {
- LogError("Could not load gamedata/left4downtown.l4d2.txt");
- }
- StartPrepSDKCall(SDKCall_GameRules);
- if(PrepSDKCall_SetFromConf(gConf, SDKConf_Signature, "SetCampaignScores")) {
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
- fSetCampaignScores = EndPrepSDKCall();
- if(fSetCampaignScores == INVALID_HANDLE)
- {
- LogError("Function 'SetCampaignScores' found, but something went wrong.");
- }
- }
- else
- {
- LogError("Function 'SetCampaignScores' not found.");
- }
- CreateTimer(1.0, Timer_Check, _, TIMER_REPEAT);
- HookEvent("player_left_start_area", EventHook:PlayerLeftStartArea_Event, EventHookMode_PostNoCopy);
- }
- public OnMapStart() {
- scores_fixed = false;
- }
- public PlayerLeftStartArea_Event(Handle:event, const String:name[], bool:dontBroadcast) {
- // show tank vote menu
- //if(IsFirstMap())
- if(IsInReady())
- {
- ShowVote();
- }
- }
- bool InFirstRound() {
- return (GameRules_GetProp("m_bInSecondHalfOfRound") == 0);
- }
- public Action:Timer_Check(Handle:timer) {
- // fix scores
- if(IsFirstMap() && IsInReady() && InFirstRound() && !scores_fixed) {
- scores_fixed = true;
- //Determine which teams are which
- new SurvivorTeamIndex = GameRules_GetProp("m_bAreTeamsFlipped") ? 1 : 0;
- new InfectedTeamIndex = GameRules_GetProp("m_bAreTeamsFlipped") ? 0 : 1;
- //Set the scores
- SDKCall(fSetCampaignScores, 0, 0); //visible scores
- L4D2Direct_SetVSCampaignScore(SurvivorTeamIndex, 0); //real scores
- L4D2Direct_SetVSCampaignScore(InfectedTeamIndex, 0);
- }
- // turn all talk on
- if(IsFirstMap() && IsInReady() && InFirstRound() && !alltalk) {
- alltalk = true;
- ServerCommand("sm_cvar sv_alltalk 1");
- CPrintToChatAll("{blue}[{default}ALLTALK{blue}]{default} ON!");
- }
- // turn all talk off
- if(IsFirstMap() && !IsInReady() && InFirstRound() && alltalk) {
- alltalk = false;
- ServerCommand("sm_cvar sv_alltalk 0");
- CPrintToChatAll("{red}[{default}ALLTALK{red}]{default} OFF!");
- }
- return Plugin_Continue;
- }
- int GetAdmin() {
- int admin_client = -1;
- for (new i = 1; i <= MaxClients; i++) {
- if(IS_VALID_INGAME(i)) {
- new AdminId:id = GetUserAdmin(i);
- if(id != INVALID_ADMIN_ID) {
- admin_client = i;
- break;
- }
- }
- }
- return admin_client;
- }
- bool IsFirstMap() {
- bool is_first_map = false;
- char map[64];
- GetCurrentMap(map, 64);
- if(StrContains(map, "m1") != -1) {
- is_first_map = true;
- }
- return is_first_map;
- }
- ShowVote() {
- g_hVoteMenu = new Menu(Handler_VoteCallback, MENU_ACTIONS_ALL);
- g_hVoteMenu.SetTitle("⮞⮞⮞ Vote to choose the first tank");
- int[] iClients = new int[MaxClients];
- int iCount = 0;
- char client_name[64];
- for (new i = 1; i <= MaxClients; i++) {
- if(IS_VALID_INGAME(i) && IS_INFECTED(i)) {
- iClients[iCount++] = i;
- GetClientName(i, client_name, 64);
- char client_id[5];
- IntToString(i, client_id, sizeof(client_id));
- g_hVoteMenu.AddItem(client_id, client_name);
- }
- }
- PrintToServer("First tank vote initialized.");
- g_hVoteMenu.ExitButton = false;
- g_hVoteMenu.DisplayVote(iClients, iCount, 30);
- }
- public int Handler_VoteCallback(Menu menu, MenuAction action, param1, param2) {
- if (action == MenuAction_VoteEnd) {
- char item[64], display[64];
- int votes, totalVotes;
- int admin_id = GetAdmin();
- GetMenuVoteInfo(param2, votes, totalVotes);
- if(totalVotes == 0) {
- if(admin_id != -1) {
- ClientCommand(admin_id, "sm_tankshuffle");
- char msg[128];
- msg = "\x04[TANK VOTE]\x01 None vote taken. The firt tank will be choose randomly.";
- PrintToInfected(msg);
- } else {
- PrintToChatAll("\x04[TANK VOTE]\x01 First tank vote not working this time.");
- }
- } else {
- menu.GetItem(param1, item, sizeof(item), _, display, sizeof(display));
- char client_name[64];
- int id = StringToInt(item);
- GetClientName(id, client_name, sizeof(client_name));
- if(admin_id != -1) {
- ClientCommand(admin_id, "sm_givetank %s", client_name);
- char buff[128];
- Format(buff, 128, "\x04[TANK VOTE]\x01 \x03%s\x01 will be the first tank with \x03%d votes\x01.", client_name, votes);
- PrintToInfected(buff);
- } else {
- PrintToChatAll("\x04[TANK VOTE]\x01 First tank vote not working this time.");
- }
- }
- } else if (action == MenuAction_End) {
- VoteMenuClose();
- }
- return 0;
- }
- PrintToInfected(char message[128]) {
- for (new i = 1; i <= MaxClients; i++) {
- if(IS_VALID_INGAME(i) && IS_INFECTED(i)) {
- PrintToChat(i, message);
- }
- }
- }
- void VoteMenuClose() {
- delete g_hVoteMenu;
- }
RAW Paste Data