| 01-22-2008, 04:34 PM | #1 |
When I used it on a spell, the first time that spell is cast, it lags. Does this happen to you or am I just making bad scripts. here is my script: JASS:scope HolyShield globals private unit array Who private effect array FX private constant real SPELL_DURATION = 10.00 private constant integer SPELL_ID = 'A000' private constant integer SPELL_ARMOREFFECT = 'A002' private constant string SPELL_EFFECT = "Abilities\\Spells\\Human\\DivineShield\\DivineShieldTarget.mdl" endglobals private function InitArrays takes nothing returns nothing local integer index = 0 local unit caster loop set Who[index] = null set FX[index] = null set index = index + 1 exitwhen index > 8192 endloop // I added this to preload the ability and avoid the first use lag set caster = CreateUnit(Player(15), 'hpea', 0, 0, 0.00) call UnitAddAbility(caster, SPELL_ARMOREFFECT) call UnitRemoveAbility(caster, SPELL_ARMOREFFECT) call RemoveUnit(caster) set caster = null // #end call BJDebugMsg(" Initialized Arrays!") endfunction private function Conditions takes nothing returns boolean return GetSpellAbilityId() == SPELL_ID and GetUnitAbilityLevel(GetTriggerUnit(), SPELL_ARMOREFFECT) == 0 endfunction private function ActionsChild takes nothing returns nothing local timer t = GetExpiredTimer() local integer index = RecycleTimer(t) local unit caster = Who[index] call DestroyEffect(FX[index]) call UnitRemoveAbility(caster, SPELL_ARMOREFFECT) set t = null set caster = null endfunction private function Actions takes nothing returns nothing local timer t = UseTimer() local unit caster = GetTriggerUnit() local integer index = UseIndex(t) local real duration = I2R( GetUnitAbilityLevel(caster, SPELL_ID) ) * SPELL_DURATION set Who[index] = caster set FX[index] = AddSpecialEffectTarget(SPELL_EFFECT, caster, "origin") call UnitAddAbility(caster, SPELL_ARMOREFFECT) // if this line is commented out the lag doesn't show up call TimerStart(t, duration, false, function ActionsChild) set t = null set caster = null endfunction //=========================================================================== public function InitTrig takes nothing returns nothing local trigger t = CreateTrigger() call InitArrays() call Preload(SPELL_EFFECT) call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition(t, Condition(function Conditions) ) call TriggerAddAction( t, function Actions ) set t = null endfunction endscope This was the attachment system I used with this spell: JASS:library ReturnBug function H2I takes handle h returns integer return h return 0 endfunction endlibrary library TimerIndexer initializer TimerInitialize requires ReturnBug globals private timer array Timer private boolean array TimerCheck private integer Index = 0 private integer Indexer = 0 private constant integer MAX = JASS_MAX_ARRAY_SIZE endglobals private function TimerInitialize takes nothing returns nothing local integer index = 0 loop exitwhen index > MAX set Timer[index] = CreateTimer() set TimerCheck[index] = false set index = index + 1 endloop set Indexer = H2I(Timer[0]) endfunction function UseTimer takes nothing returns timer if Indexer > MAX then // returns to initial value set Index = 0 endif if TimerCheck[Index] == false then set TimerCheck[Index] = true set Index = Index + 1 return Timer[Index - 1] else // in case of a collision set Index = Index + 1 loop exitwhen Index == MAX or TimerCheck[Index] == false set Index = Index + 1 endloop if Index == MAX and TimerCheck[Index] == true then return null //No more timers available else set TimerCheck[Index] = true set Index = Index + 1 return Timer[Index - 1] endif endif endfunction function RecycleTimer takes timer t returns integer local integer index = H2I(t) - Indexer call PauseTimer(Timer[index]) set TimerCheck[index] = false return index endfunction function UseIndex takes timer t returns integer local integer index = H2I(t) - Indexer if index >= 0 and index <= MAX then return index else return -1 endif endfunction endlibrary |
| 01-22-2008, 05:07 PM | #2 |
The easiest way is to create a dummy unit and add all custom abilities. at the init of the map, remove the unit JASS:private function TimerInitialize takes nothing returns nothing local integer index = 0 loop exitwhen index > MAX set Timer[index] = CreateTimer() set TimerCheck[index] = false set index = index + 1 endloop set Indexer = H2I(Timer[0]) endfunction constant integer JASS_MAX_ARRAY_SIZE = 8192 So actually you try to create 8193 timers. But the index max is 8191, and if you use the 8191 index of a variable, warcraft3 will crash on a load saved game |
| 01-22-2008, 06:12 PM | #3 |
ok thanks! I can't rep you yet but i'll do ! thanks again troll |
| 01-22-2008, 06:49 PM | #4 | |
Quote:
I don't care about rep. I don't have post any ressource and i'm not a child who need some sweets or make him cry. Btw i don't say that i don't like sweets :p |
| 01-23-2008, 03:35 AM | #5 |
But I do care, it's good manners to give rep to someone who has helped you a lot, and you did help me. : ) |
