1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Small Code Snippets

Discussion in 'Triggers & Scripts' started by PurplePoot, Sep 29, 2007.

  1. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    But you could use 99,999

    And Magtheridon, the Player library in JASS section already does what Players does but better =P.
     
  2. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Here's a small "Clipboard" library :p
    Code (vJASS):
    library Clipboard
        private module Init
            private static method onInit takes nothing returns nothing
                set Clipboard.i = 0
                set Clipboard.s = ""
                set Clipboard.b = false
                set Clipboard.r = 0.0
            endmethod
        endmodule
        struct Clipboard extends array
            static integer i
            static string s
            static boolean b
            static real r
           
            static method copyI takes integer d returns nothing
                set thistype.i = d
            endmethod
            static method pasteI takes nothing returns integer
                return thistype.i
            endmethod
           
            static method copyS takes string d returns nothing
                set thistype.s = d
            endmethod
            static method pasteS takes nothing returns string
                return thistype.s
            endmethod
           
            static method copyB takes boolean d returns nothing
                set thistype.b = d
            endmethod
            static method pasteB takes nothing returns boolean
                return thistype.b
            endmethod
           
            static method copyR takes real d returns nothing
                set thistype.r = d
            endmethod
            static method pasteR takes nothing returns real
                return thistype.r
            endmethod
           
            implement Init
        endstruct
    endlibrary


    It's similar to Copy/Paste, but it only works for primitive values (For simplicity)
     
  3. xD.Schurke

    xD.Schurke

    Joined:
    Feb 22, 2006
    Messages:
    948
    Resources:
    5
    Maps:
    1
    Spells:
    4
    Resources:
    5
    just use 99999 instead of WorldBounds()
     
  4. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    @ Nestharus

    I should really stop defending you xD
    Your ideas always get me "semi-flamed" xD xD
     
  5. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Here's a small math oriented snippet:

    Code (vJASS):
    library Powers
        function isPowerX takes real i, integer j returns boolean
            loop
                exitwhen i<j
                set i=i/j
            endloop
            return i==1.0
        endfunction
       
        // wrappers
        function isSquare takes real i returns boolean
            return isPowerX(i,2)
        endfunction
       
        function isCube takes real i returns boolean
            return isPowerX(i,3)
        endfunction
    endlibrary
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,059
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    All of those could be simplified using
    ModuloInteger
    .

    Code (vJASS):
    struct integer:
        boolean isPowerX(integer i): return this.mod(i) == 0

        boolean isSquare(): return this.mod(2) == 0

        boolean isCube(): return this.mod(3) == 0
     
     
  7. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    No Bribe, that would not work.


    62%2 = 0, but 62 isn't a power of 2.
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,059
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I think that's a fine example of why evaluating submissions should be illegal for me in the mornings -_-
     
  9. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    I knew it :ogre_hurrhurr:

    @ Bribe:
    At least you were referring to something that actually makes sense :p
    Code (vJASS):
    function isDivisible takes integer i, integer j returns boolean
        local integer m=i-(i/j)*j
        if m<0 then
            return m+j==0
        endif
        return m==0
    endfunction
     
  10. busterkomo

    busterkomo

    Joined:
    Jun 17, 2007
    Messages:
    1,423
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    If I remember correctly,
    SetUnitFlyHeight(u,d*Cos(p+vf),0)
    is equivalent to
    call SetUnitFlyHeight(u,d*Cos(p+vf),<some arbitrarily high number>)
     
  11. Justify

    Justify

    Joined:
    Mar 16, 2008
    Messages:
    935
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    3
    Resources:
    5
    It's even better. A high number takes time in theory while 0 is instant for warcraft.
     
  12. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Best Snippet Ever:

    Code (vJASS):
    library KILLGUI

        function exit takes nothing returns nothing
            loop
                call ExecuteFunc(exit.name)
            endloop
        endfunction
       
        hook DoNothing exit
       
    endlibrary


    Pretty Ironic ey?
     
  13. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,059
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Vexorian did it first with "hook DoNothing MakeGUIUsersCrash" ;)
     
  14. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    :eek:
    He was evil too? :D
     
  15. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,059
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
  16. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    xD
    lol
    He may have wanted GUI Users to Crash, but I want them to DIE!

    Code (vJASS):
    library LITERALLYKILLGUI
        function freeze takes nothing returns nothing
            loop
                call TriggerSyncReady()
                call ExecuteFunc(freeze.name)
            endloop
        endfunction

        hook DoNothing freeze

    endlibrary


    Beat That! :ogre_datass:
     
  17. D4RK_G4ND4LF

    D4RK_G4ND4LF

    Joined:
    Feb 4, 2009
    Messages:
    1,196
    Resources:
    20
    Models:
    3
    Spells:
    15
    Tutorials:
    2
    Resources:
    20
    why should GUI users use vJASS?
     
  18. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    In that case:

    Code (vJASS):
    function MakeMapAwesome takes nothing returns nothing
        loop
            call ExecuteFunc("MakeMapAwesome")
        endloop
    endfunction


    If a GUIer calls this function after he (out of some random coincidence) implements this function into his map, he will suffer >:D
     
  19. Uberplayer.

    Uberplayer.

    Joined:
    Dec 1, 2008
    Messages:
    120
    Resources:
    0
    Resources:
    0
    Why would GUI user use JASS?
     
  20. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Because GUI is insufficient? >.>