Dirac
22710180
- Reaction score
- 147
So i decided to try xecast, did many tests, only casts the spell once...
This is something similar to how my code looked like
The msg always pops up, the spell wasn't triggered. (normal stun spell with no codes)
So i made this library, honestly it works really great and it's very fastWhats your opinion on this? Is it suitable?
This is something similar to how my code looked like
JASS:
library Tester
globals
xecast Stun
endglobals
function Cast takes unit u returns nothing
call BJDebugMsg("casted")
call Stun.castOnTarget(u)
endfunction
private module Init
private static method onInit takes nothing returns nothing
set Stun=xecast.create(039;A000039;,"firebolt",Player(0))
endmethod
endmodule
private struct Initializer
implement Init
endstruct
endlibrary
So i made this library, honestly it works really great and it's very fast
JASS:
//! zinc
library Dummy requires/*
*/ UnitIndexer /* hiveworkshop.com/forums/jass-functions-413/system-unit-indexer-172090/
*/ ,RegisterPlayerUnitEvent /* hiveworkshop.com/forums/submissions-414/commonevent-203338/
***********************************************************************
API for the Dummy struct:
static method create takes integer abilityRawCode, integer orderId, player owner returns Dummy
// Allocates a new dummy for future casting, the ability should be preloaded.
method destroy takes nothing returns nothing
// Deallocates the dummy and adds it to a recycle list.
method castOnTarget takes unit target returns nothing
method castOnPoint takes real x, real y returns nothing
// Orders the dummy to cast the ability, if the dummy is busy a new one will
// be allocated to finish the purpose. If the instance isn't locked the dummy
// will be destroyed at the end of the cast.
method lock takes nothing returns nothing
method unlock takes nothing returns nothing
// Locks or unlocks the dummy to it's instance.
static method preload takes integer abilityRawCode returns nothing
// Useful for preloading abilities.
***********************************************************************
VARIABLES:
-To be set before casting.
real x
real y
// Sets the dummy's position before casting the spell, make sure to always assign
// these values before or else the dummy will move to the target's location.
real z
// Sets the dummy's flying height, resets when destroyed.
player owner
// Sets the dummy's owner.
integer level
// Sets the dummy's ability level.
***********************************************************************
Example usage:
globals
Dummy Stun
endglobals
function onEnter takes nothing returns boolean
//Every time an unit enters the region it will be stuned.
call Stun.castOnTarget(GetTriggerUnit())
return false
endfunction
function onInit takes nothing returns nothing
local trigger trig=CreateTrigger()
//Allocates the dummy.
set Stun=Dummy.create('A000',"firebolt",Player(15))
//Locks the dummy to the instance.
call Stun.lock()
call TriggerRegisterEnterRegion(trig,SomePresetRegion,null)
call TriggerAddCondition(trig,Condition(function onEnter))
set trig=null
endfunction
**********************************************************************/
{
public constant integer DUMMY_TYPE =039;e000039;;
public constant integer CROW_FORM =039;Amrf039;;
constant integer PRELOADED_DUMMIES =15;
constant boolean REMOVED_AT_END =true;
module Init{
private static method onInit(){
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_ENDCAST,function thistype.endCast);
while(m<PRELOADED_DUMMIES){
m=m+1;
r[m]=newDummy(Player(15));}
}
}
unit r[];
integer m=0;
public struct Dummy[]{
private{
//The dummy itself.
unit u;
//The order.
integer o;
//The ability rawcode.
integer a;
//Is the unit marked for destruction?
boolean d;
//Did the user set a custom point?
boolean p;}
private static method newDummy(player p)->unit{
unit u=CreateUnit(p,DUMMY_TYPE,0,0,0);
UnitAddAbility(u,CROW_FORM);
UnitRemoveAbility(u,CROW_FORM);
return u;}
static method create(integer a,integer o,player p)->thistype{
unit u;
thistype this;
if(m>0){
u=r[m];
SetUnitOwner(u,p,false);
m=m-1;}
else{
u=newDummy(p);}
this=GetUnitUserData(u);
this.u=u;
UnitRemoveAbility(u,this.a);
UnitAddAbility(u,a);
this.o=o;
this.a=a;
this.d=REMOVED_AT_END;
this.p=false;
u=null;
return this;}
method destroy(){
//Adds the dummy to a recycle list, other instances may
//access to it if they need another dummy.
m=m+1;
r[m]=this.u;
SetUnitFlyHeight(this.u,0,0);
SetUnitAbilityLevel(this.u,this.a,1);}
//NOTE: abilities WONT be removed from the dummy until it's
//used to allocate another instance.
method lock(){
this.d=false;}
method unlock(){
this.d=true;}
method operator x=(real n){
SetUnitX(this.u,n);
this.p=true;}
method operator y=(real n){
SetUnitY(this.u,n);
this.p=true;}
method operator z=(real n){
SetUnitFlyHeight(this.u,n,0);}
method operator owner=(player p){
SetUnitOwner(this.u,p,false);}
method operator level=(integer i){
SetUnitAbilityLevel(this.u,this.a,i);}
method castOnTarget(unit u){
thistype new;
//If the dummy is busy doing something it allocates a
//new one
if(0==GetUnitCurrentOrder(this.u)){
IssueTargetOrderById(this.u,this.o,u);
if(!this.p){
SetUnitX(this.u,GetUnitX(u));
SetUnitY(this.u,GetUnitY(u));}
else this.p=false;}
else{
new=create(this.a,this.o,GetOwningPlayer(this.u));
new.x=GetUnitX(this.u);
new.y=GetUnitY(this.u);
SetUnitAbilityLevel(new.u,this.a,GetUnitAbilityLevel(this.u,this.a));
new.castOnTarget(u);}
}
method castOnPoint(real x,real y){
thistype new;
if(0==GetUnitCurrentOrder(this.u)){
IssuePointOrderById(this.u,this.o,x,y);
if(!this.p){
SetUnitX(this.u,GetUnitX(u));
SetUnitY(this.u,GetUnitY(u));}
else this.p=false;}
else{
new=create(this.a,this.o,GetOwningPlayer(this.u));
new.x=GetUnitX(this.u);
new.y=GetUnitY(this.u);
SetUnitAbilityLevel(new.u,this.a,GetUnitAbilityLevel(this.u,this.a));
new.castOnPoint(x,y);}
}
static method preload(integer a){
unit u=newDummy(Player(15));
thistype this=GetUnitUserData(u);
UnitAddAbility(u,a);
UnitRemoveAbility(u,a);
this.destroy();}
private static method endCast()->boolean{
thistype this=GetUnitUserData(GetTriggerUnit());
if(this.d){
this.destroy();}
return false;}
module Init;}
}
//! endzinc