• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Function interface

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
heh, sry..
maybe tell me if this is a correct way afterall?^^

JASS:
function interface OnImpact takes Object id, unit Impact returns nothing

    struct Object
        private static method UnitGroup takes nothing returns nothing
                    call DamageFilter(dummy_id, GetEnumUnit())
                        if dummy_id.DestroyOnImpact then
                            call Release(dummy_id) // ignore all that, its statics stuff, just read the 2 lines below.
                        else
                            call dummy_id.On_Impact.execute(dummy_id, GetEnumUnit())
                        endif
                endmethod
    endstruct

is that okay? dummy_id changes before i call the ForGroup.
 
Level 11
Joined
Sep 12, 2008
Messages
657
hmm, i cant test mine, since im still on beta-part of the system,
im not really finished yet, but ill try it since its 10% done of movement..

edit:
its okay now, movement works, etc, (added BJDebugMsg to see what i did wrong)
and now im stuck,
i made it set the effect doing it like this:

JASS:
                static method setEffect takes Object id, string eff returns nothing
                    if id.Effect != null then
                        call DestroyEffect(id.Effect)
                    endif
                    if eff != "" then
                        set id.Effect = AddSpecialEffectTarget(eff, id.Object, "origin")
                    endif
                    call BJDebugMsg("|c00FF0000[DEBUG] Initialized a new effect|r")
                endmethod

this is a constant used for defaults

JASS:
        private static constant string Missle_Creation_Model_Path        = "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilMissile.mdl" // the model automaticly created to the object on creation.

and this is how i call it

JASS:
call Object.setEffect(id, Missle_Creation_Model_Path)

mind telling me why wont the model get attached? ty.
 
Last edited:
Level 6
Joined
Nov 3, 2008
Messages
117
JASS:
                static method setEffect takes Object id, string eff returns nothing
                    if id.Effect != null then
                        call DestroyEffect(id.Effect)
                    endif
                    if eff != "" then
                        set id.Effect = AddSpecialEffectTarget(eff, id.Object, "origin")
                    endif
                    call BJDebugMsg("|c00FF0000[DEBUG] Initialized a new effect|r")
                endmethod

and this is how i call it

JASS:
call Object.setEffect(id, Missle_Creation_Model_Path)

Why you make it as a static method although you know an instance?
make it a normal method and call it like this:
JASS:
                method setEffect takes  string eff returns nothing
                    if this.Effect != null then
                        call DestroyEffect(this.Effect)
                    endif
                    if eff != "" then
                        set this.Effect = AddSpecialEffectTarget(eff, this.Object, "origin")
                    endif
                    call BJDebugMsg("|c00FF0000[DEBUG] Initialized a new effect|r")
                endmethod
and call it with this: call id.setEffect(Missle_Creation_Model_Path)
 
Level 11
Joined
Sep 12, 2008
Messages
657
why this? o.o
i dont get it.. =[
and real problm was that it was in map header, it creates it now..
but i still gotta know what you meant ;p

edit: figured.. but ehh, it lines it soo good, ehh..
i guess ill change, since it looks better, and easier to use...

edit2: took me a while, but fixed everything.
now it looks like id.setEffect, and so on for everything else.
thanks for the tip =]
 
Last edited:
Level 11
Joined
Sep 12, 2008
Messages
657
hmm.. 1 other thing,
is there any reason why an arc wont support all angles?
since if im like facing left, it shoots an arced missle, and at another point, it shoots a missle with maximum height, or 0 height.
it allways changes depending on my angle ;/

JASS:
                    private static method FindMaxDistance takes real Distance, real Duration returns real
                    // this function caculates max distance using distance and duration.
                    // this is by diehard@azeroth from hiveworkshop.
                        return (Distance/0.032) * Duration
                    endmethod

                    private static method JumpParabola takes real dist, real maxdist,real curve returns real
                        // This function calculates the unit Z for a parabolic arc, by Shadow1500
                        // brought to me by diehard@azeroth from hiveworkshop.com
                        local real t = (dist*2)/maxdist-1
                        return (-t*t+1)*(maxdist/curve)
                    endmethod

JASS:
private static method CaculateArc takes Object id returns nothing
                        local real dx = 0
                        local real dy = 0
                        local real dx2 = 0
                        local real dy2 = 0
                        local real x = 0
                        local real d = 0
                        local real md = 0
                        local real pa = 0
                            if id.RunOnDuration then
                                set md = FindMaxDistance(id.Speed, id.Duration)
                            else
                                set md = id.MaxDist
                            endif
                            
                            set dx = id.startX - id.x
                            set dy = id.startY - id.y
                                set x = SquareRoot(dx * dx - dy * dy)
                            set dx2 = (id.startX + md * Cos (id.angle)) - id.startX
                            set dy2 = (id.startY + md * Sin (id.angle)) - id.startY
                                set d = SquareRoot(dx2 * dx2 - dy2 * dy2)
                                
                                set pa = JumpParabola(x, d, id.curve)
                                call SetUnitFlyHeight(id.Object, pa, 0)
                    endmethod

