- Joined
- Oct 24, 2012
- Messages
- 6,545
hello im having a problem with a high to low indexer i guess u could call it. it first takes the values from battlegrounds counter player and puts each of them into a temp integer array. i called i then it sorts them high to low. after tht i attach the string which i called place it is a string starting w 1st up till 6th place. problem is is tht it messes up for player 2. im not sure y but it works fine for the pc and for player 1. player 2 always shows 2nd place instead of 1st place. it does change to 3rd place if counter for p1 and pc r higher tho. here is the base code after tht ill place the whole trigger. thx to anyone tht can help me.
JASS:
private function leader takes nothing returns nothing
local integer start = 0
local integer end = 11
local integer curr = 2
local integer temp
local integer array i
local integer L = 0
local string array b
local multiboarditem mbi
loop
exitwhen start > end
set i[start] = Battlegrounds_Counter_Player[start]
set start = start + 1
endloop
set start = 0
loop
if i[start] < i[curr] then
set temp = i[start]
set i[start] = i[curr]
set i[curr] = temp
endif
exitwhen start == end - 1
if curr == end then
set curr = start + 2
set start = start + 1
else
set curr = curr + 1
endif
endloop
set start = 0
loop
exitwhen start > end
set L = 0
loop
exitwhen L > end
if Battlegrounds_Counter_Player[start] == i[L] then
set b[start] = place[L]
endif
set L = L + 1
endloop
set start = start + 1
endloop
set L = 0
loop
exitwhen L > 5
set mbi = MultiboardGetItem( battlegroundsMultiboard, 1, (L+2) )
call MultiboardSetItemValue( mbi, playerColors[L] + b[L] + color )
call text( b[L], 0)
call MultiboardReleaseItem( mbi)
set mbi = null
set L = L + 1
endloop
set mbi = MultiboardGetItem( battlegroundsMultiboard, 1, 1 )
call MultiboardSetItemValue( mbi, playerColors[6] + b[11] + color )
call MultiboardReleaseItem( mbi)
set mbi = null
set L = 0
loop
exitwhen L > 11
set b[L] = null
set L = L + 1
endloop
endfunction
JASS:
scope KotB initializer Battlegrounds
globals
trigger trg_BKC_Timers
timer array HeroTimerPlayer
timerdialog array HeroTimerDialogPlayer
constant real heroReviveTime = 30.00
private real array xP
private real array yP
private real bx
private real by
private integer array handleID
private region KotBr
real array HeroTimerRemPlayer
private string array place
endglobals
private function leader takes nothing returns nothing
local integer start = 0
local integer end = 11
local integer curr = 2
local integer temp
local integer array i
local integer L = 0
local string array b
local multiboarditem mbi
loop
exitwhen start > end
set i[start] = Battlegrounds_Counter_Player[start]
set start = start + 1
endloop
set start = 0
loop
if i[start] < i[curr] then
set temp = i[start]
set i[start] = i[curr]
set i[curr] = temp
endif
exitwhen start == end - 1
if curr == end then
set curr = start + 2
set start = start + 1
else
set curr = curr + 1
endif
endloop
set start = 0
loop
exitwhen start > end
set L = 0
loop
exitwhen L > end
if Battlegrounds_Counter_Player[start] == i[L] then
set b[start] = place[L]
endif
set L = L + 1
endloop
set start = start + 1
endloop
set L = 0
loop
exitwhen L > 5
set mbi = MultiboardGetItem( battlegroundsMultiboard, 1, (L+2) )
call MultiboardSetItemValue( mbi, playerColors[L] + b[L] + color )
call text( b[L], 0)
call MultiboardReleaseItem( mbi)
set mbi = null
set L = L + 1
endloop
set mbi = MultiboardGetItem( battlegroundsMultiboard, 1, 1 )
call MultiboardSetItemValue( mbi, playerColors[6] + b[11] + color )
call MultiboardReleaseItem( mbi)
set mbi = null
set L = 0
loop
exitwhen L > 11
set b[L] = null
set L = L + 1
endloop
endfunction
private function whichTimer takes timer t returns integer
local integer p = 0
local integer h = GetHandleId( t)
set t = null
loop
exitwhen p > 5
if handleID == h then
return p
endif
set p = p + 1
endloop
return 11
endfunction
private function heroRevival takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer p = whichTimer( t)
call ReviveHero( Selected_Hero_Player, xP, yP, true )
call text( "Your Hero Has Been Revived", p)
call PauseTimer( HeroTimerPlayer)
call DestroyTimerDialog( HeroTimerDialogPlayer)
call DestroyTimer( HeroTimerPlayer)
set HeroTimerDialogPlayer = null
set HeroTimerPlayer = null
endfunction
private function kills takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer ut = GetUnitTypeId( u)
local integer p = GetPlayerId( GetOwningPlayer( u))
local integer v = GetUnitPointValue( u)
local unit ku = GetKillingUnit()
local integer kp = GetPlayerId( GetOwningPlayer( ku))
local boolean b = false
local integer i = p + 2
local integer kpi = kp + 2
local integer c = p
local integer kpc = kp
local multiboarditem mbi
if p == 11 then // player 11
set i = 1
set c = 6
endif
if kp == 11 then // player 11
set kpi = 1
set kpc = 6
endif
if u == Selected_Hero_Player then
set b = true
set HeroTimerPlayer = CreateTimer()
set HeroTimerDialogPlayer = CreateTimerDialog( HeroTimerPlayer)
call TimerStart( HeroTimerPlayer, heroReviveTime, false, function heroRevival)
call TimerDialogSetTitle( HeroTimerDialogPlayer, " Your Hero Revives In")
if GetLocalPlayer() == Player(p) then
call TimerDialogDisplay( HeroTimerDialogPlayer, true)
endif
set handleID = GetHandleId( HeroTimerPlayer)
endif
if (IsUnitInGroup( u, Battlegrounds_Group_Player ) or u == Selected_Hero_Player) and IsUnitInRegion( KotBr, u ) then
set Battlegrounds_Counter_Player = Battlegrounds_Counter_Player - v
if b == false then
call GroupRemoveUnit( Battlegrounds_Group_Player, u )
endif
set mbi = MultiboardGetItem( battlegroundsMultiboard, 3, i )
call MultiboardSetItemValue( mbi, playerColors[c] + I2S(Battlegrounds_Counter_Player) + color )
call MultiboardReleaseItem( mbi)
set Lumber_Income_Player[kp] = Lumber_Income_Player[kp] + ( v / 2 )
set mbi = MultiboardGetItem( battlegroundsMultiboard, 4, kpi )
call MultiboardSetItemValue( mbi, playerColors[kpc] + I2S(Lumber_Income_Player[kp]) + color )
call MultiboardReleaseItem( mbi)
endif
if ku == Selected_Hero_Player[kp] then
set Hero_Kills_Player[kp] = Hero_Kills_Player[kp] + 1
set mbi = MultiboardGetItem( battlegroundsMultiboard, 2, kpi )
call MultiboardSetItemValue( mbi, playerColors[kpc] + I2S(Hero_Kills_Player[kp]) + color )
call MultiboardReleaseItem( mbi)
endif
call leader()
set u = null
set ku = null
set mbi = null
endfunction
private function KotB_adding takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer p = GetPlayerId( GetOwningPlayer( u ) )
local integer v = GetUnitPointValue( u )
local integer i = p + 2
local integer c = p
local multiboarditem mbi
if p == 11 then // player 11
set i = 1
set c = 6
endif
if ( IsUnitInGroup( u, Battlegrounds_Group_Player ) or u == Selected_Hero_Player ) then
set Battlegrounds_Counter_Player = Battlegrounds_Counter_Player + v
set mbi = MultiboardGetItem( battlegroundsMultiboard, 3, i )
call MultiboardSetItemValue( mbi, playerColors[c] + I2S(Battlegrounds_Counter_Player) + color )
call MultiboardReleaseItem( mbi)
endif
call leader()
set u = null
set mbi = null
endfunction
private function KotB_leaving takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer p = GetPlayerId( GetOwningPlayer( u ) )
local integer v = GetUnitPointValue( u )
local integer i = p + 2
local integer c = p
local multiboarditem mbi
if p == 11 then // player 11
set i = 1
set c = 6
endif
if ((IsUnitInGroup( u, Battlegrounds_Group_Player ) or u == Selected_Hero_Player) and IsUnitInRegion( KotBr, u ) == false ) then
set Battlegrounds_Counter_Player = Battlegrounds_Counter_Player - v
set mbi = MultiboardGetItem( battlegroundsMultiboard, 3, i )
call MultiboardSetItemValue( mbi, playerColors[c] + I2S(Battlegrounds_Counter_Player) + color )
call MultiboardReleaseItem( mbi)
endif
call leader()
set u = null
set mbi = null
endfunction
private function startup takes nothing returns nothing
set place[0] = "1st"
set place[1] = "2nd"
set place[2] = "3rd"
set place[3] = "4th"
set place[4] = "5th"
set place[5] = "6th"
set place[6] = "6th"
set place[7] = "6th"
set place[8] = "6th"
set place[9] = "6th"
set place[10] = "6th"
set place[11] = "6th"
set xP[0] = GetRectCenterX( gg_rct_Hero_Spawn_P0 )
set yP[0] = GetRectCenterY( gg_rct_Hero_Spawn_P0 )
set xP[1] = GetRectCenterX( gg_rct_Hero_Spawn_P1 )
set yP[1] = GetRectCenterY( gg_rct_Hero_Spawn_P1 )
set xP[2] = GetRectCenterX( gg_rct_Hero_Spawn_P2 )
set yP[2] = GetRectCenterY( gg_rct_Hero_Spawn_P2 )
set xP[3] = GetRectCenterX( gg_rct_Hero_Spawn_P3 )
set yP[3] = GetRectCenterY( gg_rct_Hero_Spawn_P3 )
set xP[4] = GetRectCenterX( gg_rct_Hero_Spawn_P4 )
set yP[4] = GetRectCenterY( gg_rct_Hero_Spawn_P4 )
set xP[5] = GetRectCenterX( gg_rct_Hero_Spawn_P5 )
set yP[5] = GetRectCenterY( gg_rct_Hero_Spawn_P5 )
set xP[11] = GetRectCenterX( gg_rct_P11_Battleground_Spawn )
set yP[11] = GetRectCenterY( gg_rct_P11_Battleground_Spawn )
set KotBr = CreateRegion()
call RegionAddRect( KotBr, gg_rct_King_of_the_Battlegrounds )
set bx = GetRectCenterX( gg_rct_King_of_the_Battlegrounds )
set by = GetRectCenterY( gg_rct_King_of_the_Battlegrounds )
endfunction
private function timerStartup takes nothing returns nothing
local integer p = 0
loop
exitwhen p > 3
set HeroTimerRemPlayer = heroReviveTime
if GetUnitState( Selected_Hero_Player, UNIT_STATE_LIFE) <= 0 then
set HeroTimerPlayer = CreateTimer()
set HeroTimerDialogPlayer = CreateTimerDialog( HeroTimerPlayer)
call TimerStart( HeroTimerPlayer, HeroTimerRemPlayer, false, function heroRevival)
call TimerDialogSetTitle( HeroTimerDialogPlayer, " Your Hero Revives In")
if GetLocalPlayer() == Player(p) then
call TimerDialogDisplay( HeroTimerDialogPlayer, true)
endif
set handleID = GetHandleId( HeroTimerPlayer)
endif
set p = p + 1
endloop
endfunction
//===========================================================================
private function Battlegrounds takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
call startup()
set trg_BKC_Timers = CreateTrigger()
call TriggerAddAction( trg_BKC_Timers, function timerStartup)
call TriggerRegisterPlayerUnitEvent( t, Player(0), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(1), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(2), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(3), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(4), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(5), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerRegisterPlayerUnitEvent( t, Player(11), EVENT_PLAYER_UNIT_DEATH, null )
call TriggerAddAction( t, function kills )
call TriggerRegisterEnterRegion( t1, KotBr, null )
call TriggerAddAction( t1, function KotB_adding )
call TriggerRegisterLeaveRegion( t2, KotBr, null )
call TriggerAddAction( t2, function KotB_leaving )
call TriggerAddAction( t3, function leader )
set t = null
set t1 = null
set t2 = null
endfunction
endscope