• 🏆 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!

[JASS] Jump spell...

Status
Not open for further replies.
Level 2
Joined
Apr 15, 2007
Messages
18
Well I know there are some Jump spells out there already, but since Iam a stuborn mofo I want to create one my self.

I want to create one there the user chooses the place to jump, an point. And then I convert the location to coordinates instead of location (its faster, obviously). I know how to make the unit move up into the air with a loop, but I dont know how to get the unit to move forward, and I dont know either how to make the unit go up first, then when he comes to the middle, he starts to go down.

And one more thing, is it possible to make the unit flying with a trigger?

You dont have to create a whole new spell for me, just give me a hint and help me on my way through :p

Thx :)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
And one more thing, is it possible to make the unit flying with a trigger?
Add and remove crow form ('Amrf')

but I dont know how to get the unit to move forward,
A periodic timer which moves the unit with SetUnitX/Y

and I dont know either how to make the unit go up first, then when he comes to the middle, he starts to go down.
[jass=By Shadow1500]function JumpParabola takes real dist, real maxdist,real curve returns real
local real t = (dist*2)/maxdist-1
return (-t*t+1)*(maxdist/curve)
endfunction[/code]
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
It wouldn't be as smooth as using a parabola formula I think. Timers may give you enough eye candy but parabola beats it I'm sure.

You use the parabula WITH a timer...

As to moving to a direction you want, you use trigonometry for that, here is the general idea of it
x = x + distance * cos(angle_in_radians)

y = y + distance * sin(angle_in_radians)

To change an angle to radians, multiply your angle by the constant bj_DEGTORAD.

Here is an example of moving towards the facing of a unit by 40 warcraft units:
JASS:
...
local unit u = GetTriggerUnit()
local real angle = GetUnitFacing(u)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
call SetUnitX(u) = x + 40 * cos(angle * bj_DEGTORAD)
call SetUnitY(u) = y + 40 * sin(angle * bj_DEGTORAD)
...
 
Level 2
Joined
Apr 15, 2007
Messages
18
Thx PurplePoot and GhostWolf for your answers :) I will try your tips, and I will come back here if I run into any problem :) And also thx to emperor_d3st =)
 
Level 2
Joined
Apr 15, 2007
Messages
18
Hmm, Ive got trouble... I dont know how to use a timer to make him go forward or up :/ I checked the Jump Parabola spell but I dont get the idea. And I also searched the forum, but I couldnt find anything good. If you know a thread or if you know how to use a timer. Please describe for me :)
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
I'm also a novice so please correct me if I'm wrong, but you can use timers like this:

JASS:
function Jump takes nothing returns nothing
//do your stuff here
endfunction

...
call TimerStart(t, 0.05, true, function Jump)
...

So you start a periodic timer (TimerStart(yourTimer, yourTime, ThisBooleanMakesItPeriodic!) which executes the Jump function every time the timer expires.
 
Level 11
Joined
Apr 6, 2008
Messages
760
ye like that dest but u need handle vars or struct and datasystem to get like the unit that jumps

JASS:
function Jump takes nothing returns nothing
local timer t = GetExperiedTimer()
local unit caster = GetHandleHandle(t,"caster)
//do your stuff here
endfunction

...
local unit caster = GetTriggerUnit
local timer t = CreateTimer()

call SetHandleHandle(t,"caster",caster)

call TimerStart(t, 0.05, true, function Jump)
...

something like this
 
Level 17
Joined
Apr 13, 2008
Messages
1,597
Yup, I'm not familiar with them though.
Here is a link to some "mighty knockback spell with timers and handlevars" tutorial:

http://world-editor-tutorials.thehelper.net/cat_usersubmit.php?view=28217

I think it explains the thing well.
I'm not sure if you should use handlevars though. I see the experts write "handle vars are obsolete, use structs" everywhere. I don't know much about structs yet so better wait for someone more experienced clarify this.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I think it explains the thing well.
I'm not sure if you should use handlevars though. I see the experts write "handle vars are obsolete, use structs" everywhere. I don't know much about structs yet so better wait for someone more experienced clarify this.

There are several ways to do this using either Game Cache, H2I bug, Structs + H2I, Structs + global struct array.

Game Cache is the simple game cache of warcraft.
H2I (handlevars, vexorian's thingy which I never remember the name of) uses a weird return bug which allows you to somehow change a handle to a integer and back (don't ask me how it works, I never understood it myself).

Structs + H2I simply uses the H2I systems but with structs. Now you can pass multiple values with a single set/get like this code demonstrates

JASS:
//H2I
function oldTimer takes nothing returns nothing
     local timer t = GetExpiredTimer()
     local unit u = GetHandleUnit(t, "u")
     local integer i = GetHandleInt(t, "i")
     local real r = GetHandleReal(t, "r")
endfunction
function old takes nothing returns nothing
     local timer t = CreateTimer()
     call SetHandleHandle(t, "u", unit_value)
     call SetHandleInt(t, "i", integer_value)
     call SetHandleReal(t, "r", real_value)
     call TimerStart(t, real, boolean, function oldTimer)
endfunction

//Structs + H2I

struct structName
     unit u
     integer i
     real r
endstruct

function newTimer takes nothing returns nothing
     local timer t = GetExpiredTimer()
     local structName s = GetHandleInt(t, "struct")
     local unit u = s.u
     // etc
endfunction
function new takes nothing returns nothing
     local timer t = CreateTimer()
     local structName s = structName.create() // this creates a new structName object. You might look at it as any other variable just that it holds more information then a normal variable
     set s.u = unit_value // to communicate with values inside a struct you use the structObjectName.structVariable syntax
     set s.i = integer_value
     set s.r = real_value
     call SetHandleInt(t, "struct", s) // structs are actually integers. This may confuse you but it isn't really important why it is so.
     call TimerStart(t, real, boolean, function newTimer)
endfunction

This may seem pretty stupid, but function calls are "slow" (in programming view) and thus this is a better solution then H2I alone.

The probably fastest way (but it's only good for a certain type of codes), is using a global array of structs and in the timer looping between them.
Here is a poor example of a base code

JASS:
globals
     timer T = CreateTimer()
     name array Struct
     integer Count = 0
endglobals

struct name
     //values
endstruct

function loop takes nothing returns nothing
     local name n
     local integer = 0
     loop
          exitwhen i > Count
          set n = Struct[i]
          // do stuff with the current struct
          set i = i + 1
     endloop
     // you will probably want to remove structs from the array after they are useless
endfunction

function create takes (values) returns nothing
     local name n = name.create()
     // set values etc
     if Count == 0 then // in case there are no structs in the array
        TimerStart(T, real, boolean, function loop)
     endif
     set Struct[Count] = n // putting our struct into the array
     set Count = Count + 1
endfunction

As you can see, this is only good for a certain type of codes (Knockbacks and that kind of stuff).

On a side note - you must have JNGP (Jass New Gen Pack) to use structs, global declarations in the code, and a lot more usefull things.
 
Status
Not open for further replies.
Top