• 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.

[vJass] vJass Math Genious Needed!

Status
Not open for further replies.
Level 18
Joined
Oct 18, 2007
Messages
930
Ok im making a spell that is like you summon +2 balls that starts at a height and spins down and towards the target like a whirlpool(Spiral) but just the balls. ( The time that the balls take to move down and to the target is depending on 4 globals, 3 setups and one the declares the over time that this is happening, like if you want it fast or slow :p )

Ok i need some math fixes in my spell like: To calculate some things over time etc.

The system i use made by Hanky.
JASS:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//X               °                                        Mapmaking since 2006...      X
//X            °                                                                        X
//X          °                                                                          X
//X         °                                                                           X
//X       °°°ÛÜ                                                                         X
//X      °°X°ÛÛÛ                          ÛÛÛÛÛÛÛÛ     ÿÜÛÛÛÛÛÛÛÛÜ                      X
//X     °°XX° ÛÛÛ        ßÛÛÛÛÛ        ÛÛÛÛÛÛÛÛÛÛÛÛ   ÛÛÛÛÛÛÛÛÛÛÛÛÛ                     X
//X     °XX ° ÛÛÛÛ         ÛÛÛÛÜ     ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ  ÛÛÛÛÛÛÛÛÛÛÛÛÛÛ                    X
//X     °XX °  ÛÛÛÛÛ        ÛÛÛÛ    ÛÛÛÛÛß    ßÛÛÛÛÛÛ  ÛÛÛÛÛÛÛÛÛÛÛÛÛÛ                   X 
//X    °°XXX°° ÛÛÛÛÛÛÜ       ÛÛÛÜ  ÛÛÛÛÛ        ßÛÛÛÛÛ ßÛÛÛÛ    ÛÛÛÛÛÛ                  X  
//X   °°°°°°°°  ÛÛÛÛÛÛÛ      ÛÛÛÛ  ÛÛÛÛ                 ÛÛÛÛ      ÛÛÛÛÜ                 X  
//X             ÛÛÛÛÛÛÛÛ     ÛÛÛÛ  ÛÛÛÛ        ÛÛÛÛÛÛÛ  ÛÛÛÛÛÜ     ÛÛÛÛ                 X  
//X   °°°°°°°°  ÛÛÛÛÛÛÛÛÛ    ÛÛÛÛÜ  ÛÛÛÛÜ     ÛÛÛÛÛÛÛÛ   ÛÛÛÛÛÜ  ÜÛÛÛÛÛÛ                X
//X   °°XXXXX°   ÛÛÛÛ  ÛÛÛÜ  ÛÛÛÛÛ   ÛÛÛÛÛÛÜ    ßÛÛÛÛÛ   ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ                X
//X   °°XXXXX °° ÛÛÛÛ   ÛÛÛÛÜ ÛÛÛÛ °°°ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ°°° ÛÛÛÛÛÛÛÛÛÛÛÛÛß                X
//X   °  XXXXX °°ÛÛÛÛÛ°°°°ÛÛÛÛÛÛÛÛ°°XX ÛÛÛÛÛÛÛÛÛÛÛÛÛÛ XXX°°ÛÛÛÛÛÛÛÛÛÛÛ     ÛÛÛ          X
//X   °°  XXXXX ÜÛÛÛÛÛÛ X ÛÛÛÛÛÛÛÛÛ XXX ÛÛÛÛÛÛÛÛÛÛÛ  XXXXXX  ÛÛÛÛÛÛÛ°      ÛÛÛ          X
//X    °°  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX °°°°°°   °°°°      X
//X     °°   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX °°°°°X°°       X
//X      °°°  XXXXXXXXXX  °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° XXXXXXXXXXXXXXXXX°°      X
//X        °°°°°°°°°°°°°°°°                                  °°°°°°°°  XXXXXXX °°°      X
//X                                                                  °°°°°° XX °°       X
//X   ...2008 and still moving on.                                        °°°°°°°       X
//X                                                                             °°      X
//X   Screen Solution: 1280x1024                             Visit [url=http://www.ngo.clan.su]Clan NgO - Main page[/url]!     X
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//! textmacro CostumInterface takes Loop,End,path,periodic
library CostumInterface$path$ initializer init
   interface $path$Loop
     boolean active=false
     boolean paused=false

     method $Loop$ takes nothing returns nothing
     method $End$ takes nothing returns nothing
   endinterface
   
   globals
     private $path$Loop array $path$_loopObject
     private integer $path$_size=0
	 
     private trigger $path$_loop
     constant real $path$_periodic=$periodic$
   endglobals
   
   function AddObjectTo$path$ takes $path$Loop loopObject returns integer
         set $path$_loopObject[$path$_size]=loopObject
         set $path$_loopObject[$path$_size].active=true
	 set $path$_size=$path$_size+1
	 
	 if not IsTriggerEnabled($path$_loop) then
	   call EnableTrigger($path$_loop)
	 endif

     return $path$_size
   endfunction
   
   private function Loop$path$ takes nothing returns nothing
      local integer index=0
	  
	  loop
	    exitwhen index==$path$_size
	    if $path$_loopObject[index].active and not $path$_loopObject[index].paused then
		 call $path$_loopObject[index].$Loop$.execute()
		 set index=index+1
	    elseif $path$_loopObject[index].paused then
                 set index=index+1
            else
		 call $path$_loopObject[index].$End$()
		 set $path$_size=$path$_size-1
		 set $path$_loopObject[index]=$path$_loopObject[$path$_size]
            endif
	  endloop
	  
	  if $path$_size<=0 then
	    call DisableTrigger($path$_loop)
	  endif
   endfunction
   
   private function init takes nothing returns nothing
     set $path$_loop=CreateTrigger()
     call TriggerRegisterTimerEvent($path$_loop,$path$_periodic,true)
     call TriggerAddAction($path$_loop,function Loop$path$)
     call DisableTrigger($path$_loop)
   endfunction
