• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Problem with trigger to selection mode

Status
Not open for further replies.
Level 24
Joined
Jun 26, 2020
Messages
1,852
I made this trigger to select gamemodes by just typing a code, but is not working, sometimes display the error message even it shouldn't and when no, it doesn't do anything, what's wrong?
JASS:
scope Selection initializer Init

globals
    private texttag array Modes
    private trigger Select
    private group TempGroup
    constant integer MAX_HEROS=18
endglobals

//Some functions to use
private function Filter1 takes nothing returns boolean
    return GetFilterUnit()!=udg_Golem_de_carne  and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)==false
endfunction

private function Filter2 takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(),'A04C')
    call UnitRemoveAbility(GetEnumUnit(),'A04D')
endfunction

private function Conditions takes nothing returns boolean
    return IsPlayerInForce(GetTriggerPlayer(),udg_Selector_de_modos) and SubString(GetEventPlayerChatString(),0,1)=="-"
endfunction

//The actions to the selector
private function Actions_Select takes nothing returns nothing
    local string mode=GetEventPlayerChatString()
    local string original=mode
    local boolean m2=false
    local boolean m3=false
    local boolean m4=false
    local boolean m5=false
    local string sub1
    local string sub2
    local integer i
    //Comprobando validez / Checking
    set mode=SubString(mode,1,StringLength(mode))
    set sub1=SubString(mode,0,1)
    set sub2=SubString(mode,1,2)
    if sub1!="u" and sub1!="v" then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    elseif sub2!="i" and sub2!="t" and sub2!="s" and sub2!="m" and sub2!="l" and sub2!="h" and sub2!="e" then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    set mode=SubString(mode,2,StringLength(mode))
    set sub1=SubString(mode,0,2)
    if sub1=="ca" or sub1=="nn" or sub1=="np" or sub1=="nc" or sub1=="" then
        set m2=true
    elseif sub1!="ns" and sub1!="oc" and sub1!="nr" and sub1!="ds" and sub1!="ap" and sub1!="lu" and sub1!="nl" then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    set mode=SubString(mode,2,StringLength(mode))
    set sub1=SubString(mode,0,2)
    if sub1=="ns" or sub1=="oc" or sub1=="nr" or sub1=="" then
        set m3=true
    elseif sub1!="ds" and sub1!="ap" and sub1!="lu" and sub1!="nl" then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    set mode=SubString(mode,2,StringLength(mode))
    set sub1=SubString(mode,0,2)
    if sub1=="ds" or sub1=="ap" or sub1=="" then
        set m4=true
    elseif sub1!="lu" and sub1!="nl" then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    set mode=SubString(mode,2,StringLength(mode))
    set sub1=SubString(mode,0,2)
    if sub1=="lu" or sub1=="nl" or sub1=="" then
        set m5=true
    else
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    //Modo 1: Relojes
    set mode=original
    set sub1=SubString(mode,0,1)
    set sub2=SubString(mode,1,2)
    set mode=SubString(mode,2,StringLength(mode))
    if sub1=="v" then
        call EnableTrigger(gg_trg_Reloj1)
        if sub2=="s" then
            set udg_Handicap_varios_relojes=0.60
            set udg_Modo[1]="One timer for each mission (31 minutes max.)."
        elseif sub2=="m" then
            set udg_Handicap_varios_relojes=0.80
            set udg_Modo[1]="One timer for each mission (41 minutes max.)."
        elseif sub2=="l" then
            set udg_Handicap_varios_relojes=1.00
            set udg_Modo[1]="One timer for each mission (51 minutes max.)."
        elseif sub2=="h" then
            set udg_Handicap_varios_relojes=1.20
            set udg_Modo[1]="One timer for each mission (61 minutes max.)."
        endif
    else
        call DisableTrigger(gg_trg_Reloj1)
        if sub2=="i" then
            set udg_Cantidad_de_tiempo_un_reloj=1500.00
            set udg_Modo[1]="One timer for the match (25 minutes)."
        elseif sub2=="t" then
            set udg_Cantidad_de_tiempo_un_reloj=1800.00
            set udg_Modo[1]="One timer for the match (30 minutes)."
        elseif sub2=="s" then
            set udg_Cantidad_de_tiempo_un_reloj=2100.00
            set udg_Modo[1]="One timer for the match (35 minutes)."
        elseif sub2=="m" then
            set udg_Cantidad_de_tiempo_un_reloj=2400.00
            set udg_Modo[1]="One timer for the match (40 minutes)."
        elseif sub2=="l" then
            set udg_Cantidad_de_tiempo_un_reloj=2700.00
            set udg_Modo[1]="One timer for the match (45 minutes)."
        elseif sub2=="h" then
            set udg_Cantidad_de_tiempo_un_reloj=3000.00
            set udg_Modo[1]="One timer for the match (50 minutes)."
        elseif sub2=="e" then
            set udg_Cantidad_de_tiempo_un_reloj=3300.00
            set udg_Modo[1]="One timer for the match (55 minutes)."
        endif
    endif
    //Modo 2: Creeps
    if m2 then
        set sub1=SubString(mode,0,1)
        set sub2=SubString(mode,1,2)
        set mode=SubString(mode,2,StringLength(mode))
        if sub1+sub2=="ca" then
            call EnableTrigger(gg_trg_Respawn_campamentos)
            set udg_Tip[3]="Watch for the missions (push is useless)."
            set udg_Modo[2]="Normal."
        elseif sub1=="n" then
            if sub2=="n" then
                set TempGroup=GetUnitsOfPlayerMatching(Player(PLAYER_NEUTRAL_AGGRESSIVE),Condition(function Filter1))
                call ForGroup(TempGroup, function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set udg_Tip[3]="Watch for the missions (push is useless)."
                set udg_Modo[2]="No Neutrals."
            elseif sub2=="p" then
                set TempGroup=GetUnitsOfTypeIdAll('n00D')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00F')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00S')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n002')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                call DisableTrigger(gg_trg_Aqui_vamos)
                call DisableTrigger(gg_trg_Estos_grunts_son_tontos)
                call EnableTrigger(gg_trg_Respawn_campamentos)
                set udg_Tip[3]="Watch for the missions."
                set udg_Modo[2]="No |cffff0000Draenei|r and |cff32cd32Demons|r."
            elseif sub2=="c" then
                set TempGroup=GetUnitsOfPlayerMatching(Player(PLAYER_NEUTRAL_AGGRESSIVE),Condition(function Filter1))
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00D')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00F')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00S')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n002')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                call DisableTrigger(gg_trg_Aqui_vamos)
                call DisableTrigger(gg_trg_Estos_grunts_son_tontos)
                call EnableTrigger(gg_trg_Respawn_campamentos)
                set udg_Tip[3]="Watch for the missions."
                set udg_Modo[2]="No Creeps."
            endif
        endif
    else
        call EnableTrigger(gg_trg_Respawn_campamentos)
        set udg_Tip[3]="Watch for the missions (push is useless)."
        set udg_Modo[2]="Normal."
    endif
    //Modo 3: Shops
    if m3 then
        set sub1=SubString(mode,0,2)
        set mode=SubString(mode,2,StringLength(mode))
        if sub1=="ns" then
            set udg_Modo[3]="Normal."
        elseif sub1=="oc" then
            set TempGroup=GetUnitsOfTypeIdAll('h002')
            call ForGroup(TempGroup,function HideUnitbyGroup)
            call DestroyGroup(TempGroup)
            set TempGroup=GetUnitsOfTypeIdAll('h000')
            set NewID='h00E'
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set TempGroup=GetUnitsOfTypeIdAll('h003')
            set NewID='h00F'
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set udg_Modo[3]="Only consummibles."
        elseif sub1=="nr" then
            set TempGroup=GetUnitsOfTypeIdAll('h003')
            call ForGroup(TempGroup,function HideUnitbyGroup)
            call DestroyGroup(TempGroup)
            set udg_Modo[3]="No recipes."
        endif
    else
        set udg_Modo[3]="Normal."
    endif
    //Modo 4: Selección
    if m4 then
        set sub1=SubString(mode,0,2)
        set mode=SubString(mode,2,StringLength(mode))
        if sub1=="ds" then
            set udg_Modo[4]="Normal."
        elseif sub1=="ao" then
            set udg_ver_draeneanos=CreateFogModifierRectBJ(true,Player(0),FOG_OF_WAR_VISIBLE,gg_rct_selecionador_demonios)
            set udg_ver_demonios=CreateFogModifierRectBJ(true,Player(6),FOG_OF_WAR_VISIBLE,gg_rct_selecionador_draeneanos)
            set udg_Modo[4]="Traitor (All pick)."
        endif
    else
        set udg_Modo[4]="Normal."
    endif
    //Modo 5: Heroes
    set sub1=SubString(mode,0,2)
    if sub1=="lu" or m5==false then
        set udg_Vortex_area=650.00
        set i=1
        loop
            exitwhen i>MAX_HEROS
            set TempGroup=GetUnitsOfTypeIdAll(udg_No_Heroe_Tipo[i])
            set NewID=udg_Heroe_Tipo[i]
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            set udg_Heroe_Modelo[i]=bj_lastReplacedUnit
            call DestroyGroup(TempGroup)
            set i=i+1
        endloop
        call BJDebugMsg("You can only repick until 2 minutes.")
        call TimerStart(udg_Wait_Timer[4],120.00,false,null)
        call DisableTrigger(gg_trg_Si_mueres)
        call DisableTrigger(gg_trg_Si_revives)
        call DisableTrigger(gg_trg_Heroes)
        call EnableTrigger(gg_trg_Si_mueres_Heroe)
        call EnableTrigger(gg_trg_Aviso)
        set udg_Tip[1]="There are defensive towers, the demolisher is good for destroy them."
        set udg_Tip[2]="You can heal your heros in the base."
        set TempGroup=GetUnitsOfTypeIdAll('h001')
        set NewID='h009'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('h000')
        set NewID='h00A'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('h003')
        set NewID='h00D'
        call ForGroup( TempGroup, function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        call UnitAddAbility(gg_unit_ncop_0124,'A04C')
        call UnitAddAbility(gg_unit_ncop_0124,'A04D')
        call UnitAddAbility(gg_unit_ncop_0129,'A04C')
        call UnitAddAbility(gg_unit_ncop_0129,'A04D')
        call UnitAddAbility(gg_unit_h002_0151,'A04C')
        call UnitAddAbility(gg_unit_h002_0151,'A04D')
        set TempGroup=GetUnitsOfTypeIdAll('n00H')
        call ForGroup(TempGroup,function ShowUnitbyGroup)
        call DestroyGroup(TempGroup)
        set udg_Modo[5]="Hero (Leveling up)."
    elseif sub1=="nl" then
        set udg_Vortex_area=450.00
        call EnableTrigger(gg_trg_Revivir)
        set i=1
        loop
            exitwhen i>MAX_HEROS
            set TempGroup=GetUnitsOfTypeIdAll(udg_Heroe_Tipo[i])
            set NewID=udg_No_Heroe_Tipo[i]
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set i=i+1
        endloop
        set TempGroup=GetUnitsInRectAll(bj_mapInitialPlayableArea)
        call ForGroup(TempGroup,function Filter2)
        call DestroyGroup(TempGroup)
        set udg_Tip[1]="There are special heros for destroy towers."
        set udg_Tip[2]="If you are low of health, you can use -repick to have all life and mana."
        set TempGroup=GetUnitsOfTypeIdAll('h009')
        set NewID='h001'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup = GetUnitsOfTypeIdAll('h00A')
        set NewID='h000'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup = GetUnitsOfTypeIdAll('h00D')
        set NewID='h003'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('n00H')
        call ForGroup(TempGroup,function HideUnitbyGroup)
        call DestroyGroup(TempGroup)
        call DisableTrigger(gg_trg_Aviso)
        set udg_Modo[5]="Classic (Not leveling up)."
    endif
    //Final
    loop
        exitwhen i>29
        call SetTextTagVisibility(Modes[i],false)
        set i=i+1
    endloop
    call ForceClear(udg_Selector_de_modos)
    call ConditionalTriggerExecute(gg_trg_Ultimos_detalles)
    call DisableTrigger(Select)
endfunction

//If you run this trigger, this actions will be runned
private function Actions_Text takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>29
        call SetTextTagVisibility(Modes[i],true)
        set i=i+1
    endloop
    call EnableTrigger(Select)
    if IsPlayerInForce(GetLocalPlayer(),udg_Selector_de_modos) then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,30,"To select a mode you must chat - followed the characters of a specific mode (In order), if you don't specific a mode the game (not type the characters) automatically select the default modes.")
        call StartSound(bj_questHintSound)
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local integer i=0
    local real x=GetUnitX(gg_unit_U00C_0074)
    local real y=GetUnitY(gg_unit_U00C_0074)
    set Select=CreateTrigger()
    call TriggerRegisterPlayerChatEvent(Select,Player(1),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(2),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(3),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(4),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(5),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(7),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(8),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(9),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(10),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(11),"-",false)
    call TriggerAddCondition(Select,Condition(function Conditions))
    call TriggerAddAction(Select,function Actions_Select)
    call DisableTrigger(Select)
    //-- --
    set gg_trg_Seleccion_de_modo=CreateTrigger()
    call TriggerAddAction(gg_trg_Seleccion_de_modo,function Actions_Text)
    //Floating texts to the modes
    loop
        exitwhen i>31
        set Modes[i]=CreateTextTag()
        call SetTextTagVisibility(Modes[i],true)
        if i<=13 then
            call SetTextTagPos(Modes[i],x,y-i*48,100)
        elseif i>13 and i<=23 then
            call SetTextTagPos(Modes[i],x+320,y-(i-15)*48,100)
        elseif i>23 and i<=29 then
            call SetTextTagPos(Modes[i],x+640,y-(i-25)*48,100)
        endif
        set i=i+1
    endloop
    call SetTextTagText(Modes[0],"|cffff4000Timers|r",12*0.023/10)
    call SetTextTagText(Modes[1],"  |cff0080ff-v|r: One for each mission.",12*0.023/10)
    call SetTextTagText(Modes[2],"    |cff00ff80-s|r: 60% (max. 31 minutes).",12*0.023/10)
    call SetTextTagText(Modes[3],"    |cff00ff80-m|r: 80% (max. 41 minutes).",12*0.023/10)
    call SetTextTagText(Modes[4],"    |cff00ff80-l|r: 100% (max. 51 minutes).",12*0.023/10)
    call SetTextTagText(Modes[5],"    |cff00ff80-h|r: 120% (max. 61 minutes).",12*0.023/10)
    call SetTextTagText(Modes[6]," |cff0080ff-u|r: One for the match.",12*0.023/10)
    call SetTextTagText(Modes[7],"    |cff00ff80-i|r: 25 minutes.",12*0.023/10)
    call SetTextTagText(Modes[8],"    |cff00ff80-t|r: 30 minutes.",12*0.023/10)
    call SetTextTagText(Modes[9],"    |cff00ff80-s|r: 35 minutes.",12*0.023/10)
    call SetTextTagText(Modes[10],"    |cff00ff80-m|r: 40 minutes.",12*0.023/10)
    call SetTextTagText(Modes[11],"    |cff00ff80-l|r: 45 minutes.",12*0.023/10)
    call SetTextTagText(Modes[12],"    |cff00ff80-h|r: 50 minutes.",12*0.023/10)
    call SetTextTagText(Modes[13],"    |cff00ff80-e|r: 55 minutes.",12*0.023/10)
    call SetTextTagText(Modes[14],"|cffff4000Creeps|r",12*0.023/10)
    call SetTextTagText(Modes[15],"  |cff0080ff-ca|r: Yes. (Def)",12*0.023/10)
    call SetTextTagText(Modes[16],"  |cff0080ff-n|r: No.",12*0.023/10)
    call SetTextTagText(Modes[17],"    |cff00ff80-n|r: Neutral.",12*0.023/10)
    call SetTextTagText(Modes[18],"    |cff00ff80-p|r: |cffff0000Draenei|r and |cff32cd32Demons|r.",12*0.023/10)
    call SetTextTagText(Modes[19],"    |cff00ff80-c|r: Both.",12*0.023/10)
    call SetTextTagText(Modes[20],"|cffff4000Shops|r",12*0.023/10)
    call SetTextTagText(Modes[21],"  |cff0080ff-ns|r: Normal. (Def)",12*0.023/10)
    call SetTextTagText(Modes[22],"  |cff0080ff-oc|r: Only consumibles.",12*0.023/10)
    call SetTextTagText(Modes[23],"  |cff0080ff-nr|r: No Recipes.",12*0.023/10)
    call SetTextTagText(Modes[24],"|cffff4000Selection|r",12*0.023/10)
    call SetTextTagText(Modes[25],"  |cff0080ff-ds|r: Normal. (Def)",12*0.023/10)
    call SetTextTagText(Modes[26],"  |cff0080ff-ap|r: Traitor (All pick).",12*0.023/10)
    call SetTextTagText(Modes[27],"|cffff4000Heros|r",12*0.023/10)
    call SetTextTagText(Modes[28],"  |cff0080ff-lu|r: Hero (Leveling up). (Def)",12*0.023/10)
    call SetTextTagText(Modes[29],"  |cff0080ff-nl|r: Classic (Not levelling up).",12*0.023/10)
