Multiplicating not allowed?

Lehona

New Member
Reaction score
12
Even if I am a noob in (v)Jass, I wrote a trigger for a spell which does the same as Stormbolt, but heals the caster. And i wanted to do it without any dummy unit, which heals my hero. Here's my script, but the red marked line creates a syntax error:

scope ShadowWave initializer Init

globals
private constant integer ID = 'Hess'
endglobals

private function True takes nothing returns boolean
return true
endfunction

private function Cons takes nothing returns boolean
return (GetSpellAbilityId() == ID)
endfunction

private function NewHp takes unit p returns integer
return ((R2I(GetWidgetLife(p)) + (GetUnitAbilityLevel(p, ID)) * 100)
endfunction
private function Wave takes nothing returns nothing
local unit u = GetSpellTargetUnit()
local unit t = GetTriggerUnit()
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Orc\\HealingWave\\HealingWaveTarget.mdl", t, "Chest"))
SetWidgetLife(t, NewHp(t))
endfunction

private function Init takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger()
loop
exitwhen i > 15
call TriggerRegisterUnitEvent (t, gg_unit_Hmkg_0000, EVENT_UNIT_SPELL_CAST)
set i = i + 1
endloop
call TriggerAddCondition(t, Filter(function Cons))
call TriggerAddAction(t, function Wave)
endfunction

endscope


And here in Jass (because with [Noparse]
JASS:
[/Noparse] i can't color the lines:


<div class="bbCodeSpoiler">
	<button type="button" class="bbCodeSpoiler-button button" data-xf-click="toggle" data-xf-init="tooltip" title="Click to reveal or hide spoiler"><span class="button-text">

		<span>Spoiler</span>
	</span></button>
	<div class="bbCodeSpoiler-content">
		<div class="bbCodeBlock bbCodeBlock--spoiler">
			<div class="bbCodeBlock-content"><div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="keyword">scope</span> <span>ShadowWave</span> <span class="keyword">initializer</span> <span>Init</span>

<span class="keyword">globals</span>
<span class="keyword">private</span> <span class="keyword">constant</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/integer" class="type">integer</a> <span>ID</span> <span class="symbol">=</span> &#<span class="number">0</span><span class="number">39</span>;<span>Hess</span>&#<span class="number">0</span><span class="number">39</span>;
<span class="keyword">endglobals</span>

<span class="keyword">private</span> <span class="keyword">function</span> <span>True</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/boolean" class="type">boolean</a>
    <span class="keyword">return</span> <span class="value">true</span>
<span class="keyword">endfunction</span>

<span class="keyword">private</span> <span class="keyword">function</span> <span>Cons</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/boolean" class="type">boolean</a>
    <span class="keyword">return</span> <span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetSpellAbilityId" class="native">GetSpellAbilityId</a><span class="symbol">(</span><span class="symbol">)</span> <span class="symbol">=</span><span class="symbol">=</span> <span>ID</span><span class="symbol">)</span>
<span class="keyword">endfunction</span>

<span class="keyword">private</span> <span class="keyword">function</span> <span>NewHp</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>p</span> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/integer" class="type">integer</a>
    <span class="keyword">return</span> <span class="symbol">(</span><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/R2I" class="native">R2I</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetWidgetLife" class="native">GetWidgetLife</a><span class="symbol">(</span><span>p</span><span class="symbol">)</span><span class="symbol">)</span> <span class="symbol">+</span> <span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetUnitAbilityLevel" class="native">GetUnitAbilityLevel</a><span class="symbol">(</span><span>p</span><span class="symbol">,</span> <span>ID</span><span class="symbol">)</span><span class="symbol">)</span> <span class="symbol">*</span> <span class="number">100</span><span class="symbol">)</span>
<span class="keyword">endfunction</span> 
<span class="keyword">private</span> <span class="keyword">function</span> <span>Wave</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>u</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/GetSpellTargetUnit" class="native">GetSpellTargetUnit</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>t</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/GetTriggerUnit" class="native">GetTriggerUnit</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/DestroyEffect" class="native">DestroyEffect</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/AddSpecialEffectTarget" class="native">AddSpecialEffectTarget</a><span class="symbol">(</span>&<span>quot</span>;<span>Abilities</span>\\<span>Spells</span>\\<span>Orc</span>\\<span>HealingWave</span>\\<span>HealingWaveTarget</span>.<span>mdl</span>&<span>quot</span>;<span class="symbol">,</span> <span>t</span><span class="symbol">,</span> &<span>quot</span>;<span>Chest</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">)</span>
    <a href="http://wiki.thehelper.net/wc3/jass/common.j/SetWidgetLife" class="native">SetWidgetLife</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span> <span>NewHp</span><span class="symbol">(</span><span>t</span><span class="symbol">)</span><span class="symbol">)</span> 
<span class="keyword">endfunction</span>   

    <span class="keyword">private</span> <span class="keyword">function</span> <span>Init</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/integer" class="type">integer</a> <span>i</span> <span class="symbol">=</span> <span class="number">0</span>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/trigger" class="type">trigger</a> <span>t</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/CreateTrigger" class="native">CreateTrigger</a><span class="symbol">(</span><span class="symbol">)</span>
        <span class="keyword">loop</span>
        <span class="keyword">exitwhen</span> <span>i</span> &<span>gt</span>; <span class="number">15</span>
        <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerRegisterUnitEvent" class="native">TriggerRegisterUnitEvent</a> <span class="symbol">(</span><span>t</span><span class="symbol">,</span> <span>gg_unit_Hmkg_0000</span><span class="symbol">,</span> <a href="http://wiki.thehelper.net/wc3/EVENT_UNIT_SPELL_CAST" class="variable">EVENT_UNIT_SPELL_CAST</a><span class="symbol">)</span>
        <span class="keyword">set</span> <span>i</span> <span class="symbol">=</span> <span>i</span> <span class="symbol">+</span> <span class="number">1</span>
    <span class="keyword">endloop</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerAddCondition" class="native">TriggerAddCondition</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/Filter" class="native">Filter</a><span class="symbol">(</span><span class="keyword">function</span> <span>Cons</span><span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerAddAction" class="native">TriggerAddAction</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span> <span class="keyword">function</span> <span>Wave</span><span class="symbol">)</span>
<span class="keyword">endfunction</span>

<span class="keyword">endscope</span></code></pre></div></div></div>
		</div>
	</div>
</div>
And please tell me about the green line, because I&#039;m not sure about the correctness of it.

MfG Lehona
 
Thank you, it works now.

But does anyone knows the difference between a widget and a unit/how i can convert a unit to a widget or just fix my (new) code?

JASS:
scope ShadowWave initializer Init

globals
private constant integer ID = &#039;Hess&#039;
endglobals

private function True takes nothing returns boolean
    return true
endfunction

private function Cons takes nothing returns boolean
    return (GetSpellAbilityId() == ID)
endfunction

private function NewHp takes unit p returns real
    local real r = (GetWidgetLife(p)) + GetUnitAbilityLevel(p, ID) * 100
    return r
endfunction 

private function Wave takes nothing returns nothing
    local unit u = GetSpellTargetUnit()
    local unit t = GetTriggerUnit()
    local real r =  NewHp(t)
    call DestroyEffect(AddSpecialEffectTarget(&quot;Abilities\\Spells\\Orc\\HealingWave\\HealingWaveTarget.mdl&quot;, t, &quot;Chest&quot;))
    SetWidgetLife(t, r) 
endfunction   

    private function Init takes nothing returns nothing
    local integer i = 0
    local trigger t = CreateTrigger()
        loop
        exitwhen i &gt; 15
        call TriggerRegisterUnitEvent (t, gg_unit_Hmkg_0000, EVENT_UNIT_SPELL_CAST)
        set i = i + 1
    endloop
    call TriggerAddCondition(t, Filter(function Cons))
    call TriggerAddAction(t, function Wave)
endfunction

endscope
 
All thingies that can take damage are widgets ( units, destructibles items )
Functions like IssueTargetOrder and UnitDamageTarget , take target widget so you can do stuff to for example items too..

I think you can convert your widget to unit like this:

JASS:
 function W2U takes widget w returns unit
    return w
endfunction


I think blizzard uses a typecasting like this in some of their BJ functions, but I dont really remember which function it was. ( Dont know if that new patch is gonna change this or something )

You dont have to convert unit to widget, because unit extends widget. ( It has all widgets qualities ) You can simply do GetWidgetLife( unit ) or GetWidgetLife( item ) without any problems
 
@Viikuna: Seems it won't work, i still get a Syntax Error with
JASS:
scope ShadowWave initializer Init

globals
private constant integer ID = &#039;Hess&#039;
endglobals

private function True takes nothing returns boolean
    return true
endfunction

private function Cons takes nothing returns boolean
    return (GetSpellAbilityId() == ID)
endfunction

private function NewHp takes unit p returns real
    local real r = (GetWidgetLife(p)) + GetUnitAbilityLevel(p, ID) * 100
    return r
endfunction

function W2U takes widget w returns unit
    return w
endfunction
private function Wave takes nothing returns nothing
    local unit u = GetSpellTargetUnit()
    local unit t = GetTriggerUnit()
    local real r =  NewHp(t)
    local widget w1 = W2U(t)
    call DestroyEffect(AddSpecialEffectTarget(&quot;Abilities\\Spells\\Orc\\HealingWave\\HealingWaveTarget.mdl&quot;, t, &quot;Chest&quot;))
    SetWidgetLife(w1, r) 
endfunction   

    private function Init takes nothing returns nothing
    local integer i = 0
    local trigger t = CreateTrigger()
        loop
        exitwhen i &gt; 15
        call TriggerRegisterUnitEvent (t, gg_unit_Hmkg_0000, EVENT_UNIT_SPELL_CAST)
        set i = i + 1
    endloop
    call TriggerAddCondition(t, Filter(function Cons))
    call TriggerAddAction(t, function Wave)
endfunction

endscope


@Larcenist: But how can i change the life of my unit then?^^

Edit: Nevermind, using my brain worked.
 
It seems that I posted some useless information that got you confused.

If function takes widget, you can use units, items or any other widget types that extend widget with it just fine. No need to convert anything.
 
Okay, syntax errors are all fixed (noone saw, that there were a 'call' missing :p). But my unit has full live after using the spell. Does GetWidgetLife returns the max life?
 
The current code is:
JASS:
scope ShadowWave initializer Init

globals
private constant integer ID = &#039;Hess&#039;
endglobals

private function True takes nothing returns boolean
    return true
endfunction

private function Cons takes nothing returns boolean
    return (GetSpellAbilityId() == ID)
endfunction

private function calclvl takes unit o returns real
    return I2R(GetUnitAbilityLevel(o,ID)) * 100
    endfunction
    
private function NewHp takes unit p returns real
    local real r = (GetWidgetLife(p) + calclvl(p))
    return r
endfunction

private function Wave takes nothing returns nothing
    local unit u = GetSpellTargetUnit()
    local unit t = GetTriggerUnit()
    local real r =  NewHp(t)
    call DestroyEffect(AddSpecialEffectTarget(&quot;Abilities\\Spells\\Orc\\HealingWave\\HealingWaveTarget.mdl&quot;, t, &quot;Chest&quot;))
    call SetWidgetLife(t, r) 
endfunction   

    private function Init takes nothing returns nothing
    local integer i = 0
    local trigger t = CreateTrigger()
        loop
        exitwhen i &gt; 15
        call TriggerRegisterUnitEvent (t, gg_unit_Hmkg_0000, EVENT_UNIT_SPELL_CAST)
        set i = i + 1
    endloop
    call TriggerAddCondition(t, Filter(function Cons))
    call TriggerAddAction(t, function Wave)
endfunction

endscope


I know, not very efficient and much longer than it could be.

I attached my currently testmap to the post, there's nothin specify.
 

Attachments

  • Heilschlag_Test.w3x
    19.1 KB · Views: 153
Are you sure your unit is damaged enough when testing it? Seeing as it heals 100 per level, you might just not be damaged enough (I haven't tested the map myself).

Also this:

JASS:
private function NewHp takes unit p returns real
    local real r = (GetWidgetLife(p) + calclvl(p))
    return r
endfunction


Could be changed into this instead:

JASS:
private function NewHp takes unit p returns real
    return GetWidgetLife(p) + calclvl(p)
endfunction


And the calclvl function could be moved into the NewHp function to save you that call.
 
Right, noticed the reason. For some unfathomable reason you register then event 16 times, hence the actions fire 16 times.
 
New Trigger, new (un)luck.

Everytime I want to compile
JASS:
private function HGBe4 takes nothing returns nothing
local trigger t = CreateTrigger()
local unit u = 0
loop
exitwhen GetUnitAbilityLevel(u, ID) &gt; 0
set u = GroupPickRandomUnit(GetUnitsInRectAll(GetPlayableMapRect()))
if GetUnitAbilityLevel(u, ID) &gt; 0
call TriggerRegisterUnitEvent (t, u, EVENT_UNIT_SPELL_CAST)
endif
endloop
call TriggerAddAction (t, function HoGuBe4)
call TriggerAddCondition (t, Filter(function Cons))
endfunction

I get a syntax error in the line
JASS:
if GetUnitAbilityLevel(u, ID) &gt; 0

Can't fix the problem on my own actually :/
 
I just needed any value that fills the variable first. Will 'null' work or have i to use a dummy unit?
 
leave it alone don't need to set it to anything

oops nvm xD

just leave it as

local unit u
 
Okay, thaugt i read anywhere that a variable should have a value before i use it (Because here it get his value _after_ it's used the first time).

Edit: Even, that didn't cause the error.
 
But missing the 'then' in an if-statement does. *grr*

But now I get a syntax error in this line:

Here's my full code:
JASS:
scope HGB4 initializer HGBe4

globals
private constant integer ID = &#039;HoGu&#039;
public real HP = 0.0
endglobals

private function Cons takes nothing returns boolean
return (GetSpellAbilityId() == ID)
endfunction

private function HoGuBe4 takes nothing returns nothing HolyGuardBe4
    local unit u
    loop
        exitwhen UnitHasBuffBJ(u, MyScope_BC)
        set u = GroupPickRandomUnit (GetUnitsInRectAll(GetPlayableMapRect()))
    endloop
    set HP = GetUnitState (u, UNIT_STATE_LIFE)
endfunction
        
private function HGBe4 takes nothing returns nothing
local trigger t = CreateTrigger()
local unit u
loop
exitwhen GetUnitAbilityLevel(u, ID) &gt; 0
set u = GroupPickRandomUnit(GetUnitsInRectAll(GetPlayableMapRect()))
if GetUnitAbilityLevel(u, ID) &gt; 0 then 
call TriggerRegisterUnitEvent (t, u, EVENT_UNIT_SPELL_CAST)
endif
endloop
call TriggerAddAction (t, function HoGuBe4)
call TriggerAddCondition (t, Filter(function Cons))
endfunction

endscope


scope MyScope initializer HG
globals
public constant integer BC = &#039;X001&#039;
endglobals

private function Cons takes nothing returns boolean
    return (UnitHasBuffBJ(GetTriggerUnit(), BC))
endfunction

private function HolyGuard takes nothing returns nothing
    local unit u
    local real r = GetUnitState(u, UNIT_STATE_LIFE)
    local real r2 = GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE)
    local real HPT = HGB4_HP
    loop
        exitwhen GetUnitAbilityLevel(u, &#039;HoGu&#039;) &gt; 0
        set u = GroupPickRandomUnit (GetUnitsInRectAll(GetPlayableMapRect()))
    endloop
    
    set r2 = HGB4_HP - r2
    set r = r - r2
SetUnitState (u, UNIT_STATE_LIFE, r)    
SetUnitState (GetTriggerUnit(), UNIT_STATE_LIFE, HGB4_HP)
endfunction

private function HG takes nothing returns nothing
    local trigger t = CreateTrigger()
    local unit u
    loop                                         
    exitwhen  UnitHasBuffBJ(u, BC)
    set u = GroupPickRandomUnit(GetUnitsInRectAll(GetPlayableMapRect()))
    if UnitHasBuffBJ(u, BC) then 
    call TriggerRegisterUnitEvent (t,u, EVENT_UNIT_DAMAGED)
    endif
    endloop
    call TriggerAddAction (t, function HolyGuard)
    call TriggerAddCondition(t, Filter(function Cons))
endfunction
endscope


It has no documentation and it's very large/unefficient. But I did it most of time to make sure that I didn't miss a bracket.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      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