HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Circle level spell not depending on level?

03-10-2009, 08:41 AM#1
wraithseeker
Collapse JASS:
scope Fire initializer Init

globals
private constant integer SPELL = 'A002'
private constant string EFFECT = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"   
endglobals

private function DISTANCE takes integer level returns integer
return level * 200
endfunction

private struct data
location CasterLoc
unit caster
real distance
real angle
real x
real y
timer t
timer r
integer times


static method create takes nothing returns data
local data d = data.allocate()
set d.t = NewTimer()
set d.caster = GetTriggerUnit()
set d.x = GetUnitX(d.caster)
set d.y = GetUnitY(d.caster)
set d.distance = DISTANCE(GetUnitAbilityLevel(d.caster,SPELL))
set d.times = 0
set d.r = NewTimer()
return d
endmethod

method onDestroy takes nothing returns nothing
call ReleaseTimer(.t)
endmethod

endstruct

private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL
endfunction

private function Loop takes nothing returns nothing
    local data d = data(GetTimerData(GetExpiredTimer()))
    local integer i = 0
    local integer effects = 12
    local real angle
        loop
            exitwhen i >= effects
            set angle = 2 * bj_PI * i / effects
            call AddSpecialEffect(EFFECT, d.x + d.distance * Cos(angle), d.y + d.distance * Sin(angle))
            set i = i + 1
        endloop
        set d.times = d.times + 1
        
        if d.times <= 5 then //This will see if we are in the shrinking or expanding part. The first 5 times we will lower the distance.
            set d.distance = d.distance - 50 //Shrinking circle by lowering the distance (= radius of circle).
        else //We are in the case that d.times > 5. We will expand the circle again.
            set d.distance = d.distance + 50 //expanding circle by increasing the distance (= radius of circle).
            if d.times > 10 then //The 10th time the skill circle it will end. (So as it is now, we have 5 times shrinking and 5 times expanding.)
                call d.destroy()
            endif
        endif
endfunction

private function Actions takes nothing returns nothing
    local data d = data.create()
    call SetTimerData(d.t,integer (d))
    call TimerStart(d.t,0.5,true,function Loop)
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 Conditions))
    call TriggerAddAction( t, function Actions )
endfunction

endscope

This thing is not depending on the level of my unit, what I want is that ,

Level 1 = distance is 300 , shrinks to caster 3 times which is 300/3 = 100 distance per interval.

Level 2 = Distance is 600, shirknks to caster 4 times which is 600/4 = 150, 150 distance per interval.

and so on....

If you need extra information or do not get what i mean , just reply to this thread and i will try my best to provide the information.
03-10-2009, 09:10 AM#2
xombie
First thing's first.

Collapse JASS:
call AddSpecialEffect(EFFECT, d.x + d.distance * Cos(angle), d.y + d.distance * Sin(angle))

This will leak an effect. You're going to want to clean that up.

You were a little unclear in what you wanted, it took me a little while to figure it out, but I think I know what you're trying to say. The reason it is not depending on d.distance is because you're adding/subtracting 50, 5 times, regardless of the level of the ability. This means that it will always contract and expand for a total flux over 250 distance.

Let me review the code some more.

Collapse JASS:
// added function INTERVAL based on what i thought you wanted
function INTERVAL takes integer level returns real
    return level + 2 // levels go as follows: 3/4/5... as i thought you meant
endfunction

// this is your DISTANCE function
function DISTANCE takes integer level returns real
    return level * 300.0 // before you had it as 200.0 * level, which would not give you values like 300/600 etc.
endfunction

static method create takes nothing returns data
local data d = data.allocate()
local integer spellLevel = GetUnitAbilityLevel(GetTriggerUnit(), SPELL) // added this for efficiency

set d.t = NewTimer()
set d.r = NewTimer() notice // i moved this here
set d.caster = GetTriggerUnit()
set d.x = GetUnitX(d.caster)
set d.y = GetUnitY(d.caster)

// everything that i use here that you don't have i will highlight in red, and should be added to your
// struct declaration.
set d.distance = DISTANCE(spellLevel)
set d.intervals = INTERVAL(spellLevel)
set d.contract = true
set d.distancePer = d.distance / d.intervals
set d.interval = 0

return d
endmethod

private function Loop takes nothing returns nothing
    local data d = data(GetTimerData(GetExpiredTimer()))
    local integer i = 0
    local integer effects = 12
    local real angle
        loop
            exitwhen i >= effects
            set angle = 2 * bj_PI * i / effects
            call AddSpecialEffect(EFFECT, d.x + d.distance * Cos(angle), d.y + d.distance * Sin(angle))
            set i = i + 1
        endloop

        set d.times = d.times + 1 // i changed this and moved it to the bottom of the code so that the index is easier to work with.
        
        // i removed your comments so you could read my version easier.
        if d.contract then 
            set d.distance = d.distance - d.distancePer
        else 
            set d.distance = d.distance + d.distancePer
        endif

        // it is much easier to work with the "index" which i label as d.interval if you start it off at
        // 0, rather than 1, which is what your previous code would have been doing
        if (d.contract) then
            set d.interval = d.interval + 1
            if d.interval == d.intervals then
                set d.contract = false
            endif
        else
            set d.interval = d.interval - 1
            if d.interval < 0 then
                call d.destroy()
            endif
        endif
endfunction

