• 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.

Help For Jass

Level 3
Joined
Dec 18, 2021
Messages
14
Hello. I have a small piece of code. Its function is that when holding this item, defeating an enemy will receive 1 stat. But it does not apply to clone or summoner skills. I need help.
JASS:
function GiayTest_Conditions takes nothing returns boolean
if(not(UnitHasItemOfTypeBJ(GetKillingUnitBJ(),'Ie01')==true))then
return false
endif
if(not(GetKillingUnitBJ()==GetKillingUnitBJ()))then
return false
endif
return true
endfunction
function GiayTest_Actions takes nothing returns nothing
call ModifyHeroStat(bj_HEROSTAT_STR,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_AGI,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
call ModifyHeroStat(bj_HEROSTAT_INT,GetKillingUnitBJ(),bj_MODIFYMETHOD_ADD,1)
endfunction
function trig_GiayTest takes nothing returns nothing
set gg_GiayTest=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_GiayTest,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(gg_GiayTest,Condition(function GiayTest_Conditions))
call TriggerAddAction(gg_GiayTest,function GiayTest_Actions)
endfunction
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
I don't understand your issue. If an illusion or a summoned unit kills a target, then the killing unit is just whatever killed the unit. The unit that created the killer doesn't 'inherit' the kill in any way. You can use this unit-classification boolean condition to check if the unit is summoned, and if so just... don't do anything:
  • ((Killing unit) is Summoned) Equal to True
Finally, there is no need to translate your trigger into JASS before posting here. That doesn't accomplish anything and makes it significantly harder to read because of all the bullshit formatting GUI introduces. You can do this for GUI triggers in the future: How To Post Your Trigger.
 
Level 17
Joined
Mar 21, 2011
Messages
1,611
JASS:
if(not(GetKillingUnitBJ()==GetKillingUnitBJ()))then
this makes no sense, i guess you meant
JASS:
if(not(GetTriggerUnit()==GetKillingUnitBJ()))then

To solve your problem, you could save each hero into a unit array with index being the player id (this only works if every player controls one hero only), and whenever a player controlled unit kills something, you can access your unit that way.

If you have multiple heroes per player, you have to index your units somehow and track the summoner, there are plenty of Unit Indexers on this site.

example (requires a unit indexer and vJass)

JASS:
struct Unit extends array

    unit object
    unit summoner

    static function create takes unit u returns thistype
        local thistype this = thistype[GetUnitUserData()]
        set this.object = u
        return this
    endfunction

endstruct


//... summon unit
local Unit u = Unit.create(CreateUnit('hpal', Player(0), ...))
set u.summoner = GetSummoningUnit()

//... access the summoner
Unit[GetUnitUserData(GetKillingUnit())].summoner
 
Top