• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] [vJass] Floating System

Status
Not open for further replies.
Level 3
Joined
Dec 27, 2008
Messages
56
Hey guys,

This is my new floating system.
Read everything over the system first.
Any questions, bugs, etc.. post here in the thread.

JASS:
//*******************************************************************************************
//
// FLOATING SYSTEM v1.02
//
//*******************************************************************************************
//
// by Razoron from hiveworkshop.com
//
// REQUIRES: Timer Utils, vJass
//
//Discription:
//This is a universal floating system to do jumps,...
//
//How to use:
//call Floating(unit WhichUnit, real Delay, boolean X(*), string ("up" or "down" or "middle"), real height, real strong)
//*If you want a normal jump with friction: true
//If you want a jump without friction: false
//
//up: the unit floats up
//down: the unit floats down
//middle: both
//
//If you use X=false, you can choose the height the unit should flow. Strong doesn't metter.
//If you use X=true, you can choose the force(strong). Height doesn't metter.
//WARNING: The unnecessary parameter should be replaced with a number you want.
//         But don't leave it out!
//
//YOU NEED A DUMMIE SPELL:
//1.Create a new spell(metramorphose) with the ID 'FLYY'.
//2.Set the alternative figure to a gryphon rider.
//3.Set all values to 0.
//4.Done
//
//How to import:
//1.Copy this code in a new trigger.
//2.Create the dummie spell.
//3.Give Credits to Razoron!
//
//*******************************************************************************************


library Floatingg requires TimerUtils

 globals
//
// CONFIGURABLE DATA
// 
//TIMEOUT:
//The interval of the timer.
//
//ID:
//The ID of your dummie spell.

  private constant real TIMEOUT=0.04
  private constant integer ID='FLYY'
 endglobals 

 private struct Floatinggg
  unit fl
  real delay
  boolean b
  integer steps
  real height
  integer mode
  real rate
  real strong
  real bonus
  real bonusw
  timer t
  real totalsteps
 endstruct 
 
 private function GoFloating takes nothing returns nothing
  local timer t=GetExpiredTimer()
  local Floatinggg f=GetTimerData(t)                                                    
  local real height=GetUnitFlyHeight(f.fl)
  if f.mode==1 and f.b==true then
   set f.bonus=f.bonus-f.bonusw
  endif
  if f.mode==3 and f.b==true then
   set f.bonus=f.bonus+f.bonusw
  endif
  if f.mode==2 and f.b==true then
   set f.bonus=f.bonus-f.bonusw
  endif 
  set f.steps=f.steps-1
  if f.steps<=0 and f.mode!=2 then
   call f.destroy()
   call ReleaseTimer(t)
  elseif f.steps<=0 and f.mode==2 and f.b==false then
   call f.destroy()
   call ReleaseTimer(t)
  endif 
  if f.steps<=0 and f.mode==2 and GetUnitFlyHeight(f.fl)<=10 and f.b==true then
   call f.destroy()
   call ReleaseTimer(t)
  endif
  if f.b==false then
   call SetUnitFlyHeight(f.fl,height+f.rate,10000000)
  else
   call SetUnitFlyHeight(f.fl,height+f.bonus,10000000)
  endif
  if f.steps<=f.totalsteps/2 and f.mode==2 and f.b==false and f.rate>=0 then
   set f.rate=-(f.rate)
  endif
  set t=null
 endfunction
 
 function Floating takes unit f, real delay, boolean b, string upordownormiddle, real height, real strong returns nothing
  local Floatinggg flo=Floatinggg.create()
  local timer t=CreateTimer()
  local real b1=0
  set flo.t=t
  set flo.fl=f
  set flo.delay=delay
  set flo.b=b
  set flo.height=height
  set flo.steps=R2I(delay)/R2I((TIMEOUT*100))
  set flo.strong=strong
  if upordownormiddle=="up" and b==true then
   set flo.bonus=strong
  elseif upordownormiddle=="down" and b==true then
   set flo.bonus=strong
  elseif upordownormiddle=="middle" and b==true then
   set flo.bonus=strong
  endif 
  set flo.totalsteps=flo.steps
  if upordownormiddle=="up" and b==true then
   set flo.bonusw=flo.bonus/flo.delay
  elseif upordownormiddle=="down" and b==true then
   set flo.bonusw=-(flo.bonus/flo.delay)
   set flo.bonus=0
  elseif upordownormiddle=="middle" and b==true then
   set flo.bonusw=2*(flo.bonus/flo.delay)
  elseif b==false and upordownormiddle=="middle" then
   set flo.rate=2*(height/delay)
  elseif b==false and upordownormiddle=="up" then
   set flo.rate=height/delay
  elseif b==false and upordownormiddle=="down" then
   set flo.rate=-(height/delay)
  endif
  call UnitAddAbility(flo.fl,ID)
  call UnitRemoveAbility(flo.fl,ID)
  if upordownormiddle=="up" then
   set flo.mode=1
  elseif upordownormiddle=="middle" then
   set flo.mode=2
  elseif upordownormiddle=="down" then
   set flo.mode=3
  endif
  call SetTimerData(t,flo)
  call TimerStart(t,0.01,true,function GoFloating)
  set t=null
 endfunction
  
endlibrary

v1.01 configurable data section added

v1.02 TimerUtils instead of ABC

GL&HF Give Credits! Give Feedback if you want!
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
You can do this with one timer and a global loop instead of creating a new timer for every unit. Also, 0.01 timeout is a little overkill; i recommend 0.03 or 0.04. Also, it would be better to have a config section where the user can set the dummy ability's id to whatever they want instead of forcing them to use 'FLYY'.
 
Level 11
Joined
Feb 22, 2006
Messages
752
Something like:

JASS:
library Floating initializer init

globals
    private constant integer TIMEOUT = 0.03

    private timer t
    private Float array floatArray
    private integer floatCount
endglobals

private struct Float
    // ...
    boolean toDestroy = false
endstruct

private function Callback takes nothing returns nothing
    local integer i = 0
    local Float this
    loop
        exitwhen (i >= floatCount)
        set this = floatArray[i]
        if (this.toDestroy) then
            call this.destroy()
            set floatArray[i] = floatArray[floatCount - 1]
            set floatCount = floatCount - 1
            set i = i - 1
        else
            // do movement stuff here
        endif
        set i = i + 1
    endloop
    if (floatCount == 0) then
        call PauseTimer(t)
    endif
endfunction

function Floating takes ... returns nothing
    local Float this = Float.create(...)
    // set up flying data...
    set floatArray[floatCount] = this
    set floatCount = floatCount + 1
    if (floatCount == 1) then
        call TimerStart(t, TIMEOUT, true, function Callback)
    endif
endfunction

private function init takes nothing returns nothing
    set t = CreateTimer()
    set floatCount = 0
endfunction
endlibrary
 
Level 14
Joined
Nov 18, 2007
Messages
816
No, you wont stay with your old timers. If you already use multiple timers, recycle them. If you already recycle them, use TimerUtils instead of ABC to attach the struct to the timer.
Your math for setting the length of the jump (time) is borked. I mean, delay is an integer in 1/100 seconds? Dont use strings where i can input *everything*. Integer combined with global constants, anyone? If not an integer, then i'd still like to have global constants.
I'd like to modify the granulation as well, so make a globals constant holding the period of the timer.


I think its a useless system unless the user has the need for something exactly like it.
 
Status
Not open for further replies.
Top