New spell, and more trouble

Komaqtion

You can change this now in User CP.
Reaction score
469
Hi!
Since my last/first spell now finally got approved (Thanks Andrewgosu !!! :D) I thought i could start on my next one :eek:

But, right away i got problems... Here's the current trigger:
JASS:
scope SearingDash initializer init

globals
    private constant integer ABIL_ID = 'A000'
    private constant string EFFECT_1 = "Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl"
endglobals

globals
endglobals

private struct Data
    effect e
    real x
    real y
    real speed
    unit caster
    timer t
    boolean b = false
    static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.caster = u
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        local Data d = Data.allocate()
        call DestroyEffect(.e)
    endmethod
endstruct

private function Spell_Check takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Periodic takes nothing returns boolean
    local Data d = KT_GetData()
    set d.t = NewTimer()
    set d.x = GetUnitX(d.caster)
    set d.y = GetUnitY(d.caster)
    set d.e = AddSpecialEffect(EFFECT_1,d.x,d.y)
    return d.b
endfunction

private function TimerStop takes nothing returns nothing
    local Data D = KT_GetData()
    set D.b = true
    call SetUnitMoveSpeed(D.caster, D.speed)
    call SetUnitPathing(D.caster,true)
    call SetUnitVertexColor(D.caster,255,255,255,100)
    call D.destroy()
endfunction

private function Spell takes nothing returns nothing
    local Data D = Data.create(GetTriggerUnit())
    set D.t = NewTimer()
    set D.x = GetUnitX(D.caster)
    set D.y = GetUnitY(D.caster)
    set D.speed = GetUnitMoveSpeed(D.caster)
    call SetUnitMoveSpeed(D.caster, 522)
    call SetUnitPathing(D.caster,false)
    call SetUnitVertexColor(D.caster,255,255,255,85)
    call KT_Add(function Periodic, D, 0.1)
    call TimerStart(D.t,5,false,function TimerStop)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Spell_Check))
    call TriggerAddAction(t, function Spell)
endfunction

endscope


This spell is supposed to create effects every 0.05 seconds at the caster (It's not nearly finished so haven't gotten to the point of destroying the effects or the data or anything yet).

This it now does, though the effects never gets destroyed and the other effects, like the movement speed and stuff never gets set back either :(

What's wrong (If you checked my other spell you know I'm only learning vJASS atm, so this is what i come up with XD)
 

RaiJin

New Member
Reaction score
40
JASS:
private function TimerStop takes nothing returns nothing
    local Data D = KT_GetData()
    set D.b = true
    call SetUnitMoveSpeed(D.caster, D.speed)
    call SetUnitPathing(D.caster,true)
    call SetUnitVertexColor(D.caster,255,255,255,100)
    call D.destroy()
endfunction


this won't work because you didn't use

KT_Add function so just use KT_Add instead of the timer, theres no data attached to that timer
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
You have 2 selections.

1) use CreateTimer(), SetTimerData(), GetTimerData(), PauseTimer(), DestroyTimer()
2) use KT_Add(), KT_GetData()//The period should be multiplier of 0.00125 or it will not accurate.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, i now have this:
JASS:
scope SearingDash initializer init

globals
    private constant integer ABIL_ID = 'A000'
    private constant string EFFECT_1 = "Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl"
endglobals

globals
endglobals

private struct Data
    effect e
    real x
    real y
    real speed
    real time = 1
    unit caster
    timer t
    boolean b = false
    static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.caster = u
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        local Data d = Data.allocate()
        call DestroyEffect(d.e)
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
    endmethod
endstruct

private function Spell_Check takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Periodic takes nothing returns boolean
    local Data d = KT_GetData()
    if d.time < 4.9 then
        set d.time = d.time + 0.1
        set d.x = GetUnitX(d.caster)
        set d.y = GetUnitY(d.caster)
        set d.e = AddSpecialEffect(EFFECT_1,d.x,d.y)
        set d.b = false
    elseif d.time >= 4.9 then
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
        set d.b = true
        call d.destroy()
    endif
    return d.b
endfunction

private function Spell takes nothing returns nothing
    local Data D = Data.create(GetTriggerUnit())
    set D.t = NewTimer()
    set D.x = GetUnitX(D.caster)
    set D.y = GetUnitY(D.caster)
    set D.speed = GetUnitMoveSpeed(D.caster)
    call SetUnitMoveSpeed(D.caster, 522)
    call SetUnitPathing(D.caster,false)
    call SetUnitVertexColor(D.caster,255,255,255,85)
    call KT_Add(function Periodic, D, 0.1)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Spell_Check))
    call TriggerAddAction(t, function Spell)
endfunction

endscope


But it still doesn't destroy the effects, and it only resets the movement speed, not the color or the pathing :(

