• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] get killing unit problem

Status
Not open for further replies.
get killing unit doesnt work right can anyone see y ?

JASS:
function Trig_Battlegrounds_Kills_Actions takes nothing returns nothing
    local integer i
    local integer p
    local integer v
    local integer c
    local boolean b
    local unit u
    local multiboarditem mbi
    local string color = "|r"
    local region r 
    local unit ku
    set u = GetTriggerUnit()
    set p = GetPlayerId( GetOwningPlayer( u ) )
    set ku = GetKillingUnit()
    set v = GetUnitPointValue( u )
    set b = false
    set r = CreateRegion()
    call RegionAddRect( r, gg_rct_King_of_the_Battlegrounds )
    if p == 0 then // player 0
        set i = 2
        set c = 0
    elseif p == 1 then // player 1
        set i = 3
        set c = 1
    elseif p == 2 then // player 2
        set i = 4
        set c = 2
    elseif p == 3 then // player 3
        set i = 5
        set c = 3
    elseif p == 11 then // player 11
        set i = 1
        set c = 6
    endif
    
    if ( u == Selected_Hero_Player ) then
        set b = true
    endif
    
    if ( (IsUnitInGroup( u, Battlegrounds_Group_Player ) or u == Selected_Hero_Player) and IsUnitInRegion( r, u ) ) then
        set Battlegrounds_Counter_Player = Battlegrounds_Counter_Player - v
        if ( IsUnitInGroup( u, Battlegrounds_Group_Player ) and IsUnitInRegion( r, u ) == true and b == false ) then
            call GroupRemoveUnit( Battlegrounds_Group_Player, u )
        endif
        set Lumber_Income_Player = Lumber_Income_Player + ( v / 2 )
        set mbi = MultiboardGetItem( battlegroundsMultiboard, 2, i )
        call MultiboardSetItemValue( mbi, playerColors[c] + I2S(Battlegrounds_Counter_Player) + color )
    endif
    
    if ku == Selected_Hero_Player then
        set Hero_Kills_Player = Hero_Kills_Player + 1
        call DisplayTextToForce( GetPlayersAll(), "hero kills" )
        set mbi = MultiboardGetItem( battlegroundsMultiboard, 1, i )
        call MultiboardSetItemValue( mbi, playerColors[c] + I2S(Hero_Kills_Player) + color )
    endif
    
    call TriggerExecute( trg_Battlegrounds_Leader_Checker )
    set u = null
    set ku = null
    set r = null
    set mbi = null
    set color = null
endfunction

//===========================================================================
function InitTrig_Battlegrounds_Kills takes nothing returns nothing
    local trigger t 
    set t = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent( t, Player(0), EVENT_PLAYER_UNIT_DEATH, null )
    call TriggerRegisterPlayerUnitEvent( t, Player(1), EVENT_PLAYER_UNIT_DEATH, null )
    call TriggerRegisterPlayerUnitEvent( t, Player(11), EVENT_PLAYER_UNIT_DEATH, null )
    call TriggerAddAction( t, function Trig_Battlegrounds_Kills_Actions )
    set t = null
endfunction
 
Remember to use MultiboardReleaseItem for each item you get with MultiboardGetItem.

You could use less brackets and spaces. For example here:
JASS:
if ( (IsUnitInGroup( u, Battlegrounds_Group_Player ) or u == Selected_Hero_Player) and IsUnitInRegion( r, u ) ) then
->
JASS:
if (IsUnitInGroup(u, Battlegrounds_Group_Player) or u == Selected_Hero_Player) and IsUnitInRegion(r, u) then

I find it to be easier on the eyes.

JASS:
if p == 0 then // player 0
        set i = 2
        set c = 0
    elseif p == 1 then // player 1
        set i = 3
        set c = 1
    elseif p == 2 then // player 2
        set i = 4
        set c = 2
    elseif p == 3 then // player 3
        set i = 5
        set c = 3
    elseif p == 11 then // player 11
        set i = 1
        set c = 6
    endif
->
JASS:
if p != 10 then
    set i = p + 2
    set c = p
else              // player 11
    set i = 1
    set c = 6
endif

BTW, there is no player 0. 0 = P1.
 
ik but in jass player 1 is player 0 so i just write it as player 0

also i ended up changing the brackets the spaces on the other hand i like just a personal opinion lol

umm this i do not understand how it works would u mind explaining what != does and how they change ? thx

JASS:
if p != 10 then
    set i = p + 2
    set c = p
else              // player 11
    set i = 1
    set c = 6
endif
 
Status
Not open for further replies.
Back
Top