xecast broken

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
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('A000',"firebolt",Player(0))
        endmethod
    endmodule
    private struct Initializer
        implement Init
    endstruct
endlibrary
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 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          ='e000';
    public constant integer CROW_FORM           ='Amrf';
           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
Whats your opinion on this? Is it suitable?
 

tooltiperror

Super Moderator
Reaction score
231
I still fail to see what is wrong with using DummyCaster. What scenario does this beat it in? I'm not against using this simply because it's not DummyCaster, I just don't see the point.
 

Dirac

22710180
Reaction score
147
-This works for multiple casts at the same time.
-This works for channeling spells.
-Recycles dummies.

In other words sustains the same efficiency of dummycaster with the posibilities of a local dummy with expiration timer.
 

tooltiperror

Super Moderator
Reaction score
231
> This works for multiple casts at the same time.
[del]WC3[/del] The JASS engine is linear, so I don't need to have more than one dummy to cast a spell... except:

> This works for channeling spells.
When will I use a channeling spell for something I can't do with triggers and a normal ability? Especially for a dummy.
 

Dirac

22710180
Reaction score
147
The JASS engine is linear, so I don't need to have more than one dummy to cast a spell... except:
False, if you ask the same dummy to cast the same spell against multiple targets in a very short period it will malfunction, this system takes care of it and i've seen it fixing this issue.

Plus, i find it's API to be very useful for saving lots of lines and nulling locals.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Dirac:
1. So i decided to try xecast, did many tests, only casts the spell once...

1. If you've set the <xecast_instance>.autodestroy member to true then that would explain this.
 

Dirac

22710180
Reaction score
147
Dirac:
1. So i decided to try xecast, did many tests, only casts the spell once...

1. If you've set the <xecast_instance>.autodestroy member to true then that would explain this.
No i didn't, and i read the whole code, there are two different functions

[ljass]xecast.createBasic[/ljass] allocates a new permanent instance.
[ljass]xecast.createBasicA[/ljass] allocates a new instance and marks it for destruction for when the ability is cast.

i was using the first one
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
In the example you posted:

set Stun=xecast.create('A000',"firebolt",Player(0))
but the default create method [xecast.create()] takes no arguments, so the example is invalid.

You should instead paste the real script that was giving you troubles and someone might spot where things get wrong.
 

Dirac

22710180
Reaction score
147
Again wrong, the create function takes 3 arguments, integer ability, integer order, and player owner
 

tooltiperror

Super Moderator
Reaction score
231
.createBasic takes the three arguments
.create takes no arguments

Protip: simply copy pasting documentation usually ends these arguments.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top