I made this system to make spellmaking easier, and I think I succeded. Not much to say, uses structs and methods, easy to use.
Code: (for those who actually have the time to read.)
Enjoy, and give credit to me if you use.
Code: (for those who actually have the time to read.)
JASS:
//==================================================================================================
// SS--SPELLSYSTEM
// BY VESTRAS
// ACTUAL CODE
// v1.00
//==================================================================================================
//==================================================================================================
// History:
// This system was originally created by Vestras for the map Aeon of Souls. Please give credit to
// me when using!
//
// Why?
// I made this so that spell making could be easier and funnier. I know I've accomplished one of
// the objectives: easier.
//
// What does it support?
// Currently casters, damage, shapes and sounds. The struct names are: sscaster, ssdamage, ssshapes
// and sssounds.
//
// I'm always looking for ideas for new structs and methods, so if you have some, please share!
//==================================================================================================
// !!!! START OF SS--SPELLSYSTEM CONFIG !!!! \\
globals
constant integer ss_dummy = 039;e000039;
constant integer ss_heightenabler = 039;Amrf039;
constant integer ss_player = 15
constant real ss_defaulttime = 5
constant attacktype ss_attacktype = ATTACK_TYPE_NORMAL
constant damagetype ss_defaultdtype = DAMAGE_TYPE_NORMAL
constant damagetype ss_armordtype = DAMAGE_TYPE_UNIVERSAL
endglobals
// !!!! START OF SS--CASTER MODULE !!!! \\
struct sscaster
//===============================================================================================
// Remember, that dummy casters are slow, so you might want to add a minus cooldown and
// casting time to the dummy ability!
//=====================//
static unit dummy //
//=====================//
//===============================================================================================
// create method, if time is 0, a life timer won't be added
//
static method create takes player p, real x, real y, real time returns sscaster
local sscaster d = sscaster.allocate()
set d.dummy = CreateUnit(p, ss_dummy, x, y, 0)
if time != 0 then
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, time)
else
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, ss_defaulttime)
endif
return d
endmethod
method castXY takes integer abilityid, integer level, string orderstring, real tx, real ty returns nothing
call UnitAddAbility(.dummy, abilityid)
call SetUnitAbilityLevel(.dummy, abilityid, level)
call IssuePointOrder(.dummy, orderstring, tx, ty)
endmethod
method castLoc takes integer abilityid, integer level, string orderstring, location l returns nothing
call UnitAddAbility(.dummy, abilityid)
call SetUnitAbilityLevel(.dummy, abilityid, level)
call IssuePointOrderLoc(.dummy, orderstring, l)
endmethod
method castTarget takes integer abilityid, integer level, string orderstring, unit target returns nothing
call UnitAddAbility(.dummy, abilityid)
call SetUnitAbilityLevel(.dummy, abilityid, level)
call IssueTargetOrder(.dummy, orderstring, target)
endmethod
method castInstant takes integer abilityid, integer level, string orderstring returns nothing
call UnitAddAbility(.dummy, abilityid)
call SetUnitAbilityLevel(.dummy, abilityid, level)
call IssueImmediateOrder(.dummy, orderstring)
endmethod
//===============================================================================================
// Removeing methods.
//
method removeDummy takes nothing returns nothing
call RemoveUnit(.dummy)
endmethod
method removeDummyTimed takes real time returns nothing
call UnitApplyTimedLife(.dummy, 039;BTLF039;, time)
endmethod
//===============================================================================================
//
//
static method createAndCastXY takes integer abilityid, integer level, real timed, string orderstring, real x, real y, real tx, real ty returns sscaster
local sscaster d = sscaster.allocate()
set d.dummy = CreateUnit(Player(ss_player), ss_dummy, x, y, 0)
call UnitAddAbility(d.dummy, abilityid)
call SetUnitAbilityLevel(d.dummy, abilityid, level)
call IssuePointOrder(d.dummy, orderstring, tx, ty)
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, timed)
return d
endmethod
static method createAndCastLoc takes integer abilityid, integer level, real timed, string orderstring, real x, real y, location l returns sscaster
local sscaster d = sscaster.allocate()
set d.dummy = CreateUnit(Player(ss_player), ss_dummy, x, y, 0)
call UnitAddAbility(d.dummy, abilityid)
call SetUnitAbilityLevel(d.dummy, abilityid, level)
call IssuePointOrderLoc(d.dummy, orderstring, l)
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, timed)
return d
endmethod
static method createAndCastTarget takes integer abilityid, integer level, real timed, string orderstring, real x, real y, unit target returns sscaster
local sscaster d = sscaster.allocate()
set d.dummy = CreateUnit(Player(ss_player), ss_dummy, x, y, 0)
call UnitAddAbility(d.dummy, abilityid)
call SetUnitAbilityLevel(d.dummy, abilityid, level)
call IssueTargetOrder(d.dummy, orderstring, target)
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, timed)
return d
endmethod
static method createAndCastInstant takes integer abilityid, integer level, real timed, string orderstring, real x, real y returns sscaster
local sscaster d = sscaster.allocate()
set d.dummy = CreateUnit(Player(ss_player), ss_dummy, x, y, 0)
call UnitAddAbility(d.dummy, abilityid)
call SetUnitAbilityLevel(d.dummy, abilityid, level)
call IssueImmediateOrder(d.dummy, orderstring)
call UnitApplyTimedLife(d.dummy, 039;BTLF039;, timed)
return d
endmethod
//===============================================================================================
//
//
string os
integer aid
integer lvl
real time
real x
real y
//====================================//
static sscaster adata //
static group grpg = CreateGroup() //
//====================================//
//
//
//===============================================================================================
//
static method AOE_Callback takes nothing returns boolean
local sscaster a = .adata
local unit d = CreateUnit(Player(ss_player), ss_dummy, a.x, a.y, 0)
call UnitAddAbility(d, a.aid)
call SetUnitAbilityLevel(d, a.aid, a.lvl)
call IssueTargetOrder(d, a.os, GetFilterUnit())
call UnitApplyTimedLife(d, 039;BTLF039;, a.time)
return false
endmethod
static method createAndCastAOE takes integer abilityid, integer level, real timed, string orderstring, real x, real y, real radius returns sscaster
local sscaster d = sscaster.allocate()
local unit s
set d.os = orderstring
set d.aid = abilityid
set d.lvl = level
set d.time = timed
set d.x = x
set d.y = y
set sscaster.adata = d
call GroupEnumUnitsInRange(.grpg, x, y, radius, Filter(function sscaster.AOE_Callback))
set s = null
return d
endmethod
//===============================================================================================
//
//
string xos
integer xaid
integer xlvl
real xtime
real xx
real xy
static sscaster grpdata
//
//
//===============================================================================================
//
static method Group_Callback takes nothing returns nothing
local sscaster a = .grpdata
local unit d = CreateUnit(Player(ss_player), ss_dummy, a.xx, a.xy, 0)
call UnitAddAbility(d, a.xaid)
call SetUnitAbilityLevel(d, a.xaid, a.xlvl)
call IssueTargetOrder(d, a.xos, GetFilterUnit())
call UnitApplyTimedLife(d, 039;BTLF039;, a.xtime)
endmethod
static method createAndCastGroup takes integer abilityid, integer level, real timed, string orderstring, real x, real y, group g returns sscaster
local sscaster d = sscaster.allocate()
set d.xos = orderstring
set d.xaid = abilityid
set d.xlvl = level
set d.xtime = timed
set d.xx = x
set d.xy = y
set sscaster.grpdata = d
call ForGroup(g, function sscaster.Group_Callback)
return d
endmethod
//===============================================================================================
// SetSource methods
//
method SetSourceX takes real x returns nothing
call SetUnitX(.dummy, x)
endmethod
method SetSourceY takes real y returns nothing
call SetUnitY(.dummy, y)
endmethod
method SetSourceFlyHeight takes real h returns nothing
call UnitAddAbility(.dummy, ss_heightenabler)
call SetUnitFlyHeight(.dummy, h, 0)
call UnitRemoveAbility(.dummy, ss_heightenabler)
endmethod
//
//
//===============================================================================================
endstruct
// !!!! START OF SS--DAMAGE MODULE !!!! \\
struct ssdamage
unit damager
unit target
static method DamageUnit takes unit damager, unit target, real damage, boolean armor returns nothing
local ssdamage d = ssdamage.allocate()
set d.damager = damager
set d.target = target
if armor == false then
call UnitDamageTarget(damager, target, damage, false, false, ss_attacktype, ss_armordtype, null)
else
call UnitDamageTarget(damager, target, damage, false, false, ss_attacktype, ss_defaultdtype, null)
endif
endmethod
//===============================================================================================
//
//
unit xdmgr
real xdmg
boolean xrm
//====================================//
static ssdamage dpedata //
static group grpg1 = CreateGroup() //
//====================================//
//
//
//===============================================================================================
static method DPE_Callback takes nothing returns boolean
local ssdamage a = .dpedata
local ssdamage d
if IsUnitAlly(GetFilterUnit(), GetOwningPlayer(a.xdmgr)) != true then
call ssdamage.DamageUnit(a.xdmgr, GetFilterUnit(), a.xdmg, a.xrm)
endif
return false
endmethod
static method DamagePointEnemies takes unit damager, real x, real y, real radius, real damage, boolean armor returns nothing
local ssdamage d = ssdamage.allocate()
set d.xdmgr = damager
set d.xdmg = damage
set d.xrm = armor
set d.damager = damager
set ssdamage.dpedata = d
call GroupEnumUnitsInRange(.grpg1, x, y, radius, Filter(function ssdamage.DPE_Callback))
endmethod
static method DamagePointEnemiesLoc takes unit damager, location l, real radius, real damage, boolean armor returns nothing
call .DamagePointEnemies(damager, GetLocationX(l), GetLocationY(l), radius, damage, armor)
endmethod
//===============================================================================================
//
//
unit xxdmgr
real xxdmg
boolean xxrm
//====================================//
static ssdamage dpadata //
static group grpg2 = CreateGroup() //
//====================================//
//
//
//===============================================================================================
static method DPA_Callback takes nothing returns boolean
local ssdamage a = .dpadata
local ssdamage d
if IsUnitAlly(GetFilterUnit(), GetOwningPlayer(a.xxdmgr)) == true then
call ssdamage.DamageUnit(a.xxdmgr, GetFilterUnit(), a.xxdmg, a.xxrm)
endif
return false
endmethod
static method DamagePointAllies takes unit damager, real x, real y, real radius, real damage, boolean armor returns nothing
local ssdamage d = ssdamage.allocate()
set d.xxdmgr = damager
set d.xxdmg = damage
set d.xxrm = armor
set d.damager = damager
set ssdamage.dpadata = d
call GroupEnumUnitsInRange(.grpg2, x, y, radius, Filter(function ssdamage.DPA_Callback))
endmethod
static method DamagePointAlliesLoc takes unit damager, location l, real radius, real damage, boolean armor returns nothing
call .DamagePointAllies(damager, GetLocationX(l), GetLocationY(l), radius, damage, armor)
endmethod
//===============================================================================================
//
//
unit xxxdmgr
real xxxdmg
boolean xxxrm
//====================================//
static ssdamage dpalldata //
static group grpg3 = CreateGroup() //
//====================================//
//
//
//===============================================================================================
static method DPALL_Callback takes nothing returns boolean
local ssdamage a = .dpedata
local ssdamage d
call .DamageUnit(a.xxdmgr, GetFilterUnit(), a.xxdmg, a.xxrm)
return false
endmethod
static method DamagePointAll takes unit damager, real x, real y, real radius, real damage, boolean armor returns nothing
local ssdamage d = ssdamage.allocate()
set d.xxxdmgr = damager
set d.xxxdmg = damage
set d.xxxrm = armor
set d.damager = damager
set .dpalldata = d
call GroupEnumUnitsInRange(.grpg3, x, y, radius, Filter(function ssdamage.DPALL_Callback))
endmethod
static method DamagePointAllLoc takes unit damager, location l, real radius, real damage, boolean armor returns nothing
call .DamagePointAll(damager, GetLocationX(l), GetLocationY(l), radius, damage, armor)
endmethod
endstruct
// !!!! START OF SS--SHAPES MODULE !!!! \\
struct ssshapes
//===============================================================================================
//
//
static method DistanceBetweenCoords takes real x, real y, real tx, real ty returns real
local real dx = tx - x
local real dy = ty - y
return SquareRoot(dx * dx + dy * dy)
endmethod
static method AngleBetweenCoords takes real xA, real yA, real xB, real yB returns real
return Atan2(yB - yA, xB - yB)
endmethod
//
//
//===============================================================================================
static method line takes real x, real y, real tx, real ty, unit c, string fx, integer n, real dmg, real dmgaoe, boolean armor returns nothing
local ssdamage d
local integer i = 0
local real dx = tx - x
local real dy = ty - y
local real dist = SquareRoot(dx * dx + dy * dy) / n
local real angle = Atan2(ty - y, tx - x)
local real px
local real py
loop
set i = i + 1
exitwhen i > n
set px = x + (dist * i) * Cos(angle)
set py = y + (dist * i) * Sin(angle)
call DestroyEffect(AddSpecialEffect(fx, px, py))
call ssdamage.DamagePointEnemies(c, px, py, dmgaoe, dmg, armor)
endloop
endmethod
static method circle takes real x, real y, real radius, unit c, string fx, integer n, real dmg, real dmgaoe, boolean armor returns nothing
local ssdamage d
local integer i = 0
local real angle
local real px
local real py
set px = x + radius * Cos(0 * bj_DEGTORAD)
set py = y + radius * Sin(0 * bj_DEGTORAD)
call DestroyEffect(AddSpecialEffect(fx, px, py))
call ssdamage.DamagePointEnemies(c, px, py, dmgaoe, dmg, armor)
loop
set i = i + 1
exitwhen i > n
set angle = i * (360 / n)
set px = x + radius * Cos(angle * bj_DEGTORAD)
set py = y + radius * Sin(angle * bj_DEGTORAD)
call DestroyEffect(AddSpecialEffect(fx, px, py))
call ssdamage.DamagePointEnemies(c, px, py, dmgaoe, dmg, armor)
endloop
endmethod
static method triangle takes real x, real y, real radius, unit c, string fx, real dmg, real dmgaoe, boolean armor returns nothing
local ssdamage d
local real angle = GetUnitFacing(c)
local real px
local real py
local integer i = 1
loop
set i = i + 1
exitwhen i > 4
set angle = angle + (90 * (i - 1))
set px = x + radius * Cos(angle * bj_DEGTORAD)
set py = y + radius * Sin(angle * bj_DEGTORAD)
call DestroyEffect(AddSpecialEffect(fx, px, py))
call ssdamage.DamagePointEnemies(c, px, py, dmgaoe, dmg, armor)
endloop
endmethod
endstruct
// !!!! START OF SS--SOUND MODULE !!!! \\
struct sssound
//=================//
static sound snd //
//=================//
//
//
//===============================================================================================
static method create takes string str returns sssound
//===============================================================================================
local sssound s=sssound.allocate()
set sssound.snd=CreateSound(str,false,false,true,12700,12700,"")
return s
endmethod
method PlaySoundEx takes nothing returns sound
call StartSound(sssound.snd)
call KillSoundWhenDone(sssound.snd)
return sssound.snd
endmethod
method PlaySoundCone takes real inside, real outside, integer outsideV returns sound
set sssound.snd=.PlaySoundEx()
call SetSoundConeAngles(sssound.snd,inside,outside,outsideV)
return sssound.snd
endmethod
method AddSpecialEffectWithSound takes string fx, real x, real y, string str returns sound
set sssound.snd=.PlaySoundEx()
call DestroyEffect(AddSpecialEffect(fx, x, y))
return sssound.snd
endmethod
method AddSpecialEffectTargetWithSound takes string fx, widget target, string attach, string str returns sound
set sssound.snd=.PlaySoundEx()
call DestroyEffect(AddSpecialEffectTarget(fx, target, attach))
return sssound.snd
endmethod
//
//
//===============================================================================================
endstruct
// !!!! END OF SS--SPELLSYSTEM !!!! \\
v1.01:
- Fixed minor method stuff.
v1.00:
- Initial release.
- Fixed minor method stuff.
v1.00:
- Initial release.
Enjoy, and give credit to me if you use.