- Joined
- Jul 26, 2008
- Messages
- 1,009
Hi, I'm creating a spell set that relies on a system. When a unit casts a spell that spell is saved in a hashtable attached to the unit. Details of the spell are also saved.
The spells are Double Cast Active, Mimic, and Tricast. Doublecast Active repeats the last spell cast by the unit. I'd like it to aim at the same angle on point casts instead of the same spot, but I don't think I can do the math for that.
Then there's mimic, which will take the last spell cast by a target unit and give it to you. Each cast decreases an integer and when it hits 0 you're given mimic back and the spell is removed.
Finally is Tricast. The last 3 spells cast on a unit are saved. When cast on that unit those 3 spells are called up again and cast on the unit.
All 3 spells will not cast, and won't even go to conditions. That's the first problem. I'd also prefer to optomize it so they run smoothly and do things efficiently. Later on I'll prep them for easy configuration. Thanks for the help!
The spells are Double Cast Active, Mimic, and Tricast. Doublecast Active repeats the last spell cast by the unit. I'd like it to aim at the same angle on point casts instead of the same spot, but I don't think I can do the math for that.
Then there's mimic, which will take the last spell cast by a target unit and give it to you. Each cast decreases an integer and when it hits 0 you're given mimic back and the spell is removed.
Finally is Tricast. The last 3 spells cast on a unit are saved. When cast on that unit those 3 spells are called up again and cast on the unit.
All 3 spells will not cast, and won't even go to conditions. That's the first problem. I'd also prefer to optomize it so they run smoothly and do things efficiently. Later on I'll prep them for easy configuration. Thanks for the help!
JASS:
globals
hashtable LastSpell
hashtable TripleSpell
endglobals
function Trig_LastSpell_Actions takes unit c, unit t returns nothing
local integer i = LoadInteger(TripleSpell, 0, GetHandleId(c)) + 1
//Double Cast and Mimic
call SaveReal(LastSpell, 3, GetHandleId(c), GetSpellTargetX())
call SaveReal(LastSpell, 4, GetHandleId(c), GetSpellTargetY())
call SaveStr(LastSpell, 5, GetHandleId(c), OrderId2String(GetUnitCurrentOrder(c)))
call SaveInteger(LastSpell, 6, GetHandleId(c), GetSpellAbilityId())
call SaveUnitHandle(LastSpell, 10, GetHandleId(c), t)
//Tricast
call SaveInteger(TripleSpell, 0, GetHandleId(t), i)
if i >= 3 then
call SaveInteger(TripleSpell, 0, GetHandleId(t), 0)
endif
call BJDebugMsg(I2S(i))
call SaveInteger(TripleSpell, i*10, GetHandleId(t), GetSpellAbilityId())
call SaveStr(TripleSpell, i, GetHandleId(t), OrderId2String(GetUnitCurrentOrder(c)))
endfunction
function Trig_LastSpell_Conditions takes nothing returns boolean
if not(GetSpellAbilityId() == 'DblA') or not(GetSpellAbilityId() == 'TriC') or not(GetSpellAbilityId() == 'mimi') then
call Trig_LastSpell_Actions(GetTriggerUnit(), GetSpellTargetUnit())
endif
return false
endfunction
//===========================================================================
function InitTrig_LastSpell takes nothing returns nothing
set gg_trg_LastSpell = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_LastSpell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(gg_trg_LastSpell, function Trig_LastSpell_Conditions)
set LastSpell = InitHashtable()
set TripleSpell = InitHashtable()
endfunction[/HIDDEN]
JASS:
scope DoubleCastActive initializer Init
globals
private unit TempUnit
endglobals
private function Enemy takes nothing returns boolean
return IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(TempUnit))
endfunction
private function Ally takes nothing returns boolean
return IsUnitAlly(GetEnumUnit(), GetOwningPlayer(TempUnit))
endfunction
private function Actions takes unit c,unit t,unit d, string id returns nothing
local integer i = LoadInteger(LastSpell, 6, GetHandleId(GetTriggerUnit()))
local real x = GetUnitX(c)
local real x2 = LoadReal(LastSpell, 3, GetHandleId(GetTriggerUnit()))
local real y2 = LoadReal(LastSpell, 4, GetHandleId(GetTriggerUnit()))
local group g = NewGroup()
local boolexpr boo = Filter(function Enemy)
set d = CreateUnit(GetTriggerPlayer(),'hsor',x,GetUnitY(c),GetUnitFacing(c))
call SetUnitState(d,UNIT_STATE_MANA,9999)
call UnitAddAbility(d,i)
call UnitApplyTimedLife(d,'BTLF',15.)
if IsUnitAlly(t, GetOwningPlayer(c)) then
set boo = Filter(function Ally)
endif
if x2 == 0 and x != 0 then
call IssueImmediateOrder(d,id)
elseif t != null then
call GroupEnumUnitsInRange(g, x2, y2, 400, boo)
set t = FirstOfGroup(g)
call IssueTargetOrder(d,id,t)
else
call IssuePointOrder(d,id,x2+GetRandomReal(0,100),y2+GetRandomReal(0,100))
endif
call ReleaseGroup(g)
endfunction
private function Conditions takes nothing returns boolean
local string str = LoadStr(LastSpell, 5, GetHandleId(GetTriggerUnit()))
local unit t = LoadUnitHandle(LastSpell, 10, GetHandleId(GetTriggerUnit()))
if GetSpellAbilityId() == 'DblA' then
call Actions(GetTriggerUnit(),t,null, str)
endif
return false
endfunction
//===========================================================================
public function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function Conditions))
endfunction
endscope[/HIDDEN]
JASS:
function Trig_Triple_Cast_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'TriC'
endfunction
function Trig_Triple_Cast_Actions takes nothing returns nothing
local unit c = GetTriggerUnit()
local unit t = GetSpellTargetUnit()
local unit array d
local real x = GetUnitX(c)
local real y = GetUnitY(c)
local integer i = 1
local integer array abil
local string array id
loop
exitwhen i == 4
call BJDebugMsg(I2S(i))
set abil[i] = LoadInteger(TripleSpell, i*10, GetHandleId(GetSpellTargetUnit()))
set id[i] = LoadStr(TripleSpell, i, GetHandleId(GetTriggerUnit()))
set d[i] = CreateUnit(GetTriggerPlayer(),'e002',x,GetUnitY(c),GetUnitFacing(c))
call UnitAddAbility(d[i],abil[i])
call UnitApplyTimedLife(d[i],'BTLF',5.)
call IssueTargetOrder(d[i],id[i],t)
set d[i] = null
set id[i] = null
set i = i + 1
endloop
set t = null
set c = null
endfunction
//===========================================================================
function InitTrig_Triple_Cast takes nothing returns nothing
set gg_trg_Triple_Cast = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Triple_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Triple_Cast, Condition( function Trig_Triple_Cast_Conditions ) )
call TriggerAddAction( gg_trg_Triple_Cast, function Trig_Triple_Cast_Actions )
endfunction
[/HIDDEN]
Last edited: