System cmdKick

Discussion in 'Systems and Snippets' started by Darthfett, Jan 19, 2010.

  1. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    cmdKick
    Created by Darthfett

    Description:
    A command that gives kicking functionality. The host can kick any playing player except his/her self and the map creator. The map creator can kick any player, regardless of whether he/she is the host, except his/her self. The host can kick a player using this system, using the in-game command "-kick " along with any reference to the desired player (such as their name, color, or number).

    Requirements:
    stringPlayer
    stringFind
    Event

    The rest of the documentation can be found in the system code, below:

    JASS:
    library cmdKick initializer Init uses stringPlayer,Event,stringFilter,stringFind,stringColor
    /*
    __________________________________________________________________________________
    
            cmdKick library, created by Darthfett - version 1.0
            http://www.thehelper.net/forums/showthread.php?t=144461
            
                                    Requirements
                                    
    -vJass compiler (such as JASSHelper, this version compiled for version 0.A.2.7)
                         
    +stringPlayer library - http://www.thehelper.net/forums/showthread.php?t=143590        
        +stringFilter library - http://www.thehelper.net/forums/showthread.php?t=143589
        
    +stringFind library - http://www.thehelper.net/forums/showthread.php?t=143591
    
    +Event library (this version compiled for version 1.04) - http://www.thehelper.net/forums/showthread.php?t=126846 
    
                                    Documentation
    
    -Credit for this library is not necessary.  Feel free to use it in your map.
    If you feel obligated to credit me, I won't object.  I only ask that you do 
    not simply copy and paste the library as your own.
    
                                        API
    
    <CONFIG>
        
    private constant string cmd
        Set this string to the command to be used to kick a player.
        Using a space at the end will require a space in-between the command
        and the name of the player.
        
    private constant string creator
        Set this string to your in-game name, to prevent the system from kicking you.
        
    public boolean ENABLED <cmdKick_ENABLED>
        Set this to true/false to enable/disable the in-game command.
        
    private constant string ATTEMPT_KICK_INVALID_PLAYER
        This message is displayed to the kicking player when he types in an invalid string.
        
    private constant string ATTEMPT_KICK_PLAYER_NOT_PLAYING
        This message is displayed to the kicking player when he chooses a player that is not playing.
        
    private constant string ATTEMPT_KICK_SELF
        This message is displayed to the kicking player when he attempts to kick himself.
        
    private constant string ATTEMPT_KICK_CREATOR
        This message is displayed to the kicking player when he attempts to kick the map creator.
        
    private constant string ATTEMPT_KICKER_NOT_HOST
        This message is displayed to the kicking player when he attempts to kick and is not the host (or creator).
    
    private function KICK_MESSAGE_ALL_PLAYERS takes player p returns string
        This message is displayed to all players when player p is kicked.
    
    private function KICK_MESSAGE_KICKED_PLAYER takes player p returns string
        This message is displayed to player p when he is kicked.
        
    <END CONFIG>
        
    string In-Game Command "-kick "
        This command (by default) allows you to kick a player by typing "-kick " followed
        by a reference to a player.  This reference can be anything from:
            -Player Name
            -Player Color
            -Player Number ("1" refers to Player(0))
            -Any SubString of a player's name
    
    Event EVENT_PLAYER_IS_KICKED
        This Event is fired just before a player is kicked from the game.
        Invalid kick commands will not trigger this Event.
            
    global player KickedPlayer
        OR
    function GetKickedPlayer takes nothing returns player
        When a player is kicked, just before he is booted from the game, the
        EVENT_PLAYER_IS_KICKED Event is fired.  You can refer to the Kicked player
        with this function.
        
    global player KickingPlayer
        OR
    function GetKickingPlayer takes nothing returns player
        When a player is kicked, just before he is booted from the game, the
        EVENT_PLAYER_IS_KICKED Event is fired.  You can refer to the Kicking player
        with this function.
    __________________________________________________________________________________
    */
    
    //CONFIG
    globals
        private constant string cmd = "-kick "
        private constant string creator = "Darthfett"
        
        public boolean ENABLED = true
        
        private constant string ATTEMPT_KICK_INVALID_PLAYER = CLR_RED + "Invalid Player" + CLR_END
        private constant string ATTEMPT_KICK_PLAYER_NOT_PLAYING = CLR_RED + "That player is not playing!" + CLR_END
        private constant string ATTEMPT_KICK_SELF = CLR_RED + "You cannot kick yourself!" + CLR_END
        private constant string ATTEMPT_KICK_CREATOR = CLR_RED + "You cannot kick the creator of the map!" + CLR_END
        private constant string ATTEMPT_KICKER_NOT_HOST = CLR_RED + "Only the host may kick another player." + CLR_END
    endglobals
    
    private function KICK_MESSAGE_ALL_PLAYERS takes player p returns string
        return P2CN(p) + CLR_RED + " has been kicked!" + CLR_END
    endfunction
    
    private function KICK_MESSAGE_KICKED_PLAYER takes player p returns string
        return CLR_RED + "You have been kicked." + CLR_END
    endfunction
    //END CONFIG
    
    globals
        Event EVENT_PLAYER_IS_KICKED
        player KickedPlayer
        player KickingPlayer
        
        private player host
        private string tempStr
        
        private integer temp
    endglobals
        
    
    function GetKickedPlayer takes nothing returns player
        return KickedPlayer
    endfunction
    
    function GetKickingPlayer takes nothing returns player
        return KickingPlayer
    endfunction
    
    private function GetHost takes nothing returns nothing
        local gamecache g = InitGameCache("Map.w3v")
        call StoreInteger ( g, "Map", "Host", GetPlayerId(GetLocalPlayer ())+1)
        call TriggerSyncStart ()
        call SyncStoredInteger ( g, "Map", "Host" )
        call TriggerSyncReady ()
        set host = Player( GetStoredInteger ( g, "Map", "Host" )-1)
        call FlushGameCache( g )
        set g = null
    endfunction
    
    private function Conditions takes nothing returns boolean
        local string s = GetEventPlayerChatString()
        local player kicker = GetTriggerPlayer()
        local player tar
        if StartsWith(s,cmd,false) and ENABLED then
            set tar = S2P(Strip(SubString(s,StringLength(cmd),StringLength(s))))
            if tar == null or (DEBUG_MODE and tar == Player(12)) then
                call DisplayTextToPlayer(kicker,0,0,ATTEMPT_KICK_INVALID_PLAYER)
                return false
            endif
            if GetPlayerSlotState(tar) != PLAYER_SLOT_STATE_PLAYING then
                call DisplayTextToPlayer(kicker,0,0,ATTEMPT_KICK_PLAYER_NOT_PLAYING)
                return false
            endif
            if tar == kicker then
                call DisplayTextToPlayer(kicker,0,0,ATTEMPT_KICK_SELF)
                return false
            endif
            if StringCase(GetPlayerName(tar),false) == StringCase(creator,false) then
                call DisplayTextToPlayer(kicker,0,0,ATTEMPT_KICK_CREATOR)
                return false
            endif
            if StringCase(GetPlayerName(kicker),false) == StringCase(creator,false) then
                set KickedPlayer = tar
                set KickingPlayer = kicker
                return true
            endif
            call GetHost()
            if kicker == host then
                set KickedPlayer = tar
                set KickingPlayer = kicker
                return true
            endif
            call DisplayTextToPlayer(kicker,0,0,ATTEMPT_KICKER_NOT_HOST)
        endif
        return false
    endfunction
    
    private function Actions takes nothing returns nothing
        call EVENT_PLAYER_IS_KICKED.fire()
        call RemovePlayer(KickedPlayer,PLAYER_GAME_RESULT_DEFEAT)
        call DisplayTextToPlayer(GetLocalPlayer(),0,0,KICK_MESSAGE_ALL_PLAYERS(KickedPlayer))
        call CustomDefeatDialogBJ(KickedPlayer,KICK_MESSAGE_KICKED_PLAYER(KickedPlayer))
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        set temp = 0
        loop
            exitwhen temp >= 12
            call TriggerRegisterPlayerChatEvent(t,Player(temp),"",false)
            set temp = temp + 1
        endloop
        call TriggerAddCondition(t,Condition(function Conditions))
        call TriggerAddAction(t,function Actions)
        set EVENT_PLAYER_IS_KICKED = Event.create()
    endfunction
    
    endlibrary
    
    library_once stringColor
    
    globals
        constant string CLR_RED =         "|cffff0000"
        constant string CLR_END =        "|r"
    endglobals
    
    endlibrary
     
    • Like Like x 1
  2. jig7c

    jig7c Stop reading me...-statement

    Ratings:
    +123 / 0 / -0
    nice!!
    i'm sure people will use this a lot!

    is there a vote kick in this too?
    doesn't look like it!

    -kick ass system :)
     
  3. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    I would recommend molding this with the stringPlayer library.
     
  4. Joker(Div)

    Joker(Div) Always Here..

    Ratings:
    +86 / 0 / -0
    So many tiny things, I wish you could bunch a few together. :/
     
  5. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    They're mainly tiny because all of the work has been delegated to the libraries they require. They don't exactly fit together, so I don't think it's a good idea to merge libraries. It wouldn't make sense to combine all the commands together, because not everyone wants to include a name-changing and color changing system/command in their map. It would be excess and bloat.

    The two are unrelated. This system uses the stringPlayer library to convert from string to a player, and then kicks the player. It uses a smart priority system to prevent any player from kicking his/her self, regular players from kicking, and the host from kicking the map creator.

    For anyone who is wondering, no this is not a vote-kick system. Vote-kick systems usually suffer from having a terrible interface (such as "type yes or no to vote to kick this player", or an annoying dialog box that gets in the way). I also think it is fair for the host and map creator both to have kick privileges.
     
  6. Azlier

    Azlier Old World Ghost

    Ratings:
    +461 / 0 / -0
    >and the host from kicking the map creator.

    Why?

    I detest maps that have these mystical "safelists" of players that can't be kicked.
     
  7. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    It has room for one player, not a list of them. Why should I allow myself to be kicked from a game I created?
     
  8. gameman

    gameman It's been a long, long time.

    Ratings:
    +97 / 0 / -0
    at least a add a constant allowing the kicking of the creator or not.

    constant boolean Allowhostkick = false

    otherwise, great system. Many times kicking by name has failed the map host.
     
  9. bLu3_eYeS

    bLu3_eYeS New Member

    Ratings:
    +31 / 0 / -0
    Is it possible to be set to two owners ??? I dont really understand JASS
     
  10. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    Why?

    If you want to disable the creator thing entirely, set it to "". However, I see no point in giving the host priority over the map creator.

    Thanks, but I don't think I understand what you mean. Are you saying it's good because it supports numbers and colors as well? :eek:

    Currently, it is not set up to support multiple map creators, no. I want to discourage people from using this as an 'admin' list or 'unkickable' list, and so I specifically limited the creator to one possible player.

    You don't need to know JASS in order to know how to use this. The documentation in the code is relatively simple, just look in the <CONFIG> section. That will explain the config.
     
  11. bLu3_eYeS

    bLu3_eYeS New Member

    Ratings:
    +31 / 0 / -0
    if possible , Please :( tell me how can i use it with two admins , i am making a map with a friend and we need immunity...so they cannot kick the map maker...
     
  12. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    Just to let any mods who are reviewing resources know, this was previously known as Multi Kick, and was approved. I simply renamed the system and standardized it to make it fit in with my 'cmd' libraries.

    Anything I can work on to get this approved?
     
  13. Ghan

    Ghan Administrator - Servers are fun Staff Member

    Ratings:
    +773 / 0 / -0
    Approved.
     
  14. Crazy_Dead

    Crazy_Dead New Member

    Ratings:
    +24 / 0 / -0
    Darth, i think this could be very much more simplier. I think.
     
  15. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    It probably could if you left out the customization/constant stuff, and the event system. However, it would not be a whole lot shorter, and it's not currently doing a whole lot. Most of the string parsing work is done by the two required string libs, which can't really get much simpler without losing a lot of functionality for the user.

    Overall, this is one the systems I'm most happy with, as far as how lightweight it is.
     
  16. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    JASS:
    library cmdKick initializer Init uses stringPlayer,Event,stringFilter,stringFind,stringColor


    Doesn't say it needs stringColor in the thread.
     
  17. Crazy_Dead

    Crazy_Dead New Member

    Ratings:
    +24 / 0 / -0
    Yes. You are true.
    But i was thinking like this:

    Register when someone enters it. Check if the "typer" is player(0) and if his name is the Mapmakers. Done?
     
  18. Darthfett

    Darthfett Super Mod

    Ratings:
    +614 / 0 / -0
    The systems detect whether the entered string is a name, part of a name (in case the persons name is long and/or hard to read), a player's color (which works with player-color switching systems), or a player's number (e.g. '1' is Player(0) or Player 1).

    They also allow the "host" to be in any slot, rather than forcing him to be in slot 1, and allow there to be a host AND a map maker in the same game, correctly giving the map maker priority over the host.

    If used with my cmdName system, it also prevents players from changing their name TO the map maker's name, thus avoiding any problems with name spoofing (though the hack-spoofing can still be a problem).

    It's quite a bit more useful than it seems on the surface. :)

    Whoops, I forgot to include the library_once:

    It has been added at the very end. It should now work without the stringColor library, and have no problems if you happen to have it imported.
     

Share This Page