• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Spell] Help with trigg about Kill Hero

Status
Not open for further replies.
Level 2
Joined
Feb 4, 2014
Messages
8
Even enemy's Hero get assistant EXP (Normal their can't get).

JASS:
function Trig_Player_HeroDryLTB_Conditions takes nothing returns boolean
    local unit HeroKiller = GetKillingUnit()
    local unit HeroKilled = GetDyingUnit()
    local player PlayerOwnHeroKilled = GetOwningPlayer(HeroKilled)
    local integer N = 1

    if (GetUnitTypeId(HeroKilled) == 'U000') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U001') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U002') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U003') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U004') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U005') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U006') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U00B') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U00C') then
        set N = 0




    elseif (IsUnitIllusionBJ(HeroKilled) == true) then
        set N = 0
    elseif (IsUnitType(HeroKilled, UNIT_TYPE_HERO) == false) then
        set N = 0
    elseif (IsUnitEnemy(HeroKiller, PlayerOwnHeroKilled) == false) then
        set N = 0
    endif

    set HeroKiller = null
    set HeroKilled = null
    set PlayerOwnHeroKilled = null

    if ( N == 1) then
        return true
    else
        return false
    endif
endfunction

function Player_Own_Player_and_Hero001 takes unit HeroA returns boolean
    local integer N =1

    if (IsUnitType(HeroA, UNIT_TYPE_HERO) == false ) then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U000') then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U001') then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U002') then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U003') then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U004') then
        set N = 0
    elseif (GetUnitTypeId(HeroA) == 'U005') then
        set N = 0



    endif
    if ( N == 1 ) then
        return true
    else
        return false
    endif
endfunction

function HeroDryLTB_ClearNoUse takes nothing returns nothing
    local unit NextUnit = GetEnumUnit()

    if (Player_Own_Player_and_Hero001(NextUnit) == false) then
         call GroupRemoveUnitSimple( NextUnit, udg_UnitGroup_SpellEffect02 )
    endif

    set NextUnit = null
endfunction

function Hero_Have_ManaRegenKA_Item takes unit HeroA returns integer
    local integer N = 0

    if (UnitHasItemOfTypeBJ(HeroA, 'I006') == true) then
        set N = 1
    elseif (UnitHasItemOfTypeBJ(HeroA, 'I08V') == true) then
        set N = 1
    elseif (UnitHasItemOfTypeBJ(HeroA, 'I08W') == true) then
        set N = 1
    elseif (UnitHasItemOfTypeBJ(HeroA, 'I016') == true) then
        set N = 1
    elseif (UnitHasItemOfTypeBJ(HeroA, 'I01A') == true) then
        set N = 1
    elseif (UnitHasItemOfTypeBJ(HeroA, 'I01B') == true) then
        set N = 1
    endif

    return N
endfunction

function HeroDryLTB_KillAssWork_Killer takes nothing returns nothing
  local unit HeroKiller = GetEnumUnit()
  local real HeroCurrentMana = 0.000
  local integer EXPExtra = udg_UnitGroup_IntegerSent
  local integer EXPGainSS = IMaxBJ((udg_GPlayTime + 100) / 2 + EXPExtra,50)

  if (Hero_Have_ManaRegenKA_Item(HeroKiller)>0) then
    set HeroCurrentMana = GetUnitState(HeroKiller,UNIT_STATE_MANA) + GetUnitState(HeroKiller,UNIT_STATE_MAX_MANA)*0.15
    call SetUnitManaBJ( HeroKiller, HeroCurrentMana )
  endif

  call AddHeroXPSwapped( EXPGainSS, HeroKiller, true )

  set HeroKiller = null
endfunction

function HeroDryLTB_KillAssWork_Asster takes nothing returns nothing
  local unit HeroKiller = GetEnumUnit()
  local real HeroCurrentMana = 0.000
  local integer EXPExtra = udg_UnitGroup_IntegerSent
  local integer EXPGainSS = IMaxBJ((udg_GPlayTime + 100) / 3 + EXPExtra/2,35)

  if (Hero_Have_ManaRegenKA_Item(HeroKiller)>0) then
    set HeroCurrentMana = GetUnitState(HeroKiller,UNIT_STATE_MANA) + GetUnitState(HeroKiller,UNIT_STATE_MAX_MANA)*0.15
    call SetUnitManaBJ( HeroKiller, HeroCurrentMana )
  endif

    call DisplayTextToForce( GetPlayersAll(), I2S(EXPGainSS) )

  call AddHeroXPSwapped( EXPGainSS, HeroKiller, true )

  set HeroKiller = null