I kinda understand why the effects aren't destroyed (d.e gets overwritten) so how can i implement an easy and small timedeffect function here ??? :S
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
JASS:
    method onDestroy takes nothing returns nothing
        local Data d = Data.allocate()

You can remove the allocation there. It isn't needed.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I think you need to use an effect array. Also, if you're submitting this as a spell it needs to be more configurable, i.e. the user must be able to change how long the spell lasts and the period. I did this for you :D

Tell me if this works, I couldn't compile it since I don't know what systems you are using.

JASS:
scope SearingDash initializer init

globals
    private constant integer ABIL_ID = 'A000'
    private constant string EFFECT_1 = "Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl"
    private constant real DURATION = 5 //How long the spell lasts
    private constant real PERIOD = .1 //Time between 'ticks'
endglobals


//DO NOT TOUCH THIS VARIABLE BLOCK <-- put a message in there when you submit this spell or whatever
globals
    private constant ARRAY_SIZE = DURATION / PERIOD //DONT TOUCH! This is the size of the effect array!
endglobals

private struct Data
    effect array e[ARRAY_SIZE]
    real x
    real y
    real speed
    real time = 1
    unit caster
    timer t
    integer index = 0//this is for the effect array
    static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.caster = u
        set d.t = NewTimer()
        set d.x = GetUnitX(u)
        set d.y = GetUnitY(u)
        set d.speed = GetUnitMoveSpeed(u)
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        //local Data d = Data.allocate() T.S.E said this isn't needed, I trust the noodle man. I personally don't use onDestroy much myself.
        //call DestroyEffect(d.e) We'll need a loop since it is an array!
        loop
            call DestroyEffect(d.e[d.index])
            exitwhen d.index <= 0
            set d.index = d.index-1 //Do you see what I did there? <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite12" alt="o_O" title="Er... what?    o_O" loading="lazy" data-shortname="o_O" />
        endloop            
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
    endmethod
endstruct

private function Spell_Check takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Periodic takes nothing returns boolean
    local Data d = KT_GetData()
    if d.time &lt; (DURATION - PERIOD) then
        set d.time = d.time + PERIOD
        set d.x = GetUnitX(d.caster)
        set d.y = GetUnitY(d.caster)
        set d.e[d.index] = AddSpecialEffect(EFFECT_1,d.x,d.y)
        //set d.b = false //Why comment this out? It isn&#039;t even needed!
        set d.index = d.index+1
        return false
    else //Why the elseif? If it isn&#039;t less than, it must be greater than or equal to!
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
        call d.destroy()
        return true
    endif
endfunction

private function Spell takes nothing returns nothing
    local Data D = Data.create(GetTriggerUnit())
    call SetUnitMoveSpeed(D.caster, 522)
    call SetUnitPathing(D.caster,false)
    call SetUnitVertexColor(D.caster,255,255,255,85)
    call KT_Add(function Periodic, D, PERIOID)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Spell_Check))
    call TriggerAddAction(t, function Spell)
endfunction
endscope
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Ok, after mixing around a bit ... (It didn't compile right away, nor does it now) This is how it looks atm:
JASS:
scope SearingDash initializer init

globals
    private constant integer ABIL_ID = &#039;A000&#039;
    private constant string EFFECT_1 = &quot;Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl&quot;
    private constant real DURATION = 5 //How long the spell lasts
    private constant real PERIOD = .1 //Time between &#039;ticks&#039;
endglobals


//DO NOT TOUCH THIS VARIABLE BLOCK &lt;-- put a message in there when you submit this spell or whatever
globals
    private constant integer ARRAY_SIZE = DURATION / PERIOD //DONT TOUCH! This is the size of the effect array!
endglobals

private struct Data
    effect array e[ARRAY_SIZE]
    real x
    real y
    real speed
    real time = 1
    unit caster
    timer t
    integer index = 0
    static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.caster = u
        set d.t = NewTimer()
        set d.x = GetUnitX(u)
        set d.y = GetUnitY(u)
        set d.speed = GetUnitMoveSpeed(u)
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        loop
            call DestroyEffect(.e[.index])
            exitwhen .index &lt;= 0
            set .index = .index-1
        endloop            
        call SetUnitMoveSpeed(.caster, .speed)
        call SetUnitPathing(.caster,true)
        call SetUnitVertexColor(.caster,255,255,255,100)
    endmethod
endstruct

private function Spell_Check takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Periodic takes nothing returns boolean
    local Data d = KT_GetData()
    if d.time &lt; DURATION - PERIOD then
        set d.time = d.time + PERIOD
        set d.x = GetUnitX(d.caster)
        set d.y = GetUnitY(d.caster)
        set d.e[d.index] = AddSpecialEffect(EFFECT_1,d.x,d.y)
        set d.index = d.index+1
        return false
    else
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
        call d.destroy()
        return true
    endif
endfunction

private function Spell takes nothing returns nothing
    local Data D = Data.create(GetTriggerUnit())
    call SetUnitMoveSpeed(D.caster, 522)
    call SetUnitPathing(D.caster,false)
    call SetUnitVertexColor(D.caster,255,255,255,85)
    call KT_Add(function Periodic, D, PERIOD)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Spell_Check))
    call TriggerAddAction(t, function Spell)