endfunction
endscope
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
At the end I solved it by myself:
JASS:
scope Selection initializer Init

globals
    private texttag array Modes
    private texttag array Modes2
    private trigger Select
    private group TempGroup
    constant integer MAX_HEROS=18
endglobals

//Some functions to use
private function Filter1 takes nothing returns boolean
    return GetFilterUnit()!=udg_Golem_de_carne  and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)==false
endfunction

private function Filter2 takes nothing returns nothing
    call UnitRemoveAbility(GetEnumUnit(),'A04C')
    call UnitRemoveAbility(GetEnumUnit(),'A04D')
endfunction

private function Conditions takes nothing returns boolean
    return IsPlayerInForce(GetTriggerPlayer(),udg_Selector_de_modos) and SubStringMejor(GetEventPlayerChatString(),0,1)=="-"
endfunction

//The actions to the selector
private function Actions_Select takes nothing returns nothing
    local string mode=GetEventPlayerChatString()
    local boolean m2=true
    local boolean m3=true
    local boolean m4=true
    local boolean m5=true
    local string sub1
    local string sub2
    local integer i
    //Comprobando validez / Checking
    set mode=SubStringMejor(mode,2,StringLength(mode))
    if StringLength(mode)>10 then //No debe haber más de 10 caracteres
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode (Too much characters)|r")
        return
    endif
    set sub1=SubStringMejor(mode,1,1)
    set sub2=SubStringMejor(mode,2,2)
    //Primeros 2 caracteres (obligatorios)
    if sub1=="u" or sub1=="v" then
        if sub1=="v" then
            if sub2!="s" and sub2!="m" and sub2!="l" and sub2!="h" then
                call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
                return
            endif
        else
            if sub2!="i" and sub2!="t" and sub2!="s" and sub2!="m" and sub2!="l" and sub2!="h" and sub2!="e" then
                call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
                return
            endif
        endif
    else
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    //-- --
    set mode=SubStringMejor(mode,3,StringLength(mode))
    set sub1=SubStringMejor(mode,1,2)
    if sub1=="ca" or sub1=="nn" or sub1=="np" or sub1=="nc" or sub1==null then
        if sub1==null then
            set m2=false
        else
            set mode=SubStringMejor(mode,3,StringLength(mode))
        endif
    else
        if sub1!="ns" and sub1!="oc" and sub1!="nr" and sub1!="ds" and sub1!="ap" and sub1!="lu" and sub1!="nl" then
            call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
            return
        else
            set m2=false
        endif
    endif
    //-- --
    set sub1=SubStringMejor(mode,1,2)
    if sub1=="ns" or sub1=="oc" or sub1=="nr" or sub1==null then
        if sub1==null then
            set m3=false
        else
            set mode=SubStringMejor(mode,3,StringLength(mode))
        endif
    else
        if sub1!="ds" and sub1!="ap" and sub1!="lu" and sub1!="nl" then
            call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
            return
        else
            set m3=false
        endif
    endif
    //-- --
    set sub1=SubStringMejor(mode,1,2)
    if sub1=="ds" or sub1=="ap" or sub1==null then
        if sub1==null then
            set m4=false
        else
            set mode=SubStringMejor(mode,3,StringLength(mode))
        endif
    else
        if sub1!="lu" and sub1!="nl" then
            call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
            return
        else
            set m4=false
        endif
    endif
    //-- --
    set sub1=mode
    if sub1=="lu" or sub1=="nl" or sub1==null then
        if sub1==null then
            set m5=false
        endif
    else
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"|cffff0000Not valid mode|r")
        return
    endif
    //Modo 1: Relojes
    set mode=GetEventPlayerChatString()
    set mode=SubStringMejor(mode,2,StringLength(mode))
    set sub1=SubStringMejor(mode,1,1)
    set sub2=SubStringMejor(mode,2,2)
    set mode=SubStringMejor(mode,3,StringLength(mode))
    if sub1=="v" then
        call EnableTrigger(gg_trg_Reloj1)
        if sub2=="s" then
            set udg_Handicap_varios_relojes=0.60
            set udg_Modo[1]="One timer for each mission (31 minutes max.)."
        elseif sub2=="m" then
            set udg_Handicap_varios_relojes=0.80
            set udg_Modo[1]="One timer for each mission (41 minutes max.)."
        elseif sub2=="l" then
            set udg_Handicap_varios_relojes=1.00
            set udg_Modo[1]="One timer for each mission (51 minutes max.)."
        elseif sub2=="h" then
            set udg_Handicap_varios_relojes=1.20
            set udg_Modo[1]="One timer for each mission (61 minutes max.)."
        endif
    else
        call DisableTrigger(gg_trg_Reloj1)
        if sub2=="i" then
            set udg_Cantidad_de_tiempo_un_reloj=1500.00
            set udg_Modo[1]="One timer for the match (25 minutes)."
        elseif sub2=="t" then
            set udg_Cantidad_de_tiempo_un_reloj=1800.00
            set udg_Modo[1]="One timer for the match (30 minutes)."
        elseif sub2=="s" then
            set udg_Cantidad_de_tiempo_un_reloj=2100.00
            set udg_Modo[1]="One timer for the match (35 minutes)."
        elseif sub2=="m" then
            set udg_Cantidad_de_tiempo_un_reloj=2400.00
            set udg_Modo[1]="One timer for the match (40 minutes)."
        elseif sub2=="l" then
            set udg_Cantidad_de_tiempo_un_reloj=2700.00
            set udg_Modo[1]="One timer for the match (45 minutes)."
        elseif sub2=="h" then
            set udg_Cantidad_de_tiempo_un_reloj=3000.00
            set udg_Modo[1]="One timer for the match (50 minutes)."
        elseif sub2=="e" then
            set udg_Cantidad_de_tiempo_un_reloj=3300.00
            set udg_Modo[1]="One timer for the match (55 minutes)."
        endif
    endif
    //Modo 2: Creeps
    if m2 then
        set sub1=SubStringMejor(mode,1,1)
        set sub2=SubStringMejor(mode,2,2)
        set mode=SubStringMejor(mode,3,StringLength(mode))
        if sub1+sub2=="ca" then
            call EnableTrigger(gg_trg_Respawn_campamentos)
            set udg_Tip[3]="Watch for the missions (push is useless)."
            set udg_Modo[2]="Normal."
        elseif sub1=="n" then
            if sub2=="n" then
                set TempGroup=GetUnitsOfPlayerMatching(Player(PLAYER_NEUTRAL_AGGRESSIVE),Condition(function Filter1))
                call ForGroup(TempGroup, function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set udg_Tip[3]="Watch for the missions (push is useless)."
                set udg_Modo[2]="No Neutrals."
            elseif sub2=="p" then
                set TempGroup=GetUnitsOfTypeIdAll('n00D')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00F')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00S')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n002')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                call DisableTrigger(gg_trg_Aqui_vamos)
                call DisableTrigger(gg_trg_Estos_grunts_son_tontos)
                call EnableTrigger(gg_trg_Respawn_campamentos)
                set udg_Tip[3]="Watch for the missions."
                set udg_Modo[2]="No |cffff0000Draenei|r and |cff32cd32Demons|r."
            elseif sub2=="c" then
                set TempGroup=GetUnitsOfPlayerMatching(Player(PLAYER_NEUTRAL_AGGRESSIVE),Condition(function Filter1))
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00D')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00F')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n00S')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                set TempGroup=GetUnitsOfTypeIdAll('n002')
                call ForGroup(TempGroup,function RemoveUnitbyGroup)
                call DestroyGroup(TempGroup)
                call DisableTrigger(gg_trg_Aqui_vamos)
                call DisableTrigger(gg_trg_Estos_grunts_son_tontos)
                call EnableTrigger(gg_trg_Respawn_campamentos)
                set udg_Tip[3]="Watch for the missions."
                set udg_Modo[2]="No Creeps."
            endif
        endif
    else
        call EnableTrigger(gg_trg_Respawn_campamentos)
        set udg_Tip[3]="Watch for the missions (push is useless)."
        set udg_Modo[2]="Normal."
    endif
    //Modo 3: Shops
    if m3 then
        set sub1=SubStringMejor(mode,1,2)
        set mode=SubStringMejor(mode,3,StringLength(mode))
        if sub1=="ns" then
            set udg_Modo[3]="Normal."
        elseif sub1=="oc" then
            set TempGroup=GetUnitsOfTypeIdAll('h002')
            call ForGroup(TempGroup,function HideUnitbyGroup)
            call DestroyGroup(TempGroup)
            set TempGroup=GetUnitsOfTypeIdAll('h000')
            set NewID='h00E'
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set TempGroup=GetUnitsOfTypeIdAll('h003')
            set NewID='h00F'
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set udg_Modo[3]="Only consummibles."
        elseif sub1=="nr" then
            set TempGroup=GetUnitsOfTypeIdAll('h003')
            call ForGroup(TempGroup,function HideUnitbyGroup)
            call DestroyGroup(TempGroup)
            set udg_Modo[3]="No recipes."
        endif
    else
        set udg_Modo[3]="Normal."
    endif
    //Modo 4: Selección
    if m4 then
        set sub1=SubStringMejor(mode,1,2)
        set mode=SubStringMejor(mode,3,StringLength(mode))
        if sub1=="ds" then
            set udg_Modo[4]="Normal."
        elseif sub1=="ap" then
            set udg_ver_draeneanos=CreateFogModifierRectBJ(true,Player(0),FOG_OF_WAR_VISIBLE,gg_rct_selecionador_demonios)
            set udg_ver_demonios=CreateFogModifierRectBJ(true,Player(6),FOG_OF_WAR_VISIBLE,gg_rct_selecionador_draeneanos)
            set udg_Modo[4]="Traitor (All pick)."
        endif
    else
        set udg_Modo[4]="Normal."
    endif
    //Modo 5: Heroes
    set sub1=SubStringMejor(mode,1,2)
    if sub1=="lu" or not m5 then
        set udg_Vortex_area=650.00
        set i=1
        loop
            exitwhen i>MAX_HEROS
            set TempGroup=GetUnitsOfTypeIdAll(udg_No_Heroe_Tipo[i])
            set NewID=udg_Heroe_Tipo[i]
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            set udg_Heroe_Modelo[i]=bj_lastReplacedUnit
            call DestroyGroup(TempGroup)
            set i=i+1
        endloop
        call BJDebugMsg("You can only repick until 2 minutes.")
        call TimerStart(udg_Wait_Timer[4],120.00,false,null)
        call DisableTrigger(gg_trg_Si_mueres)
        call DisableTrigger(gg_trg_Si_revives)
        call DisableTrigger(gg_trg_Heroes)
        call EnableTrigger(gg_trg_Si_mueres_Heroe)
        call EnableTrigger(gg_trg_Aviso)
        set udg_Tip[1]="There are defensive towers, the demolisher is good for destroy them."
        set udg_Tip[2]="You can heal your heros in the base."
        set TempGroup=GetUnitsOfTypeIdAll('h001')
        set NewID='h009'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('h000')
        set NewID='h00A'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('h003')
        set NewID='h00D'
        call ForGroup( TempGroup, function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        call UnitAddAbility(gg_unit_ncop_0124,'A04C')
        call UnitAddAbility(gg_unit_ncop_0124,'A04D')
        call UnitAddAbility(gg_unit_ncop_0129,'A04C')
        call UnitAddAbility(gg_unit_ncop_0129,'A04D')
        call UnitAddAbility(gg_unit_h002_0151,'A04C')
        call UnitAddAbility(gg_unit_h002_0151,'A04D')
        set TempGroup=GetUnitsOfTypeIdAll('n00H')
        call ForGroup(TempGroup,function ShowUnitbyGroup)
        call DestroyGroup(TempGroup)
        set udg_Modo[5]="Hero (Leveling up)."
    elseif sub1=="nl" then
        set udg_Vortex_area=450.00
        call EnableTrigger(gg_trg_Revivir)
        set i=1
        loop
            exitwhen i>MAX_HEROS
            set TempGroup=GetUnitsOfTypeIdAll(udg_Heroe_Tipo[i])
            set NewID=udg_No_Heroe_Tipo[i]
            call ForGroup(TempGroup,function ReplaceUnitbyGroup)
            call DestroyGroup(TempGroup)
            set i=i+1
        endloop
        set TempGroup=GetUnitsInRectAll(bj_mapInitialPlayableArea)
        call ForGroup(TempGroup,function Filter2)
        call DestroyGroup(TempGroup)
        set udg_Tip[1]="There are special heros for destroy towers."
        set udg_Tip[2]="If you are low of health, you can use -repick to have all life and mana."
        set TempGroup=GetUnitsOfTypeIdAll('h009')
        set NewID='h001'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup = GetUnitsOfTypeIdAll('h00A')
        set NewID='h000'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup = GetUnitsOfTypeIdAll('h00D')
        set NewID='h003'
        call ForGroup(TempGroup,function ReplaceUnitbyGroup)
        call DestroyGroup(TempGroup)
        set TempGroup=GetUnitsOfTypeIdAll('n00H')
        call ForGroup(TempGroup,function HideUnitbyGroup)
        call DestroyGroup(TempGroup)
        call DisableTrigger(gg_trg_Aviso)
        set udg_Modo[5]="Classic (Not leveling up)."
    endif
    //Final
    set i=0
    loop
        exitwhen i>29
        call SetTextTagVisibility(Modes[i],false)
        call SetTextTagVisibility(Modes2[i],false)
        set i=i+1
    endloop
    call ClearTextMessages()
    call ForceClear(udg_Selector_de_modos)
    call ConditionalTriggerExecute(gg_trg_Ultimos_detalles)
    call DisableTrigger(Select)
endfunction

//If you run this trigger, this actions will be runned
private function Actions_Text takes nothing returns nothing
    local integer i=0
    loop
        exitwhen i>29
        if IsPlayerInForce(GetLocalPlayer(),udg_Grupo_Demonios) then
            call SetTextTagVisibility(Modes[i],true)
            call SetTextTagVisibility(Modes2[i],false)
        else
            call SetTextTagVisibility(Modes[i],false)
            call SetTextTagVisibility(Modes2[i],true)
        endif
        set i=i+1
    endloop
    call EnableTrigger(Select)
    if IsPlayerInForce(GetLocalPlayer(),udg_Selector_de_modos) then
        call ClearTextMessages()
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,30,"To select a mode you must chat '-' followed the characters of a specific mode (In order), if you don't specific a mode the game (not type the characters) automatically select the default modes.")
        call StartSound(bj_questHintSound)
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local integer i
    local real x=GetUnitX(gg_unit_U00C_0074)-192
    local real y=GetUnitY(gg_unit_U00C_0074)+192
    set Select=CreateTrigger()
    call TriggerRegisterPlayerChatEvent(Select,Player(1),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(2),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(3),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(4),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(5),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(7),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(8),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(9),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(10),"-",false)
    call TriggerRegisterPlayerChatEvent(Select,Player(11),"-",false)
    call TriggerAddCondition(Select,Condition(function Conditions))
    call TriggerAddAction(Select,function Actions_Select)
    call DisableTrigger(Select)
    //-- --
    set gg_trg_Seleccion_de_modo=CreateTrigger()
    call TriggerAddAction(gg_trg_Seleccion_de_modo,function Actions_Text)
    //Floating texts to the modes
 
    //! runtextmacro MODES("Modes","x")
    //! runtextmacro MODES("Modes2","x+1920")
 
    //! textmacro MODES takes VAR,VALUE
    set i=0
    loop
        exitwhen i>29
        set $VAR$[i]=CreateTextTag()
        if i<=13 then
            call SetTextTagPos($VAR$[i],$VALUE$,y-i*48,100)
        elseif i>13 and i<=23 then
            call SetTextTagPos($VAR$[i],$VALUE$+320,y-(i-14)*48,100)
        elseif i>23 and i<=29 then
            call SetTextTagPos($VAR$[i],$VALUE$+640,y-(i-24)*48,100)
        endif
        set i=i+1
    endloop
    call SetTextTagText($VAR$[0],"|cffff40001. Timers|r",12*0.023/10)
    call SetTextTagText($VAR$[1],"  |cff0080ff-v|r: One for each mission.",12*0.023/10)
    call SetTextTagText($VAR$[2],"    |cff00ff80-s|r: 60% (max. 31 minutes).",12*0.023/10)
    call SetTextTagText($VAR$[3],"    |cff00ff80-m|r: 80% (max. 41 minutes).",12*0.023/10)
    call SetTextTagText($VAR$[4],"    |cff00ff80-l|r: 100% (max. 51 minutes).",12*0.023/10)
    call SetTextTagText($VAR$[5],"    |cff00ff80-h|r: 120% (max. 61 minutes).",12*0.023/10)
    call SetTextTagText($VAR$[6]," |cff0080ff-u|r: One for the match.",12*0.023/10)
    call SetTextTagText($VAR$[7],"    |cff00ff80-i|r: 25 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[8],"    |cff00ff80-t|r: 30 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[9],"    |cff00ff80-s|r: 35 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[10],"    |cff00ff80-m|r: 40 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[11],"    |cff00ff80-l|r: 45 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[12],"    |cff00ff80-h|r: 50 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[13],"    |cff00ff80-e|r: 55 minutes.",12*0.023/10)
    call SetTextTagText($VAR$[14],"|cffff40002. Creeps|r",12*0.023/10)
    call SetTextTagText($VAR$[15],"  |cff0080ff-ca|r: Yes. (Def)",12*0.023/10)
    call SetTextTagText($VAR$[16],"  |cff0080ff-n|r: No.",12*0.023/10)
    call SetTextTagText($VAR$[17],"    |cff00ff80-n|r: Neutral.",12*0.023/10)
    call SetTextTagText($VAR$[18],"    |cff00ff80-p|r: |cffff0000Draenei|r and |cff32cd32Demons|r.",12*0.023/10)
    call SetTextTagText($VAR$[19],"    |cff00ff80-c|r: Both.",12*0.023/10)
    call SetTextTagText($VAR$[20],"|cffff40003. Shops|r",12*0.023/10)
    call SetTextTagText($VAR$[21],"  |cff0080ff-ns|r: Normal. (Def)",12*0.023/10)
    call SetTextTagText($VAR$[22],"  |cff0080ff-oc|r: Only consumibles.",12*0.023/10)
    call SetTextTagText($VAR$[23],"  |cff0080ff-nr|r: No Recipes.",12*0.023/10)
    call SetTextTagText($VAR$[24],"|cffff40004. Selection|r",12*0.023/10)
    call SetTextTagText($VAR$[25],"  |cff0080ff-ds|r: Normal. (Def)",12*0.023/10)
    call SetTextTagText($VAR$[26],"  |cff0080ff-ap|r: Traitor (All pick).",12*0.023/10)
    call SetTextTagText($VAR$[27],"|cffff40005. Heros|r",12*0.023/10)
    call SetTextTagText($VAR$[28],"  |cff0080ff-lu|r: Hero (Leveling up). (Def)",12*0.023/10)
    call SetTextTagText($VAR$[29],"  |cff0080ff-nl|r: Classic (Not levelling up).",12*0.023/10)
    //! endtextmacro
endfunction
endscope
The function SubString stops the trigger when it has invalid values, so I changed it:
JASS:
function SubStringMejor takes string source, integer min, integer max returns string
    if min>max or source=="" or source==null or min>StringLength(source) then
        return null
    else
        return SubString(source,IMaxBJ(min,1)-1,IMinBJ(max,StringLength(source)))
    endif
endfunction
 
Status
Not open for further replies.
Top