thanks in advance..
 
not sure... since ideally it should support any angle... and didnt encounter such an error from the systems I'm using... though the parabola function I use is different from that one...

but set d = SquareRoot(dx2 * dx2 - dy2 * dy2)

why is it minus?

anyway I believe that the maxdist used for the parabola function must be the same all thru out the flight...

and what is the value of id.curve?

btw this is the parabola I use [URL-"http://www.wc3c.net/showthread.php?p=1030107"]From this thread[/url]:
JASS:
 function ParabolaZ takes real h, real d, real x returns real
        return (4 * h / d) * (d - x) * (x / d)
    endfunction

but rather than using a local variable that is only used once per run, just use JumpParabola() directly on the setflyheight
 
Level 11
Joined
Sep 12, 2008
Messages
657
omg, apperantly i used - instead of +
btw, this parabola takes a curve, not max height,
so it can reach ANY location you want, with the curve.
it somehow caculates it, (1.8 curve = pretty high, but thats what my system use as default)
thanks, i finnaly got arc working =] (after so much time :p)

edit: hmm gah, i hate this..
anyways, i've tried the arc, it worked perfect,
then i made a grenade spell

JASS:
library Grenade initializer OnInit requires ObjectSystem
    
    private function OnImpactFunction takes Object id, unit target returns nothing
        local Object new = 0
        local real angle = 0
        local integer c = 0
        local real c2 = 0
        local real minaoe = 235
        local real maxaoe = 275
            loop
            set c = c + 1
            set c2 = c2 + 60
                set angle = GetRandomReal(c2 - 59, c2)
                set new = Object.create(GetOwningPlayer(id.Object), id.x, id.y, angle)
                call new.maxdistance(GetRandomReal(minaoe, maxaoe))
                call new.setEffect("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl")
                call new.damage(85, 0)
                call new.arc(true)
                call new.arcCurve(0.539)
                call new.distance(7)
                call new.heightDiffrence(25)
            exitwhen c == 6
            endloop
    endfunction
    
    private function OnCast takes nothing returns nothing
        local unit u = udg_u
        local Object dat = Object.create(GetOwningPlayer(u), GetUnitX(u), GetUnitY(u), GetUnitFacing(u)) 
        call dat.arc(true)
        call dat.arcCurve(1.8)
        call dat.heightDiffrence(25)
        call dat.TriggerAddImpactAction(OnImpact.OnImpactFunction)
        set u = null
    endfunction
    
    private function OnCond takes nothing returns boolean
        return GetSpellAbilityId() == 'A002'
    endfunction
    
    private function OnInit takes nothing returns nothing
        local trigger DM = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(DM, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            call TriggerAddCondition(DM, Condition(function OnCond))
            call TriggerAddAction(DM, function OnCast)
        set DM = null
    endfunction
    
endlibrary

it works cool,but it explodes on mid-air when units go near it.. (cuz of the height ;/)
so i tried doing this:

JASS:
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(dummy_id.Object)) and GetWidgetLife(GetFilterUnit()) > 0.405 /*
                        */                   and GetUnitFlyHeight(GetFilterUnit()) - dummy_id.Height >= dummy_id.HeightDiffrence /*
                        */                   and dummy_id.Height - GetUnitFlyHeight(GetFilterUnit()) <= dummy_id.HeightDiffrence

in my system,
it seems to fail.. any idea? ;/

btw, i also tried this and it failed too:

JASS:
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(dummy_id.Object)) and GetWidgetLife(GetFilterUnit()) > 0.405 /*
                        */                   and GetUnitFlyHeight(GetFilterUnit()) - dummy_id.Height >= dummy_id.HeightDiffrence /*
                        */                   and dummy_id.Height - GetUnitFlyHeight(GetFilterUnit()) <= dummy_id.HeightDiffrence

sorry, and thanks in advance. ;/

edit just figured how second one works (the 1 i wrote last)

JASS:
300 - 100 = 200 > >= 25
obj   tar   diff     hd

100 - 300 = -200 > <= 25
tar   obj   diff      hd

basicly, it never happends, because it has to be bigger then 25, and lower then 25..
how do i fix that? ;/
 
Last edited:
Im not sure if I understood it... but for the first one you want the missile to only explode if a unit with about the same height goes near? you can try looking at my Meteor system on how I did that, but yours seem fine...

basically I just checked if the height difference is between a certain range...

oh... change the 2nd one to -25 so it will be from -25 to 25

but shouldnt it be 25 > dif > -25? (diff is less than 25 but greater than -25)

