System BuffStruct

Discussion in 'Systems and Snippets' started by Jesus4Lyf, Jan 28, 2010.

  1. 13lade619

    13lade619 is now a game developer :)

    Ratings:
    +399 / 0 / -0
    didnt work.

    thistype(GetTimerData(t)) was still the same value after the destroy.

    EDIT:

    fixed by adding a new boolean member of the struct that gets flagged when onDestroy is called,.
     
  2. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    That won't work. If another buff is created since that buff is destroyed, it will overwrite the boolean and destroy the new buff.

    The correct way to dispel a buff, if you're using destroyTimed, is:
    So basically, instead of destroying the buff, use .setUnit(null) to move it into the void until whatever created it effectively destroys it. :)
     
  3. 13lade619

    13lade619 is now a game developer :)

    Ratings:
    +399 / 0 / -0
    JASS:
    function DestroyDeathRunes takes BuffStruct whatBuff returns nothing
        if whatBuff.getType()==RuneWolf.typeid or whatBuff.getType()==RuneTerror.typeid or whatBuff.getType()==RuneOgre.typeid or whatBuff.getType()==RuneArch.typeid then
            call whatBuff.setUnit(null)
        endif
    endfunction
    
        call BuffList[target].forEachBuff(BUFF_ALIGNMENT_POSITIVE, DestroyDeathRunes)
        call BuffList[target].forEachBuff(BUFF_ALIGNMENT_NEGATIVE, DestroyDeathRunes)
        call BuffList[target].forEachBuff(BUFF_ALIGNMENT_NEUTRAL, DestroyDeathRunes)


    works. thanks again.
     
  4. Switch33

    Switch33 New Member

    Ratings:
    +12 / 0 / -0
    JASS:
    library Returning
    globals
    private real x
    private real y
    endglobals
    //! runtextmacro BuffType("Returning")
        //! runtextmacro SetBuffName("Returning")
        //! runtextmacro SetBuffAlignment("NEUTRAL")
        //! runtextmacro SetBuffTooltip("This unit is being Returned; it will return to its previous location soon.")
        //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNUnload.blp")
    //! runtextmacro BuffStruct()
        method onCreate takes nothing returns nothing
            set x=GetUnitX(this.unit)
            set y=GetUnitY(this.unit)
        endmethod
        method preDestroy takes nothing returns nothing
            local Returned b = Returned.create(this.unit)
        endmethod
    //! runtextmacro EndBuff()
    
    //! runtextmacro BuffType("Returned")
        //! runtextmacro SetBuffName("Returned")
        //! runtextmacro SetBuffAlignment("NEUTRAL")
        //! runtextmacro SetBuffTooltip("This unit has just been returned to it's previous location.")
        //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNLoad.blp")
    //! runtextmacro BuffStruct()
    
        method onApply takes nothing returns nothing
            call SetUnitX(this.unit,x)
            call SetUnitY(this.unit,y) 
        endmethod
        method preDestroy takes nothing returns nothing
    
        endmethod
    //! runtextmacro EndBuff()
    
    endlibrary


    Should this work?:nuts:
    Its supposed to be a sort of stealable "return unit" buff. It's similar to one on first post but i like the idea of the buff icon being unload/load cause it makes it look snazzier.
     
  5. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    Each time you use the "BuffType("SOMETHING")" textmacro, it creates a new struct, and after it you can configure it until you close it with the "EndBuff()" textmacro (it adds the endstruct).
    So I think that will work. But you can easily test it.
     
  6. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    Sorry for the delayed response. :)

    It will not multi-instance whatsoever, since the coordinates are stored, for the duration of the buff, in global variables.

    Instead, see the below:
    JASS:
    //! runtextmacro BuffType("Returning")
        //! runtextmacro SetBuffName("Returning")
        //! runtextmacro SetBuffAlignment("NEUTRAL")
        //! runtextmacro SetBuffTooltip("This unit is being Returned; it will return to its previous location soon.")
        //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNUnload.blp")
    //! runtextmacro BuffStruct()
        real x
        real y
        method onCreate takes nothing returns nothing
            set x=GetUnitX(this.unit)
            set y=GetUnitY(this.unit)
        endmethod
        method preDestroy takes nothing returns nothing
            local Returned b = Returned.create(null)
            set b.x = x
            set b.y = y
            call b.setUnit(this.unit)
        endmethod
    //! runtextmacro EndBuff()
    
    //! runtextmacro BuffType("Returned")
        //! runtextmacro SetBuffName("Returned")
        //! runtextmacro SetBuffAlignment("NEUTRAL")
        //! runtextmacro SetBuffTooltip("This unit has just been returned to it's previous location.")
        //! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNLoad.blp")
    //! runtextmacro BuffStruct()
        real x
        real y
        method onApply takes nothing returns nothing
            call SetUnitX(this.unit,x)
            call SetUnitY(this.unit,y) 
        endmethod
    //! runtextmacro EndBuff()

    Freehanded, but should work. :thup:

    (Why you want to do it this way, I do not understand. I would restore the unit's position at the end of the "Returning" buff, and add the other buff as purely aesthetic.. at least. :))
     
  7. Switch33

    Switch33 New Member

    Ratings:
    +12 / 0 / -0
    :banghead:Yeah, i think i originally was going to do it this way but changed it and forgot. I re-did it roughly the way you did it in your first post and made the returned buff part just an aesthetic. Thanks
     
    • Like Like x 1
  8. codart

    codart New Member

    Ratings:
    +0 / 0 / -0
    hey j4l. Let say i want to detect when a buffstruct is created. Then check, if it's a negative buff then multiple it's duration by 2. Can you add or teach me the way to make a event similar to 'EVENT_BUFF_CREATED'
     
  9. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    I have an idea J4L. You should use a global, non-static timer member to call the "destroyTimed" method. If you call it, and you try to set the buff's duration to something different (for example from 5 sec to 10), the buff'll be destroyed after 5 seconds, and we'll have one more timer without any data.
     
  10. XeNiM666

    XeNiM666 I lurk for pizza

    Ratings:
    +138 / 1 / -0
    Noob question: How does one apply the buff created? :eek:
     
  11. Laiev

    Laiev Hey Listen!!

    Ratings:
    +187 / 0 / -0
    JASS:
    //          All BuffStructs have the .setUnit(unit) method, which will remove
    //          the buff instance from the current unit, and apply it to the given unit.
    //          Use .setUnit(null) to unapply a buff without destroying it.


    JASS:
    call MyBuffInstance.setUnit(myUnit)
     
    • Like Like x 1
  12. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    or
    JASS:
    call MyBuff.create(<unit>)


    Both versions work (but I prefer using the "create" method to apply and the "seUnit" method to move the buff, just for clarity :p)
     
  13. Laiev

    Laiev Hey Listen!!

    Ratings:
    +187 / 0 / -0
    i'm with luorax, and Jesus4Lyf at some point in this thread said the same thing... create the buff for a null unit and set the buff to the target unit
     
  14. emootootoo

    emootootoo Top Banana

    Ratings:
    +51 / 0 / -0
    so i seem to have hit a wall with buffstruct

    it seems if i try to make more than around 60 buffs grimoire stuffs up and chucks out an error pointing to grimex.txt

    C:\Users\XX\AppData\Local\Temp\VB55C.tmp.lua:1783: attempt to index field '?' (a nil value)

    fyi - the last buff that is made before the error is B@Z&
     
  15. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    Ah, funny that.

    Find this in the code:
    JASS:
            //! runtextmacro BuffStruct__AllowSysId("@a")
            //! runtextmacro BuffStruct__AllowSysId("@b")
            //! runtextmacro BuffStruct__AllowSysId("@c")
            //! runtextmacro BuffStruct__AllowSysId("@d")
            //! runtextmacro BuffStruct__AllowSysId("@e")
            //! runtextmacro BuffStruct__AllowSysId("@f")
            //! runtextmacro BuffStruct__AllowSysId("@g")
            //! runtextmacro BuffStruct__AllowSysId("@h")
            //! runtextmacro BuffStruct__AllowSysId("@i")
            //! runtextmacro BuffStruct__AllowSysId("@j")
            //! runtextmacro BuffStruct__AllowSysId("@k")
            //! runtextmacro BuffStruct__AllowSysId("@l")
            //! runtextmacro BuffStruct__AllowSysId("@m")
            //! runtextmacro BuffStruct__AllowSysId("@n")
            //! runtextmacro BuffStruct__AllowSysId("@o")
            //! runtextmacro BuffStruct__AllowSysId("@p")
            //! runtextmacro BuffStruct__AllowSysId("@q")
            //! runtextmacro BuffStruct__AllowSysId("@r")
            //! runtextmacro BuffStruct__AllowSysId("@s")
            //! runtextmacro BuffStruct__AllowSysId("@t")
            //! runtextmacro BuffStruct__AllowSysId("@u")
            //! runtextmacro BuffStruct__AllowSysId("@v")
            //! runtextmacro BuffStruct__AllowSysId("@w")
            //! runtextmacro BuffStruct__AllowSysId("@x")
            //! runtextmacro BuffStruct__AllowSysId("@y")
            //! runtextmacro BuffStruct__AllowSysId("@z")
            //! runtextmacro BuffStruct__AllowSysId("@A")
            //! runtextmacro BuffStruct__AllowSysId("@B")
            //! runtextmacro BuffStruct__AllowSysId("@C")
            //! runtextmacro BuffStruct__AllowSysId("@D")
            //! runtextmacro BuffStruct__AllowSysId("@E")
            //! runtextmacro BuffStruct__AllowSysId("@F")
            //! runtextmacro BuffStruct__AllowSysId("@G")
            //! runtextmacro BuffStruct__AllowSysId("@H")
            //! runtextmacro BuffStruct__AllowSysId("@I")
            //! runtextmacro BuffStruct__AllowSysId("@J")
            //! runtextmacro BuffStruct__AllowSysId("@K")
            //! runtextmacro BuffStruct__AllowSysId("@L")
            //! runtextmacro BuffStruct__AllowSysId("@M")
            //! runtextmacro BuffStruct__AllowSysId("@N")
            //! runtextmacro BuffStruct__AllowSysId("@O")
            //! runtextmacro BuffStruct__AllowSysId("@P")
            //! runtextmacro BuffStruct__AllowSysId("@Q")
            //! runtextmacro BuffStruct__AllowSysId("@R")
            //! runtextmacro BuffStruct__AllowSysId("@S")
            //! runtextmacro BuffStruct__AllowSysId("@T")
            //! runtextmacro BuffStruct__AllowSysId("@U")
            //! runtextmacro BuffStruct__AllowSysId("@V")
            //! runtextmacro BuffStruct__AllowSysId("@W")
            //! runtextmacro BuffStruct__AllowSysId("@X")
            //! runtextmacro BuffStruct__AllowSysId("@Y")
            //! runtextmacro BuffStruct__AllowSysId("@Z")

    Add some more. It ran out. :p
     
  16. emootootoo

    emootootoo Top Banana

    Ratings:
    +51 / 0 / -0
    thanks, a little after this post i was thinking it might be something like that, just havent been able to check
     
  17. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    Yea, just stick more garbage in that config section. It has comments explaining how it uses it. :)

    Basically, it just ran out of allocated abil/buff ids, and you need to allocate some more to the system.
     
  18. Nestharus

    Nestharus o-o

    Ratings:
    +83 / 0 / -0
    Would be nice if the object generation done here and in Status was updated to use the Lua stuff so that they're safe to use.

    Would also be nice to update all of the other object generating scripts like AIDS.
     
  19. Jesus4Lyf

    Jesus4Lyf Good Idea™

    Ratings:
    +394 / 0 / -0
    It does use LUA. So does Status.
    Explain..
     
  20. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Jesus, I'll actually be planning on writing a tutorial about it.

    Basically, Nestharus explained to me last night that the object generation used in BuffStruct and Status is unsafe, because just plain old object merger calls and lua calls with predefined variables can just overwrite things. So if someone has 'A000' in their map and you overwrite it, they can't get it back unless it's backed up, and there's no warning it will be overwritten, so it's ... bad.

    Nestharus' system LUA_GET_VAR_OBJECT as well as the ones it requires make safe unique ID's.

    Also, interesting spin on your interface:
    JASS:
    
    //! runtextmacro Buff() // empty textmacro call
    	//! runtextmacro BuffType("Knockback")
    		//! runtextmacro SetBuffName("Knocked")
    		//! runtextmacro SetBuffAlignment("NEGATIVE")
    		//! runtextmacro SetBuffTooltip("This unit is being Knocked Back; it is stunned and sliding backwards.")
    		//! runtextmacro SetBuffIcon("ReplaceableTextures\\CommandButtons\\BTNBash.blp")
    	//! runtextmacro BuffStruct()
    		real speed=400*T32_PERIOD
    		private effect e
    		private method periodic takes nothing returns nothing
    			local real r=GetUnitFacing(this.unit)*bj_DEGTORAD
    			call SetUnitX(this.unit,GetUnitX(this.unit)-Cos(r)*this.speed)
    			call SetUnitY(this.unit,GetUnitY(this.unit)-Sin(r)*this.speed)
    		endmethod
    		implement T32x
    		method onApply takes nothing returns nothing
    			call Status[this.unit].addStun()
    			call this.startPeriodic()
    			set this.e=AddSpecialEffectTarget("Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl",this.unit,"overhead")
    		endmethod
    		method onRemove takes nothing returns nothing
    			call Status[this.unit].removeStun()
    			call this.stopPeriodic()
    			call DestroyEffect(this.e)
    		endmethod
    	//! runtextmacro EndBuffStruct() // empty textmacro call
    //! runtextmacro EndBuff()
     

Share This Page