HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why doesnt this function work?

05-06-2006, 06:45 PM#1
Thunder_Eye
Why doesnt this trigger work? There's no errors or anything like that, it just doesnt add the ability "buffid", I tried changing it from integer to ability but that just gave me some errors.

Collapse JASS:
function DoT takes unit caster, unit target, real interval, integer intervals, real damage, string doteffect, integer buffid returns nothing
    local integer curinterval = 0
    local effect eff
    call UnitAddAbility(target, buffid)
    loop
        call TriggerSleepAction(interval - 0.40)
        call UnitDamageTarget(caster, target, damage, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_FIRE, WEAPON_TYPE_WHOKNOWS)
        set eff = AddSpecialEffectTarget( doteffect, target, "chest" )
        call TriggerSleepAction(0.40)
        call DestroyEffect(eff)
        set curinterval = curinterval + 1
        exitwhen curinterval == intervals
    endloop
    call UnitRemoveAbility(target, buffid)
    set doteffect = ""
    set eff = null
    set caster = null
    set target = null
    set interval = 0.00
    set intervals = 0
    set damage = 0.00
    set curinterval = 0
    set buffid = 0
05-06-2006, 06:53 PM#2
Captain Griffen
a) The function is incomplete.
b) This isn't a trigger.

You haven't declared the buffid as a local variable, though.
05-06-2006, 06:58 PM#3
Vuen
Quote:
Originally Posted by Captain Griffen
You haven't declared the buffid as a local variable, though.

It's one of the arguments.

Integer is the correct type; don't use ability as a type, I never do. Are you sure the loop is working properly? If the loop is broken, it could be adding the buff and then removing it right away. Try adding 'return' immediately after the add ability to kill the function, just to see if the buff ever gets added at all.

Calling BJDebugMsg at a variety of places in a function is a quick and easy way to see which parts run when.
05-06-2006, 07:40 PM#4
weaaddar
Try the code alone to add the buff. Can you add buffs? I believe you can't. I know you can detect a buffs existence by level, but I don't think UnitAddAbility(my_unit,my_buff) works. Thier probably is some trick using a caster to cast a spell that does nothing but give the buff.

You have no need to zero out reals and ints. Thats automatically done. The code seems very odd. You shouldn't use TriggerSleepAction, its mostly bad practice. you should save the environment and launch a timer.
05-06-2006, 07:46 PM#5
Captain Griffen
I presume that buffid is merely the integer that correlates to the correct ability to generate the buff. Put in debuff messages to check:

- The integer is right.
- The trigger runs.
05-06-2006, 09:42 PM#6
PipeDream
Besides the other stuff mentioned:
Collapse JASS:
        exitwhen curinterval == intervals
This should never work. curinterval >= intervals will be a bit better.
---
Nm, I see interval is a real, while intervals is an integer. You should still look both ways before crossing a one way street however. e.g., intervals == 0 will suicide atm.
05-06-2006, 11:23 PM#7
Vuen
Quote:
Originally Posted by weaaddar
The code seems very odd. You shouldn't use TriggerSleepAction, its mostly bad practice. you should save the environment and launch a timer.

TriggerSleepAction is not bad practice; it's just inaccurate. In this case, saving the environment and launching a timer is a good idea only because it seems you're scripting a special effect, which you need good timing resolution to have it look right.

And I'm pretty sure you're right, you can't just add a buff to a unit. Thunder_Eye, instead make an ability based on something that gives a buff without a command button, like Item Trueshot Aura (set all its effects and range to zero), and then add that ability instead.
05-07-2006, 10:22 AM#8
Thunder_Eye
Hi all, sry I went offline. So now I have to clear this out :P

The ability that I add 'A01|' is NOT an buff, it is the rawdata of the slow aura ability that I made that has the buff in it. There is no problem with the loop. It does the damage and the SpecialEffect shows up exactly as I want it. My problem is that the ability before the loop never gets added. I tried remove the "UnitRemoveAbility" after the loop incase it somehow jumped over the loop as it was working and removed the ability instantly.

I also tried changing the ability to something else, still not working. Whatever ability I try to add it doesnt work, here's the call.
Collapse JASS:
        call DoT(caster, target, 3.00, 5, 40.00, "Abilities\\Spells\\Undead\\DeathandDecay\\DeathandDecayDamage.mdl", 'A01|')

@Shadow1500: yes I know TriggerSleepAction is inaccurate and screws up if someone lags. Though I'm only using it for 1sec so it doesnt really matter.

@PipeDream: I know I could do it another way, but It works as it is so it doesnt matter.

@Captain Griffen: I know that the function runs as the unit gets damage and all that, not sure about the integer though. I'll test it.

@weaaddar: I know that it is impossible to add buffs directly, that's why I use the Slow Aura. I know the TriggerSleepAction is inaccurate and timers is better. But that would make the code more complicated and I need it to be clean and easy as for now, might use timers when all is done.

@Vuen: As I stated above the function works but the UnitAddAbility doesnt. And I dont try to add an buff. I will test a DebugMsg

EDIT: Ok I tested the DebugMsg, it showed this: "1093677436"
So what does that mean?
05-07-2006, 10:29 AM#9
Captain Griffen
Try adding it with a the code directly for the ability (use the A0?? code). If that works, then you know that the problem is there.
05-07-2006, 10:34 AM#10
Thunder_Eye
My problem is that whatever ability I try to add, it doesnt work

EDIT: Adding the ability directly didnt work either.
05-07-2006, 12:11 PM#11
Captain Griffen
Then the problem logically lies with 'target' not being correct.

EDIT: Or it immediately takes it away again. Add a debuff message to make sure that isn't the case.
05-07-2006, 12:48 PM#12
Thunder_Eye
Well target must be correct as it works in the damage function
How would I add an debug on that?
05-07-2006, 01:18 PM#13
Captain Griffen
Just make it display a text message once the loop finishes.

Hmmm...well, the only other possibility I can think of is that you're adding the ability wrong. Try doing it with the BJ function.