endlibrary
//! endtextmacro

//! runtextmacro CostumInterface("motion","endmotion","Motion","0.03")

Ok now for my unfinished Spell

JASS:
scope LightningStrike initializer Init_Strike

    globals
        private constant integer AID         = 'A000'              // The Ability beign cast
        private constant integer DumTyp      = 'n000'             // The dummy unit of the Ball
        private constant string Look         = ""                // This is how the missile looks like
        private constant string Ex           = ""               // The Effect that the Ball create
        private constant string Attachment   = "origin"        // The Attachment for the Look-alike for the Ball
        private constant real SHeight        = 1000.          // The Starting Height of the Ball
        private constant real MHeight        = 5.            // The lowest vale of the Ball beafore it "explodes"
        private constant real Weight         = 4.           // The Weight of the Ball ( Higher numbers equals Faster Drop )
        private constant real Speed          = 8.          // The Far-Off speed the Ball travel inn ( If this is a large number the circle is going to be large )
        private constant real Rotation       = 4.         // The speed of the Ball traveling around the target
        private constant real AOE            = 200.      // This is the Area Of Effect the damage does to enemies
        private constant real Dam            = 75.      // This damage is divided by 2 and timed with the level value (see line 24- 26)
        private constant real Offset         = 400.    // The Offset the Balls Start Inn
        private constant real MOffset       = 20
        private constant real T2E            = 1.      // The Speed To End ( in other words, the time it will take to the spell to end. 1 Will make it take 1 seccond "The timer is at 0.03 secconds")
        
//************* End of Constants, DO NOT CHANGE THEESE VALUES BELOW THIS LINE -CRITICAL!- ****************

        private group G
    endglobals

    private constant function Damage takes integer lvl returns real
        return Dam/2*lvl
    endfunction

    private struct BallMotion extends MotionLoop
        unit Ball
        unit Target
        unit Caster
        real BX
        real BY
        real TX
        real TY
