Spell Deadly Survival

manofsteel

New Member
Reaction score
36
This is my first submitted spell and also one of my first spells done in JASS.

Name: Deadly Survival
Description Absorbs energy from nearby corpses and gives it to you. If the corpse is an ally corpse you gain mana if it's an enemy corpse you gain health.
GUI/JASS: JASS
MUI/MPI: Both
Laggfree: Yes
Leakfree: Yes
Import difficulty: Very Easy
, just follow the instructions in the map.

A didn't think a screenshot was needed since it's really nothing to see(and I can't take screenshots on this computer...).

Code:
JASS:
function Trig_DS_Conditions takes nothing returns boolean
     return GetSpellAbilityId() == 'A000'     //the ability that's being casted
endfunction

function Trig_dead takes nothing returns boolean
    return IsUnitType (GetFilterUnit (), UNIT_TYPE_DEAD)
endfunction

function Trig_DS_Actions takes nothing returns nothing
     local unit c = GetTriggerUnit()
     local real x = GetUnitX(c)
     local real y = GetUnitY(c)
     local unit pu
     local group g = CreateGroup()
     local real r = (R2I(GetUnitAbilityLevel(c, 'A000' ))) *5 + 20
  
     call GroupEnumUnitsInRange(g, x, y, 800.00, Condition(function Trig_dead))
     loop
          set pu = FirstOfGroup(g)
          exitwhen pu == null
          call GroupRemoveUnit(g, pu)
          if IsUnitEnemy(pu, GetOwningPlayer(c)) == true then
                call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
                call RemoveUnit( pu )
           else
                call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
                call RemoveUnit( pu )
           endif
       endloop
      call DestroyGroup(g)
      set g = null
      set c = null
endfunction

//===========================================================================
function InitTrig_DS takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_DS_Conditions ) )
    call TriggerAddAction( t, function Trig_DS_Actions )
endfunction
 

Attachments

  • Deadly Survival-Jass.w3x
    21.9 KB · Views: 191

Seannny

Why GUI when you can Jass?
Reaction score
46
Lol at the Cliche name, anyways ill take a look at it. =)
 

Flare

Stops copies me!
Reaction score
662
1)
Just a minor lagg on first cast, but nothing that you notice.

Then preload stuff in your InitTrig - if it's an ability, create a dummy unit, add the ability to the unit, remove the unit (similar applies to unit preloading). If it's an SFX, create the SFX and destroy it

2)
JASS:

Ewww, a stupid BJ
JASS:
//can become
GetWidgetLife (GetFilterUnit ()) < .405
//OR, if you want to be safe (since you can use SetUnitState (whichUnit, UNIT_STATE_LIFE, whichVal) on dead units which screws up the above condition, but you shouldn&#039;t be dumb enough to increase a dead unit&#039;s life anyway <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
IsUnitType (GetFilterUnit (), UNIT_TYPE_DEAD)
//which is safer (if you have a tendency to add life to dead units (which has no effect whatsoever)


3) Your indentation method is... strange. IMO, you should have it something like
JASS:
//Just a random example
function MyFunc takes nothing returns nothing
  local integer i = 0
  loop
  exitwhen i &gt; 5
     call DoSomething(i)
     if i == 3 then
         call AnotherThing (i)
     endif
     set i = i + 1
  endloop
endfunction

That way, you know exactly what is contained in what block (since all code contained within the open/close statements is indented a bit further than the open/close statements)

4) Configuration header would be nice - if you're using vJASS, you can do
JASS:
globals
//private syntax requires a scope or library
   private constant integer SPELLID = &#039;A000&#039;
   private constant real RESTOREVAL = 20.
   private constant real MULTIPLIER = 5.
endglobals

If you're not using vJASS
JASS:
constant function SpellId takes nothing returns nothing
   return &#039;A000&#039;
endfunction

constant function GetRestoreVal takes integer level returns integer //not sure if I2R works within a constant function :\
  return 20 + level * 5