( based on your posts yours would be greater than 25 and less than -25)
 
Level 11
Joined
Sep 12, 2008
Messages
657
ohh.. thanks xD my bad..

and wait.. 25 > diff > -25?
lets say caster height is 15, and unit height is 10
diffrence = 15 - 10 = 5
height diffrence > diffrence > - height diffrence?
so basicly:
25 > 5 > -25
25 is bigger then 5, and 5 is bigger then -25.

oh, that should work..
example if diffrence is 200
25 < 200 > -25,
so 1 check fails, that means it returns false, nice, thanks alot =]
i would've +rep you, but i allready did :p
 
ohh.. thanks xD my bad..

and wait.. 25 > diff > -25?
lets say caster height is 15, and unit height is 10
diffrence = 15 - 10 = 5
height diffrence > diffrence > - height diffrence?
so basicly:
25 > 5 > -25
25 is bigger then 5, and 5 is bigger then -25.

oh, that should work..
example if diffrence is 200
25 < 200 > -25,
so 1 check fails, that means it returns false, nice, thanks alot =]
i would've +rep you, but i allready did :p

yeah, so it would only explode on units within a range of 25 fly height difference...
 
Level 11
Joined
Sep 12, 2008
Messages
657
again, it fails =[

i've tried this:

JASS:
private static method DamageBoolexpr takes nothing returns boolean
                    local real diffrence = dummy_id.Height - GetUnitFlyHeight(GetFilterUnit())
                    local boolean result = dummy_id.HeightDiffrence > diffrence and diffrence > -dummy_id.HeightDiffrence
                    if dummy_id.EnemiesOnly then
                        set result = IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(dummy_id.Object)) /*
                        */           and dummy_id.HeightDiffrence > diffrence and diffrence > -dummy_id.HeightDiffrence
                    endif
                    return GetWidgetLife(GetFilterUnit()) > 0.405 and result
                endmethod

but it seems to fail, it never hits enemies like that.
25 = it never hits.
(yeah, im sure it reaches 25, cuz it hits the ground)
and idea?;/
 
Level 11
Joined
Sep 12, 2008
Messages
657
well.. the problem is,
all works perfectly, the only thing that doesnt work is the check of height ;/
(cuz i got 7 other abilities i can test with..)
and all of them fails, but some of them got OnImpact triggers, (added a function interface, as the name of this thread), but it works.
basicly, if its true (it hits a target), it calls the OnImpact of the missle,
but if its false, it returns it on collide with terrain.

edit: putted a higher number then 25, it works.. but now its too high, ill try to balance it ;p
 
well.. the problem is,
all works perfectly, the only thing that doesnt work is the check of height ;/
(cuz i got 7 other abilities i can test with..)
and all of them fails, but some of them got OnImpact triggers, (added a function interface, as the name of this thread), but it works.
basicly, if its true (it hits a target), it calls the OnImpact of the missle,
but if its false, it returns it on collide with terrain.

edit: putted a higher number then 25, it works.. but now its too high, ill try to balance it ;p

tried adding debugs to see what is the diff value and others?

EDIT: what value did you use? my meteor uses 100 I think... ^^... the only I hate about height check is that it does not consider unit size... so grounded giant units wont get hit by it while on mid-air... ^^
 
wait, the bigger the number is, the more height diffrence it needs? so 55 = really big,
100 = small? ;o

100 is bigger... but 55 is pretty small, based on my experience... and I think units usually have more than 100 units of physical height (not flying height, I mean the model's height)... so I used 100 to at least somehow take a normal unit's size into consideration since flying height is measured from the origin of the model... but not very accurate if you use -100 up to 100... I would suggest using a higher number for the low bound and a smaller on for the high bound like (50>diff>-100)

EDIT: hmm, no... I think units normally have physical height of about 200-400...
 
Level 11
Joined
Sep 12, 2008
Messages
657
Omg.. i just noticed i did the /* and */ comments..
gah, i forgot i tested something, ill edit in 5 sec and tell you if it works..

edit: terribly sorry..
i just forgot to edit id.Height each time arc takes place.. (i looked on the arc..)
well, it just works perfectly now, sry for all this =]
time for homing missles! ;p
 
private static integer array example Arrays cannot be constant.

The difference between including the static keyword and not is this:

globals
integer myvar
integer array myvar2
endglobals

That's basically the same as:

struct x
static integer myvar
integer myvar2
endstruct

Notice the omission of the "static" keyword turns the variable into an array.
 
private static integer array example Arrays cannot be constant.

The difference between including the static keyword and not is this:

globals
integer myvar
integer array myvar2
endglobals

That's basically the same as:

struct x
static integer myvar
integer myvar2
endstruct

Notice the omission of the "static" keyword turns the variable into an array.

right, I forgot about that... my bad... ^^
 
Status
Not open for further replies.
Top