• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[vJASS] Jump

Level 1
Joined
Mar 30, 2008
Messages
7
ive been trying back and forth to understand all this jass madness, but ive got nothing figured out and a substantially painful headache, my tiger still doesnt jump and i hate her for it:(
 
Level 1
Joined
Jan 24, 2008
Messages
5
Nice jump thingy however I'm wondering how I can detect the end of the map because if you jump out of the map your hero is lost and you can't do anything or you get fatal errors. So is it possible to make this so you can't jump out of the map?
 
Level 9
Joined
Apr 5, 2008
Messages
529
You should change this:

JASS:
    method onDestroy takes nothing returns nothing
        local real x
        local real y
        local rect r

        if .r != 0.00 then
            set x = GetUnitX(.u)
            set y = GetUnitY(.u) 
           set r = Rect(x - .r, y - .r, x + .r, y + .r)
            call EnumDestructablesInRect(r, Bool, function TreeKill)
            call RemoveRect(r)

            set r = null
        endif

        if .s != "" and .s != null then
            call DestroyEffect(AddSpecialEffect(.s, x, y))
        endif

        call PauseUnit(.u, false)
    endmethod

to this:

JASS:
    method onDestroy takes nothing returns nothing
        local real x = GetUnitX(.u)
        local real y = GetUnitY(.u)
        local rect r

        if .r != 0.00 then
            set r = Rect(x - .r, y - .r, x + .r, y + .r)
            call EnumDestructablesInRect(r, Bool, function TreeKill)
            call RemoveRect(r)

            set r = null
        endif

        if .s != "" and .s != null then
            call DestroyEffect(AddSpecialEffect(.s, x, y))
        endif

        call PauseUnit(.u, false)
    endmethod

Why? Because, if the radius was 0 and the special effect 2 was not "", the x and y would not be initialized in the second if/then/else statement, which would cause errors.

I also suggest adding IssueImmediateOrder in the onDestroy method. When the unit is paused while doing an action, and then is unpaused, he'll continue doing the action, resulting in a repeat of the jump until the game crashes because the hero reaches the end of the map.

JASS:
        call PauseUnit(.u, false)
        call IssueImmediateOrder(.u, "stop")
 
Ok, I got the sliding effect, though... Looks like it works on some computers, but not on all. Depending on duration, curve and distance, I'm sliding after the jump or before. Did you remember to take Initial map height into account? 'casue mine is 4, not 2.

EDIT: That's the problem. You do not account for cliff heigt. I dropped it two notches, and it worked perfectly. I would really suggest to add an option to play animation during the jump, though.

EDIT2: And to be able to run a function when landing would also be great, wouldn't have to use waits or triggersleep action.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
heh, again, sorry for the bugs, i'll try to fix them as soon as i find time

EDIT: ok i'm gonna install wc3 now to fix the bugs once and for all

ok, to sum it up, it's basically:

1) bug - sliding effect
2) improvement - adding an extra parameter for animation (wouldn't it have too many parameters then?)
3) bug - i should remove the possibility that the distance between the jumping point and the jumper is 0..... isn't it also useful if a unit can jump in place?
3) bug - something about cliffs?
4) bug - map boundaries (pretty serious)
5) bug - if a person jumps to a spot that is lower than him, than it doesn't fully land (if i got that one right)... should be easily fixable

.... did i miss anything?
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
I did some testing and

- I fixed the error so the jumping unit cannot jump out of the map anymore (I just used analogy from my knockback code)
- the sliding effect is definitely caused by the problem that the unit has trouble (mostly visually) to jump on a point of a different height

I've been thinking, and I can't really think of the solution for the second notice. Most probably because....wait, I think I have an idea, I hope it will work :)

Sorry for double-posting.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Ok, I fixed the code (meaning I edited the first post). It is now usable on any terrain height, jumping on cliffs etc.

It still has some stroke movements, but it looks fair, it will be fine if your map isn't full of cliffs :D

This is only temporarily, I spent about 4 hours on these fixes, I know it's a lot, but errors were hard to find. You wouldn't imagine how much calculations with terrain height, unit height, differences etc. I had to go through for doing this.

Damn you, SetUnitHeight....damn you to hell....

EDIT: Ok, I changed it now :D, you can see under fixes (the new parameter has been explained below the code)

EDIT2: I'll probably rewrite the whole engine to use Bezier curves, as they are exactly what I need. I just need to learn those :p. Just look at the picture, isn't it pretty?

Btw, I'm aware that I'm talking to myself.
 

Attachments

  • 800px-Bezier_curve.jpg
    800px-Bezier_curve.jpg
    63.9 KB · Views: 101
Last edited:
Level 9
Joined
Nov 4, 2007
Messages
931
Nice jump, thanks for making, I can't tell you how much of a pain in the ass it is tryin to make one from scratch because you probably know what its like, but great jump (slightly buggy but no biggie).
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
I know this is a little late comment, but i think i have a question,,
Isnt it 'more efficient' to create a global unit for the 'TreeFilter' function, move it, and then order that one to 'harvest', it would cause less lag (i think) and seems more efficient to me,,
You can delete the unit after, or not delete it at all, just move it everytime you run the 'TreeFilter' function,,

