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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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