Last human plugin.

Discussion in 'Zombie Panic: Source' started by Tom Hackers, 5 Oct 2008.

  1. Last human plugin.

    Well it's still not final, but some guys know code well so they can correct mine.
    Notice it works well. (Tested only on zp 1.25b...) You can compile it and use, and ofc report bugs.

    Q: What plugin do?
    A: Announce in chat Who is last human and plays music you choose.

    Q: How turn music on/off?
    A: Type in console or in chat "lasthuman" without ""

    Code:
    //Basic includes and other stuff %)
    #include <sourcemod>
    #include <sdktools>
    
    #pragma semicolon 1
    
    #define PLUGIN_VERSION "1.0.1"
    #define MAX_FILE_LEN 80
    
    //Plugin definitions
    public Plugin:myinfo =
    {
       name = "LastHuman",
       author = "Tom Hackers",
       description = "Last Human Sound",
       version = PLUGIN_VERSION,
       url = "https://www.gamingmasters.org/forum/index.php"
    };
    
    //Cvars
    new g_soundPreference[MAXPLAYERS + 1];
    new Handle:g_CvarChat = INVALID_HANDLE;
    new Handle:g_CvarSoundName = INVALID_HANDLE;
    new Handle:g_CvarEnabled = INVALID_HANDLE;
    new String:g_soundName[MAX_FILE_LEN];
    
    //Cvars
    public OnPluginStart()
    {
       g_CvarEnabled = CreateConVar("sm_lasthuman_enable", "1", "Enables the Lasthuman plugin");
       CreateConVar("sm_lasthuman_version", PLUGIN_VERSION, "Last Man Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
       g_CvarSoundName = CreateConVar("sm_lasthuman_sound", "lasthuman_reload.mp3", "The sound to play");
       HookConVarChange(g_CvarSoundName, OnSoundChanged);
       AutoExecConfig(true, "Lasthuman");
       HookEvent("player_death", EventPlayerDeath);
       HookEvent("round_start", Eventnextmp3);
       RegConsoleCmd("lasthuman", PanelLasthuman);
       RegConsoleCmd("say", Command_Say);
       RegConsoleCmd("say_team", Command_Say);
    }
    
    public OnConfigsExecuted()
    {
       GetConVarString(g_CvarSoundName, g_soundName, MAX_FILE_LEN);
       decl String:buffer[MAX_FILE_LEN];
       PrecacheSound(g_soundName, true);
       Format(buffer, sizeof(buffer), "sound/%s", g_soundName);
       AddFileToDownloadsTable(buffer);
    }
    
    //If we change sound do next...
    public OnSoundChanged(Handle:convar, const String:oldValue[], const String:newValue[])
    {
       decl String:buffer[MAX_FILE_LEN];
       strcopy(g_soundName, sizeof(g_soundName), newValue);
       PrecacheSound(g_soundName, true);
       Format(buffer, sizeof(buffer), "sound/%s", g_soundName);
       AddFileToDownloadsTable(buffer);
    }
    
    //Set client basicly hear music, 0 make him not hear until he type in chat !lasthuman
    public OnClientAuthorized(client, const String:auth[])
    {
       if(client && !IsFakeClient(client))
       {
          g_soundPreference[client] = 1;
       }
    }
    
    //Lets hook player deathes and guess who be last human
    public EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
    {
       if(!GetConVarBool(g_CvarEnabled))
       {
          return;
       }
       
       new victimId = GetEventInt(event, "userid");
    
       new victimClient = GetClientOfUserId(victimId);
    
       new killedTeam = GetClientTeam(victimClient);
    
       new playersConnected = GetMaxClients();
    
       // Here  we check to see if there is only one person left.
       new LasthumanId = 0;
       for (new i = 1; i < playersConnected; i++)
       {
          if(IsClientInGame(i))
          {
             if(killedTeam==GetClientTeam(i) && IsPlayerAlive(i))
             {
                if(LasthumanId)
                {
                   LasthumanId = -1;
                } else {
                   
                   LasthumanId = i;
                }
             }
          }
       }
       // Aha! If team 1 and he is last do next (btw 3 - zombie and 1 - spectator, i'm sure)
       if(LasthumanId > 0 && GetClientTeam(LasthumanId) == 2)
       {
          new String:clientname[64];
          GetClientName(LasthumanId, clientname, sizeof(clientname));
          if(GetConVarBool(g_CvarChat))
          {
          // Lets say who is last human in chat
             PrintToChatAll("%s is the last human alive!", clientname);
          }
          // Here we execue in player console play command! Btw we check want he hear sound or no, if no we let him alone :)
          for (new i = 1; i < playersConnected; i++)
          {
             if(IsClientInGame(i) && g_soundPreference[i] && !IsFakeClient(i))
             {
             ClientCommand (i, "play %s", g_soundName);
             ClientCommand (i, "stopmp3");   
             }
          }
       }
    
    }
    
    // On new round we make all clients play another sound (to silence music) and announce in chat some random test...
    public Eventnextmp3(Handle:event, const String:objective[], bool:dontBroadcast)
    {
       static iClient = -1, iMaxClients = 0;
    
           iMaxClients = GetMaxClients ();
          
          for (iClient = 1; iClient <= iMaxClients; iClient++)
          {
             if (IsClientConnected (iClient) && IsClientInGame (iClient))
             {
             if (IsFakeClient (iClient))
                           {
                }
             else
                {
                   //this is sound
                   ClientCommand (iClient, "play common/talk.wav"); //notice its half second sound, quite enough and exist on all servers and clients.
                   //this make them listen zp music
                   ClientCommand (iClient, "nextmp3");
                   //this is text :)
                   PrintToChatAll("Pick up your weapons and fight!");
                }
             }
          }
    }
    
    //This 2 next sections hold menu "Want you hear or no" yes no
    public PanelHandlerLasthuman(Handle:menu, MenuAction:action, param1, param2)
    {
       if (action == MenuAction_Select)
          if(param2 == 2)
             g_soundPreference[param1] = 0;
          else
             g_soundPreference[param1] = param2;
       else if(action == MenuAction_Cancel)
          PrintToServer("Client %d's Last Human menu was cancelled.  Reason: %d", param1, param2);
    }
    
    public Action:PanelLasthuman(client, args)
    {
       new Handle:panel = CreatePanel();
       SetPanelTitle(panel, "Last Human Standing Sound");
       DrawPanelItem(panel, "Enable");
       DrawPanelItem(panel, "Disable");
    
       SendPanelToClient(panel, client, PanelHandlerLasthuman, 20);
    
       CloseHandle(panel);
    
       return Plugin_Handled;
    }
    
    //Last! Let's check who say in chat !lasthuman or lasthuman
    public Action:Command_Say(client, args)
    {
       decl String:text[192];
       if (!GetCmdArgString(text, sizeof(text)))
       {
          return Plugin_Continue;
       }
       
       new startidx = 0;
       if(text[strlen(text)-1] == '"')
       {
          text[strlen(text)-1] = '\0';
          startidx = 1;
       }
       
       if (strcmp(text[startidx], "lasthuman", false) == 0)
       {
    
       new Handle:panel = CreatePanel();
       SetPanelTitle(panel, "Last Human Standing Sound");
       DrawPanelItem(panel, "Enable");
       DrawPanelItem(panel, "Disable");
    
       SendPanelToClient(panel, client, PanelHandlerLasthuman, 20);
    
       CloseHandle(panel);
    
       return Plugin_Handled;
       
       }
       
       return Plugin_Continue;   
    }
    //The end
    
    Good song you can get here: Click
     
    Last edited by a moderator: 27 Nov 2013

Users Viewing Thread (Users: 0, Guests: 0)

Users found this page by searching for:

  1. zp plugins human

    ,
  2. max_file_len definition code