endfunction


5) You never nulled owner
 

Exide

I am amazingly focused right now!
Reaction score
448
Nice, cool idea. :thup:

I saw one or two things in your code that could be changed, though..

JASS:

function Trig_dead takes nothing returns boolean
    return ( IsUnitDeadBJ(GetFilterUnit()) == true )
endfunction


could probably be:

JASS:

function Trig_dead takes nothing returns boolean
    return ( GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) &lt;= 0 )
endfunction


Also:

JASS:

    set gg_trg_DeadlyS = CreateTrigger(  )


Could be:

JASS:

    local trigger gg_trg_DeadlyS = CreateTrigger(  )


EDIT: Beaten, and pwned. :(
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Cool spell (though I never tried it out) but kinda simple.

@Exide:

What good would it do localizing the trigger if you're using the gg_trg_blablabla?
JASS:

local trigger T = CreateTrigger()

or

local trigger trig = CreateTrigger()


Using easy trigger names saves you some time when adding conditions and events (unless you lame and convert a GUi trigger with event and condition).
 
Reaction score
456
Nice to see a new Jasser here.

I usually don't mention anything about the spell's description, but this time I do. It is kinda weird that it's saying "Absorbs deadly energy from nearby corpses", when it's still giving hit points/mana to the caster. The "deadly" word could be removed completely from it ;).

Then about intendation. When code is intended correctly, it's much easier to read. So.

1. Everything that's inside functions, should never be on the same 'level' as "function" and "endfunction" keywords. (I don't personally mind if comments or text macros are.):
JASS:
function Trig_DeadlyS_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit() //the triggering unit
    local location p
    local unit pu
    local group g
    local real r
    local player owner

    //owner of triggering unit
    set owner = GetOwningPlayer(c)
    //amount of healing and mana gained
    set r = 20 + (R2I(GetUnitAbilityLevel(c, &#039;A000&#039; *(5))))
    //position of triggering unit
    set p = GetUnitLoc(c)
    set g = GetUnitsInRangeOfLocMatching(800, p, Condition( function Trig_dead ) )
    loop
    set pu = FirstOfGroup(g)
    exitwhen pu==null
    call GroupRemoveUnit(g,pu)
    if IsUnitEnemy(pu, owner)==true then
    call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
    call RemoveUnit( pu )
    else
    call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
    call RemoveUnit( pu )
    endif
    endloop
// the functions bellow removes and nulls the variables, prevents memory leaks
    call DestroyGroup(g)
    call RemoveLocation(p)
    set pu = null
    set g = null
    set c = null
    set p = null
endfunction

2. It's same with loops and if-then-else statements (some people like to leave the exitwhen part to the same level with loop and endloop keywords):
JASS:
function Trig_DeadlyS_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit() //the triggering unit
    local location p
    local unit pu
    local group g
    local real r
    local player owner

    //owner of triggering unit
    set owner = GetOwningPlayer(c)
    //amount of healing and mana gained
    set r = 20 + (R2I(GetUnitAbilityLevel(c, &#039;A000&#039; *(5))))
    //position of triggering unit
    set p = GetUnitLoc(c)
    set g = GetUnitsInRangeOfLocMatching(800, p, Condition( function Trig_dead ) )
    loop
        set pu = FirstOfGroup(g)
        exitwhen pu==null
        call GroupRemoveUnit(g,pu)
        if IsUnitEnemy(pu, owner)==true then
            call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
            call RemoveUnit( pu )
        else
            call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
            call RemoveUnit( pu )
        endif
    endloop
    // the functions bellow removes and nulls the variables, prevents memory leaks
    call DestroyGroup(g)
    call RemoveLocation(p)
    set pu = null
    set g = null
    set c = null
    set p = null
endfunction

Then about optimization. You're able to set the variables' values when you're declaring them (like the you've done for the unit c):
JASS:
function Trig_DeadlyS_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit() //the triggering unit
    local location p = GetUnitLoc(c)
    local unit pu
    local group g
    local real r = 20 + (R2I(GetUnitAbilityLevel(c, &#039;A000&#039; *(5))))
    local player owner = GetOwningPlayer(c)
    
    set g = GetUnitsInRangeOfLocMatching(800, p, Condition( function Trig_dead ) )
    loop
        set pu = FirstOfGroup(g)
        exitwhen pu==null
        call GroupRemoveUnit(g,pu)
        if IsUnitEnemy(pu, owner)==true then
            call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
            call RemoveUnit( pu )
        else
            call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
            call RemoveUnit( pu )
        endif
    endloop
    // the functions bellow removes and nulls the variables, prevents memory leaks
    call DestroyGroup(g)
    call RemoveLocation(p)
    set pu = null
    set g = null
    set c = null
    set p = null
endfunction

You don't actually need the owner variable, because you're only using it once. Locations can be replaced by coordinates (reals). The group picking function has to be changed to GroupEnumUnitsInRange(..) function, and it works a bit differently. You now have to create the group yourself, because this new function doesn't do it. And you don't have to null the pu variable, because it gets automatically nulled by the loop:
JASS:
function Trig_DeadlyS_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit() //the triggering unit
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    local unit pu
    local group g = CreateGroup()
    local real r = 20 + (R2I(GetUnitAbilityLevel(c, &#039;A000&#039; *(5))))
    
    //see this new function
    call GroupEnumUnitsInRange(g, x, y, 800.00, Condition(function Trig_dead))
    loop
        set pu = FirstOfGroup(g)
        exitwhen pu == null
        call GroupRemoveUnit(g, pu)
        if IsUnitEnemy(pu, GetOwningPlayer(c)) == true then
            call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
            call RemoveUnit( pu )
        else
            call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
            call RemoveUnit( pu )
        endif
    endloop
    // the functions bellow removes and nulls the variables, prevents memory leaks
    call DestroyGroup(g)
    set g = null
    set c = null
endfunction
 

Exide

I am amazingly focused right now!
Reaction score
448
Cool spell (though I never tried it out) but kinda simple.

@Exide:

What good would it do localizing the trigger if you're using the gg_trg_blablabla?
JASS:

local trigger T = CreateTrigger()

or

local trigger trig = CreateTrigger()


Using easy trigger names saves you some time when adding conditions and events (unless you lame and convert a GUi trigger with event and condition).

I didn't know the name mattered? :p :eek:
 

quraji

zap
Reaction score
144
I didn't know the name mattered? :p :eek:

It matters if you like typing quickly and easily. "t" is a lot faster and easier to type than "gg_trg_InitTrig_MyTrig". Plus it's less confusing, and less cluttering. :thup:
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I suggest making a few constant functions for the configuration options, one for the rawcode, other for the "healing" amount.

That way the user has to change the rawcode only once and in addition, makes the spell easier to use.


Also, you should make the spell more appealing, add some special effects.

It's currently too dull and basic.


Next, screenshots are always welcomed, though, you need some special effects (check the suggestion above).


if IsUnitEnemy(pu, GetOwningPlayer(c)) == true then
- call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
- call RemoveUnit(pu)
else
- call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
- call RemoveUnit(pu)
endif

Can be shortened to because you are going to remove the dead unit anyway.

if IsUnitEnemy(pu, GetOwningPlayer(c)) == true then
- call SetUnitState (c, UNIT_STATE_LIFE, GetWidgetLife(c) + r )
else
- call SetUnitState (c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) + r )
endif
call RemoveUnit(pu)


Lastly, just a tip, try giving your variables descriptive names instead of "c", "b".

Currently it's easy to understand what each variable does because of the laconic code, but later, when you advance
and start scripting more elaborate spells, systems or snippets, you'll soon realise naming variables
"the long way" will avoid much trouble and time.
 
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
    +1
  • 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