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 poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    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. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    517
    Resources:
    4
    Spells:
    1
    JASS:
    3
    Resources:
    4
    That dies with a "FATAL ERROR", the recursive death is more silent, I think =).
     
  2. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Nice! lol, I always complicate myself =D

    Edited my post

    EDIT:

    How about
    hook DoNothing ExitWarcraft
    ? GUI users should not be using this function after all =).
     
    Last edited: Dec 19, 2016
  3. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Another one
    Code (vJASS):
    library CodeArray /*


        */
    requires /*

        */
    Typecast /*  - http://www.hiveworkshop.com/threads/accessing-memory-from-the-script-its-time-of-the-revolution.279262/

        |=====|
        | API |
        |=====|

            //! runtextmacro GLOBAL_CODE_ARRAY("PRIVACY", "NAME")
                - Declares a global code array

        */

        //! textmacro GLOBAL_CODE_ARRAY takes PRIVACY, NAME
        $PRIVACY$ struct $NAME$ extends array

            private static integer codes

            static method operator [] takes integer index returns code
                return I2C(codes[index])
            endmethod

            static method operator []= takes integer index, code c returns nothing
                set codes[index] = C2I(c)
            endmethod

        endstruct
        //! endtextmacro


    endlibrary
     
     
    Last edited: Dec 21, 2016
  4. Wietlol

    Wietlol

    Joined:
    Aug 1, 2013
    Messages:
    4,653
    Resources:
    3
    Spells:
    3
    Resources:
    3
    Is the "Code" really required in the name?
     
  5. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Oh surely not. It should be $NAME$ only. Edited.
     
  6. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,860
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Code (vJASS):
    /**********************************************************
    *
    *   FatalError
    *   v1.1.2.1
    *   By Magtheridon96 (Special Thanks to Nestharus)
    *
    *   Uses:
    *   -----
    *
    *       - Annoying a player. lol
    *
    *   API:
    *   ----
    *
    *       - function ExitGame             takes nothing           returns nothing
    *       - function ExitGameForPlayer    takes player p          returns nothing
    *
    *       - function FreezeGame           takes nothing           returns nothing
    *       - function FreezeGameForPlayer  takes player p          returns nothing
    *
    *       - function CrashGame            takes nothing           returns nothing
    *       - function CrashGameForPlayer   takes player p          returns nothing
    *
    *       - function DesyncGameForPlayer  takes player p          returns nothing
    *
    *       - function EatRAM               takes nothing           returns nothing
    *           - This function can take up about 1 GB of memory in a minute.
    *           - Use this on cheaters ;D
    *           - This function may crash the game at one point.
    *
    *       - function StopThread          takes nothing           returns nothing
    *
    **********************************************************/

    library FatalError
       
        globals
            private trigger Q = CreateTrigger()
        endglobals
       
        function ExitGame takes nothing returns nothing
            loop
                call ExecuteFunc("ExitGame")
            endloop
        endfunction
       
        function ExitGameForPlayer takes player p returns nothing
            if GetLocalPlayer()==p then
                call ExitGame()
            endif
        endfunction
       
        function FreezeGame takes nothing returns nothing
            loop
                call TriggerSyncReady()
                call ExecuteFunc("FreezeGame")
            endloop
        endfunction
       
        function FreezeGameForPlayer takes player p returns nothing
            if GetLocalPlayer()==p then
                call FreezeGame()
            endif
        endfunction
       
        function CrashGame takes nothing returns nothing
            call Player(-1)
        endfunction
       
        function CrashGameForPlayer takes player p returns nothing
            if GetLocalPlayer()==p then
                call CrashGame()
            endif
        endfunction
       
        function DesyncGameForPlayer takes player p returns nothing
            if GetLocalPlayer()==p then
                call CreateTrigger()
            endif
        endfunction
       
        private function Z takes nothing returns boolean
            local location l
            local integer i = 1000
            loop
                exitwhen 0==i
                set l = Location(0,0)
                set l = Location(0,0)
                set l = Location(0,0)
                set i=i-1
            endloop
            return false
        endfunction
       
        function EatRAM takes nothing returns boolean
            loop
                call TriggerEvaluate(Q)
            endloop
            return false
        endfunction
       
        function StopThread takes nothing returns nothing
            local integer i = 1/0
        endfunction
       
        private module Init
            private static method onInit takes nothing returns nothing
                call TriggerAddCondition(Q,Condition(function Z))
            endmethod
        endmodule
        private struct Inits extends array
            implement Init
        endstruct
    endlibrary


    you forgot that this existed lol

    link: Fatal Error
     
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,792
    Resources:
    1
    Spells:
    1
    Resources:
    1
    This is dumb and really simple, but I needed a way to remove an effect without showing its death animation. (Specifically to replace it with something else.) I didn't see something like this in this thread from my searching.

    Edit: see below
     
    Last edited: Jul 16, 2019
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    If the effect is some kind of missile with a trail (like Phoenix Fire) this will cause a trail to appear between the special effect and its destination.
     
  9. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,792
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Huh, didn't notice that. This one shouldn't.
    Code (vJASS):
    library RemoveEffect
      //Destroying an effect always plays its death animation and any associated sounds.
      //This library fixes it in a simple way: move the effect to a location where nobody can see or hear it.

      globals
        private real SAFE_X = -3900.
        private real SAFE_Y =  3900.
        private real SAFE_Z = -1000. //not strictly necessary

        private real TIMESCALE = 10. //doesn't really matter but we set it to > 0 so the animations actually finish
      endglobals

      function RemoveEffect takes effect e returns nothing
        call BlzSetSpecialEffectAlpha(e, 255)
        call BlzSetSpecialEffectZ(e, SAFE_Z)
        call BlzSetSpecialEffectPosition(e, SAFE_X, SAFE_Y, SAFE_Z)
        call BlzSetSpecialEffectTimeScale(e, TIMESCALE)
        call DestroyEffect(e)
      endfunction
    endlibrary