• 🏆 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!

[Solved] Help with a couple of triggers

Status
Not open for further replies.
Level 3
Joined
Aug 25, 2013
Messages
22
So, I decided to start getting myself into JASS coding, after reading the guide (And understanding 25% of it), I decided to try a couple of triggers for simple spells, but they seem not to be working correctly

Here's the first and simplest one, it's for a 'phased movement' spell. It is basically a spell based off Haste Potion that makes the target ethereal for its duration and gives it a slowing aura

JASS:
function PMovement_Condition takes nothing returns boolean
return GetSpellAbilityId()=='A00C' //ID FOR PHASED MOVEMENT SPELL
endfunction

function PMovement_Action takes nothing returns nothing
local unit caster = GetSpellAbilityUnit()
local integer PMLevel = GetUnitAbilityLevel(caster,'B00C')
call UnitAddAbilityBJ('Aetl',caster)//ETHEREAL ABILITY
call UnitAddAbilityBJ('A01T',caster)//SLOW AURA ABILITY BASED OFF TORNADO AURA
call SetUnitPathing(caster,false)
call TriggerSleepAction(8)
loop
exitwhen(PMLevel==0)//PHASED MOVEMENT BUFF
endloop
call UnitRemoveAbilityBJ('Aetl',caster)
call UnitRemoveAbilityBJ('A01T',caster)
call SetUnitPathing(caster,true)
set caster = null
endfunction

function InitTrig_PMovement takes nothing returns nothing
local trigger PMovement = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(PMovement,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(PMovement,Condition(function PMovement_Condition))
call TriggerAddAction(PMovement,function PMovement_Action)
endfunction

The problem with this one is in the 'loop' part. I tried to make it so the trigger would remove the 'Ethereal' and 'Slow Aura' spells off the unit once it checked it didn't have the 'Phased movement' debuff anymore, but for some reason it didn't work, so I was forced to use 'TriggerSleepAction(8)' function to solve it (8 seconds being the duration of the spell). It works this way, but it seems far from optimal, and besides I'd like to know what I'm doing wrong with the loop.

The second one is a bit more complicated (At least for my capabilities in jass), it's a simple spell based off Berserk. What I intended to do is that, when a unit with the spell buff receives damage, the damage source receives the same amount of damage it dealt (I could've used Thorns Aura, but it wouldn't reflect ranged attacks nor spell damage)
I tried to make it work, but I get an 'expected a name' error and I don't clearly know how to fix it, also I'm unsure as to whether the spell would work even if I fixed that part
JASS:
function PBalance_Condition takes nothing returns boolean
if(not(UnitHasBuffBJ(GetTriggerUnit(),'B00B')==true)) then//CONTRARY TO WHAT YOU MAY THINK, 'B00B' IS THE ID FOR THE SPELL BUFF
        return false
    endif
    return true
endfunction

function PBalance_Action takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit PMDamageSource = GetEventDamageSource()
local real PMDamage = GetEventDamage()
call UnitDamageTargetBJ(caster,PMDamageSource,PMDamage,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNKNOWN)
endfunction

function InitTrig_PBalance takes nothing returns nothing
local trigger PBalance = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(PBalance,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerRegisterUnitEvent(PBalance,caster,EVENT_UNIT_DAMAGED )//THIS IS WHERE I GET AN 'EXPECTED A NAME' ERROR
call TriggerAddCondition(PBalance,Condition(function PBalance_Condition))
call TriggerAddAction(PBalance,function PBalance_Action)
endfunction


I'm just started into this whole JASS thing, so I admit it may look dreadful, but in any case, any sort of guidance concerning these 2 triggers is appreciated
 
Level 3
Joined
Aug 25, 2013
Messages
22
Thanks for the answer, I'll take a look. Anything that helps me understand JASS is good.

However, I still would like to know what is wrong in these precise 2 triggers (Mainly the loop one)
 
Level 3
Joined
Aug 25, 2013
Messages
22
The triggers are posted fully in the first post.

In the first trigger, I just wanted a spell (Like I said, based off Haste potion) that gives a unit the 'ethereal' and 'slow aura' abilities when it casts a spell, and then removes them when it detects it doesn't have the spell buff on itself anymore. No matter what I try with the loop, it always ends up on the abilities being removed instantly upon cast, or never actually removed (So the unit remains ethereal and with a slow aura even after the spell wears off).

As for the second one, I'll look into one of those Damage detection systems, seems like it's the only way.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
it will not remove the etheral and slow if PMLevel is not equal to zero, coz PMLevel does not talk about the buff but the integer which is greater than 0 so your loop is infinite...

buff is not immediately detected when a spell is cast or in effect, it has a delay so a timer is best for it...

for the second one, a damage detection system is required, if you dont know how to use DDS, you can just make a global trigger and add that unit to it...
 
Level 3
Joined
Aug 25, 2013
Messages
22
it will not remove the etheral and slow if PMLevel is not equal to zero, coz PMLevel does not talk about the buff but the integer which is greater than 0 so your loop is infinite...

buff is not immediately detected when a spell is cast or in effect, it has a delay so a timer is best for it...

for the second one, a damage detection system is required, if you dont know how to use DDS, you can just make a global trigger and add that unit to it...

Put the sleep inside the loop, the current one on your code is an infinite loop and the game engine stops its execution.


I tried these advices and now it works properly.
I thank you guys very much, you do not know how much of a headache this was for me (being noobish at JASS and all that).

As for the second one, I searched among the hive for some Damage detection system (The one I used was called Damage engine or something like that) and it also works nice now.
It causes some weird behaviour with AI though. Sometimes when you are under the effects of the 'reflect damage' spell they'll try to avoid attacking you, they'll usually flee from you and rarely attack (then again, as long as you are under the spell buff)
but I guess it only makes sense, lol.

So in any case, thanks for the help, I guess the thread is solved now
 
Status
Not open for further replies.
Top