Name | Type | is_array | initial_value |
library xebasic
//**************************************************************************
//
// xebasic 0.4
// =======
// XE_DUMMY_UNITID : Rawcode of the dummy unit in your map. It should
// use the dummy.mdx model, so remember to import it as
// well, just use copy&paste to copy the dummy from the
// xe map to yours, then change the rawcode.
//
// XE_HEIGHT_ENABLER: Medivh's raven form ability, you may need to change
// this rawcode to another spell that morphs into a flier
// in case you modified medivh's spell in your map.
//
// XE_TREE_RECOGNITION: The ancients' Eat tree ability, same as with medivh
// raven form, you might have to change it.
//
// XE_ANIMATION_PERIOD: The global period of animation used by whatever
// timer that depends on it, if you put a low value
// the movement will look good but it may hurt your
// performance, if instead you use a high value it
// will not lag but will be fast.
//
// XE_MAX_COLLISION_SIZE: The maximum unit collision size in your map, if
// you got a unit bigger than 197.0 it would be
// a good idea to update this constant, since some
// enums will not find it. Likewise, if none of
// your units can go bellow X and X is much smaller
// than 197.0, it would be a good idea to update
// as well, since it will improve the performance
// those enums.
//
// Notice you probably don't have to update this library, unless I specify
// there are new constants which would be unlikely.
//
//**************************************************************************
//===========================================================================
globals
constant integer XE_DUMMY_UNITID = 'e000'
constant integer XE_HEIGHT_ENABLER = 'Amrf'
constant integer XE_TREE_RECOGNITION = 'Aeat'
constant real XE_ANIMATION_PERIOD = 0.025
constant real XE_MAX_COLLISION_SIZE = 197.0
endglobals
endlibrary
//TESH.scrollpos=45
//TESH.alwaysfold=0
library xefx initializer init requires xebasic
//**************************************************
// xefx 0.7
// --------
// Recommended: ARGB (adds ARGBrecolor method)
// For your movable fx needs
//
//**************************************************
//==================================================
globals
private constant integer MAX_INSTANCES = 8190 //change accordingly.
private constant real RECYCLE_DELAY = 4.0
//recycling, in order to show the effect correctly, must wait some time before
//removing the unit.
private timer recycler
private timer NOW
endglobals
private struct recyclebin extends array
unit u
real schedule
static recyclebin end=0
static recyclebin begin=0
static method Recycle takes nothing returns nothing
call RemoveUnit(.begin.u) //this unit is private, systems shouldn't mess with it.
set .begin.u=null
set .begin=recyclebin(integer(.begin)+1)
if(.begin==.end) then
set .begin=0
set .end=0
else
call TimerStart(recycler, .begin.schedule-TimerGetElapsed(NOW), false, function recyclebin.Recycle)
endif
endmethod
endstruct
private function init takes nothing returns nothing
set recycler=CreateTimer()
set NOW=CreateTimer()
call TimerStart(NOW,43200,true,null)
endfunction
struct xefx[MAX_INSTANCES]
public integer tag=0
private unit dummy
private effect fx=null
private real zang=0.0
private integer r=255
private integer g=255
private integer b=255
private integer a=255
private integer abil=0
static method create takes real x, real y, real facing returns xefx
local xefx this=xefx.allocate()
set this.dummy= CreateUnit(Player(15), XE_DUMMY_UNITID, x,y, facing*bj_RADTODEG)
call UnitAddAbility(this.dummy,XE_HEIGHT_ENABLER)
call UnitAddAbility(this.dummy,'Aloc')
call UnitRemoveAbility(this.dummy,XE_HEIGHT_ENABLER)
call SetUnitX(this.dummy,x)
call SetUnitY(this.dummy,y)
return this
endmethod
method operator owner takes nothing returns player
return GetOwningPlayer(this.dummy)
endmethod
method operator owner= takes player p returns nothing
call SetUnitOwner(this.dummy,p,false)
endmethod
method operator teamcolor= takes playercolor c returns nothing
call SetUnitColor(this.dummy,c)
endmethod
method operator scale= takes real value returns nothing
call SetUnitScale(this.dummy,value,value,value)
endmethod
//! textmacro XEFX_colorstuff takes colorname, colorvar
method operator $colorname$ takes nothing returns integer
return this.$colorvar$
endmethod
method operator $colorname$= takes integer value returns nothing
set this.$colorvar$=value
call SetUnitVertexColor(this.dummy,this.r,this.g,this.b,this.a)
endmethod
//! endtextmacro
//! runtextmacro XEFX_colorstuff("red","r")
//! runtextmacro XEFX_colorstuff("green","g")
//! runtextmacro XEFX_colorstuff("blue","b")
//! runtextmacro XEFX_colorstuff("alpha","a")
method recolor takes integer r, integer g , integer b, integer a returns nothing
set this.r=r
set this.g=g
set this.b=b
set this.a=a
call SetUnitVertexColor(this.dummy,this.r,this.g,this.b,this.a)
endmethod
implement optional ARGBrecolor
method operator abilityid takes nothing returns integer
return this.abil
endmethod
method operator abilityid= takes integer a returns nothing
if(this.abil!=0) then
call UnitRemoveAbility(this.dummy,this.abil)
endif
if(a!=0) then
call UnitAddAbility(this.dummy,a)
endif
set this.abil=a
endmethod
method operator abilityLevel takes nothing returns integer
return GetUnitAbilityLevel( this.dummy, this.abil)
endmethod
method operator abilityLevel= takes integer newLevel returns nothing
call SetUnitAbilityLevel(this.dummy, this.abil, newLevel)
endmethod
method flash takes string fx returns nothing
call DestroyEffect(AddSpecialEffectTarget(fx,this.dummy,"origin"))
endmethod
method operator xyangle takes nothing returns real
return GetUnitFacing(this.dummy)*bj_DEGTORAD
endmethod
method operator xyangle= takes real value returns nothing
call SetUnitFacing(this.dummy,value*bj_RADTODEG)
endmethod
method operator zangle takes nothing returns real
return this.zang
endmethod
method operator zangle= takes real value returns nothing
local integer i=R2I(value*bj_RADTODEG+90.5)
set this.zang=value
if(i>=180) then
set i=179
elseif(i<0) then
set i=0
endif
call SetUnitAnimationByIndex(this.dummy, i )
endmethod
method operator x takes nothing returns real
return GetUnitX(this.dummy)
endmethod
method operator y takes nothing returns real
return GetUnitY(this.dummy)
endmethod
method operator z takes nothing returns real
return GetUnitFlyHeight(this.dummy)
endmethod
method operator z= takes real value returns nothing
call SetUnitFlyHeight(this.dummy,value,0)
endmethod
method operator x= takes real value returns nothing
call SetUnitX(this.dummy,value)
endmethod
method operator y= takes real value returns nothing
call SetUnitY(this.dummy,value)
endmethod
method operator fxpath= takes string newpath returns nothing
if (this.fx!=null) then
call DestroyEffect(this.fx)
endif
if (newpath=="") then
set this.fx=null
else
set this.fx=AddSpecialEffectTarget(newpath,this.dummy,"origin")
endif
endmethod
method hiddenReset takes string newfxpath, real newfacing returns nothing
local real x = GetUnitX(this.dummy)
local real y = GetUnitY(this.dummy)
local real z = this.z
local real za = this.zangle
local integer level = this.abilityLevel
set fxpath=null
call RemoveUnit(this.dummy)
set this.dummy= CreateUnit(Player(15), XE_DUMMY_UNITID, x,y, newfacing*bj_RADTODEG)
if(level != 0) then
call UnitAddAbility(this.dummy, abilityid)
endif
call UnitAddAbility(this.dummy,XE_HEIGHT_ENABLER)
call UnitAddAbility(this.dummy,'Aloc')
call UnitRemoveAbility(this.dummy,XE_HEIGHT_ENABLER)
call SetUnitX(this.dummy,x)
call SetUnitY(this.dummy,y)
set this.z = z
set zangle = za
endmethod
private method onDestroy takes nothing returns nothing
if(this.abil!=0) then
call UnitRemoveAbility(this.dummy,this.abil)
endif
if(this.fx!=null) then
call DestroyEffect(this.fx)
set this.fx=null
endif
if (recyclebin.end==MAX_INSTANCES) then
//I'd like to see this happen...
call TimerStart(recycler,0,false,function recyclebin.Recycle)
call ExplodeUnitBJ(this.dummy)
else
set recyclebin.end.u=this.dummy
set recyclebin.end.schedule=TimerGetElapsed(NOW)+RECYCLE_DELAY
set recyclebin.end= recyclebin( integer(recyclebin.end)+1)
if( recyclebin.end==1) then
call TimerStart(recycler, RECYCLE_DELAY, false, function recyclebin.Recycle)
endif
call SetUnitOwner(this.dummy,Player(15),false)
endif
set this.dummy=null
endmethod
method hiddenDestroy takes nothing returns nothing
call ShowUnit(dummy,false)
call destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+)
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
endglobals
//==========================================================================================
function NewTimer takes nothing returns timer
if (tN==0) then
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
set tT[0]=CreateTimer()
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],0)
return tT[tN]
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library GroupUtils initializer Init requires optional xebasic
//******************************************************************************
//* BY: Rising_Dusk
//*
//* This library is a combination of several features relevant to groups. First
//* and foremost, it contains a group stack that you can access dynamic groups
//* from. It also provides means to refresh groups and clear any shadow
//* references within them. The included boolexprs are there for backwards
//* compatibility with maps that happen to use them. Since the 1.24c patch,
//* null boolexprs used in GroupEnumUnits* calls no longer leak, so there is no
//* performance gain to using the BOOLEXPR_TRUE constant.
//*
//* Instead of creating/destroying groups, we have moved on to recycling them.
//* NewGroup pulls a group from the stack and ReleaseGroup adds it back. Always
//* remember to call ReleaseGroup on a group when you are done using it. If you
//* fail to do so enough times, the stack will overflow and no longer work.
//*
//* GroupRefresh cleans a group of any shadow references which may be clogging
//* its hashtable. If you remove a unit from the game who is a member of a unit
//* group, it will 'effectively' remove the unit from the group, but leave a
//* shadow in its place. Calling GroupRefresh on a group will clean up any
//* shadow references that may exist within it. It is only worth doing this on
//* groups that you plan to have around for awhile.
//*
//* Constants that can be used from the library:
//* [group] ENUM_GROUP As you might expect, this group is good for
//* when you need a group just for enumeration.
//* [boolexpr] BOOLEXPR_TRUE This is a true boolexpr, which is important
//* because a 'null' boolexpr in enumeration
//* calls results in a leak. Use this instead.
//* [boolexpr] BOOLEXPR_FALSE This exists mostly for completeness.
//*
//* This library also includes a simple implementation of a group enumeration
//* call that factors collision of units in a given area of effect. This is
//* particularly useful because GroupEnumUnitsInRange doesn't factor collision.
//*
//* In your map, you can just replace all instances of GroupEnumUnitsInRange
//* with GroupEnumUnitsInArea with identical arguments and your spells will
//* consider all units colliding with the area of effect. After calling this
//* function as you would normally call GroupEnumUnitsInRange, you are free to
//* do anything with the group that you would normally do.
//*
//* If you don't use xebasic in your map, you may edit the MAX_COLLISION_SIZE
//* variable below and the library will use that as the added radius to check.
//* If you use xebasic, however, the script will automatically use xe's
//* collision size variable.
//*
//* You are also able to use GroupUnitsInArea. This function returns all units
//* within the area, no matter what they are, which can be convenient for those
//* instances where you actually want that.
//*
//* Example usage:
//* local group MyGroup = NewGroup()
//* call GroupRefresh(MyGroup)
//* call ReleaseGroup(MyGroup)
//* call GroupEnumUnitsInArea(ENUM_GROUP, x, y, 350., BOOLEXPR_TRUE)
//* call GroupUnitsInArea(ENUM_GROUP, x, y, 350.)
//*
globals
//If you don't have xebasic in your map, this value will be used instead.
//This value corresponds to the max collision size of a unit in your map.
private constant real MAX_COLLISION_SIZE = 197.
//If you are insane and don't care about any of the protection involved in
//this library, but want this script to be really fast, set this to true.
private constant boolean LESS_SAFETY = false
endglobals
globals
//* Constants that are available to the user
group ENUM_GROUP = CreateGroup()
boolexpr BOOLEXPR_TRUE = null
boolexpr BOOLEXPR_FALSE = null
endglobals
globals
//* Hashtable for debug purposes
private hashtable ht = InitHashtable()
//* Temporary references for GroupRefresh
private boolean Flag = false
private group Refr = null
//* Arrays and counter for the group stack
private group array Groups
private integer Count = 0
//* Variables for use with the GroupUnitsInArea function
private real X = 0.
private real Y = 0.
private real R = 0.
private hashtable H = InitHashtable()
endglobals
private function HookDestroyGroup takes group g returns nothing
if g == ENUM_GROUP then
call BJDebugMsg(SCOPE_PREFIX+"Warning: ENUM_GROUP destroyed")
endif
endfunction
debug hook DestroyGroup HookDestroyGroup
private function AddEx takes nothing returns nothing
if Flag then
call GroupClear(Refr)
set Flag = false
endif
call GroupAddUnit(Refr, GetEnumUnit())
endfunction
function GroupRefresh takes group g returns nothing
set Flag = true
set Refr = g
call ForGroup(Refr, function AddEx)
if Flag then
call GroupClear(g)
endif
endfunction
function NewGroup takes nothing returns group
if Count == 0 then
set Groups[0] = CreateGroup()
else
set Count = Count - 1
endif
static if not LESS_SAFETY then
call SaveInteger(ht, 0, GetHandleId(Groups[Count]), 1)
endif
return Groups[Count]
endfunction
function ReleaseGroup takes group g returns boolean
local integer id = GetHandleId(g)
static if LESS_SAFETY then
if g == null then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Null groups cannot be released")
return false
elseif Count == 8191 then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Max groups achieved, destroying group")
call DestroyGroup(g)
return false
endif
else
if g == null then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Null groups cannot be released")
return false
elseif not HaveSavedInteger(ht, 0, id) then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Group not part of stack")
return false
elseif LoadInteger(ht, 0, id) == 2 then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Groups cannot be multiply released")
return false
elseif Count == 8191 then
debug call BJDebugMsg(SCOPE_PREFIX+"Error: Max groups achieved, destroying group")
call DestroyGroup(g)
return false
endif
call SaveInteger(ht, 0, id, 2)
endif
call GroupClear(g)
set Groups[Count] = g
set Count = Count + 1
return true
endfunction
private function Filter takes nothing returns boolean
return IsUnitInRangeXY(GetFilterUnit(), X, Y, R)
endfunction
private function HookDestroyBoolExpr takes boolexpr b returns nothing
local integer bid = GetHandleId(b)
if HaveSavedHandle(H, 0, bid) then
//Clear the saved boolexpr
call DestroyBoolExpr(LoadBooleanExprHandle(H, 0, bid))
call RemoveSavedHandle(H, 0, bid)
endif
endfunction
hook DestroyBoolExpr HookDestroyBoolExpr
private constant function GetRadius takes real radius returns real
static if LIBRARY_xebasic then
return radius+XE_MAX_COLLISION_SIZE
else
return radius+MAX_COLLISION_SIZE
endif
endfunction
function GroupEnumUnitsInArea takes group whichGroup, real x, real y, real radius, boolexpr filter returns nothing
local real prevX = X
local real prevY = Y
local real prevR = R
local integer bid = 0
//Set variables to new values
set X = x
set Y = y
set R = radius
if filter == null then
//Adjusts for null boolexprs passed to the function
set filter = Condition(function Filter)
else
//Check for a saved boolexpr
set bid = GetHandleId(filter)
if HaveSavedHandle(H, 0, bid) then
//Set the filter to use to the saved one
set filter = LoadBooleanExprHandle(H, 0, bid)
else
//Create a new And() boolexpr for this filter
set filter = And(Condition(function Filter), filter)
call SaveBooleanExprHandle(H, 0, bid, filter)
endif
endif
//Enumerate, if they want to use the boolexpr, this lets them
call GroupEnumUnitsInRange(whichGroup, x, y, GetRadius(radius), filter)
//Give back original settings so nested enumerations work
set X = prevX
set Y = prevY
set R = prevR
endfunction
function GroupUnitsInArea takes group whichGroup, real x, real y, real radius returns nothing
local real prevX = X
local real prevY = Y
local real prevR = R
//Set variables to new values
set X = x
set Y = y
set R = radius
//Enumerate
call GroupEnumUnitsInRange(whichGroup, x, y, GetRadius(radius), Condition(function Filter))
//Give back original settings so nested enumerations work
set X = prevX
set Y = prevY
set R = prevR
endfunction
private function True takes nothing returns boolean
return true
endfunction
private function False takes nothing returns boolean
return false
endfunction
private function Init takes nothing returns nothing
set BOOLEXPR_TRUE = Condition(function True)
set BOOLEXPR_FALSE = Condition(function False)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library BoundSentinel initializer init
//*************************************************
//* BoundSentinel
//* -------------
//* Don't leave your units unsupervised, naughty
//* them may try to get out of the map bounds and
//* crash your game.
//*
//* To implement, just get a vJass compiler and
//* copy this library/trigger to your map.
//*
//*************************************************
//==================================================
globals
// High enough so the unit is no longer visible, low enough so the
// game doesn't crash...
//
// I think you need 0.0 or soemthing negative prior to patch 1.22
//
private constant real EXTRA = 500.0
endglobals
//=========================================================================================
globals
private real maxx
private real maxy
private real minx
private real miny
endglobals
//=======================================================================
private function dis takes nothing returns nothing
local unit u=GetTriggerUnit()
local real x=GetUnitX(u)
local real y=GetUnitY(u)
if(x>maxx) then
set x=maxx
elseif(x<minx) then
set x=minx
endif
if(y>maxy) then
set y=maxy
elseif(y<miny) then
set y=miny
endif
call SetUnitX(u,x)
call SetUnitY(u,y)
set u=null
endfunction
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local region r=CreateRegion()
local rect rc
set minx=GetCameraBoundMinX() - EXTRA
set miny=GetCameraBoundMinY() - EXTRA
set maxx=GetCameraBoundMaxX() + EXTRA
set maxy=GetCameraBoundMaxY() + EXTRA
set rc=Rect(minx,miny,maxx,maxy)
call RegionAddRect(r, rc)
call RemoveRect(rc)
call TriggerRegisterLeaveRegion(t,r, null)
call TriggerAddAction(t, function dis)
//this is not necessary but I'll do it anyway:
set t=null
set r=null
set rc=null
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library InitMap initializer Init
globals
unit Hero
endglobals
private function Init takes nothing returns nothing
call SetFloatGameState(GAME_STATE_TIME_OF_DAY, 12.)
set Hero = CreateUnit(Player(0),'Emoo',0,0,270)
call SelectUnit(Hero,true)
call DisplayTextToPlayer(Player(0),0,0,"Wish by watermelon_1234\nType -lvl x to set hero's level to x\nPress Esc to refresh your hero.")
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope ReviveUnits initializer Init
globals
private hashtable Revive = InitHashtable()
private constant real DELAY = 30.
private constant real HERO_DELAY = 5.
endglobals
private function SaveData takes unit u returns nothing
call SaveReal(Revive,0,GetHandleId(u),GetUnitX(u))
call SaveReal(Revive,1,GetHandleId(u),GetUnitY(u))
call SaveReal(Revive,2,GetHandleId(u),GetUnitFacing(u))
endfunction
private function ReviveFilter takes nothing returns boolean
local unit u = GetFilterUnit()
call SaveData(u)
set u = null
return true
endfunction
private struct Data
unit d
static method create takes unit d returns Data
local Data D = Data.allocate()
set D.d = d
return D
endmethod
static method onRevive takes nothing returns nothing
local timer t = GetExpiredTimer()
local Data D = Data(GetTimerData(t))
local real x = LoadReal(Revive,0,GetHandleId(D.d))
local real y = LoadReal(Revive,1,GetHandleId(D.d))
local real ang = LoadReal(Revive,2,GetHandleId(D.d))
if IsUnitType(D.d,UNIT_TYPE_HERO) == true then
call ReviveHero(D.d,x,y,true)
call SetUnitFacing(D.d,ang)
if GetLocalPlayer() == GetOwningPlayer(D.d) then
call PanCameraTo(x,y)
endif
call SetUnitState( D.d,UNIT_STATE_MANA,GetUnitState(D.d,UNIT_STATE_MAX_MANA))
else
call SaveData(CreateUnit(GetOwningPlayer(D.d),GetUnitTypeId(D.d),x,y,ang))
endif
set D.d = null
call D.destroy()
call ReleaseTimer(t)
set t = null
endmethod
endstruct
private function Actions takes nothing returns boolean
local timer t = NewTimer()
local unit d = GetTriggerUnit()
local real delay = DELAY
if IsUnitType(d,UNIT_TYPE_STRUCTURE) == false and IsUnitType(d,UNIT_TYPE_SUMMONED) == false then
call SetTimerData(t,Data.create(d))
if IsUnitType(d,UNIT_TYPE_HERO) == true then
set delay = HERO_DELAY
endif
call TimerStart(t,delay,false,function Data.onRevive)
set t = null
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger( )
local boolexpr e = Condition(function ReviveFilter)
local group g = CreateGroup()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition(function Actions))
call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,e)
call DestroyBoolExpr(e)
call DestroyGroup(g)
set g = null
set e = null
endfunction
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Refresh_Actions takes nothing returns nothing
call SetWidgetLife( Hero,GetUnitState(Hero,UNIT_STATE_MAX_LIFE))
call SetUnitState( Hero,UNIT_STATE_MANA,GetUnitState(Hero,UNIT_STATE_MAX_MANA))
call UnitResetCooldown( Hero )
endfunction
function InitTrig_Refresh takes nothing returns nothing
set gg_trg_Refresh = CreateTrigger( )
call TriggerRegisterPlayerEvent( gg_trg_Refresh, Player(0),EVENT_PLAYER_END_CINEMATIC )
call TriggerAddAction( gg_trg_Refresh, function Trig_Refresh_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Level_Actions takes nothing returns nothing
call SetHeroLevel( Hero, S2I(SubString(GetEventPlayerChatString(), 5, StringLength(GetEventPlayerChatString()))), false )
endfunction
function InitTrig_LvlUp takes nothing returns nothing
set gg_trg_LvlUp = CreateTrigger()
call TriggerRegisterPlayerChatEvent( gg_trg_LvlUp, Player(0), "-lvl", false )
call TriggerAddAction( gg_trg_LvlUp, function Trig_Level_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
//***************************************************
//Wish v1.01 by watermelon_1234
//***************************************************
//Required Libraries: TimerUtils, xebasic, xefx
//***************************************************
scope Wish
native UnitAlive takes unit id returns boolean //Remove this line if it's already implemented.
//===================================================
//CONSTANTS
//===================================================
globals
private constant integer SPELL_ID = 'A000' //The raw id of the Wish ability
private constant real HEIGHT = 1500. //The height the wish should ascend
private constant string WISH_SFX = "Abilities\\Weapons\\FaerieDragonMissile\\FaerieDragonMissile.mdl" //The sfx used for the missile that will orbit the point
private constant real WISH_SPEED = 225. //Determines the speed for the wish and the timer repitition for the Data.wishEffect. A smaller number means a faster wish missile
private constant real TIMER_LOOP = XE_ANIMATION_PERIOD //How often the timer will loop
private constant string STAR_SFX = "Abilities\\Spells\\NightElf\\Starfall\\StarfallTarget.mdl" //The star sfx that will be used for the falling star
private constant real STAR_AREA = 75. //The area for the stars to affect nearby units upon impact.
private constant real STAR_INTERVAL = .25 //The interval between each star creation
private constant real STAR_DELAY = .7 //The delay the star has after being shown before actually doing anything.
private constant string HEAL_SFX = "Abilities\\Spells\\Other\\HealingSpray\\HealBottleMissile.mdl" //The sfx that will play when a unit is healed by the wish
private constant real HEAL_INTERVAL = .4 //The interval between each heal sfx played
private constant integer MAX_ARRAY_SIZE = 6 //Number should be equal to the number of wishes created by the spell
private constant attacktype ATK_TYPE = ATTACK_TYPE_NORMAL //Attack type for the star damage
private constant damagetype DMG_TYPE = DAMAGE_TYPE_UNIVERSAL //Damage type for the star damage
private constant weapontype WPN_TYPE = null //Weapon type for the star damage
private constant boolean PRELOAD = true //Determines whether or not to preload the spell sfx
endglobals
//===================================================
//Configuration for other parts of the spell
//===================================================
private constant function WishNumber takes integer lvl returns integer //The number of wishes created, purely a visual effect. I suggest that this number increases with the spell area.
return 3+1*lvl
endfunction
private constant function HeightSpeed takes integer lvl returns real //How much time should it take for the wishes to reach the height
return 5.+0*lvl
endfunction
private constant function StarRate takes integer lvl returns integer //The number of stars created depending on how many friendly people there are
return 0+1*lvl
endfunction
private constant function HealNumber takes integer lvl returns integer
return 1+1*lvl
endfunction
private constant function Area takes integer lvl returns real //Determines the area of effect of the spell
return 150.+50*lvl
endfunction
private constant function AreaHeal takes integer lvl returns real //Amount healed per second in the AoE at the beginning of the spell
return 5.+10*lvl
endfunction
private function StarHeal takes integer lvl returns real //Amount healed when friendly units are hit by the star
return 15.+5*lvl
endfunction
private constant function StarDamage takes integer lvl returns real //Damage done to enemy units if hit by the star
return 5.+5*lvl
endfunction
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//CODING OF THE SPELL. Please look at the method filter to determine which units can be healed and damaged.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
globals
private boolexpr e //Used as a filter.
private group GROUP_ENUM //This will be used if GroupUtils isn't there.
endglobals
private struct Data
unit cast //The caster of the spell
real x //Holds the x coordinate of the spell target point
real y //Holds the y coordinate of the spell target point
integer lvl //The level of the ability when it was casted
integer stars = 0 //Used to determine when to stop creating stars by counting how many stars that were created
integer which //For the filter method. 0 - acts for units affected by the wishEffect, 1 - acts for units affected by the starEffect
integer wnumber //Stores the number of wishes that will be made
integer hnumber //Stores the number of heal sfx's that will be played
integer snumber = 0 //Stores the number of stars that will be created based on how many friendly units were in that area
group sgroup = CreateGroup() //This group will be used to find out how many stars to create from the friendly units
real count = 0 //Used to determine the wish's height
real hcount = 0 //Used to determine when to play the heal sfx
real area //Stores the area of effect for the wish
real hspeed //Stores the speed it will take to reach HEIGHT
timer t //Timer used by the spell
xefx array wish[MAX_ARRAY_SIZE] //The missile for the wish effect
real array ang[MAX_ARRAY_SIZE] //The angle for the wish
private static thistype temp //Used to pass information from a specific struct to the filter method.
static method create takes unit c, real x, real y returns thistype //Used for the initial storage and creation of the struct
local thistype this = thistype.allocate()
set .cast = c
set .x = x
set .y = y
set .t = NewTimer()
return this
endmethod
static method filter takes nothing returns boolean //Determines which units will be affected by the wish and star. Also applies the effects on them.
local unit u = GetFilterUnit()
if UnitAlive(u) then //Filter only for alive units
if IsUnitAlly(u,GetOwningPlayer(temp.cast)) and not IsUnitType(u,UNIT_TYPE_MECHANICAL) then //Healing effect
if temp.which == 0 then //Wish part
call SetWidgetLife(u,GetWidgetLife(u)+AreaHeal(temp.lvl)*TIMER_LOOP)
if not IsUnitInGroup(u,temp.sgroup) then //Adds to a group so it won't be recounted
call GroupAddUnit(temp.sgroup,u)
set temp.snumber = temp.snumber + StarRate(temp.lvl)
endif
else //Star part
call SetWidgetLife(u,GetWidgetLife(u)+StarHeal(temp.lvl))
endif
elseif temp.which == 1 and IsUnitEnemy(u,GetOwningPlayer(temp.cast)) then //Star damaging effects
call UnitDamageTarget(temp.cast,u,StarDamage(temp.lvl),false,true,ATK_TYPE,DMG_TYPE,WPN_TYPE)
endif
endif
set u = null
return false //Returns false since we don't need to put the units in the group
endmethod
static method effectStar takes nothing returns nothing //Deals damage and healing after STAR_DELAY seconds
local thistype this = GetTimerData(GetExpiredTimer())
set .which = 1 //Filter will be used for star effect
set temp = this //Sets this so that the struct can be referenced from the static method
static if LIBRARY_GroupUtils then
call GroupEnumUnitsInArea(ENUM_GROUP,.x,.y,STAR_AREA,e)
else
call GroupEnumUnitsInRange(GROUP_ENUM,.x,.y,STAR_AREA,e)
endif
call ReleaseTimer(.t)
call .destroy()
endmethod
static method createStar takes nothing returns nothing //Deals with the creation of the stars
local thistype this = GetTimerData(GetExpiredTimer())
local thistype D
if .stars < .snumber then //Used to check when to stop creating stars
set D = Data.create(.cast,.x + GetRandomReal(-.area/2,.area/2),.y + GetRandomReal(-.area/2,.area/2)) //I decided to stick with having one struct so that it could access the same filter method.
call DestroyEffect(AddSpecialEffect(STAR_SFX,D.x,D.y))
call SetTimerData(D.t,D)
call TimerStart(D.t,STAR_DELAY,false,function thistype.effectStar)
set .stars = .stars + 1
else
call ReleaseTimer(.t)
call .destroy()
endif
endmethod
static method effectWish takes nothing returns nothing //Deals with the wish movements, height, and healing.
local thistype this = GetTimerData(GetExpiredTimer())
local integer i = 0
if .count <= .hspeed then
loop
set .ang[i] = .ang[i] + WISH_SPEED*TIMER_LOOP*.017453278
set .wish[i].x = .x + (.area-.area/.hspeed*.count) * Cos(.ang[i])
set .wish[i].y = .y + (.area-.area/.hspeed*.count) * Sin(.ang[i])
set .wish[i].z = HEIGHT/.hspeed*.count
set i = i + 1
exitwhen i == .wnumber
endloop
set .count = .count + TIMER_LOOP
if .hcount >= HEAL_INTERVAL then
set .hcount = 0
endif
set .which = 0 //Filter will be used for wish effect
set temp = this //Sets this so that the struct can be referenced from the static method
static if LIBRARY_GroupUtils then
call GroupEnumUnitsInArea(ENUM_GROUP,.x,.y,.area,e)
else
call GroupEnumUnitsInRange(GROUP_ENUM,.x,.y,.area,e)
endif
if .hcount == 0 then
set i = 0
loop
call DestroyEffect(AddSpecialEffect(HEAL_SFX,.x+GetRandomReal(-Area(.lvl)/2,Area(.lvl)/2),.y+GetRandomReal(-Area(.lvl)/2,Area(.lvl)/2)))
set i = i + 1
exitwhen i == .hnumber
endloop
endif
set .hcount = .hcount + TIMER_LOOP
else
loop
call .wish[i].destroy() //Destroy the wish missile since it's no longer needed
set i = i + 1
exitwhen i == .wnumber
endloop
call ReleaseTimer(.t)
call GroupClear(.sgroup) //No longer needed.
if .snumber > 0 then
set .t = NewTimer()
call SetTimerData(.t,this)
call TimerStart(.t,STAR_INTERVAL,true,function Data.createStar)
else
call .destroy()
endif
endif
endmethod
static method spellActions takes nothing returns boolean
local thistype this
local integer i = 0
local real wx //For readability
local real wy
if GetSpellAbilityId() == SPELL_ID then
set this = Data.create(GetTriggerUnit(),GetSpellTargetX(),GetSpellTargetY())
set .lvl = GetUnitAbilityLevel(.cast,SPELL_ID)
set .area = Area(.lvl)
set .wnumber = WishNumber(.lvl)
set .hnumber = HealNumber(.lvl)
set .hspeed = HeightSpeed(.lvl)
loop
set wx = .x + Area(.lvl)*Cos(6.28285608/WishNumber(.lvl)*i)
set wy = .y + Area(.lvl)*Sin(6.28285608/WishNumber(.lvl)*i)
set .wish[i] = xefx.create(wx,wy,0)
set .wish[i].fxpath = WISH_SFX
set .ang[i] = Atan2(.y - wy, .x - wx)
set i = i + 1
exitwhen i == WishNumber(.lvl)
endloop
call SetTimerData(.t,this)
call TimerStart(.t,TIMER_LOOP,true,function thistype.effectWish)
endif
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition( function thistype.spellActions)) //Because trigger conditions are faster than actions
set e = Condition(function thistype.filter) //Sets the filter
//Preload effects
static if PRELOAD then
call Preload(WISH_SFX)
call Preload(STAR_SFX)
call Preload(HEAL_SFX)
endif
static if not LIBRARY_GroupUtils then
set GROUP_ENUM = CreateGroup() //Don't bother creating the group if we'll just use GroupUtils
endif
set t = null //Just to null handles.
endmethod
endstruct
endscope