[Solved] Issue with script

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
So this script is a kick script. And it checks if the player is the host, and if he types either

-deport playername -> kick
or
-deport playercolor -> kick

Currently -deport playername works fine but
-deport player color only works for player red

Any idea why that is? I can't figure out why it ignores the other colors.

JASS:
scope HostKick initializer init
    globals
        private string s
        private string temp
        private string array playerNames[12]
    endglobals

    private function Act takes nothing returns nothing
        local integer i = 0
        local integer j = 0
        local integer length
        local integer plen
        local integer matchCount = 0
        local integer deportIndex = 0
        local player deported
       local string array playerColors
       
   set playerColors[0] = "red"
    set playerColors[1] = "blue"
    set playerColors[2] = "teal"
    set playerColors[3] = "purple"
    set playerColors[4] = "yellow"
    set playerColors[5] = "orange"
    set playerColors[6] = "green"
    set playerColors[7] = "pink"
    set playerColors[8] = "grey"
    set playerColors[9] = "lb"
    set playerColors[10] = "dg"
    set playerColors[11] = "brown"
       
        if GetHost() == GetTriggerPlayer() then
            set s = StringCase(SubString(GetEventPlayerChatString(), 8, StringLength(GetEventPlayerChatString())), false)
            set length = StringLength(s)
            loop
                exitwhen i >= 12
                if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
                    set plen = StringLength(playerNames[i])
                   
                    loop
                        exitwhen j > (plen - length)
                        if SubString(playerNames[i], j, j + length) == s then
                            set matchCount = matchCount + 1
                            set deportIndex = i
                            exitwhen true
                       elseif SubString(playerColors[i], j, j + length) == s then
                           set matchCount = matchCount + 1
                           set deportIndex = i
                        exitwhen true
                                             
                           
                        endif
                        set j = j + 1
                    endloop
                endif
                set i = i + 1
            endloop
           
            if matchCount == 1 then
                set deported = Player(deportIndex)
                call CustomDefeatBJ(deported, "Kicked by host")
                call PlayerLeave_onPlayerLeaves(deported)
                set deported = null
            endif
        endif
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
       
        loop
            exitwhen i >= 12
            call TriggerRegisterPlayerChatEvent(t, Player(i), "-deport ", false)
            set playerNames[i] = GetPlayerName(Player(i))
            set i = i + 1
        endloop
        call TriggerAddAction(t, function Act)
        set t = null
    endfunction
endscope
 
Status
Not open for further replies.
Top