endfunction

function Trig_Player_HeroDryLTB_Actions takes nothing returns nothing
  local unit HeroKiller = GetKillingUnit()
  local unit HeroKilled = GetDyingUnit()
  local player PlayerOwnHeroKiller = GetOwningPlayer(HeroKiller)
  local player PlayerOwnHeroKilled = GetOwningPlayer(HeroKilled)

  local integer OKN = GetConvertedPlayerId(PlayerOwnHeroKiller)-1
  local integer ODN = GetConvertedPlayerId(PlayerOwnHeroKilled)-1
  local integer I  = 0
  local integer I1 = udg_MaxPlayerJoinGame - 1

  local real TaxK1  = udg_P_HeroS001_Kill[OKN] - udg_P_HeroS002_Die[OKN] + udg_P_HeroS003_Ass[OKN] / 5
  local real TaxK2  = TaxK1 + udg_P_HeroS005_DeniceHero[OKN] + udg_P_HeroS006_DeniceMinion[OKN] / 5
  local real TaxK3  = TaxK2 + udg_P_HeroS007_ChainKill[OKN] - udg_P_HeroS008_ChainDie[OKN]
  local real BTaxK1 = udg_P_HeroS001_Kill[ODN] - udg_P_HeroS002_Die[ODN] + udg_P_HeroS003_Ass[ODN] / 5
  local real BTaxK2 = BTaxK1 - udg_P_HeroS005_DeniceHero[ODN] - udg_P_HeroS006_DeniceMinion[ODN] / 5
  local real BTaxK3 = BTaxK2 + udg_P_HeroS007_ChainKill[ODN] - udg_P_HeroS008_ChainDie[ODN]
  local real FTaxK  = 300 + (BTaxK3-TaxK3) * 15

  local integer BountMoney = IMaxBJ(R2I(FTaxK),25)
  local integer AssMoney   = IMaxBJ(R2I(FTaxK),25)/3

  if ( OKN < I1 ) then
    set udg_P_HeroS001_Kill[OKN]          = udg_P_HeroS001_Kill[OKN] + 1
    set udg_P_HeroS007_ChainKill[OKN]     = udg_P_HeroS007_ChainKill[OKN] + 1
    set udg_P_HeroS008_ChainDie[OKN]      = 0
    set udg_P_HeroS009_CooldownKill [OKN] = 60
    set udg_P_HeroS010_ComboKill[OKN]     = udg_P_HeroS010_ComboKill[OKN] + 1
  endif

  if ( ODN < I1 ) then
    set udg_P_HeroS002_Die[ODN]       = udg_P_HeroS002_Die[ODN] + 1
    set udg_P_HeroS008_ChainDie[ODN]  = udg_P_HeroS008_ChainDie[ODN] + 1
    set udg_P_HeroS007_ChainKill[ODN] = 0
  endif

  call AdjustPlayerStateBJ( BountMoney, PlayerOwnHeroKiller, PLAYER_STATE_RESOURCE_GOLD )

  call GroupClear(udg_UnitGroup_SpellEffect02)

  set udg_UnitGroup_IntegerSent = R2I((BTaxK3-TaxK3) * 15)
  set udg_UnitGroup_SpellEffect02 = GetUnitsOfPlayerAll(Player(OKN))
  call ForGroup(udg_UnitGroup_SpellEffect02, function HeroDryLTB_ClearNoUse )
  call ForGroup(udg_UnitGroup_SpellEffect02, function HeroDryLTB_KillAssWork_Killer )
  call GroupClear(udg_UnitGroup_SpellEffect02)

  if (ODN == 0) then
    set udg_GPlayer01_HeroBeHit[OKN] = 0
    loop
      exitwhen I > I1
      if (udg_GPlayer01_HeroBeHit[I] > 0) then
        set udg_P_HeroS003_Ass[I] = udg_P_HeroS003_Ass[I] + 1
        call AdjustPlayerStateBJ( AssMoney, Player(I), PLAYER_STATE_RESOURCE_GOLD )

        call GroupClear(udg_UnitGroup_SpellEffect04)

        set udg_UnitGroup_SpellEffect04 = GetUnitsOfPlayerAll(Player(I))
        call ForGroup(udg_UnitGroup_SpellEffect04, function HeroDryLTB_ClearNoUse )
        call ForGroup(udg_UnitGroup_SpellEffect04, function HeroDryLTB_KillAssWork_Asster )
        call GroupClear(udg_UnitGroup_SpellEffect04)
        set udg_GPlayer01_HeroBeHit[I] = 0
      endif
      set I = I +1
    endloop

  endif

    set HeroKiller = null
    set HeroKilled = null
    set PlayerOwnHeroKiller = null
    set PlayerOwnHeroKilled = null
    set udg_UnitGroup_IntegerSent = 0
    call GroupClear(udg_UnitGroup_SpellEffect02)
    call GroupClear(udg_UnitGroup_SpellEffect04)
