HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Spell Reflection Small bug

11-13-2006, 09:32 PM#1
Daxtreme
Well the title explains itself much at the very least. I'm making a spell reflection spell which when activated reflects spells cast at the unit to their original caster. The trigger actually works but one thing.

I was forced to do it in JASS since ordering a unit to do the same thing as another unit can only be done in JASS.

Here it is!

You don't have to analyze it all. It works, except one part. I'll explain.

Collapse JASS:
function SpellReflectCheck_2 takes nothing returns boolean
    return GetBooleanAnd( (GetSpellAbilityId() != 'A022'), (GetSpellAbilityId() != 'A007'))
endfunction

function SpellReflectCheck_1 takes nothing returns boolean
    return GetBooleanAnd( (GetSpellAbilityId() != 'A00C'), SpellReflectCheck_2())
endfunction

function SpellReflectCheck_Unit takes nothing returns boolean
    return GetBooleanAnd(GetUnitTypeId(GetSpellTargetUnit()) == 'H00Z', SpellReflectCheck_1())
endfunction

function SpellReflectCheck_Level takes nothing returns boolean
    return ( GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId()) > GetUnitAbilityLevel(GetSpellTargetUnit(), 'A02Z') )
endfunction

function SpellReflectCheck_Buff takes nothing returns boolean
    return GetBooleanAnd( GetUnitAbilityLevel( GetSpellTargetUnit(), 'B00O' ) > 0, SpellReflectCheck_Level())
endfunction

function Trig_Spell_Reflection_Conditions takes nothing returns boolean
    return GetBooleanAnd( SpellReflectCheck_Buff(), SpellReflectCheck_Unit())
endfunction

function Trig_Spell_Reflection_Actions takes nothing returns nothing
    local unit reflect = GetSpellTargetUnit()
    local unit cast = GetTriggerUnit()
    local unit dummy
    local integer Order = GetUnitCurrentOrder(cast)
    local location p = GetUnitLoc(reflect)
    local location pp = GetUnitLoc(cast)

//   call DisplayTimedTextToForce( GetPlayersAll(), 15.00, Order )

    call CreateNUnitsAtLoc( 1, 'H010', GetOwningPlayer(reflect), p, bj_UNIT_FACING )
    set dummy = GetLastCreatedUnit()
    call UnitAddAbility(dummy, GetSpellAbilityId())
    call SetHeroLevelBJ(dummy, 20, false)
    call SetUnitAbilityLevel(dummy, GetSpellAbilityId(), GetUnitAbilityLevel(cast, GetSpellAbilityId()))
    call IssueImmediateOrder( cast, "stop" )
    call IssueTargetOrderById( dummy, Order, cast )
    call CreateTextTagUnitBJ( "TRIGSTR_2550", cast, 0.00, 10.00, 100, 0.00, 0.00, 0 )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersAll() )
    call SetTextTagPermanent( GetLastCreatedTextTag(), false )
    call SetTextTagLifespan( GetLastCreatedTextTag(), 5 )
    call RemoveLocation(p)
    call RemoveLocation(pp)
    call TriggerSleepAction(6.00)
    call RemoveUnit( dummy )
    set reflect = null
    set cast = null
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Spell_Reflection takes nothing returns nothing
    set gg_trg_Spell_Reflection = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Spell_Reflection, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Spell_Reflection, Condition( function Trig_Spell_Reflection_Conditions ) )
    call TriggerAddAction( gg_trg_Spell_Reflection, function Trig_Spell_Reflection_Actions )
endfunction


EDIT: Actually the small bug is that when I cast one of the 3 spells I don't wish to be reflected, it doesn't reflect it (As I wish) but still shows the Floating text and stuff, like if it was reflected.

EDIT#2: Edited the trigger a lot.
11-13-2006, 09:59 PM#2
Anitarf
So, what exactly doesn't work, and how does it work?

Debug messages are your friend.
11-14-2006, 03:16 AM#3
Matarael
Hey I actually just tried a similar ability in GUI. I would create a dummy unit, add the ability to it, and cast it on the caster.
Ofcourse this wouldn't work it the original caster uses a dummy unit to actually cast the spell, and you can't "activate" it T_T...
I need to test it first though.
11-14-2006, 10:22 AM#4
BertTheJasser
Plx, clean the script of all the nasty BJ-funcs. My eyes burn. If you don't know how you clould optimize your code, read Vex' tutorials and DL JassCraft form Zocx.

EDIT:
You have 2 problems (in one sinle line which makes the hole spell not work):
Collapse JASS:
local string Order = OrderId2StringBJ(GetUnitCurrentOrder(cast))
1. Not every orderID has a corresponding orderstring. So
Code:
OrderId2StringBJ
might return
Code:
""
,
Code:
null
or
Code:
"DefaultString"
.
2. It can happen (depending on the ability+some randomness)that at the effect of a spell the order got allready reseted, whchih means a wrong order, which means nothing will happen. To avoid that, you must recoginze the cast event(check here the conditions), store the order, reload the order in the spell effect trigger and cast that trigger. Note: Be shure to clear GC if your unit with that ability dies/deactivates its spell.
11-14-2006, 08:52 PM#5
Daxtreme
> store the order, reload the order in the spell effect trigger and cast that trigger.

Which function should I use in the condition check if orderid2stringbj isn't going to return always the right string?

@Other posters: Sorry I forgot to mention the small bug! Post edited.
11-15-2006, 02:51 PM#6
BertTheJasser
Collapse JASS:
GetUnitCurrentOrder(cast)
it returns an integer.
To order a unit to cast that ability, just use the order funcs you allready have in your code with the suffix 'ById' before '(' and change the variable which stores the order to an int type variable.

But the second point is stell relevant.
Read my last post, again.
11-15-2006, 08:48 PM#7
Daxtreme
Quote:
Originally Posted by BertTheJasser
Collapse JASS:
GetUnitCurrentOrder(cast)
it returns an integer.
To order a unit to cast that ability, just use the order funcs you allready have in your code with the suffix 'ById' before '(' and change the variable which stores the order to an int type variable.

But the second point is stell relevant.
Read my last post, again.

I just did. Thanks.

BTW: Improved my code a bit with natives. Looks a bit better now.

On to checking the order right now... Thanks for the function :)

EDIT: Uh-oh... I don't know how to use gamecaches in JASS. Never actually used them, especially to store... an order? Are there tuts or a magic function that can return the order and store it, fast?

.... Or do I simply use an integer variable ? :P

EDIT#2: I am already using the Spell cast event instead of Spell Effect event :P

EDIT#3: Just edited the code a lot. Take a look at it! Looking forward for more tests, but consider I have the same bug for now.
11-16-2006, 03:04 PM#8
BertTheJasser
Collapse JASS:
GetBooleanAnd( (GetSpellAbilityId() != 'A022'), (GetSpellAbilityId() != 'A007'))
is odd.
Just replace it with
Collapse JASS:
 (GetSpellAbilityId() != 'A022') and  (GetSpellAbilityId() != 'A007')

You can store it as an integer, yes.
Btw, I do not see any changes in the code on top.

If you have still questions, ask.
Btw, there are some quite good jasstutorials for beginners.