Would that have any effect?
Im only still quite a noob to vJass, so it was a only a question,,

-Yixx,,-
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Well, when we talk about efficiency, we talk about as less double actions (like BJ's) as possible (a.o.),,
You now create a unit for every tree you filter, right?
Wouldnt it be more efficient if you create a global unit, and move it with every tree you filter?
That would create less units, so less lag for slow internet persons, (IF it creates lagg, which is doesnt)
instead of:
JASS:
set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),Dummy_Id,x,y,blablabla)
call IssueImmediateOrder(u,blabla)
do:
JASS:
call SetUnitPosition(GLOBAL_TREE_FILTER_UNIT,x,y)
call IssueImmediateOrder(GLOBAL_TREE_FILTER_UNIT,blablabla)

Then you wouldnt have to create a unit everytime,,
Wouldnt that be more efficient?

EDIT:
This is what you have:

JASS:
private function TreeFilter takes nothing returns boolean     local destructable d = GetFilterDestructable()
    local boolean i = IsDestructableInvulnerable(d)
    local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), DUMMY_ID,GetWidgetX(d), GetWidgetY(d), 0)
    local boolean result = false
    call UnitAddAbility(u, 'Ahrl')
    if i then
        call SetDestructableInvulnerable(d, false)
    endif
    set result = IssueTargetOrder(u, "harvest", d)
    call RemoveUnit(u)
    if i then
      call SetDestructableInvulnerable(d, true)
    endif
    set u = null
    set d = null
    return result
endfunction

This is what i mean:

JASS:
globals
    private unit DUMMY = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE)Dummy_Id, blablabla)
endglobals
private function TreeFilter takes nothing returns boolean     local destructable d = GetFilterDestructable()
    local boolean i = IsDestructableInvulnerable(d)
    local boolean result = false
    call SetUnitPosition(DUMMY,GetWidgetX(d),GetWidgetY(d))
    call UnitAddAbility(DUMMY, 'Ahrl')
    if i then
        call SetDestructableInvulnerable(d, false)
    endif
    set result = IssueTargetOrder(DUMMY, "harvest", d)
    if i then
      call SetDestructableInvulnerable(d, true)
    endif
    set d = null
    return result
endfunction
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Ok i can test it ;)
Oh, and actually i didnt think of it, i read it in a tutorial (i thought) which used 'CheckPathabilityCheck' ,, it created an item every time,, they said it was more efficient to make a global one,, (cant remember who write it unfortunately)
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
SetUnitPosition(Dummy,GetWidgetX(d),GetWidgetY(d))

Should be:
call SetUnitPosition(blabla)

Minor mistake ;)

And somehow it didnt destroy trees,, even after i set the radius to 10000,,
Oh, and you removed local unit u = CreateUnit(blabla) , but you didnt removeset u = null[/code] Those were 2 errors and the Trees didnt get killed,, somehow,,
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
I edited the code now, so you must do this:

Copy the dummy unit called caster (Caster System) from Vexorian's CasterSystem map. The id of the copied unit in your map will most probably be 'e000', but if it's not, you MUST change the DUMMY_ID constant integer (in the code above) to that unit's id.

in order for the kill tree part to work. It worked normally for me that way.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
ya i forgot to make a dummy ;D,,
it now worked, but you forgot one thing:
The dummy is global, so you have to order it to stop again,, it now didnt stop harvesting ><,, one minor flaw,, but it looked really strange xD,,
But add the action to stop its harvesting also,, so it stops harvesting,, (lol stupid sentence)

Oh, andi just created a footmen with locust, invulnerable and no model file,,
Rest was not important for the test,, like food cost,, But that worked so,,
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Ok fixed, thanks.

I also put the reason why I'm using that dummy unit below the code:

The reason why I used this specific version of a dummy unit is because I want to make you start using it (if you already haven't), because it's really great. You can have a single dummy unit for casting, effects etc. For effects you can just attach an effect to its origin, then you can modify the size, the vertex and whatever else with just applying the changes for the unit! Having that unit really simplifies everything and you don't have to create a dummy unit for each moving special effect.

All you need to do to be able to modify everything is do the following sequence:

JASS:
call UnitAddAbility(<caster>, 'Amrf')
call UnitRemoveAbility(<caster>, 'Amrf')
call UnitAddAbility(<caster>, 'Aloc')
call SetUnitAnimationByIndex(<caster>, 90)
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Back from vacation.

I see you create a unit every time the function is run, but I don't see it killed or removed.

so when you null the global Dummy variable, you've leaked a unit

I see a unit created only once when Init function is called. Can you be more specific?

Did you also fixed the unit not landing when a unit is below him? I also have a jump spell with the same problem and i don't know how to fix.

I wasn't aware of that bug at all. I'll see if I have the same problem.

When I think about it....what is the best was to fix that problem? What is supposed to happen when a unit lands on another unit? Naturally, it should knock it back a little?
 
Level 7
Joined
Mar 8, 2009
Messages
360
I hope you didn't already changed your code, i thought you already said somewhere before that you had this bug but i think it was an other bug that i understood wrong.

So it's possible that you don't have bug.

Element of water also made a system that you can use to jump units, he moves his jumping unit to the closest free location by using SetUnitPosition after the unit has landed.
 
Top