Page 1 of 2

Custom Event Responses

Posted: Fri Jul 02, 2010 11:50 am
by Greenspawn
Is there a way to do something like this?

Code: Select all

    call TriggerRegisterUnitEvent(sometrigger, someunit, EVENT_UNIT_RECEIVES_BUFF_BLAH)
or this:

Code: Select all

    call TriggerRegisterUnitEvent(sometrigger, someunit, EVENT_UNIT_LOSES_BUFF_BLAH)
I'm designing a buff system with hashtables, and I want to store triggers in the hashtable which run when the above events occurs.

Re: Custom Event Responses

Posted: Fri Jul 02, 2010 1:16 pm
by Fledermaus
Look at how dusk did his damage events.

Re: Custom Event Responses

Posted: Fri Jul 02, 2010 1:51 pm
by Greenspawn
I did, but he used EVENT_UNIT_DAMAGED, which is a Blizzard constant.

Re: Custom Event Responses

Posted: Sat Jul 03, 2010 12:44 am
by Fledermaus
I meant the other stuff:

Code: Select all

    private          integer       Count               = 0
    private          Table         TrigTable           = 0
    private          Table         RegiTable           = 0
    private          boolean       IgnPrior            = false
and

Code: Select all

    loop
        exitwhen i > Count or IgnPrior
        //Ensure all variables are correct for nesting
        set Damage            = r
        set DamageBase        = b
        set DamageTarget      = t
        set DamageSource      = s
        set DamageType        = d
        set DamageId          = id
        set NewDamage[id]     = 0.
        set NewDamageType[id] = -1
        if IsTriggerEnabled(Trg[i]) and TriggerEvaluate(Trg[i]) then
            call TriggerExecute(Trg[i])
        endif
        if NewDamage[id] > 0. then
            //Update damage if it was changed
            set r = NewDamage[id]
        endif
        if NewDamageType[id] >= 0 then
            //Update damagetype if it was changed
            set d = NewDamageType[id]
        endif
        set i = i + 1
    endloop
(and obviously all the trigger registering stuff too).

Re: Custom Event Responses

Posted: Sat Jul 03, 2010 10:13 am
by Greenspawn
Ok I see. Here's what I came up with. It's a function that registers the specific buff events with a trigger. So:

Code: Select all

function TriggerRegisterBuffEvent takes trigger trig, integer BuffEvent returns boolean
    call SaveInteger(Hashtable, GetHandleId(trig), StringHash(I2S(BuffEvent)), Count)
endfunction
Well, it'd do more than that, but you get the idea. Then if one of those events ran, I would just call the triggers registered with that event, evaluate them, and if they evaluate, then execute (because the buff is applied through triggers, so I would know if the event occurred).

Count is just an integer that keeps track of registrations.

Re: Custom Event Responses

Posted: Sat Jul 03, 2010 11:44 pm
by Fledermaus
Err, I gave you a lot of missing code in that last post :p

Check this out

Re: Custom Event Responses

Posted: Sun Jul 04, 2010 1:48 pm
by Greenspawn
I've actually got a prototype worked out. It doesn't work, but I was wondering if someone wanted to review it to suggest what the problem might be.

Re: Custom Event Responses

Posted: Sun Jul 04, 2010 6:05 pm
by Fledermaus
If you post your code within the next hour, I might be able to give it a read. Otherwise I'm gone for 2 weeks.

Re: Custom Event Responses

Posted: Mon Jul 12, 2010 9:06 pm
by Greenspawn
Well after debugging it I managed to get it to work for the most part. One little hiccup is that the buffs aren't being applied correctly. For instance, I'll have the code:

Code: Select all

set dummy = CreateUnit(GetOwningPlayer(source), Buff1DummyId, GetUnitX(target), GetUnitY(target), Atan2(GetUnitY(target),GetUnitX(target))*bj_DEGTORAD - 180)
call IssueTargetOrder(dummy, Buff1AbilityOrder, target)
but it won't be applied. It creates the unit for sure, but I don't know why it wouldn't cast the ability. I'm almost positive the ability order is correct.

The Buff1DummyId is a constant for the system, so I don't have to keep looking up the Id of the unit, and Buff1AbilityOrder (also a constant) is the order used to cast the spell.

Re: Custom Event Responses

Posted: Tue Jul 13, 2010 2:49 am
by Fledermaus
Does the dummy unit have enough mana to cast the spell?
Is it all buff spells that aren't applying or only a few?
Are there any requirements on the buff spells?
Does the dummy unit have the buff spells already? (I don't see any UnitAddAbility)

Re: Custom Event Responses

Posted: Tue Jul 13, 2010 12:16 pm
by Greenspawn
The spells don't cost any mana, no spells work (not even the Blizzard spells), there aren't any requirements, and the dummy has the spells already. Could it be because it's being created by a function which is called from another trigger?

Re: Custom Event Responses

Posted: Tue Jul 13, 2010 7:06 pm
by Fledermaus
I don't get what you're asking.

If the unit's being created and all that other stuff is correct, it is probably the wrong order being issued, can you give me an example of a spell you're using and the order string?

Re: Custom Event Responses

Posted: Tue Jul 13, 2010 10:29 pm
by Greenspawn
One of the base spells is Acid Bomb, with all the damage stuff set to 0, as well as the mana cost. It is only used for the buff. The order string I'm using is "acidbomb".

Re: Custom Event Responses

Posted: Wed Jul 14, 2010 11:01 am
by Fledermaus
Are you trying to apply it to an ally or enemy? Are the targeting fields correct? If it's an ally, try using a different spell (say, Unholy Frenzy) to see if Acidbomb is hard coded to not allow ally targeting.

Re: Custom Event Responses

Posted: Wed Jul 14, 2010 2:52 pm
by Greenspawn
It's supposed to be able to apply to both an ally and an enemy. It works if I order it manually, but not through triggers.