endfunction

//===========================================================================
function InitTrig_Player_HeroDryLTB takes nothing returns nothing
    set gg_trg_Player_HeroDryLTB = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_HeroDryLTB, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Player_HeroDryLTB, Condition( function Trig_Player_HeroDryLTB_Conditions ) )
    call TriggerAddAction( gg_trg_Player_HeroDryLTB, function Trig_Player_HeroDryLTB_Actions )
endfunction
 

Attachments

  • MapNew.w3x
    7.5 MB · Views: 56
Last edited:

EdgeOfChaos

E

EdgeOfChaos

Tell us what it's supposed to do and what isn't working. I don't think anyone wants to read through all that without knowing those beforehand, and I don't really get what you're trying to say.

Glancing through it though I saw some coding that adds greatly to the length and makes it harder to read:

Code:
    if (GetUnitTypeId(HeroKilled) == 'U000') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U001') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U002') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U003') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U004') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U005') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U006') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U00B') then
        set N = 0
    elseif (GetUnitTypeId(HeroKilled) == 'U00C') then
        set N = 0
    elseif (IsUnitIllusionBJ(HeroKilled) == true) then
        set N = 0
    elseif (IsUnitType(HeroKilled, UNIT_TYPE_HERO) == false) then
        set N = 0
    elseif (IsUnitEnemy(HeroKiller, PlayerOwnHeroKilled) == false) then
        set N = 0
    endif
^ All of this stuff can be replaced by a single If statement using "Or", for example. And it's not the only time this was done.

->
Code:
    local integer hid = GetUnitTypeId(HeroKilled)
    if(hid=='U000' or hid=='U001' or hid=='U002' or hid=='U003' or hid=='U003' or hid=='U004' or hid=='U005' or hid=='U006' or hid=='U00B' or hid=='U00C' or IsUnitIllusionBJ(HeroKilled) == true or IsUnitType(HeroKilled, UNIT_TYPE_HERO) == false or IsUnitEnemy(HeroKiller, PlayerOwnHeroKilled) == false)  then
        set N = 0
    endif
 
Level 2
Joined
Feb 4, 2014
Messages
8
When kill an Enemy Hero, You will get Killer EXP, Gold. while your teammate will get Assistant EXP, Gold.

However the trigg also let enemy get assistant EXP, Gold too
 

EdgeOfChaos

E

EdgeOfChaos

Code:
    loop
      exitwhen I > I1
      if (udg_GPlayer01_HeroBeHit[I] > 0) then
        set udg_P_HeroS003_Ass[I] = udg_P_HeroS003_Ass[I] + 1
        call AdjustPlayerStateBJ( AssMoney, Player(I), PLAYER_STATE_RESOURCE_GOLD )

        call GroupClear(udg_UnitGroup_SpellEffect04)

        set udg_UnitGroup_SpellEffect04 = GetUnitsOfPlayerAll(Player(I))
        call ForGroup(udg_UnitGroup_SpellEffect04, function HeroDryLTB_ClearNoUse )
        call ForGroup(udg_UnitGroup_SpellEffect04, function HeroDryLTB_KillAssWork_Asster )
        call GroupClear(udg_UnitGroup_SpellEffect04)
        set udg_GPlayer01_HeroBeHit[I] = 0
      endif
      set I = I +1
    endloop
I think this code section should have some filter to make sure it's not giving it to an enemy, I think. Make sure that Player(I) is an ally of the killer before using ForGroup.

Also I believe that you should not use GetUnitsOfPlayerAll as it causes a memory leak.
 
Status
Not open for further replies.
Top