Infinitegde
O.O
- Reaction score
- 86
Chain Link System V0.70
By Infinitegde
Requires ABC.
Written in vJass.
What Is This?: Simply, it's a lightning system, except, instead of lightning it uses units for the lightning effect. This allows you to customize the lightning effect a lot more than the regular one. Example, Alpha Gradient. (Meaning, going from most transparent to least transparent.) Flexibility, (Flexible chains)(not in this version; but coming soon). And it comes built in with a unit attacher. Also, it is a great way to make the effect of an army in a cinematics. Because the Chainlink uses units as chains, you can simply put 'hfoo' for the unit code and come up with 1000's of footmen in a straight line.
Also, for those who know how to program in another language, this is imitating a "class" by using structs. So, you can use it just like you'd use a lightning effect. If you don't know how to use structs, look at a tutorial or read the vJass documentation. They are both very helpful
And, as always, a picture can demonstrate just exactly what I mean, so here:
Screenshots:
Unfortunately, setting the transparency to all units doesn't work as well as you'd think. Some units, like these, the transparency is hard to tell. (only the glow effect is transparent.)
Again, another one where the transparency isn't effective (most missiles are like this.)
Here is where it works, with units, now take a look at it. Simply, deanchor and deattach the anchor and heads and destroy them, (make a few more rows), apply a slightly dark black mask, tweak the camera angle a bit, and you have an army fit for display.
How to Import:
1) Make sure you have ABC installed correctly on your map.
2) Create a new trigger named ChainLinkSys and put the following code in it.
3) Use as you please.
Function List:
Code:
I know that some people are new to vJass and don't like using it that much, here are a few "BJ" functions you can use.
Heres a test map: (Sorry it's so bland, running out of space ...)
By Infinitegde
Requires ABC.
Written in vJass.
What Is This?: Simply, it's a lightning system, except, instead of lightning it uses units for the lightning effect. This allows you to customize the lightning effect a lot more than the regular one. Example, Alpha Gradient. (Meaning, going from most transparent to least transparent.) Flexibility, (Flexible chains)(not in this version; but coming soon). And it comes built in with a unit attacher. Also, it is a great way to make the effect of an army in a cinematics. Because the Chainlink uses units as chains, you can simply put 'hfoo' for the unit code and come up with 1000's of footmen in a straight line.
Also, for those who know how to program in another language, this is imitating a "class" by using structs. So, you can use it just like you'd use a lightning effect. If you don't know how to use structs, look at a tutorial or read the vJass documentation. They are both very helpful
Code:
[B]Features: [/B]
-3D Points
-Attachable
-Anchorable
-X&Y&Z Offsets
-GetChains
[B]Upcoming Features:[/B]
-Flexible Chain
-Retractable Chain
-One-by-One creation
[B] Extras:[/B]
-Alpha Gradient
[B]Upcoming Extras:[/B]
-Color Gradient
And, as always, a picture can demonstrate just exactly what I mean, so here:
Screenshots:
Unfortunately, setting the transparency to all units doesn't work as well as you'd think. Some units, like these, the transparency is hard to tell. (only the glow effect is transparent.)
Again, another one where the transparency isn't effective (most missiles are like this.)
Here is where it works, with units, now take a look at it. Simply, deanchor and deattach the anchor and heads and destroy them, (make a few more rows), apply a slightly dark black mask, tweak the camera angle a bit, and you have an army fit for display.
How to Import:
1) Make sure you have ABC installed correctly on your map.
2) Create a new trigger named ChainLinkSys and put the following code in it.
3) Use as you please.
Function List:
Code:
.destroy() takes nothing returns nothing
-Destroys the chain.
Ex. call Link.destroy()
.Deattach() && .Deanchor() takes nothing returns nothing
-Deattaches from the units its already attached/anchored to.
Ex. call Link.Deattach()
Ex2. call Link.Deanchor()
.Alpha_Gradient() takes real BeginFade,real EndFade, real MaxPercent, real MinPercent returns nothing
-Apply from beginpercent of chain to endpercent of chain. Start at Minpercent and go to MaxPercent.
Ex, call Link.Alpha_Gradient(0.00, 1.00, 0.50, 1.00)
What this does is it starts a 0% of the chain (Or the start) and goes to 100% of the chain(or all the way to the end), and evenly shifts from 50% transparency to 100% transparency.
.GetAnchoredOn() && .GetAttachedTo() takes nothing returns unit
-Gets the specified units.
Ex. set Anchor = Link.GetAnchoredOn()
Ex. set Head = Link.GetAttachedTo()
.Anchor() && .Attach() takes unit u returns boolean
-Attach or Anchor the chain to a specific unit.
Ex. set flag = Link.Attach(u)
if(flag == false)then
call BJDebugMsg("Attachment Failed.")
endif
.SetXOffset() && .SetYOffset() && .SetZOffset() takes real (x,y, or z) returns nothing
-Preset Offsets.
Ex. call Link.SetZOffset(100)
.create() takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, integer unitcode, real ChainEvery,player P returns ChainLink
-Creates the chain
Ex. local ChainLink global = ChainLink.create(0,0,0,1000,1000,1000,'u000',50,Player(0))
.MoveChain() takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, real ChainEvery returns nothing
- Moves the Chain.
Ex. call Link.MoveChain(0,0,100,100,100,0,50)
.GetChains() takes nothing returns group
-Puts all the chains into a group so you can apply your own transformation to it.
Ex. call ForGroup(Link.GetChain(), ApplyTransformation)
Code:
JASS:
//========================================
// ChainLink System
// By Infinitegde
//========================================
// Version: 0.70
// WhatIsThis: This is a simple system that basically makes lightning effects, without the actual "lightning."
// Meaning, it basically creates units for the lightning instead of actual lightning.
// Features:
// -3D Points
// -Attachable
// -Anchorable
// -X&Y&Z Offsets
// -GetChains
// Upcoming Features:
// -Flexible Chain
// -Retractable Chain
// -One-by-One creation
// Extras:
// -Alpha Gradient
//
// Upcoming Extras:
// -Color Gradient
globals
constant integer MAXCHAINS = 200
endglobals
library ChainLinkSys requires ABC
function Trigger_Move takes nothing returns nothing
local ChainLink t = GetTriggerStructA(GetTriggeringTrigger())
local unit u = t.GetAnchoredOn()
local real x1
local real x2
local real y1
local real y2
local real z1
local real z2
local unit Attach2 = t.GetAttachedTo()
if( u != null) then
set x1 = GetUnitX(u)
set y1 = GetUnitY(u)
set z1 = GetUnitFlyHeight(u)
else
set x1 = t.P1X
set y1 = t.P1Y
set z1 = t.P1Z
endif
if( Attach2 != null) then
set x2 = GetUnitX(Attach2)
set y2 = GetUnitY(Attach2)
set z2 = GetUnitFlyHeight(Attach2)
else
set x2 = t.P2X
set y2 = t.P2Y
set z2 = t.P2Z
endif
call t.MoveChain(x1,y1,z1,x2,y2,z2,t.ChainEvery)
call t.CheckStats()
set u = null
set Attach2 = null
endfunction
function RoundReal takes real r returns integer
if (r-R2I(r)>.5)then
return R2I(r)+1
endif
return (R2I(r))
endfunction
struct STATS
real AGMinPercent=0
real AGMaxPercent=0
real AGBeginPercent=0
real AGEndPercent=0
real XOffset=0
real YOffset=0
real ZOffset=0
endstruct
struct ChainLink
real ChainEvery
real P1X
real P1Y
real P1Z
real P2X
real P2Y
real P2Z
trigger Follow = null
integer unitcode
unit anchor
private unit AttachedTo = null
private unit Anchoredon = null
unit head
unit array Chains[MAXCHAINS]
player Owner
boolean AGon = false
STATS Get
method onDestroy takes nothing returns nothing
set .ChainEvery = 0
set .P1X = 0
set .P2X = 0
set .P1Y = 0
set .P2Y = 0
set .P1Z = 0
set .P2Z = 0
call .Deattach()
call .Deanchor()
set .AGon = false
set .head = null
set .anchor = null
set .AttachedTo = null
set .Anchoredon = null
call .Get.destroy()
call .DestroyChain()
endmethod
method Realto255 takes real percent returns integer
return RoundReal(percent*255)
endmethod
method GetDistance takes nothing returns real
return SquareRoot(Pow(.P1X-.P2X,2)+Pow(.P1Y-.P2Y,2)+Pow(.P1Z-.P2Z,2))
endmethod
method Deattach takes nothing returns nothing
set .AttachedTo = null
if (.Anchoredon == null and .AttachedTo == null)then
call DestroyTrigger(.Follow)
set .Follow = null
endif
endmethod
method CheckStats takes nothing returns nothing
if (.AGon == true) then
call .Apply_AG()
endif
endmethod
method TurnOff_AG takes nothing returns nothing
set .AGon = false
endmethod
method Apply_AG takes nothing returns nothing
local integer i = RoundReal(.GetDistance()/.ChainEvery)+2
local integer BeginI = RoundReal(i*.Get.AGBeginPercent)
local integer EndI = RoundReal(i*.Get.AGEndPercent)
local real increment = (.Get.AGMaxPercent-.Get.AGMinPercent)/(EndI-BeginI)
local real CP = .Get.AGMinPercent
local integer var =1
loop
exitwhen var > i
if(var>BeginI and var<EndI)then
call SetUnitVertexColor(.Chains[var],255,255,255,.Realto255(CP))
set CP = CP+increment
endif
set var = var +1
endloop
endmethod
method Alpha_Gradient takes real BeginFade,real EndFade, real MaxPercent, real MinPercent returns nothing
set .AGon = true
set .Get.AGMinPercent = MinPercent
set .Get.AGMaxPercent = MaxPercent
set .Get.AGBeginPercent = BeginFade
set .Get.AGEndPercent = EndFade
call .CheckStats()
endmethod
method Deanchor takes nothing returns nothing
set .Anchoredon = null
if (.Anchoredon == null and .AttachedTo == null)then
call DestroyTrigger(.Follow)
set .Follow = null
endif
endmethod
method GetAnchoredOn takes nothing returns unit
return this.Anchoredon
endmethod
method GetAttachedTo takes nothing returns unit
return this.AttachedTo
endmethod
method Anchor takes ChainLink t, unit u returns boolean
if .Anchoredon == null then
set .Anchoredon = u
if(.Follow ==null) then
set .Follow = CreateTrigger()
call TriggerRegisterTimerEvent(.Follow,0.03,true)
call SetTriggerStructA(.Follow,this)
call TriggerAddAction(.Follow, function Trigger_Move)
endif
return true
else
return false
endif
endmethod
method SetZOffset takes real z returns nothing
set .Get.ZOffset = z
endmethod
method SetYOffset takes real y returns nothing
set .Get.YOffset = y
endmethod
method SetXOffset takes real x returns nothing
set .Get.XOffset = x
endmethod
method Attach takes ChainLink t, unit u returns boolean
if .AttachedTo == null then
set .AttachedTo = u
if(.Follow ==null) then
set .Follow = CreateTrigger()
call TriggerRegisterTimerEvent(.Follow,0.03,true)
call SetTriggerStructA(.Follow,this)
call TriggerAddAction(.Follow, function Trigger_Move)
endif
return true
else
return false
endif
endmethod
static method create takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, integer unitcode, real ChainEvery,player P returns ChainLink
local ChainLink t= ChainLink.allocate()
set t.P1X = X1
set t.P1Y = Y1
set t.P1Z = Z1
set t.P2X = X2
set t.P2Y = Y2
set t.P2Z = Z2
set t.unitcode = unitcode
set t.ChainEvery = ChainEvery
set t.Owner = P
call t.CreateChain(t)
set t.Get = STATS.create()
return t
endmethod
method DestroyChain takes nothing returns nothing
local integer i = 0
loop
exitwhen i > MAXCHAINS
if(.Chains<i> != null) then
call RemoveUnit(.Chains<i>)
set .Chains<i> = null
endif
set i = i +1
endloop
set .anchor = null
set .Anchoredon = null
set .head = null
set .Owner = null
endmethod
method MoveChain takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, real ChainEvery returns nothing
local real dist = SquareRoot(Pow(X1-X2,2)+Pow(Y1-Y2,2)+Pow(Z1-Z2,2))
local integer i = RoundReal(dist/ChainEvery)
local integer var =2
local real phi = Acos((Z2-Z1)/dist)
local real theta = Atan2(Y2-Y1,X2-X1)
local real cX = X1 + .Get.XOffset
local real cY = Y1 + .Get.YOffset
local real cZ = Z1 + .Get.ZOffset
local unit u
local integer T = 0
set .P1X = X1
set .P1Y = Y1
set .P1Z = Z1
set .P2X = X2
set .P2Y = Y2
set .P2Z = Z2
set .ChainEvery = ChainEvery
if(i > MAXCHAINS)then
debug call BJDebugMsg("CHAINLINKSYS: Failure, try increasing the CHAINEVERY or MAXCHAINS.")
return
endif
loop
exitwhen T>MAXCHAINS
if(T>=i+2)then
if(.Chains[T]!=null)then
call RemoveUnit(.Chains[T])
set .Chains[T]=null
endif
endif
set T=T+1
endloop
if(.Chains[1] ==null)then
set .anchor = CreateUnit(.Owner,.unitcode,.P1X,.P1Y,0)
set .Chains[1] = .anchor
endif
set .anchor = .Chains[1]
call SetUnitX(.anchor,cX)
call SetUnitY(.anchor,cY)
call UnitAddAbility(.anchor,039;Amrf039;)
call SetUnitFlyHeight(.anchor,cZ,0)
call UnitRemoveAbility(.anchor,039;Amrf039;)
call SetUnitUserData(.anchor,this)
loop
exitwhen var > (i)
set cX = cX + .ChainEvery*Cos(theta)*Sin(phi)
set cY = cY + .ChainEvery*Sin(theta)*Sin(phi)
set cZ = cZ + .ChainEvery*Cos(phi)
if(.Chains[var] == null)then
set u = CreateUnit(.Owner,.unitcode,cX,cY,0)
set .Chains[var] = u
endif
set u = .Chains[var]
call SetUnitX(u,cX)
call SetUnitY(u,cY)
call UnitAddAbility(u,039;Amrf039;)
call SetUnitFlyHeight(u,cZ,0)
call UnitRemoveAbility(u,039;Amrf039;)
call SetUnitUserData(u,this)
set var=var+1
endloop
if(.Chains[var] ==null)then
set .head = CreateUnit(.Owner,.unitcode,.P2X,.P2Y,0)
set .Chains[var] = .head
endif
set .head = .Chains[var]
call SetUnitX(.head,.P2X + .Get.XOffset)
call SetUnitY(.head,.P2Y + .Get.YOffset)
call UnitAddAbility(.head,039;Amrf039;)
call SetUnitFlyHeight(.head,.P2Z + .Get.ZOffset,0)
call UnitRemoveAbility(.head,039;Amrf039;)
call SetUnitUserData(.head,this)
endmethod
private static method CreateChain takes ChainLink t returns nothing
local real dist = SquareRoot(Pow(t.P1X-t.P2X,2)+Pow(t.P1Y-t.P2Y,2)+Pow(t.P1Z-t.P2Z,2))
local integer i = R2I(dist/t.ChainEvery)
local integer var =0
local real phi = Acos((t.P2Z-t.P1Z)/dist)
local real theta = Atan2(t.P2Y-t.P1Y,t.P2X-t.P1X)
local real cX = t.P1X + t.Get.XOffset
local real cY = t.P1Y + t.Get.YOffset
local real cZ = t.P1Z + t.Get.ZOffset
local unit u
if(i > MAXCHAINS)then
debug call BJDebugMsg("CHAINLINKSYS: Failure, try increasing the CHAINEVERY or MAXCHAINS.")
return
endif
set t.anchor =CreateUnit(t.Owner,t.unitcode,t.P1X,t.P1Y,0)
call UnitAddAbility(t.anchor,039;Amrf039;)
call SetUnitFlyHeight(t.anchor,t.P1Z,0)
call UnitRemoveAbility(t.anchor,039;Amrf039;)
set t.Chains[1] = t.anchor
call SetUnitUserData(t.anchor,t)
loop
exitwhen var > (i-1)
set cX = cX + t.ChainEvery*Cos(theta)*Sin(phi)
set cY = cY + t.ChainEvery*Sin(theta)*Sin(phi)
set cZ = cZ + t.ChainEvery*Cos(phi)
set u =CreateUnit(t.Owner,t.unitcode,cX,cY,0)
call UnitAddAbility(u,039;Amrf039;)
call SetUnitFlyHeight(u,cZ,0)
call UnitRemoveAbility(u,039;Amrf039;)
set t.Chains[var+2] = u
call SetUnitUserData(u,t)
set var=var+1
endloop
set t.head = CreateUnit(t.Owner,t.unitcode,t.P2X,t.P2Y,0)
call UnitAddAbility(t.head,039;Amrf039;)
call SetUnitFlyHeight(t.head,t.P2Z,0)
call UnitRemoveAbility(t.head,039;Amrf039;)
call SetUnitUserData(t.head,t)
set t.Chains[var+2] = t.head
call t.CheckStats()
endmethod
endstruct
function GetChains takes ChainLink t returns group
local group g = CreateGroup()
local integer i = 0
loop
exitwhen i > MAXCHAINS
if(t.Chains<i> != null) then
call GroupAddUnit(g,t.Chains<i>)
endif
set i = i +1
endloop
if bj_lastCreatedGroup != null then
call DestroyGroup(bj_lastCreatedGroup)
set bj_lastCreatedGroup = CreateGroup()
endif
call GroupAddGroup(g,bj_lastCreatedGroup)
call DestroyGroup(g)
set g = null
return bj_lastCreatedGroup
endfunction
endlibrary</i></i></i></i></i>
I know that some people are new to vJass and don't like using it that much, here are a few "BJ" functions you can use.
JASS:
library CLSBJs requires ChainLinkSys
function CreateChain takes real X1, real Y1, real Z1, real X2, real Y2, real Z2, integer unitcode, real ChainEvery, player P returns ChainLink
local ChainLink new = ChainLink.create(X1,Y1,Z1,X2,Y2,Z2,unitcode,ChainEvery,P)
return new
endfunction
function MoveChainLink takes ChainLink t, real X1, real Y1, real Z1, real X2, real Y2, real Z2, real ChainEvery returns nothing
call t.MoveChain(X1,Y1,Z1,X2,Y2,Z2,ChainEvery)
endfunction
function MoveAnchor takes ChainLink t, real X1, real Y1, real Z1 returns nothing
call t.MoveChain(X1,Y1,Z1,t.P2X,t.P2Y,t.P2Z,t.ChainEvery)
endfunction
function MoveHead takes ChainLink t, real X1, real Y1, real Z1 returns nothing
call t.MoveChain(t.P1X,t.P1Y,t.P1Z,X1,Y1,Z1,t.ChainEvery)
endfunction
endlibrary
Heres a test map: (Sorry it's so bland, running out of space ...)