function duel takes nothing returns nothing
local group gr=CreateGroup()
local unit array u
local timer time=GetExpiredTimer()
local integer table=GetHandleId(time)
local timerdialog td=LoadTimerDialogHandle(udg_h,table,0)
local integer i=0
call DestroyTimerDialog(td)
call FlushChildHashtable(udg_h,table)
call DestroyTimer(time)
loop
exitwhen i > 11
call GroupAddUnit(gr,udg_player_hero[i])
set i = i + 1
endloop
if CountUnitsInGroup(gr)<4 then
set u[1]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[1],gr)
set u[2]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[2],gr)
call SaveInteger(udg_h,1,1,GetPlayerId(GetOwningPlayer(u[1])) )
call SaveInteger(udg_h,1,2,GetPlayerId(GetOwningPlayer(u[2])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Дуэль: "+GetPlayerName(GetOwningPlayer(u[1]))+" против "+ GetPlayerName(GetOwningPlayer(u[2])))
call SaveInteger(udg_h,1,13,1 )
elseif CountUnitsInGroup(gr)==4 or CountUnitsInGroup(gr)==5 then
set u[1]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[1],gr)
set u[2]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[2],gr)
call SaveInteger(udg_h,1,1,GetPlayerId(GetOwningPlayer(u[1])) )
call SaveInteger(udg_h,1,2,GetPlayerId(GetOwningPlayer(u[2])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Первая дуэль: "+GetPlayerName(GetOwningPlayer(u[1]))+" против "+ GetPlayerName(GetOwningPlayer(u[2])))
set u[3]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[3],gr)
set u[4]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[4],gr)
call SaveInteger(udg_h,1,3,GetPlayerId(GetOwningPlayer(u[3])) )
call SaveInteger(udg_h,1,4,GetPlayerId(GetOwningPlayer(u[4])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Вторая дуэль: "+GetPlayerName(GetOwningPlayer(u[3]))+" против "+ GetPlayerName(GetOwningPlayer(u[4])))
call SaveInteger(udg_h,1,13,2 )
elseif CountUnitsInGroup(gr)==6 or CountUnitsInGroup(gr)==7 then
set u[1]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[1],gr)
set u[2]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[2],gr)
call SaveInteger(udg_h,1,1,GetPlayerId(GetOwningPlayer(u[1])) )
call SaveInteger(udg_h,1,2,GetPlayerId(GetOwningPlayer(u[2])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Первая дуэль: "+GetPlayerName(GetOwningPlayer(u[1]))+" против "+ GetPlayerName(GetOwningPlayer(u[2])))
set u[3]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[3],gr)
set u[4]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[4],gr)
call SaveInteger(udg_h,1,3,GetPlayerId(GetOwningPlayer(u[3])) )
call SaveInteger(udg_h,1,4,GetPlayerId(GetOwningPlayer(u[4])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Вторая дуэль: "+GetPlayerName(GetOwningPlayer(u[3]))+" против "+ GetPlayerName(GetOwningPlayer(u[4])))
set u[5]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[5],gr)
set u[6]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[6],gr)
call SaveInteger(udg_h,1,5,GetPlayerId(GetOwningPlayer(u[5])) )
call SaveInteger(udg_h,1,6,GetPlayerId(GetOwningPlayer(u[6])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Третья дуэль: "+GetPlayerName(GetOwningPlayer(u[5]))+" против "+ GetPlayerName(GetOwningPlayer(u[6])))
call SaveInteger(udg_h,1,13,3 )
else
set u[1]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[1],gr)
set u[2]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[2],gr)
call SaveInteger(udg_h,1,1,GetPlayerId(GetOwningPlayer(u[1])) )
call SaveInteger(udg_h,1,2,GetPlayerId(GetOwningPlayer(u[2])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Первая дуэль: "+GetPlayerName(GetOwningPlayer(u[1]))+" против "+ GetPlayerName(GetOwningPlayer(u[2])))
set u[3]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[3],gr)
set u[4]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[4],gr)
call SaveInteger(udg_h,1,3,GetPlayerId(GetOwningPlayer(u[3])) )
call SaveInteger(udg_h,1,4,GetPlayerId(GetOwningPlayer(u[4])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Вторая дуэль: "+GetPlayerName(GetOwningPlayer(u[3]))+" против "+ GetPlayerName(GetOwningPlayer(u[4])))
set u[5]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[5],gr)
set u[6]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[6],gr)
call SaveInteger(udg_h,1,5,GetPlayerId(GetOwningPlayer(u[5])) )
call SaveInteger(udg_h,1,6,GetPlayerId(GetOwningPlayer(u[6])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Третья дуэль: "+GetPlayerName(GetOwningPlayer(u[5]))+" против "+ GetPlayerName(GetOwningPlayer(u[6])))
set u[7]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[7],gr)
set u[8]=GroupPickRandomUnit(gr)
call GroupRemoveUnitSimple(u[8],gr)
call SaveInteger(udg_h,1,7,GetPlayerId(GetOwningPlayer(u[7])) )
call SaveInteger(udg_h,1,8,GetPlayerId(GetOwningPlayer(u[8])) )
call DisplayTextToForce(bj_FORCE_ALL_PLAYERS,"Четвертая дуэль: "+GetPlayerName(GetOwningPlayer(u[7]))+" против "+ GetPlayerName(GetOwningPlayer(u[8])))
set udg_timertores[140]=4
endif
call startd2()
set udg_level=udg_level+1
call DestroyGroup(gr)
set gr=null
set td=null
endfunction