endfunction
endscope


Though there is only 1 error left:

JASS:
    effect array e[ARRAY_SIZE]


Error: Line 467: Wrong [size] definition.

:(

I remember i got this error on my last spell, though can't remember how I fixed it XD

Note: And Frozenhelfir... I know I need more constants and stuff like that, but this isn't nearly finished atm, so I'll get to that later :D But thanks anyway :thup:
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
put an R2I() around the DURATION/PERIOD and then add 1
R2I(DURATION/PERIOD) + 1 Sorry about it not compiling :( I couldn't test it because you have some custom functions in there.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Nope, sorry... Still doesn't work :( If I just could remember how I fixed it last time :S

And, for your information, I'm using KT2 for some extra functions :D
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I just compiled and realized how many stupid mistakes I made :p

JASS:
effect array e[R2I(5/.1)]


That doesn't even work. It looks like you can only put a straight up number in the brackets. I'm going to go download the newest JassHelper and see if that will work. If it doesn't the method may be a bit ugly but meh :/

EDIT: Just out of curiosity, do these effects need to show until the spell is done? And the new JassHelper can only put numbers in there too. If it needs to be an array, you can either put in 8190 (max size) or have the user do the math. I'm not sure if 8190 array size will lag or not, but it is probably better than having the user do the math.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
So there is no way of doing this then ??? Anyone knows ??? :S It's just much easier, both for me and for the users :D
 

roXplosive

New Member
Reaction score
15
As far as I know the arrays need not be initialized . They always get the maximum size of 8190 and if you define them in globals the specified size is initialized to 0 or NULL . For locals just use the goddamn array as it is . O defined 1 with just

local unit array spirits

and got no syntax error . Try this one .
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Arrays are different in a struct. JassHelper manual says they need a size when created.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, struct members need to have initialized arrays :( I know that :D

But still, any ideas to the problem ??? :S
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
just make it 8190, or something high like 3000. But you forgot to answer my question: does the effect need to stay around until the ability finishes? Tell me if this gives the desired outcome:

JASS:
scope SearingDash initializer init

globals
    private constant integer ABIL_ID = &#039;A000&#039;
    private constant string EFFECT_1 = &quot;Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl&quot;
    private constant real DURATION = 5 //How long the spell lasts
    private constant real PERIOD = .1 //Time between &#039;ticks&#039;
endglobals

private struct Data
    effect e
    real x
    real y
    real speed
    real time = 1
    unit caster
    timer t
    static method create takes unit u returns Data
        local Data d = Data.allocate()
        set d.caster = u
        set d.t = NewTimer()
        set d.x = GetUnitX(u)
        set d.y = GetUnitY(u)
        set d.speed = GetUnitMoveSpeed(u)
        return d
    endmethod
    
    method onDestroy takes nothing returns nothing
        call DestroyEffect(.e)           
        call SetUnitMoveSpeed(.caster, .speed)
        call SetUnitPathing(.caster,true)
        call SetUnitVertexColor(.caster,255,255,255,100)
    endmethod
endstruct

private function Spell_Check takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Periodic takes nothing returns boolean
    local Data d = KT_GetData()
    if d.time &lt; DURATION - PERIOD then
        set d.time = d.time + PERIOD
        set d.x = GetUnitX(d.caster)
        set d.y = GetUnitY(d.caster)
        call DestroyEffect(d.e)
        set d.e = AddSpecialEffect(EFFECT_1,d.x,d.y)
        return false
    else
        call SetUnitMoveSpeed(d.caster, d.speed)
        call SetUnitPathing(d.caster,true)
        call SetUnitVertexColor(d.caster,255,255,255,100)
        call d.destroy()
        return true
    endif
endfunction

private function Spell takes nothing returns nothing
    local Data D = Data.create(GetTriggerUnit())
    call SetUnitMoveSpeed(D.caster, 522)
    call SetUnitPathing(D.caster,false)
    call SetUnitVertexColor(D.caster,255,255,255,85)
    call KT_Add(function Periodic, D, PERIOD)
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Spell_Check))
    call TriggerAddAction(t, function Spell)
endfunction
endscope
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah it works :D But I'd at least like the effects to stand longer than 0.1 seconds :(

And I'd also like to decrease the period, and creating more effect since it looks a bit shabby with so little effect XD Any ideas ??? :S

(And I'm no longer using TimerUtils, so no NewTimer() anymore :D)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top