I changed your code up quite a bit because there was a lot to cover, so if you don't understand something I did then just ask. Also, this code is not optimized as you can see from the two if d.contract then statements, though I left it as-is so that you could follow it a little better.
03-10-2009, 09:26 AM#3
wraithseeker
Ok no problem ,

Collapse JASS:
call AddSpecialEffect(DestroySpecialEffect(EFFECT, d.x + d.distance * Cos(angle), d.y + d.distance * Sin(angle)))
like that I know , got my code mixed up >.<
03-10-2009, 09:37 AM#4
xombie
I'm bumping this just in-case you got confused as to whether or not I updated, wraithseeker.
03-10-2009, 10:24 AM#5
wraithseeker
Woah , That worked!

Could you explain it to me what you just added and what about them? My math is really bad sorry , I am in grade 8 (form 2 ).

I want to learn how you did that so I could teach other people next time or just be more knowledagle =)
03-10-2009, 10:29 AM#6
xombie
Well, what exactly don't you understand. Copy and paste the lines that you do not understand so I may address them directly.
03-10-2009, 10:31 AM#7
Pyrogasm
You simply weren't factoring the level into the number of times you changed the radius.

He made a new variable that stored how many times it should contract (which you previously did not do), a second variable that stored the number of times it has contracted so far, a third that stores the distance it should contract each time, and a fourth new variable that says whether it's contracting or not (though this last one isn't really necessary; you could compare d.interval > d.intervals each time instead)

Anyway, after that he just updated the interval each time a new ring was created, and then added/subtracted d.distancePer each time it should contract. There really isn't any math involved at all that isn't basic arithmetic; it's more of just knowing what to do.
03-10-2009, 10:35 AM#8
xombie
Quote:
Originally Posted by Pyrogasm
(though this last one isn't really necessary; you could compare d.interval > d.intervals each time instead)

Same reason I added d.distancePer, it is more efficient. Also, it increases readability, you just wanted to suggest you're more leet than I am :P

Its true though, there isn't much math at all involved here, I suggest you go to math class more and tell your teacher that somebody from Warcraft told you to.
03-10-2009, 10:44 AM#9
wraithseeker
Collapse JASS:
set d.distancePer = d.distance / d.intervals

What does this do?

Collapse JASS:
set d.times = d.times + 1

Why is this still needed? I don't see it used anymore, can be removed right =).

Collapse JASS:
if d.contract then 

this wasn't set to true or false ?

should be

Collapse JASS:
if d.contract == true or == false // I am not sure which one then
Collapse JASS:
if (d.contract) then

same for this one
03-10-2009, 10:48 AM#10
Pyrogasm
d.contract is a boolean variable, so its output is either true or false. Thus, you don't need to compare it to true or false. If you did, it would essentially be if true == true then, which can be simplified to if true then, so there's no reason to have the comparison in there.


Edit: You are correct that d.times is not being used (d.interval essentially serves the same purpose).

Setting set d.distancePer = d.distance / d.intervals makes it so that the number of rings are evenly spaced from the outermost to the innermost. Think about it: you're dividing the total distance by how many rings you want to make. That value is then used to decrease/increase d.distance to make the rings as necessary.
03-10-2009, 10:48 AM#11
xombie
set d.distancePer = d.distance / d.intervals
Quote:
Originally Posted by wraithseeker
which is 300/3 = 100 distance per interval.

Quote:
Originally Posted by wraithseeker
Why is this still needed? I don't see it used anymore, can be removed right =).

I figured you'd figure it out.

Quote:
Originally Posted by wraithseeker
this wasn't set to true or false ?

Quote:
Originally Posted by xombie
Collapse JASS:
set d.intervals = INTERVAL(spellLevel)
set d.contract = true
set d.distancePer = d.distance / d.intervals
set d.interval = 0

Lets play eye-spy, shall we?

I left out the part about the if-statement because I knew Pyrogasm would cover it. By the time I had posted this he had already posted that, so I had no idea before-hand, I just had a good feeling :P
03-10-2009, 10:56 AM#12
wraithseeker
Thanks alot guys! fixed problem!

Collapse JASS:
set d.distancePer = d.distance / d.intervals 

Quote:
Originally Posted by wraithseeker
which is 300/3 = 100 distance per interval.

This was a really good example bro , =).

Pyrograsm , i didn't know about that, I usually do if true == true which I think I should start changing now.

OFF TOPIC: Pyrograsm , you would know me as Wraith as the past which I think I have changed and I don't hope to be such a person again.

+ REP to pyrogasm but can't to XOMBIE need to spread..
03-10-2009, 10:59 AM#13
Pyrogasm
Aha! I thought you might be one and the same...

Just please ignore it if someone mentions your water wars thread here and there :P
03-10-2009, 11:02 AM#14
xombie
Quote:
Originally Posted by wraithseeker
+ REP to pyrogasm but can't to XOMBIE need to spread..

...you have no idea how this makes me feel.

So how exactly does this rep work? He can't give me reputation because I need to spread some reputation around? Okay - here wraithseeker, good job on being you. I don't understand how I do all of the work here and Pyrogasm says you don't need to do true == true - so he gets the rep. Argh.
03-10-2009, 11:10 AM#15
wraithseeker
It's not that I don't want , I pressed the REPUATATION button and it said that I needed to spread REP, sorry xombie..

The annoying message was
Quote:
Originally posted by Repuatation
You must spread some Reputation around before giving it to xombie again.