Raised This Month: $32 Target: $400
 8% 

[TF2] Random Player (version 1.3 dated 14 Sept2022)


Post New Thread Reply   
 
Thread Tools Display Modes
Author
PC Gamer
Veteran Member
Join Date: Mar 2014
Plugin ID:
7406
Plugin Version:
1.0
Plugin Category:
Fun Stuff
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Administrator can select a Random (or not so random) Human Player
    Old 12-04-2020 , 23:10   [TF2] Random Player (version 1.3 dated 14 Sept2022)
    Reply With Quote #1

    Description:
    This plugin allows Administrators to randomly select a human player who is currently in the game and not spectating.

    Commands:
    !randomplayer - This will find a random player. A player is selected and a short song is played along with a countdown to prepare the player for whatever is next.
    !randomplayer <target> - This will appear to find a random player, but it will pick the target player.

    Example: !randomplayer
    Effect: A random human player will be chosen.

    Example: !randomplayer johnny
    Effect: The player named Johnny will be chosen, but it will look random.

    I typically use this after a vote asking if a random player should become a BOSS. You might use it for other purposes such as determining who wins a prize.

    How it looks in game:


    Dependencies needed if you want to edit source:
    More Colors include by Dr. McKay (link: https://forums.alliedmods.net/showthread.php?t=185016)

    Installation:
    Place randomplayer.smx in tf/addons/sourcemod/plugins directory
    Place randomplayer.sp in tf/addons/sourcemod/scripting directory
    Place Get_Ready.mp3 in tf/sound/custom directory
    Attached Files
    File Type: zip randomplayer.zip (518.3 KB, 109 views)
    File Type: sp Get Plugin or Get Source (randomplayer.sp - 48 views - 6.7 KB)
    File Type: smx randomplayer.smx (13.2 KB, 52 views)

    Last edited by PC Gamer; 09-14-2022 at 17:28.
    PC Gamer is offline
    Psyk0tik
    Veteran Member
    Join Date: May 2012
    Location: Homeless
    Old 12-05-2020 , 00:08   Re: [TF2] Random Player
    Reply With Quote #2

    For your countdown timer, you can avoid all if/else-if statements by using a switch statement like this:
    PHP Code:
    public Action RPTimer_CountDown(Handle timer)
    {
        switch (
    iAmount)
        {
            case 
    5EmitSoundToAll("/vo/announcer_ends_5sec.mp3");
            case 
    4EmitSoundToAll("/vo/announcer_ends_4sec.mp3");
            case 
    3EmitSoundToAll("/vo/announcer_ends_3sec.mp3");
            case 
    2EmitSoundToAll("/vo/announcer_ends_2sec.mp3");
            case 
    1EmitSoundToAll("/vo/announcer_ends_1sec.mp3");
            case 
    0:
            {
                
    PrintCenterTextAll("Done!");
                
    EmitSoundToAll("/player/taunt_bell.wav");
                
    PrintToServer("Countdown Complete");
                return 
    Plugin_Stop;
            }
        }

        if (
    iAmount 0)
        {
            
    PrintCenterTextAll("Countdown: %i"iAmount);
            
    iAmount--;
        }

        return 
    Plugin_Continue;

    26 lines vs. 72 lines
    __________________
    Psyk0tik is offline
    StrikeR14
    AlliedModders Donor
    Join Date: Apr 2016
    Location: Behind my PC
    Old 12-05-2020 , 09:54   Re: [TF2] Random Player
    Reply With Quote #3

    Quote:
    Originally Posted by PC Gamer View Post
    Example: !randomplayer johnny
    Effect: The player named Johnny will be chosen, but it will look random
    Ah, so you're helping players cheat?
    Nice plugin, thanks for the release!
    __________________
    Currently taking TF2/CSGO paid private requests!

    My Plugins | My Discord Account
    StrikeR14 is offline
    PC Gamer
    Veteran Member
    Join Date: Mar 2014
    Old 12-05-2020 , 16:11   Re: [TF2] Random Player
    Reply With Quote #4

    Quote:
    Originally Posted by Crasher_3637 View Post
    26 lines vs. 72 lines
    Thanks for tip! Plugin in original post updated to version 1.1 with change suggested by Crasher_3637.

    If anyone else has any other coding recommendations feel free to post them. You won't hurt my feelings and I'm always eager to learn.
    PC Gamer is offline
    FluffPuro
    New Member
    Join Date: Dec 2020
    Old 12-10-2020 , 01:04   Re: [TF2] Random Player [version 1.1 dated 05 Dec 2020]
    Reply With Quote #5

    Sweet plugin, dude!

    I went ahead and modified it a bit to my liking. You should use this version for following updates as it fixes a weird bug such as text overlapping (attached a screenshot of said bug to this reply).

    I would also suggest fixing the "[SM] More than one client matched the given pattern." printing in chat when you run the command but don't specify a player. A player is going to be randomly selected anyways so there's no reason it should show up.

    And restrict the ability to use @red, @blue, @all, etc... best to just limit it to @me and@aim when you want to not-so-randomly select a player as an alternative to typing their username.
    Attached Thumbnails
    Click image for larger version

Name:	bug.png
Views:	99
Size:	65.3 KB
ID:	185513  
    Attached Files
    File Type: smx randomplayer.smx (13.1 KB, 88 views)
    File Type: sp Get Plugin or Get Source (randomplayer.sp - 88 views - 6.6 KB)
    FluffPuro is offline
    PC Gamer
    Veteran Member
    Join Date: Mar 2014
    Old 12-11-2020 , 19:18   Re: [TF2] Random Player [version 1.2 dated 11 Dec 2020]
    Reply With Quote #6

    Version 1.2 updated in original post with changes made by FluffPuro. I revised the text from words like 'chose' and 'has chosen' to 'selected'. That's because saying 'Bob has chosen Mary' sounds weird to me, and 'Bob chose Mary' sounds weird to you. 'Bob selected Mary' is my compromise.

    Version 1.2 now requires morecolors.inc include file if you want to compile it yourself.

    Thanks FluffPuro!

    Last edited by PC Gamer; 12-11-2020 at 19:18.
    PC Gamer is offline
    PC Gamer
    Veteran Member
    Join Date: Mar 2014
    Old 09-14-2022 , 17:34   Re: [TF2] Random Player (version 1.3 dated 14 Sept2022)
    Reply With Quote #7

    Plugin in original post updated to version 1.3.

    This version uses SourceMod 1.11 syntax. No new features since it already works as intended.

    You don't need to install the morecolors.inc file unless you want to compile the plugin yourself. If so, you'll need to put the morecolors.inc file into your \sourcemod\scripting\include\ folder.
    PC Gamer is offline
    Reply



    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 18:17.


    Powered by vBulletin®
    Copyright ©2000 - 2024, vBulletin Solutions, Inc.
    Theme made by Freecode