//- - - - - - - - - - - - All of theese values has something to do with the global real S2E - - - - - - - - - - 
        real HL //The Height Loss ( THIS HAS SOMETHING TO DO WITH THE GLOBAL WEIGHT )
        real S //The Speed ( THIS HAS SOMETHING TO DO WITH THE GLOBAL SPEED )
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        real BHeight
        real Distance
        real Angle
        integer lvl
        effect E

        method motion takes nothing returns nothing
            local real x
            local real y
            if .BHeight<=MHeight or .Distance<=MOffset then
                set .active=false
            else
                set .BX=GetUnitX(.Ball)
                set .BY=GetUnitY(.Ball)
                set .TX=GetUnitX(.Target)
                set .TY=GetUnitY(.Target)
                set .Angle=.Angle+Rotation
                set .Distance = SquareRoot((.TX-.BX)*(.TX-.BX)+(.TY-.BY)*(.TY-.BY))
                set x =.BX+.Distance-.S*Cos(.Angle*bj_DEGTORAD)
                set y =.BY+.S*Sin(.Angle*bj_DEGTORAD)
                call SetUnitFlyHeight(.Ball,.BHeight-.HL,0.)
                call SetUnitPosition(.Ball,x,y)
            endif
        endmethod
        
        method endmotion takes nothing returns nothing
            set .TX=GetUnitX(.Target)
            set .TY=GetUnitY(.Target)
            call RemoveUnit(.Ball)
            call DestroyEffect(AddSpecialEffect(Ex,.TX,.TY))
            call DestroyEffect(.E)
            call UnitDamagePoint(.Caster,0.,AOE,.TX,.TY,Damage(.lvl),false,true,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
            set .Ball=null
            set .Target=null
            set .Caster=null
            set .E=null
            call .destroy()
        endmethod

    endstruct
    
    private function Strike_Conditions takes nothing returns boolean
        return GetSpellAbilityId() == AID
    endfunction

    private function Strike_Actions takes nothing returns nothing
        local unit A=GetTriggerUnit()
        local unit B=GetSpellTargetUnit()
        local player P=GetOwningPlayer(A)
        local integer index=0
        local real Angle
        local integer lvl=GetUnitAbilityLevel(A,AID)
        local real x=GetUnitX(B)
        local real y=GetUnitY(B)
        local real xx
        local real yy
        local real N=360/R2I(lvl+1)
        local BallMotion bm
        loop
            exitwhen index > lvl
            set bm = BallMotion.create()
            set bm.Caster = A
            set bm.Target = B
            set bm.lvl = lvl
//- - - - - - - - - - - THINGS THAT NEEDS A FIX - - - - - - - - - - - - - - - -
            set bm.HL = 0 // DONT HAVE THE MATH THINGY FOR THIS!
            set bm.S = 0 // DONT HAVE THE MATH THINGY FOR THIS!
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
            set xx =x+Offset*Cos((I2R(index)*N)*bj_DEGTORAD)
            set yy =y+Offset*Sin((I2R(index)*N)*bj_DEGTORAD)
            set bm.Ball=CreateUnit(P,DumTyp,xx,yy,0)
            set bm.BHeight=SHeight
            call SetUnitFlyHeight(bm.Ball,bm.BHeight,0.)
            set bm.E=AddSpecialEffectTarget(Look,bm.Ball,Attachment)
            set index=index+1
        endloop
        set A=null
        set B=null
        set P=null
    endfunction

//===========================================================================
    private function Init_Strike takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, Condition( function Strike_Conditions ) )
        call TriggerAddAction( t, function Strike_Actions )
        set t = null
    endfunction
endscope

Edit: Picture!
asdasdasdasdasdeeeeee.png
 
Last edited:
Level 18
Joined
Oct 18, 2007
Messages
930
Be more clear what you are after.

I need the values so that the global value T2E (time to end) controlls the time it takes for the missile to fall down and hit the target from a distance.

The balls spin around the target in a vortex. When the balls are in range and the Height is almost 0 then they do damage.

I need the math calculations for making the T2E real work.

The values it controlls are the speed that the missile falls and the speed that the missile moves towards the targeted point.

Hope this helped
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Simple solution is to make them fall at a constant rate over that time.
You then make them also close in at a constant rate over that time separatly.
Thus they both close in and reach height 0 at the same time.

Basically what I am saying is you handle the height change and the motion of the balls separatly.

For height loss per update, its simply
(start height - end height) * update delay / time to fall

This is basically linear and will result in it falling at the same rate and ariving at the ground at the correct time.

I have no idea what speed is meant to be. Is it the rate at which the radius of the circle they spin in decreases or the rate of their movement speed around the arc? Please explain more clearly how you want them to circle in.

If you do mean the rate of change of radius, I would imagine.
(start radius - end radius) * update delay / time to fall

Again its linear and as long as they are started at the same time and finish at the same time, they should be syncronized.
 
Level 18
Joined
Oct 18, 2007
Messages
930
Ok you have the global
JASS:
private constant real SHeight        = 1000.[/JASS that is the height that the ball is starting at.
The [code=jass]private constant real MHeight        = 5.
is the minimum height of the ball, or the end value of the height.
The
JASS:
private constant real Weight        = 4.
is the rate that it is dropping.
The
JASS:
private constant real Speed          = 8.
is the value that the Main Speed to the target
The
JASS:
private constant real Offset         = 400.
is the offset that the ball start off. This has something to do with the speed.
the
JASS:
private constant real MOffset       = 25.
is the minimum range of the ball. The ball have to travel from the offset to this value in the T2E time
The
JASS:
private constant real T2E            = 1.
Is the over time that all the constant above this are used inn. The ball have to get to the height <= MHeight over that time, and the distance between the ball and the target have to be <= MOffset over that time.

I want the T2E to controll how long the whole spell will take. And by doing this you can change every value and make it happen over that time. Else it would be hard to change values ;)

Over all the timer is at 0.03 so it is not 0.1 or 0.01.
 
Last edited:
Status
Not open for further replies.
Top