- Joined
- Apr 27, 2011
- Messages
- 272
I usually see vJASS casting systems, so i decided to make one for JASS... although this uses some vJASS features I'm planning to change them after sometime... so they can be used with plain JASS...
please leave constructive comments about it! ( i know the coding sucks that's why i want some comments about it)
there are 6 functions:
-AllocateCaster(pl) : returns a dummy caster under the control of player "pl".
-DeallocateCaster(caster) : deallocates the unit "caster"
-CastSpellOnTarget(caster,target,spellid,orderstr,lvl)
-CastSpellOnAreaLvl(caster,x,y,r,spellid,orderstr,v,lvl) : "v" determines the targets.. I used "caster" as the first argument instead of a player argument directly because i want to keep the library's convention...
-CastSpellOnPointLvl(caster,x,y,range,angle,spellid,orderstr,lvl) : casts a point target spell towards "angle"... from "x" and "y"
-CastSpellInPointLvl(caster,x,y,spellid,orderstr,lvl) : casts a point-blank spell in "x" and "y"
this lib was inspired by CS... this is a lightweight one.
i also managed to somehow integrate this also... targeting multiple units with instant spells, using one dummy caster
and the good news is now we can target 20+ units unlike the previous one on the link...
(chicken's the dummy caster)
JASS:
library DummyCast
//===========================================================================
// DummyCast
//===========================================================================
//=======================================================================
// alloc. & dealloc. Caster
//=======================================================================
globals
private integer c =-1
private integer w = 0
private unit cs
private unit array rcs
private constant player DEFAULT_OWNER = Player(15)
private constant integer INITIAL_CASTERS = 30
private constant trigger ENDCAST_SENTINEL = CreateTrigger()
private constant integer SC_DUMMY_UNIT = 'n000'
endglobals
//=======================================================================
function AllocateCaster takes player pl returns unit
if(w==0)then
set cs=CreateUnit(pl,SC_DUMMY_UNIT,0,0,0)
call TriggerRegisterUnitEvent(ENDCAST_SENTINEL,cs,EVENT_UNIT_SPELL_ENDCAST)
else
set w=w-1
set cs=rcs[w]
call SetUnitOwner(cs,pl,false)
endif
return cs
endfunction
//=======================================================================
function DeallocCaster takes unit u returns nothing
call SetUnitOwner(u,DEFAULT_OWNER,false)
set rcs[w]=u
set w=w+1
endfunction
//=======================================================================
private function DeallocCasterX takes unit u, integer spellid returns nothing
call DeallocCaster(u)
call UnitRemoveAbility(u,spellid)
endfunction
//=======================================================================
private function EndcastFilter takes nothing returns boolean
call DeallocCasterX(GetTriggerUnit(),GetSpellAbilityId())
return false
endfunction
//=======================================================================
private module initA
private static method onInit takes nothing returns nothing
local integer nloops=INITIAL_CASTERS
loop
exitwhen nloops==0
set rcs[w]=CreateUnit(DEFAULT_OWNER,SC_DUMMY_UNIT,0,0,0)
call TriggerRegisterUnitEvent(ENDCAST_SENTINEL,rcs[w],EVENT_UNIT_SPELL_ENDCAST)
set w=w+1
set nloops=nloops-1
endloop
call TriggerAddCondition(ENDCAST_SENTINEL,Condition(function EndcastFilter))
endmethod
endmodule
//=======================================================================
// CreateTargetGroup...
//=======================================================================
globals
private unit picked
private group affected=CreateGroup()
private filterfunc CTG_FILTER
endglobals
//=======================================================================
private function CustomCheck takes unit u returns boolean
return GetUnitTypeId(u)!=SC_DUMMY_UNIT
endfunction
//=======================================================================
private function ctgfilter takes nothing returns boolean
set picked=GetFilterUnit()
if(CustomCheck(picked))then
call GroupAddUnit(affected,picked)
endif
return false
endfunction
//=======================================================================
private function CreateTargetGroup takes real x, real y, real r returns nothing
call GroupEnumUnitsInRange(affected,x,y,r,CTG_FILTER) // inline friendly :D
endfunction
//=======================================================================
private module initB
private static method onInit takes nothing returns nothing
set CTG_FILTER=Filter(function ctgfilter)
endmethod
endmodule
//=======================================================================
// common functions...
//=======================================================================
private function AddSpellLeveled takes unit caster, integer id, integer lvl returns nothing
call UnitAddAbility(caster,id)
call SetUnitAbilityLevel(caster,id,lvl)
endfunction
//=======================================================================
//! textmacro ScCaster_SetUnitXY takes UNIT, X, Y
call SetUnitX($UNIT$,$X$)
call SetUnitY($UNIT$,$Y$)
//! endtextmacro
//===========================================================================
function CastSpellOnTargetLvl takes unit caster, unit target, integer id, string os, integer lvl returns nothing
call AddSpellLeveled(caster,id,lvl)
//! runtextmacro ScCaster_SetUnitXY("caster","GetUnitX(target)","GetUnitY(target)")
call IssueTargetOrder(caster,os,target)
endfunction
//=======================================================================
function CastSpellOnTarget takes unit caster, unit target, integer id, string os returns nothing
call CastSpellOnTargetLvl(caster,target,id,os,1)
endfunction
//===========================================================================
function CastSpellOnAreaLvl takes unit caster, real x, real y, real r, integer id, string os, boolean v, integer lvl returns nothing
local player pl=GetOwningPlayer(caster)
local unit target
call CreateTargetGroup(x,y,r)
call DeallocCaster(caster)
loop
set target=FirstOfGroup(affected)
exitwhen target==null
set caster=AllocateCaster(pl)
if((IsUnitAlly(target,pl) and v) or (IsUnitEnemy(target,pl) and not v))then
call CastSpellOnTargetLvl(caster,target,id,os,lvl)
endif
call GroupRemoveUnit(affected,target)
endloop
endfunction
//=======================================================================
function CastSpellOnArea takes unit caster, real x, real y, real r, integer id, string os, boolean v returns nothing
call CastSpellOnAreaLvl(caster,x,y,r,id,os,v,1)
endfunction
//===========================================================================
function CastSpellOnPointLvl takes unit caster, real x, real y, real rng, real a, integer id, string os, integer lvl returns nothing
call AddSpellLeveled(caster,id,lvl)
//! runtextmacro ScCaster_SetUnitXY("caster","x","y")
call IssuePointOrder(caster,os,Cos(a)*rng,Sin(a)*rng)
endfunction
//=======================================================================
function CastSpellOnPoint takes unit caster, real x, real y, real rng, real a, integer id, string os returns nothing
call CastSpellOnPointLvl(caster,x,y,rng,a,id,os,1)
endfunction
//===========================================================================
function CastSpellInPointLvl takes unit caster, real x, real y, integer id, string os, integer lvl returns nothing
call AddSpellLeveled(caster,id,lvl)
//! runtextmacro ScCaster_SetUnitXY("caster","x","y")
call IssueImmediateOrder(caster,os)
endfunction
//=======================================================================
function CastSpellInPoint takes unit caster, real x, real y, integer id, string os returns nothing
call CastSpellInPointLvl(caster,x,y,id,os,1)
endfunction
//===========================================================================
private struct s extends array
implement initA
implement initB
endstruct
//===========================================================================
endlibrary
please leave constructive comments about it! ( i know the coding sucks that's why i want some comments about it)
there are 6 functions:
-AllocateCaster(pl) : returns a dummy caster under the control of player "pl".
-DeallocateCaster(caster) : deallocates the unit "caster"
-CastSpellOnTarget(caster,target,spellid,orderstr,lvl)
-CastSpellOnAreaLvl(caster,x,y,r,spellid,orderstr,v,lvl) : "v" determines the targets.. I used "caster" as the first argument instead of a player argument directly because i want to keep the library's convention...
-CastSpellOnPointLvl(caster,x,y,range,angle,spellid,orderstr,lvl) : casts a point target spell towards "angle"... from "x" and "y"
-CastSpellInPointLvl(caster,x,y,spellid,orderstr,lvl) : casts a point-blank spell in "x" and "y"
this lib was inspired by CS... this is a lightweight one.
i also managed to somehow integrate this also... targeting multiple units with instant spells, using one dummy caster
and the good news is now we can target 20+ units unlike the previous one on the link...
(chicken's the dummy caster)
Last edited: