Spell Optic Blast

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Optic Blast is more or less [pretty much =)] a clone of the Starcraft 2's Colossus Thermal Lance attack.
The underlying struct requires feeding it some points and other data after that it caries the actions.

Required libraries:

TimerUtils
GroupUtils
LightningRecycle
TimedEffect

JASS:
//! zinc

library opticblast requires TimerUtils, GroupUtils, LightningRecycle, TimedEffect
{
    constant integer    ENERGY_BEAM_COUNT                = 4;
    constant real       BEAM_MOVEMENT_UPDATES_PER_SECOND = 32;
    constant string     DEFAULT_SOUND_LOCATION           = "Abilities\\Spells\\Human\\AerialShackles\\MagicLariatLoop1.wav";
    constant string     DEFAULT_EFFECT_LOCATION          = "Abilities\\Weapons\\SpiritOfVengeanceMissile\\SpiritOfVengeanceMissile.mdl";
    constant attacktype ATTACK_TYPE                      = ATTACK_TYPE_NORMAL;
    constant damagetype DAMAGE_TYPE                      = DAMAGE_TYPE_NORMAL;

    location loc = Location(0, 0);
    unit     tmpu = null;

    boolexpr filter;
    function targets_allowed() -> boolean
    {
        unit u = GetFilterUnit();
        boolean b;
        b = IsUnitEnemy(u, GetOwningPlayer(tmpu));

        return b;
    }

    struct sounddata
    {
        sound s;
    }

    function StopLoopingSoundTimed()
    {
        timer t = GetExpiredTimer();
        sounddata sd = GetTimerData(t);
        StopSound(sd.s, false, false);
        sd.destroy();
        ReleaseTimer(t);
    }

    function PlayLoopingSoundTimed(string file_location, real x, real y, real z, real duration, integer volume)
    {
        timer t = NewTimer();
        sounddata sd = sounddata.create();
        sound s = CreateSound(file_location, true, true, true, 10, 10, "SpellsEAX");
        SetSoundVolume(s, volume);
        SetSoundDistances(s, 2000, 2000);
        /*SetSoundDistanceCutoff(s, 2000);*/
        SetSoundPosition(s, x, y, z);
        StartSound(s);
    
        sd.s = s;
        SetTimerData(t, sd);
        TimerStart(t, duration, false, function StopLoopingSoundTimed);
    }

    function dummy()
    {
        opticblast(GetTimerData(GetExpiredTimer())).exe();
    }

    public struct opticblast
    {

    private
    {
        lightning beam[ENERGY_BEAM_COUNT];
        real      beam_distance_from_hit_to_move_to[ENERGY_BEAM_COUNT];
        real      beam_traveled_distance[ENERGY_BEAM_COUNT];
        real      t[ENERGY_BEAM_COUNT];
        real      t_inc[ENERGY_BEAM_COUNT];
        integer   slowest_beam_index;
        timer     executefuncer;
        group     damaged_units;
    }

        unit   caster;
        widget target;

        string beam_model[ENERGY_BEAM_COUNT];

        real beam_start_x[ENERGY_BEAM_COUNT];
        real beam_start_y[ENERGY_BEAM_COUNT];
        real beam_start_z[ENERGY_BEAM_COUNT];

        real beam_hit_x[ENERGY_BEAM_COUNT];
        real beam_hit_y[ENERGY_BEAM_COUNT];

        real beam_move_to_x[ENERGY_BEAM_COUNT];
        real beam_move_to_y[ENERGY_BEAM_COUNT];

        real beam_duration[ENERGY_BEAM_COUNT];

        integer beam_count;
        boolean play_sound;
        string  sound_location = "";

        boolean beam_spawn_effect[ENERGY_BEAM_COUNT];
        string  beam_effect_location[ENERGY_BEAM_COUNT];

        real beam_hit_radius = 0;
        real damage          = 0;

        method setup()
        {
            integer i    = 0;
            real    dx   = 0;
            real    dy   = 0;
            real    highest_duration = 0;
            integer highest_duration_index = 0;

            PauseUnit(caster, true);
            
            for (0 <= i < beam_count)
            {
                t<i> = 0;
                t_inc<i> = 1.0 / (beam_duration<i> * BEAM_MOVEMENT_UPDATES_PER_SECOND);

                dx = beam_move_to_x<i> - beam_hit_x<i>;
                dy = beam_move_to_y<i> - beam_hit_y<i>;
                beam_distance_from_hit_to_move_to<i> = SquareRoot(dx * dx + dy * dy);

                if (highest_duration &lt; beam_duration<i>)
                {
                    highest_duration = beam_duration<i>;
                    highest_duration_index = i;
                }

                beam<i> = GetLightning(GetLightningIdByCodeName(beam_model<i>));
                MoveLightningEx(beam<i>, false, beam_start_x<i>, beam_start_y<i>, beam_start_z<i>, beam_hit_x<i>, beam_hit_y<i>, 0);
            }
            slowest_beam_index = highest_duration_index;

            damaged_units = NewGroup();
            executefuncer = NewTimer();
            SetTimerData(executefuncer, this);
            TimerStart(executefuncer, 1.0 / BEAM_MOVEMENT_UPDATES_PER_SECOND, true, function dummy);

            if (play_sound)
            {
                dx = GetWidgetX(target);
                dy = GetWidgetY(target);
                MoveLocation(loc, dx, dy);
                if (sound_location == &quot;&quot; || sound_location == null)
                    PlayLoopingSoundTimed(DEFAULT_SOUND_LOCATION, dx, dy, GetLocationZ(loc), beam_duration[slowest_beam_index], 100);
                else
                    PlayLoopingSoundTimed(sound_location, dx, dy, GetLocationZ(loc), beam_duration[slowest_beam_index], 100);
            }
        }
        
        method exe()
        {
            integer i = 0;
            real    x = 0;
            real    y = 0;

            for (0 &lt;= i &lt; beam_count)
            {
                t<i> = t<i> + t_inc<i>;
                if (t<i> &gt; 1)
                {
                    if (beam<i> != null)
                    {
                        RecycleLightning(beam<i>, GetLightningIdByCodeName(beam_model<i>));
                        beam<i> = null;
                    }
                }
                else
                {
                    x = beam_hit_x<i> + t<i> * (beam_move_to_x<i> - beam_hit_x<i>);
                    y = beam_hit_y<i> + t<i> * (beam_move_to_y<i> - beam_hit_y<i>);

                    MoveLocation(loc, x, y);
                    MoveLightningEx(beam<i>, false, beam_start_x<i>, beam_start_y<i>, beam_start_z<i>, x, y, GetLocationZ(loc));

                    beam_traveled_distance<i> = beam_traveled_distance<i> + t_inc<i> * beam_distance_from_hit_to_move_to<i>;
                    // if (ModuloReal(beam_traveled_distance<i>, beam_hit_radius) &lt;= 16)
                    // { 
                            tmpu = caster;
                            GroupEnumUnitsInArea(ENUM_GROUP, x, y, beam_hit_radius, filter);
                            tmpu = FirstOfGroup(ENUM_GROUP);
                            while (tmpu != null)
                            {
                                if (!IsUnitInGroup(tmpu, damaged_units))
                                {
                                    UnitDamageTarget(caster, tmpu, damage, true, false, ATTACK_TYPE, DAMAGE_TYPE, WEAPON_TYPE_WHOKNOWS);
                                    GroupAddUnit(damaged_units, tmpu);
                                }
                                GroupRemoveUnit(ENUM_GROUP, tmpu);
                                tmpu = FirstOfGroup(ENUM_GROUP);
                            }
                    // }

                    // if (ModuloReal(beam_traveled_distance<i>, 32.0) &lt;= 8)
                    // {
                        if (beam_spawn_effect<i>)
                        {
                            if (beam_effect_location<i> == &quot;&quot; || beam_effect_location<i> == null)
                            {
                                AddSpecialEffectTimed(DEFAULT_EFFECT_LOCATION, x, y, beam_duration[slowest_beam_index] * (1 - t[slowest_beam_index]));
                            }
                            else
                            {
                                AddSpecialEffectTimed(beam_effect_location<i>, x, y, beam_duration[slowest_beam_index] * (1 - t[slowest_beam_index]));
                            }
                        }
                    // }
                }

                if (t[slowest_beam_index] &gt; 1)
                {
                    stop();
                    i = beam_count; // break;
                } 
            }
        }
        
        method stop()
        {
            destroy();
            ReleaseTimer(executefuncer);
            ReleaseGroup(damaged_units);
            PauseUnit(caster, false);
        }
    }
    
    function spell_optic_blast() -&gt; boolean
    {
        opticblast ob;
        unit       caster;
        real       cx;
        real       cy;
        unit       target;
        real       tx;
        real       ty;
        real       dx;
        real       dy;
        real       dirx;
        real       diry;
        real       dist;
        real       line_length;

        caster  = GetEventDamageSource();

        if (GetUnitName(caster) == &quot;Colossus&quot; &amp;&amp; !IsUnitPaused(caster))
        {
            cx          = GetUnitX(caster);
            cy          = GetUnitY(caster);
            target      = GetTriggerUnit();
            tx          = GetUnitX(target);
            ty          = GetUnitY(target);
            dx          = tx - cx;
            dy          = ty - cy;
            dist        = SquareRoot(dx * dx + dy * dy);
            dirx        = dx / dist;
            diry        = dy / dist;
            line_length = 256;

            ob = opticblast.create();

            ob.caster = caster;
            ob.target = target;

            ob.beam_model[0]           = LIGHTNING_DRAIN_MANA;
            ob.beam_start_x[0]         = dirx * 128 + cx - 24;
            ob.beam_start_y[0]         = diry * 128 + cy;
            ob.beam_start_z[0]         = 295;
            ob.beam_hit_x[0]           = -diry * line_length * 0.5 + tx;
            ob.beam_hit_y[0]           = dirx  * line_length * 0.5 + ty;
            ob.beam_move_to_x[0]       = diry  * line_length * 0.5 + tx;
            ob.beam_move_to_y[0]       = -dirx * line_length * 0.5 + ty;
            ob.beam_duration[0]        = 0.49;
            ob.beam_spawn_effect[0]    = true;

            ob.beam_model[1]           = LIGHTNING_DRAIN_MANA;
            ob.beam_start_x[1]         = dirx * 128 + cx + 24;
            ob.beam_start_y[1]         = diry * 128 + cy;
            ob.beam_start_z[1]         = 295;
            ob.beam_hit_x[1]           =  diry * line_length * 0.5 + tx;
            ob.beam_hit_y[1]           = -dirx * line_length * 0.5 + ty;
            ob.beam_move_to_x[1]       = -diry * line_length * 0.5 + tx;
            ob.beam_move_to_y[1]       =  dirx * line_length * 0.5 + ty;
            ob.beam_duration[1]        = 0.5;
            ob.beam_spawn_effect[1]    = true;

            ob.beam_count              = 2;
            ob.play_sound              = true;
            ob.beam_hit_radius         = 128;
            ob.damage = 100;

            ob.setup();
        }

        return false;
    }

    function onInit()
    {
        unit u;
        trigger t = CreateTrigger();
        GroupEnumUnitsInRect(ENUM_GROUP, GetPlayableMapRect(), null);

        u = FirstOfGroup(ENUM_GROUP);
        while (u != null)
        {
            TriggerRegisterUnitEvent(t, u, EVENT_UNIT_DAMAGED);
            GroupRemoveUnit(ENUM_GROUP, u);
            u = FirstOfGroup(ENUM_GROUP);
        }
        TriggerAddCondition(t, Condition(function spell_optic_blast));       

        filter = Filter(function targets_allowed);
    }       

}

//! endzinc
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Attachments

  • optic_blast.w3x
    46.5 KB · Views: 391

Laiev

Hey Listen!!
Reaction score
188
You really should use some Damage System.

Leak:
JASS:
function onInit()
    {
        unit u;

(and other function that you don't null locals)

Why this:
JASS:

if (GetUnitName(caster) == &quot;Colossus&quot; &amp;&amp; !IsUnitPaused(caster))


This should be based on ability or unit type id, also this SHOULD be configurable.
And unit paused?????

This is a bad practice

Also, your system/spell/library/something just register preplaced units in the map, not any other entering unit, so this will fail if you use dynamic spawn (which happen in 99% of maps)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • 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 Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top