 |   |  |  |
| "Graveyard" Resources which were not approved are moved to this section. |
02-03-2008, 10:35 PM
|
#1 (permalink)
|
Just another Nobody
Join Date: Jul 2007
Posts: 2,384
|
Raising/Lowering heights with a timer
I made this nice and easy code that raises or lowers units based on a timer.
You set the height which the unit will stop moving/die (you choose if he dies based on a boolean) and what speed he moves at.
Here is the code with more explenations inside it
//****************************************************************************************// Move unit's height with timers// call goingdown(whichUnit,speed,deadheight,kill)//// Warning ! The dead height CANNOT BE 0 ! (I think this is a bug in warcraft)// If you want your units to die/stop on the ground, make the deadheight=1//// If you want the unit to go up, its height should be -lower- then the deadheight and vice versa.//// Remember: to calculate speed per second, do your speed value * 50 !function goingdowntimer takes nothing returns nothing local timer t = GetExpiredTimer () local boolean kill = GetHandleBoolean (t, "kill") local real deadheight = GetHandleReal (t, "deadheight") local unit whichUnit = GetHandleUnit (t, "whichUnit") local real speed = GetHandleReal (t, "speed") local real whichUnitStartheight = GetHandleReal (t, "whichUnitStartheight") local real whichUnitHeight = GetUnitFlyHeight (whichUnit ) if deadheight > whichUnitStartheight then if whichUnitHeight < deadheight then call SetUnitFlyHeight (whichUnit, whichUnitHeight+speed, 1000000 ) else call FlushHandleLocals (t ) call DestroyTimer (t ) if kill == true then call KillUnit (whichUnit ) endif endif elseif deadheight < whichUnitStartheight then if whichUnitHeight > deadheight then call SetUnitFlyHeight (whichUnit, whichUnitHeight-speed, 1000000 ) else call FlushHandleLocals (t ) call DestroyTimer (t ) call KillUnit (whichUnit ) endif endif set t = null set whichUnit = nullendfunctionfunction goingdown takes unit whichUnit, real speed, real deadheight, boolean kill returns nothing local timer t = CreateTimer () local real whichUnitStartheight = GetUnitFlyHeight (whichUnit ) call SetHandleBoolean (t, "kill", kill ) call SetHandleReal (t, "whichUnitStartheight", whichUnitStartheight ) call SetHandleReal (t, "deadheight", deadheight ) call SetHandleHandle (t, "whichUnit", whichUnit ) call SetHandleReal (t, "speed", speed ) call TimerStart (t, 0.02, true, function goingdowntimer ) set t = nullendfunction
Example raising units and killing them when they get to the max height you want
function Example_Actions takes nothing returns nothing local unit whichUnit = GetTriggerUnit () call goingdown (whichUnit,10,800, true) // WhichUnit will raise at 500 per second untill // he gets to a height of 800 and then he will dieendfunction//==== Init Trigger NewTrigger ====function InitTrig_Example takes nothing returns nothing set gg_trg_Example = CreateTrigger () call TriggerRegisterAnyUnitEventBJ ( gg_trg_Example, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddAction (gg_trg_Example, function Example_Actions )endfunction
Example lowering units and not killingthem when they get to the max (min) height you want
function Example_Actions takes nothing returns nothing local unit whichUnit = GetTriggerUnit () call goingdown (whichUnit,5,1, false) // WhichUnit will get lowerd at 250 per second untill // he gets to a height of 1endfunction//==== Init Trigger NewTrigger ====function InitTrig_Example takes nothing returns nothing set gg_trg_Example = CreateTrigger () call TriggerRegisterAnyUnitEventBJ ( gg_trg_Example, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddAction (gg_trg_Example, function Example_Actions )endfunction
I will say it again, please notice that the lowering/raising is based on the unit's current height which means that if you give him a value higher then his height - he will be flying up, if you give him a lower value then his height, he will descend down.
|
|
|
02-06-2008, 01:16 AM
|
#2 (permalink)
|
iRawr
Join Date: Dec 2005
Posts: 8,349
|
This is useless due to the 'rate' parameter on SetUnitFlyHeight. (Except for the Kill, but that is very easy to do since rate works fine anyways)
Also, 0 rate works as instant as well as a very large number.
|
|
|
02-06-2008, 01:38 AM
|
#3 (permalink)
|
Spell and Map Moderator
The Helpful Personage
Join Date: Jan 2005
Posts: 4,261
|
0 rate is better than a very large number probably is more demanding and not as instant as 0.
|
|
|
02-06-2008, 01:42 AM
|
#4 (permalink)
|
iRawr
Join Date: Dec 2005
Posts: 8,349
|
Not that it really matters anyways, as this entire function is basically a slower SetUnitFlyHeight. (I'll graveyard this soon, just waiting for the author to respond)
|
|
|
02-06-2008, 12:43 PM
|
#5 (permalink)
|
Just another Nobody
Join Date: Jul 2007
Posts: 2,384
|
Quote:
Originally Posted by PurplePoot
This is useless due to the 'rate' parameter on SetUnitFlyHeight. (Except for the Kill, but that is very easy to do since rate works fine anyways)
|
Hmm... I guess I never thought about it that way... guess you're right 
|
|
|
02-06-2008, 06:24 PM
|
#6 (permalink)
|
iRawr
Join Date: Dec 2005
Posts: 8,349
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|  |  |  |  |   |  |
|