SineCosine
I'm still looking for my Tangent
- Reaction score
- 77
JASS:
//==[WIP] System: Effects v3 ===========================================================
// SineCosine's
// _______ _______ _______ _______ ______ .___________. _______.
// | ____|| ____|| ____|| ____| / || | / |
// | |__ | |__ | |__ | |__ | ,----'`---| |----` | (----`
// | __| | __| | __| | __| | | | | \ \
// | |____ | | | | | |____ | `----. | | .----) |
// |_______||__| |__| |_______| \______| |__| |_______/
// Credits To:
// ____ ____ ____
// \ \ / / |___ \ kingkingyyk3 BlackRose
// \ \/ / __) | Komaqtion Tyrande_ma3x
// \ / |__ < J4L SanKakU
// \ / ___) | Executor Vikuna
// \__/ |____/ -For All The Valuable Input =)
//
//======================================================================================
Eh, It's a really long bunch of stuff to type, so..
I hope you aren't too lazy and actually read the documentation
Changes in V3
01) No more KT as an optional library
02) TimerUtils is a must
03) Added more effect making functions
04) Added some ways to modify the effects
To be honest, I haven't checked if all of the methods will work =x
But I think they do, except for SetEffectVertexColor.
I need help on that one :thdown:
Also, can anyone think of a better function name for all my functions? XD
I am horrible with naming standards.
The Code..
JASS:
//==[WIP] System: Effects v3 ===========================================================
// SineCosine's
// _______ _______ _______ _______ ______ .___________. _______.
// | ____|| ____|| ____|| ____| / || | / |
// | |__ | |__ | |__ | |__ | ,----'`---| |----` | (----`
// | __| | __| | __| | __| | | | | \ \
// | |____ | | | | | |____ | `----. | | .----) |
// |_______||__| |__| |_______| \______| |__| |_______/
// Credits To:
// ____ ____ ____
// \ \ / / |___ \ kingkingyyk3 BlackRose
// \ \/ / __) | Komaqtion Tyrande_ma3x
// \ / |__ < J4L SanKakU
// \ / ___) | Executor Vikuna
// \__/ |____/ -For All The Valuable Input =)
//
//======================================================================================
// What this system does for you:
// 01) It provides an easy way to deal with effects =)
// 02) You can create effects easily and define how long they will be shown
// 03) You can remove effects prematurely
// 04) You can move an effect any way you like
// 05) You can create an effect in the air (Z-Offset)
// 06) You can change the size of an effect
// 07) You can rotate an effect (SetEffectFacing)
// 08) You can change how high an effect is floating
// 09) You can extend the duration of an effect
// 10) You can shorten the duration of an effect
// 11) You can delay the appearance of an effect
// 12) There are 12 different ways to create an effect using EFFECTS
//
// How do I implement it?
// 01) Go to the trigger editor
// 02) Create a New Trigger
// 03) Rename the Trigger to "Effects"
// 04) Go to: Edit -> Convert To Custom Text
// 05) Copy+Paste this entire library in
// 06) Go to the Object Editor
// 07) Copy+Paste the dummy unit in there, it was used in Vexorians xefx thingy.
// 08) Modify the DummyID constant below to match the raw-code in the Object editor
// 09) Enjoy =)
//
// Q: How do I use it?
// A: Well, generally, you'd do it this way..
/*
function TestEffect takes nothing returns nothing
local Effect_Timed ET = 0
//That's the creation of the effect
set ET = AddTimedSpecialEffect(modelName, x, y, duration)
//This is the modifying of effect while it still exists
call ET.AddEffectDuration(9001.00)
endfunction
*/
// Q: Okay.. So what Effect Creating functions does your library offer?
// A: A lot. I mean it.
// 01) AddTimedSpecialEffect takes string modelName, real x, real y, real duration returns Effect_Timed
// 02) AddTimedSpecialEffectZ takes string modelName, real x, real y, real z, real duration returns Effect_Timed
// 03) AddTimedSpecialEffectDelayed takes string modelName, real x, real y, real duration, real delay returns Effect_Timed
// 04) AddTimedSpecialEffectDelayedZ takes string modelName, real x, real y, real z, real duration, real delay returns Effect_Timed
// 05) AddTimedSpecialEffectLoc takes string modelName, location where, real duration returns Effect_Timed
// 06) AddTimedSpecialEffectLocZ takes string modelName, location where, real z, real duration returns Effect_Timed
// 07) AddTimedSpecialEffectLocDelayed takes string modelName, location where, real duration, real delay returns Effect_Timed
// 08) AddTimedSpecialEffectLocDelayedZ takes string modelName, location where, real z, real duration, real delay returns Effect_Timed
// 09) AddTimedSpecialEffectTarget takes string modelName, widget targetWidget, string attachPointName, real duration returns Effect_Timed
// 10) AddTimedSpecialEffectTargetDelayed takes string modelName, widget targetWidget, string attachPointName, real duration, real delay returns Effect_Timed
// 11) UnitPosTimedSpecialEffect takes string modelName, unit targetUnit, real duration returns Effect_Timed
// 12) UnitPosTimedSpecialEffectDelayed takes string modelName, unit targetUnit, real duration, real delay returns Effect_Timed
//
// Q: F*CK YOU! Why so many functions?
// A: Err, I duno, I just figured that you wouldn't wanna' put 0.0 as the 'delay'
// everytime you wanna' create an Effect =)
//
// Q: Then how will I understand the Jumble of functions? How will I know which to use?
// A: functions that end with 'Z' allow you to specify a 'Fly-Height' for your effect
// (Same can be achieved with SetEffectZ and SetEffectPositionZ)
//
// functions that end with Delayed allow you to specify a delay-time before
// EFFECTS creates an effect at the defined location.
//
// AddTimedSpecialEffectTarget and AddTimedSpecialEffectTargetDelayed are for
// attaching effects to units.
//
// UnitPosTimedSpecialEffect creates an effect at a unit's X-Y-Z co-ordinates by
// default but the effect does not follow the unit.
//
// UnitPosTimedSpecialEffectDelayed creates an effect at a unit's X-Y-Z co-ordinates
// after a specified amount of delay by default. The effect does not follow the unit.
//
// Q: What methods do you offer for me to mess around with my effects?
// A: Quite a bit, and I am looking for ideas for this library/snippet thingy.
// 01) SetEffectDuration takes real newDuration, boolean Reset returns nothing
// 02) AddEffectDuration takes real addDuration returns nothing
// 03) MinusEffectDuration takes real minusDuration returns nothing
// 04) ClearEffect takes nothing returns nothing
// 05) ScaleEffect takes real newSize returns nothing
// 06) SetEffectVertexColor takes integer red, integer green, integer blue, integer alpha returns nothing
// Warning: do not use SetEffectVertexColor for now, I am trying to fix it =)
// 07) SetEffectFacing takes real newFacing returns nothing
// 08) SetEffectPosition takes real newX, real newY returns nothing
// 09) SetEffectPositionZ takes real newX, real newY, real newZ returns nothing
// 10) SetEffectZ takes real newZ returns nothing
//
// Q: What does 'boolean reset' do in SetEffectDuration?
// A: Well, if 'reset' is set to true..
// Let us say you want Effect X to be displayed for 10seconds
// 8seconds through the effect, you decide to set it to 15seconds
// So, you call SetEffectDuration. If 'reset' is true, it will cause your effect to
// last for an extra 15seconds, so, it will have been around for 8 + 15 seconds.
//
// If 'reset' is set to false, SetEffectDuration will only increase the
// life-span of the effect by 15 - 8 seconds = 7seconds.
// It will have lasted exactly 15seconds.
//
// If an effect has lasted for 30seconds and you use:
// call ET.SetEffectDuration(6, false)
// It will immediately remove the effect from the game.
// Why? Because 30 - 6seconds will result in a negative value.
//
//
// Extra info:
// 01) This library requires TimerUtils (It is NOT an option, it is a REQUIREMENT =P)
//
// Known attachment points:
// (Copied + Pasted from <a href="http://world-editor-tutorials.thehelper.net/" target="_blank" class="link link--external" rel="nofollow ugc noopener">http://world-editor-tutorials.thehelper.net/</a>)
// -->Attachment Point Names:
// 01) overhead (floats over the unit's head, but doesn't sway with)
// 02) head (sways with the unit's animation)
// 03) chest (also good for wings)
// 04) origin (usually at the base of a unit's feet)
// 05) hand
// 06) foot
// 07) weapon (for heroes)
// 08) sprite (for buildings)
// 09) medium (for buildings)
// 10) large (for buildings)
//
// -->Attachment Point Modifiers:
// 01) left
// 02) right
// 03) mount (for mounted units)
// 04) rear (for quadrupeds)
// 05) first (for buildings)
// 06) second (for buildings)
// 07) third (for buildings)
// 08) fourth (for buildings)
// 09) fifth (for buildings)
// 10) sixth (for buildings)
// 11) rallypoint (for buildings)
library Effects requires TimerUtils
globals
private constant integer DummyID = 039;e000039;
endglobals
struct Effect_Timed
private string ModelName
private string AttachPointName
private real X
private real Y
private real Z
private real Facing
private real Duration
private widget TargetWidget
private effect e
private unit Dummy
private timer t
private boolean AttachToUnit
private boolean DelayOver
private real Scale
private integer Red
private integer Green
private integer Blue
private integer Alpha
private unit TargetUnit
//This is the 'Core' of Effects
static method End takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
call DestroyEffect(e)
call ReleaseTimer(t)
if AttachToUnit == false then
call KillUnit(Dummy)
call RemoveUnit(Dummy)
endif
set e = null
set Dummy = null
set t = null
set TargetWidget = null
set TargetUnit = null
call this.destroy()
endmethod
static method Delay takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
if AttachToUnit == false and TargetUnit == null then
set Dummy = CreateUnit(Player(15), DummyID, X, Y, Facing)
call SetUnitInvulnerable(Dummy, true)
call UnitAddAbility(Dummy, 039;Amrf039;)
call SetUnitFlyHeight(Dummy, Z, 0)
call UnitRemoveAbility(Dummy, 039;Amrf039;)
call SetUnitPathing(Dummy, false)
set e = AddSpecialEffectTarget(ModelName, Dummy, "origin")
call SetUnitScale(Dummy, Scale, Scale, Scale)
call SetUnitVertexColor(Dummy, Red, Green, Blue, Alpha)
call SetUnitFacing(Dummy, Facing)
elseif TargetUnit != null then
set X = GetUnitX(TargetUnit)
set Y = GetUnitY(TargetUnit)
if Z == 0.0 then
set Z = GetUnitFlyHeight(TargetUnit)
endif
set Dummy = CreateUnit(Player(15), DummyID, X, Y, Facing)
call SetUnitInvulnerable(Dummy, true)
call UnitAddAbility(Dummy, 039;Amrf039;)
call SetUnitFlyHeight(Dummy, Z, 0)
call UnitRemoveAbility(Dummy, 039;Amrf039;)
call SetUnitPathing(Dummy, false)
set e = AddSpecialEffectTarget(ModelName, Dummy, "origin")
call SetUnitScale(Dummy, Scale, Scale, Scale)
call SetUnitVertexColor(Dummy, Red, Green, Blue, Alpha)
call SetUnitFacing(Dummy, Facing)
else
set e = AddSpecialEffectTarget(ModelName, TargetWidget, AttachPointName)
endif
set DelayOver = true
call TimerStart(t, Duration, false, function thistype.End)
endmethod
static method Start takes string modelName, string attachPointName, real x, real y, real z, real duration, real delay, widget targetWidget, unit targetUnit returns Effect_Timed
local thistype this = thistype.allocate()
set ModelName = modelName
set AttachPointName = attachPointName
set X = x
set Y = y
set Z = z
set Facing = bj_UNIT_FACING
set Duration = duration
set TargetWidget = targetWidget
set DelayOver = false
set Scale = 1.0
set TargetUnit = targetUnit
if TargetWidget != null then
set AttachToUnit = true
else
set AttachToUnit = false
endif
set t = NewTimer()
call SetTimerData(t, this)
call TimerStart(t, delay, false, function thistype.Delay)
return this
endmethod
//The following methods are for manipulating the effects created
method SetEffectDuration takes real newDuration, boolean Reset returns nothing
if DelayOver == false then
set Duration = newDuration
else
call PauseTimer(t)
if Reset == true then
set Duration = newDuration
call TimerStart(t, newDuration, false, function thistype.End)
else
set Duration = newDuration - (TimerGetElapsed(t))
if Duration <= 0.0 then
call DestroyEffect(e)
call ReleaseTimer(t)
if AttachToUnit == false then
call KillUnit(Dummy)
call RemoveUnit(Dummy)
endif
set e = null
set Dummy = null
set t = null
set TargetWidget = null
set TargetUnit = null
else
call TimerStart(t, Duration, false, function thistype.End)
endif
endif
endif
endmethod
method AddEffectDuration takes real addDuration returns nothing
if DelayOver == false then
set Duration = Duration + addDuration
else
set Duration = TimerGetRemaining(t) + addDuration
call PauseTimer(t)
call TimerStart(t, Duration, false, function thistype.End)
endif
endmethod
method MinusEffectDuration takes real minusDuration returns nothing
if DelayOver == false then
set Duration = Duration - minusDuration
else
set Duration = TimerGetRemaining(t) - minusDuration
if Duration <= 0.0 then
call DestroyEffect(e)
call ReleaseTimer(t)
if AttachToUnit == false then
call KillUnit(Dummy)
call RemoveUnit(Dummy)
endif
set e = null
set Dummy = null
set t = null
set TargetWidget = null
set TargetUnit = null
call this.destroy()
else
call PauseTimer(t)
call TimerStart(t, Duration, false, function thistype.End)
endif
endif
endmethod
method ClearEffect takes nothing returns nothing
if DelayOver == true then
call DestroyEffect(e)
call ReleaseTimer(t)
if AttachToUnit == false then
call KillUnit(Dummy)
call RemoveUnit(Dummy)
endif
set e = null
set Dummy = null
set t = null
set TargetWidget = null
set TargetUnit = null
call this.destroy()
else
call ReleaseTimer(t)
set t = null
set TargetWidget = null
endif
endmethod
method ScaleEffect takes real newSize returns nothing
if DelayOver == true then
set Scale = newSize
call SetUnitScale(Dummy, newSize, newSize, newSize)
else
set Scale = newSize
endif
endmethod
method SetEffectVertexColor takes integer red, integer green, integer blue, integer alpha returns nothing
if DelayOver == true then
set Red = red
set Green = green
set Blue = blue
set Alpha = alpha
call SetUnitVertexColor(Dummy, red, green, blue, alpha)
else
set Red = red
set Green = green
set Blue = blue
set Alpha = alpha
endif
endmethod
method SetEffectFacing takes real newFacing returns nothing
if DelayOver == true then
set Facing = newFacing
call SetUnitFacing(Dummy, newFacing)
else
set Facing = newFacing
endif
endmethod
method SetEffectPosition takes real newX, real newY returns nothing
if DelayOver == true then
call SetUnitPosition(Dummy, newX, newY)
else
set X = newX
set Y = newY
endif
endmethod
method SetEffectPositionZ takes real newX, real newY, real newZ returns nothing
if DelayOver == true then
set X = newX
set Y = newY
set Z = newZ
call SetUnitPosition(Dummy, newX, newY)
call UnitAddAbility(Dummy, 039;Amrf039;)
call SetUnitFlyHeight(Dummy, newZ, 0)
call UnitRemoveAbility(Dummy, 039;Amrf039;)
else
set X = newX
set Y = newY
set Z = newZ
endif
endmethod
method SetEffectZ takes real newZ returns nothing
if DelayOver == true then
set Z = newZ
call UnitAddAbility(Dummy, 039;Amrf039;)
call SetUnitFlyHeight(Dummy, newZ, 0)
call UnitRemoveAbility(Dummy, 039;Amrf039;)
else
set Z = newZ
endif
endmethod
endstruct
//All the functions that you will need to make the Effects are below.
function AddTimedSpecialEffect takes string modelName, real x, real y, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, null, x, y, 0.0, duration, 0.0, null, null)
endfunction
function AddTimedSpecialEffectZ takes string modelName, real x, real y, real z, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, null, x, y, z, duration, 0.0, null, null)
endfunction
function AddTimedSpecialEffectDelayed takes string modelName, real x, real y, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, null, x, y, 0.0, duration, delay, null, null)
endfunction
function AddTimedSpecialEffectDelayedZ takes string modelName, real x, real y, real z, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, null, x, y, z, duration, delay, null, null)
endfunction
function AddTimedSpecialEffectLoc takes string modelName, location where, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), GetLocationZ(where), duration, 0.0, null, null)
endfunction
function AddTimedSpecialEffectLocZ takes string modelName, location where, real z, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), z, duration, 0.0, null, null)
endfunction
function AddTimedSpecialEffectLocDelayed takes string modelName, location where, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), GetLocationZ(where), duration, delay, null, null)
endfunction
function AddTimedSpecialEffectLocDelayedZ takes string modelName, location where, real z, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, null, GetLocationX(where), GetLocationY(where), z, duration, delay, null, null)
endfunction
function AddTimedSpecialEffectTarget takes string modelName, widget targetWidget, string attachPointName, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, attachPointName, 0.0, 0.0, 0.0, duration, 0.0, targetWidget, null)
endfunction
function AddTimedSpecialEffectTargetDelayed takes string modelName, widget targetWidget, string attachPointName, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, attachPointName, 0.0, 0.0, 0.0, duration, delay, targetWidget, null)
endfunction
//Extra functionality
function UnitPosTimedSpecialEffect takes string modelName, unit targetUnit, real duration returns Effect_Timed
return Effect_Timed.Start(modelName, null, 0.0, 0.0, 0.0, duration, 0.0, null, targetUnit)
endfunction
function UnitPosTimedSpecialEffectDelayed takes string modelName, unit targetUnit, real duration, real delay returns Effect_Timed
return Effect_Timed.Start(modelName, null, 0.0, 0.0, 0.0, duration, delay, null, targetUnit)
endfunction
endlibrary
The demo-map has only 3 GUI examples =x
First-Example:
AddSpecialEffectTargetTimed
When Rifleman attacks
It creates the starfall effect and destroys it 2.0 seconds later.
Second-Example:
AddSpecialEffectLocTimed
When DragonWhelp attacks
It creates a ring of fire effect and destroys it 3.0 seconds later.
Tip: Try running around, you'll see that the 'ring of fire' effect will appear at the sniper every time xD
Third-Example:
AddSpecialEffectTimed
It creates the Phoenix-Egg effect for 5 seconds after a DragonWhelp dies.
The effect will last for another 5seconds, then, the DragonWhelp will revive.
You'll notice that those 3examples were done without waits in the effects =)
(Perfect for GUI-users)
It's a simple snippet, but works =x
Seriously, I had no idea xefx and a hell lot of other libraries like this existed =x