Name | Type | is_array | initial_value |
//TESH.scrollpos=77
//TESH.alwaysfold=0
//==================================================================================//
// //
// Lightning Test by Maker v1.00 //
// //
// Allows the user to see available lightnings and lists their string code //
// Press ESC to toggle lightnings //
// Type -code to set variable called LLL to the entered string //
// For example -mbur //
// Then you can use LLL in your spell and easily change the lightning type //
// between casts. //
//==================================================================================//
library LightningTest initializer Init
globals
private constant real SZ = 0.028 // Floating text size
private constant real OX = 0 // Origin x of upmost lightning
private constant real OY = 0 // Origin y of upmost lightning
private constant real OF = 100 // Space between lightnings
private boolean ESC = true // Begins test when Esc is pressed
// Do not change the ones below
string LLL = "LEAS"
private boolean TOG = true
private string array SA
private lightning array LA
private texttag array TA
endglobals
private function InitStrings takes nothing returns nothing
set SA[0] = "CLPB - Chain Lightning Primary"
set SA[1] = "CLSB - Chain Lightning Secondary"
set SA[2] = "DRAB - Drain"
set SA[3] = "DRAL - Drain Life"
set SA[4] = "DRAM - Drain Mana"
set SA[5] = "AFOD - Finger of Death"
set SA[6] = "FORK - Forked Lightning"
set SA[7] = "HWPB - Healing Wave Primary"
set SA[8] = "HWSB - Healing Wave Secondary"
set SA[9] = "CHIM - Lightning Attack"
set SA[10] = "LEAS - Magic Leash"
set SA[11] = "MBUR - Mana Burn"
set SA[12] = "MFPB - Mana Flare"
set SA[13] = "SPLK - Spirit Link"
endfunction
private function SetStr takes nothing returns nothing
set LLL = SubString(GetEventPlayerChatString(), 1, 5)
endfunction
function LightningTestBegin takes nothing returns nothing
local integer i = 0
local real alpha
if TOG then
call FogEnable(false)
call FogMaskEnable(false)
call SetCameraPosition(OX, OY)
set alpha = 1
else
set alpha = 0
endif
loop
call SetTextTagVisibility(TA[i], TOG)
call SetLightningColor(LA[i], 1, 1, 1, alpha)
set i = i + 1
exitwhen LA[i] == null
endloop
set TOG = not TOG
endfunction
function LightningTestEnd takes nothing returns nothing
set TOG = true
call LightningTestBegin()
endfunction
private function Init takes nothing returns nothing
local trigger t1
local trigger t2 = CreateTrigger()
local real x = OX
local real y = OY
local integer i = 0
if ESC then
set t1 = CreateTrigger()
call TriggerAddAction(t1, function LightningTestBegin)
call TriggerRegisterPlayerEvent(t1, Player(0), EVENT_PLAYER_END_CINEMATIC)
set t1 = null
endif
call InitStrings()
loop
set TA[i] = CreateTextTag()
call SetTextTagText(TA[i], SA[i], SZ)
call SetTextTagPos(TA[i], x, y, 80)
set LA[i] = AddLightningEx(SubString(SA[i], 0, 4), false, x, y, 50, x + 300, y, 50)
call SetTextTagVisibility(TA[i], false)
call SetLightningColor(LA[i], 1, 1, 1, 0)
set i = i + 1
exitwhen SA[i] == null
set y = y - 100
endloop
call TriggerRegisterPlayerChatEvent(t2, Player(0), "-", false)
call TriggerAddAction(t2, function SetStr)
call DisplayTimedTextToPlayer(Player(0), 0, 0, 1000, "Press ESC to show/hide lightning types.")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 1000, "Type -xxxx to change the lightning string.")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 1000, "For example -mbur")
set t2 = null
endfunction
endlibrary
//TESH.scrollpos=221
//TESH.alwaysfold=0
scope Barrier
globals
// Ability raw code
private constant integer AID = 'A000'
private constant integer DID1 = 'h000'
private constant integer DID2 = 'h001'
private constant integer BARS = 8
private constant integer ARSIZE = BARS*2 + 2
private constant real MOVEDIST = 200.
private constant real ROTSPD = 5. * bj_PI/180
private constant real DURCHAN = 0.3
private constant real DURLAST = 8.
private constant real RADIUS = 200.
private constant real RADIUS2 = RADIUS*RADIUS
private constant real WIDTH = 40.
private constant real WIDTH2 = WIDTH*WIDTH
private constant real SETBACK = 15.
private constant real FLYMIN = 20.
private constant real FLYMAX = 200.
private constant real DMGBASE = 15.
private constant real DMGBONUS = 10.
// Lightning type
private constant string LID = "LEAS"
private constant string HID = "Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl"
private player PLR
private location loc = Location(0,0)
private hashtable ht = InitHashtable()
private group GRP = CreateGroup()
endglobals
private function getDamage takes integer lvl returns real
return DMGBASE + DMGBONUS*(lvl-1)
endfunction
private function filter takes nothing returns boolean
local unit u = GetFilterUnit()
if not IsUnitType(u, UNIT_TYPE_DEAD) and /*
*/ IsUnitEnemy(u, PLR) and /*
*/ not IsUnitType(u, UNIT_TYPE_STRUCTURE) then
set u = null
return true
else
set u = null
return false
endif
endfunction
struct LightningBarrier
unit c
boolean b // Channeling or up and running
real dur // Duration after channeling is done
real hd // Flying height change speed
real h // Flying height cumulative change
real ho // Original flying height
real a // Rotation angle of orb 1
real x // Origin x
real y // Origin y
real dmg // Damage
static thistype dat
private method destroyThis takes nothing returns nothing
local integer i = 0
local integer id = GetHandleId(dat.c)
loop
call KillUnit(LoadUnitHandle(ht, id, i+10))
call DestroyLightning(LoadLightningHandle(ht, id, i+100))
set i = i + 1
exitwhen i > ARSIZE
endloop
call FlushChildHashtable(ht, id)
call dat.stopPeriodic()
call dat.destroy()
endmethod
private method periodic takes nothing returns nothing
local real x
local real y
local unit u
local real ang
local real dist
local integer i
local integer id = GetHandleId(.c)
//call DisplayTimedTextToPlayer(Player(0), 0, 0, 1, "loop")
if GetWidgetLife(.c) <= 0.405 or .dur < DURLAST then
if .h + .ho < FLYMAX then //.b == false then
set .h = .h + .hd
set i = 0
loop
set u = LoadUnitHandle(ht, id, i+10)
call SetUnitFlyHeight(u, .ho + .h, 0)
set u = LoadUnitHandle(ht, id, i+11)
call SetUnitFlyHeight(u, .ho - .h, 0)
set x = GetUnitX(u)
set y = GetUnitY(u)
call MoveLocation(loc, x, y)
call MoveLightningEx(LoadLightningHandle(ht, id, i+100), true, x, y, GetLocationZ(loc) + .ho - .h, x, y, GetLocationZ(loc) + .ho + .h)
set i = i + 2
exitwhen i == ARSIZE
endloop
call SetUnitFlyHeight(LoadUnitHandle(ht, id, 10+ARSIZE-2), .ho + .h, 0)
call SetUnitFlyHeight(LoadUnitHandle(ht, id, 10+ARSIZE-1), .ho - .h, 0)
set u = null
else
set .dur = .dur + T32_PERIOD
set .a = .a + ROTSPD
set u = LoadUnitHandle(ht, id, 10+ARSIZE-2)
call SetUnitX(u, .x + RADIUS * Cos(.a))
call SetUnitY(u, .y + RADIUS * Sin(.a))
set u = LoadUnitHandle(ht, id, 10+ARSIZE-1)
call SetUnitX(u, .x + RADIUS * Cos(-.a+bj_PI))
call SetUnitY(u, .y + RADIUS * Sin(-.a+bj_PI))
set PLR = GetOwningPlayer(.c)
call GroupEnumUnitsInRange(GRP, .x, .y, RADIUS + WIDTH, function filter)
loop
exitwhen FirstOfGroup(GRP) == null
set u = FirstOfGroup(GRP)
set x = GetUnitX(u)
set y = GetUnitY(u)
set dist = (x-.x)*(x-.x)+(y-.y)*(y-.y)
//if IsUnitInRangeXY(u, .x, .y, RADIUS) then
if dist < RADIUS2 then
//if not IsUnitInRangeXY(u, .x, .y, RADIUS-WIDTH) then
if dist > RADIUS2 - WIDTH2 then
set ang = Atan2(.y-y, .x-x)
call SetUnitPosition(u, x + SETBACK * Cos(ang), y + SETBACK * Sin(ang))
call IssuePointOrder(u, "move", .x, .y)
//call SetUnitX(u, x + SETBACK * Cos(ang))
//call SetUnitY(u, y + SETBACK * Sin(ang))
//call DisplayTimedTextToPlayer(Player(0), 0, 0, 1, "inside")
call DestroyEffect(AddSpecialEffectTarget(HID, u, "chest"))
endif
else
set ang = Atan2(y-.y, x-.x)
call SetUnitPosition(u, x + SETBACK * Cos(ang), y + SETBACK * Sin(ang))
//call SetUnitX(u, x + SETBACK * Cos(ang))
//call SetUnitY(u, y + SETBACK * Sin(ang))
call IssuePointOrder(u, "move", x + MOVEDIST * Cos(ang), y + MOVEDIST * Sin(ang))
//call DisplayTimedTextToPlayer(Player(0), 0, 0, 1, "outside")
call DestroyEffect(AddSpecialEffectTarget(HID, u, "chest"))
endif
call GroupRemoveUnit(GRP, u)
endloop
set u = null
endif
else
set dat = this
call .destroyThis()
//call DisplayTimedTextToPlayer(Player(0), 0, 0, 1, "stop")
endif
endmethod
implement T32x
private static method onChannel takes unit u returns nothing
local integer id = GetHandleId(u)
local thistype this = LoadInteger(ht, id, 0)
local integer i = 0
local real ang = GetRandomReal(0,2*bj_PI)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real x2
local real y2
local real h = (FLYMIN+FLYMAX)/2
local unit un
loop
set x2 = x + RADIUS * Cos(ang)
set y2 = y + RADIUS * Sin(ang)
set un = CreateUnit(Player(15), DID2, x2, y2, 0)
call SetUnitFlyHeight(un, h, 0)
call SaveUnitHandle(ht, id, i+10, un)
set un = CreateUnit(Player(15), DID2, x2, y2, 0)
call SetUnitFlyHeight(un, h, 0)
call SaveUnitHandle(ht, id, i+11, un)
call MoveLocation(loc, x2, y2)
call SaveLightningHandle(ht, id, i+100, AddLightningEx(LLL, true, x2, y2, GetLocationZ(loc), x2, y2, GetLocationZ(loc)))
set i = i + 2
exitwhen i == 2*BARS
set ang = ang + 2*bj_PI/BARS
endloop
set ang = ang + bj_PI
set un = CreateUnit(Player(15), DID1, x2, y2, 0)
call SetUnitFlyHeight(un, h, 0)
call SaveUnitHandle(ht, id, 10+ARSIZE-2, un)
set un = CreateUnit(Player(15), DID1, x2 + 2*RADIUS * Cos(ang), y2 + 2*RADIUS * Sin(ang), 0)
call SaveUnitHandle(ht, id, 10+ARSIZE-1, un)
call SetUnitFlyHeight(un, h, 0)
set .a = ang - bj_PI
set .c = u
set .b = false
set .h = 0
set .ho = h
set .dur = 0
set .hd = (h-FLYMIN)/(DURCHAN/T32_PERIOD)
set .x = GetUnitX(u)
set .y = GetUnitY(u)
set .dmg = getDamage(GetUnitAbilityLevel(u, AID))
set un = null
call this.startPeriodic()
endmethod
private static method onEffect takes unit u returns nothing
local thistype this = LoadInteger(ht, GetHandleId(u), 0)
set.b = true
endmethod
private static method cond takes nothing returns boolean
local integer id
if GetSpellAbilityId() == AID then
if GetHandleId(GetTriggerEventId()) == 272 then
set id = GetHandleId(GetTriggerUnit())
if HaveSavedInteger(ht, id, 0) then
set dat = LoadInteger(ht, id, 0)
call dat.destroyThis()
endif
call SaveInteger(ht, id, 0, thistype.allocate())
call .onChannel(GetTriggerUnit())
else
call .onEffect(GetTriggerUnit())
endif
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerAddCondition(t, function thistype.cond)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
set t = null
endmethod
endstruct
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Timer32 ~~ By Jesus4Lyf ~~ Version 1.06 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What is Timer32?
// - Timer32 implements a fully optimised timer loop for a struct.
// - Instances can be added to the loop, which will call .periodic every
// PERIOD until .stopPeriodic() is called.
//
// =Pros=
// - Efficient.
// - Simple.
//
// =Cons=
// - Only allows one period.
// - The called method must be named ".periodic".
//
// Methods:
// - struct.startPeriodic()
// - struct.stopPeriodic()
//
// - private method periodic takes nothing returns nothing
//
// This must be defined in structs that implement Periodic Module.
// It will be executed by the module every PERIOD until .stopPeriodic() is called.
// Put "implement T32x" BELOW this method.
//
// Modules:
// - T32x
// Has no safety on .stopPeriodic or .startPeriodic (except debug messages
// to warn).
//
// - T32xs
// Has safety on .stopPeriodic and .startPeriodic so if they are called
// multiple times, or while otherwise are already stopped/started respectively,
// no error will occur, the call will be ignored.
//
// - T32
// The original, old version of the T32 module. This remains for backwards
// compatability, and is deprecated. The periodic method must return a boolean,
// false to continue running or true to stop.
//
// Details:
// - Uses one timer.
//
// - Do not, within a .periodic method, follow a .stopPeriodic call with a
// .startPeriodic call.
//
// How to import:
// - Create a trigger named T32.
// - Convert it to custom text and replace the whole trigger text with this.
//
// Thanks:
// - Infinitegde for finding a bug in the debug message that actually altered
// system operation (when in debug mode).
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
library T32 initializer OnInit
globals
public constant real PERIOD=0.03125
public constant integer FPS=R2I(1/PERIOD)
public integer Tick=0 // very useful.
//==============================================================================
private trigger Trig=CreateTrigger()
endglobals
//==============================================================================
// The standard T32 module, T32x.
//
module T32x
private thistype next
private thistype prev
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
call this.periodic()
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
debug if this.prev!=0 or thistype(0).next==this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had startPeriodic called while already running!")
debug endif
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
endmethod
method stopPeriodic takes nothing returns nothing
debug if this.prev==0 and thistype(0).next!=this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had stopPeriodic called while not running!")
debug endif
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
debug set this.prev=0
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// The standard T32 module with added safety checks on .startPeriodic() and
// .stopPeriodic(), T32xs.
//
module T32xs
private thistype next
private thistype prev
private boolean runningPeriodic
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
call this.periodic()
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
if not this.runningPeriodic then
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
set this.runningPeriodic=true
endif
endmethod
method stopPeriodic takes nothing returns nothing
if this.runningPeriodic then
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
set this.runningPeriodic=false
endif
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// The original T32 module, for backwards compatability only.
//
module T32 // deprecated.
private thistype next
private thistype prev
private static method PeriodicLoop takes nothing returns boolean
local thistype this=thistype(0).next
loop
exitwhen this==0
if this.periodic() then
// This is some real magic.
set this.prev.next=this.next
set this.next.prev=this.prev
// This will even work for the starting element.
debug set this.prev=0
endif
set this=this.next
endloop
return false
endmethod
method startPeriodic takes nothing returns nothing
debug if this.prev!=0 or thistype(0).next==this then
debug call BJDebugMsg("T32 ERROR: Struct #"+I2S(this)+" had startPeriodic called while already running!")
debug endif
set thistype(0).next.prev=this
set this.next=thistype(0).next
set thistype(0).next=this
set this.prev=thistype(0)
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddCondition(Trig,Condition(function thistype.PeriodicLoop))
endmethod
endmodule
//==============================================================================
// System Core.
//
private function OnExpire takes nothing returns nothing
set Tick=Tick+1
call TriggerEvaluate(Trig)
endfunction
private function OnInit takes nothing returns nothing
call TimerStart(CreateTimer(),PERIOD,true,function OnExpire)
endfunction
endlibrary