| 04-25-2007, 12:48 AM | #1 |
My Problem, My map requires a jump ability that I have taken from an open source map (notd am 1.3). Having very limited jass knowledge attempting to implement it into my map has failed. I got it to the point where my unit would "fly" but will not come back down. I'm 99% sure the problem is in the JumpStart and JumpCallBack functions and that the problem is the local varables are not following the timer to the next function. I would really appreciate it if someone would give me the proper code to replace where i went wrong. Thank You in Advance. What im using... gc_handlevars = gamecache gc_array = gamecache A003 = Jump - skill used by player [Based on Flamestrike] A004 = Jump Effect - ability given to hero, I assume so it can fly [Based on Crow Form] A005 = Dazed - ability given to hero when jumps from too high "kattana's"... JASS://=========================================================================== // Game Cache and Handles //=========================================================================== //Based on Kattana's FadeUnitVertexColor function InitHandleVars takes nothing returns nothing set udg_gc_handlevars = InitGameCache("jasslocalvars.w3v") endfunction function H2I takes handle h returns integer return h return 0 endfunction function FlushHandleLocals takes handle h returns nothing call FlushStoredMission(udg_gc_handlevars, I2S(H2I(h)) ) endfunction function SetHandleInteger takes handle h, string name, integer i returns nothing call StoreInteger(udg_gc_handlevars, I2S(H2I(h)), name, i) endfunction function GetHandleInteger takes handle h, string name returns integer return GetStoredInteger(udg_gc_handlevars, I2S(H2I(h)),name) endfunction function SetHandleReal takes handle h, string name, real r returns nothing call StoreReal(udg_gc_handlevars, I2S(H2I(h)), name, r) endfunction function GetHandleReal takes handle h, string name returns real return GetStoredReal(udg_gc_handlevars, I2S(H2I(h)),name) endfunction function SetHandleHandle takes handle h, string name, handle value returns nothing call StoreInteger(udg_gc_handlevars, I2S(H2I(h)), name, H2I(value)) endfunction function GetHandleUnit takes handle h, string name returns unit return GetStoredInteger(udg_gc_handlevars, I2S(H2I(h)),name) return null endfunction function SetHandleBoolean takes handle h, string name, boolean b returns nothing call StoreBoolean(udg_gc_handlevars, I2S(H2I(h)), name, b) endfunction function GetHandleBoolean takes handle h, string name returns boolean return GetStoredBoolean(udg_gc_handlevars, I2S(H2I(h)),name) endfunction function SetHandleString takes handle h, string name, string s returns nothing call StoreString(udg_gc_handlevars, I2S(H2I(h)), name, s) endfunction function GetHandleString takes handle h, string name returns string return GetStoredString(udg_gc_handlevars, I2S(H2I(h)),name) endfunction function GetHandleForce takes handle h, string name returns force return GetStoredInteger(udg_gc_handlevars, I2S(H2I(h)),name) return null endfunction function GetHandleWeatherEffect takes handle h, string name returns weathereffect return GetStoredInteger(udg_gc_handlevars, I2S(H2I(h)),name) return null endfunction function GetHandleLocation takes handle h, string name returns location return GetStoredInteger(udg_gc_handlevars,I2S(H2I(h)),name) return null endfunction function GetHandlePlayer takes handle h, string name returns player return GetStoredInteger(udg_gc_handlevars,I2S(H2I(h)),name) return null endfunction function GetHandleTimer takes handle h, string name returns timer return GetStoredInteger(udg_gc_handlevars, I2S(H2I(h)),name) return null endfunction function GetHandleTriggerAction takes handle h, string name returns triggeraction return GetStoredInteger(udg_gc_handlevars,I2S(H2I(h)),name) return null endfunction //array data type that can be passed function InitializeArrayType takes nothing returns nothing set udg_gc_array = InitGameCache("arrays.w3v") endfunction function CreateArray takes string name returns nothing call StoreInteger(udg_gc_array,name,"n",0) endfunction function GetLength takes string name returns integer return GetStoredInteger(udg_gc_array,name,"n") endfunction function AddItemToArray takes string name, integer x returns nothing local integer i = GetLength(name) + 1 call StoreInteger(udg_gc_array,name,I2S(i),x) call StoreInteger(udg_gc_array,name,"n",i) endfunction function GetI takes string name, integer i returns integer return GetStoredInteger(udg_gc_array,name,I2S(i)) endfunction function SetI takes string name, integer i, integer x returns nothing call StoreInteger(udg_gc_array,name,I2S(i),x) endfunction function SetS takes string name, integer i, string s returns nothing call StoreString(udg_gc_array,name,I2S(i),s) endfunction function GetS takes string name, integer i returns string return GetStoredString(udg_gc_array,name,I2S(i)) endfunction function I2T takes integer i returns timer return i return null endfunction function surucompare takes real c, real t, real s returns boolean return ((s>=0 and c>=t) or (s<0 and c<=t)) endfunction function SmoothUnitResize_Update takes nothing returns nothing local timer t = GetExpiredTimer() local real dsc = GetHandleReal(t,"dsc") local real csc = GetHandleReal(t,"csc") + dsc local real tsc = GetHandleReal(t,"tsc") local unit u = GetHandleUnit(t,"unit") if ( u == null or surucompare(csc,tsc,dsc)) then call FlushHandleLocals(t) call DestroyTimer(t) set t = null else call SetHandleReal(t,"csc",csc) endif call SetUnitScale(u,csc,csc,csc) endfunction function SmoothUnitResize takes unit u, real cscale, real targetscale, real time returns nothing local timer t local real dt = 0.05 if time<=0 then call SetUnitScale(u,cscale,cscale,cscale) endif set t = CreateTimer() call SetUnitScale(u,cscale,cscale,cscale) call SetHandleReal(t,"csc",cscale) call SetHandleReal(t,"tsc",targetscale) call SetHandleReal(t,"dsc",dt*(targetscale-cscale)/time) call SetHandleHandle(t,"unit",u) call TimerStart(t,dt,true,function SmoothUnitResize_Update) endfunction function ShiftMoveSpeed takes unit u, real shift returns nothing local string s = I2S(H2I(u)) local real ms if GetUnitState(u,UNIT_STATE_LIFE)>0 then set ms = GetStoredReal(udg_gc_handlevars,s,"MoveSpeed") call StoreReal(udg_gc_handlevars,s,"MoveSpeed",ms+shift) call SetUnitMoveSpeed( u, GetUnitDefaultMoveSpeed(u) + ms + shift ) endif endfunction JASS:function JumpDamage takes nothing returns nothing local unit u = GetHandleUnit(null,"jumpunit") call SetHandleInteger(null,"jumpunit",0) call SetUnitAnimation(u,"death") call UnitDamageTargetBJ( u, u, 120.0, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL ) call UnitAddAbility(u,'A005') call ShiftMoveSpeed(u,-80.0) call TriggerSleepAction(0) call ResetUnitAnimation(u) call PolledWait(2.5) call ShiftMoveSpeed(u,30.0) call PolledWait(2.5) call UnitRemoveAbility(u,'A005') call ShiftMoveSpeed(u,50.0) set u = null endfunction function JumpCallBack takes nothing returns nothing local timer t = GetExpiredTimer() local integer i = GetHandleInteger(t,"i") local real x0 = GetHandleReal(t,"x0") local real y0 = GetHandleReal(t,"y0") local real x1 = GetHandleReal(t,"x1") local real y1 = GetHandleReal(t,"y1") local integer maxiter = R2I(SquareRoot((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0))/20) local real s = i/(maxiter + 0.001) local unit u = GetHandleUnit(t,"u") if t==null then call BJDebugMsg("Bunny hop timer in hell") elseif u==null then call FlushHandleLocals(t) call DestroyTimer(t) elseif i>maxiter then call FlushHandleLocals(t) call DestroyTimer(t) call SetUnitFlyHeight(u,0.00,1000.00) call SetUnitPathing(u,true) call UnitRemoveAbility(u,'A004') if GetTerrainCliffLevel(x0,y0)-GetTerrainCliffLevel(x1,y1)>1 then call SetHandleHandle(null,"jumpunit",u) call ExecuteFunc("JumpDamage") endif else call PauseUnit(u,true) call SetUnitX(u,(1.0-s)*x0 + s*x1) call SetUnitY(u,(1.0-s)*y0 + s*y1) call PauseUnit(u,false) call SetHandleInteger(t,"i",i+1) endif set t = null set u = null endfunction function JumpStart takes unit u, real x0, real y0, real x1, real y1 returns nothing local integer t = H2I(CreateTimer()) call AttachSoundToUnit(gg_snd_Jump, u) call SetSoundVolume(gg_snd_Jump, 127) call StartSound(gg_snd_Jump) call UnitAddAbility(u,'A004') call SetUnitPathing(u,false) call SetUnitFlyHeight(u,45.00,500.00) call SetHandleHandle(I2T(t),"u",u) call SetHandleReal(I2T(t),"x0",x0) call SetHandleReal(I2T(t),"y0",y0) call SetHandleReal(I2T(t),"x1",x1) call SetHandleReal(I2T(t),"y1",y1) call SetHandleInteger(I2T(t),"i",1) call TimerStart(I2T(t),0.030,true,function JumpCallBack) endfunction function JumpConditions takes nothing returns boolean if ( not ( GetSpellAbilityId() == 'A003' ) ) then return false endif return true endfunction function Jump takes nothing returns nothing local unit u = GetTriggerUnit() local location l = GetSpellTargetLoc() local location l2 = GetUnitLoc(u) local real x0 = GetLocationX(l2) local real y0 = GetLocationY(l2) local real x1 = GetLocationX(l) local real y1 = GetLocationY(l) local real dx = x0 - x1 local real dy = y0 - y1 if GetTerrainCliffLevel(x0,y0)<GetTerrainCliffLevel(x1,y1) then call DisplayTimedTextToPlayer( GetOwningPlayer(u), 0, 0, 3.00, "Target point is too high." ) call IssueImmediateOrder(u,"holdposition") call RemoveLocation(l) set l = null call RemoveLocation(l2) set l2 = null set u = null return elseif ( dx*dx+dy*dy>=(325.00)*(325.00) or (dx*dx+dy*dy>=(225.00)*(225.00) and GetTerrainCliffLevel(x0,y0)==GetTerrainCliffLevel(x1,y1)) ) then call DisplayTimedTextToPlayer( GetOwningPlayer(u), 0, 0, 3.00, "Distance too great." ) call IssueImmediateOrder(u,"holdposition") call RemoveLocation(l) set l = null call RemoveLocation(l2) set l2 = null set u = null return elseif x1>GetRectMaxX(bj_mapInitialPlayableArea) or x1<GetRectMinX(bj_mapInitialPlayableArea) or y1>GetRectMaxY(bj_mapInitialPlayableArea) or y1<GetRectMinY(bj_mapInitialPlayableArea) then call DisplayTimedTextToPlayer( GetOwningPlayer(u), 0, 0, 3.00, "Off Map." ) call IssueImmediateOrder(u,"holdposition") call RemoveLocation(l) set l = null call RemoveLocation(l2) set l2 = null set u = null return endif call RemoveLocation(l) set l = null call RemoveLocation(l2) set l2 = null call JumpStart(u,x0,y0,x1,y1) set u = null endfunction //=========================================================================== function InitTrig_Jump takes nothing returns nothing set gg_trg_Jump = CreateTrigger() call TriggerRegisterAnyUnitEventBJ( gg_trg_Jump, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Jump, Condition( function JumpConditions ) ) call TriggerAddAction( gg_trg_Jump, function Jump ) endfunction |
| 04-25-2007, 12:28 PM | #2 |
Is the spell cast on target/point or cast on self because if the spell is cast on self, then the height would be infinite. |
| 04-25-2007, 01:45 PM | #3 |
The jump spell is based on flamestrike. So the height should not be infinite. |
| 04-27-2007, 12:22 AM | #4 |
try using channel |
| 04-27-2007, 03:46 AM | #5 |
Tried using channel, did not solve my problem. Is there a reason for your suggestions or are you just making me jump through hoops ? Edit: Anyways does not matter now, I found my anwser. The following was required in a trigger in order for the system to work. Wish i had known this sooner :P JASS:function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing set udg_gc_handlevars = InitGameCache("jasslocalvars.w3v") endfunction //=========================================================================== function InitTrig_Untitled_Trigger_004 takes nothing returns nothing set gg_trg_Untitled_Trigger_004 = CreateTrigger( ) call TriggerAddAction( gg_trg_Untitled_Trigger_004, function Trig_Untitled_Trigger_004_Actions ) endfunction |
