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
 

Lehona

New Member
Reaction score
12
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
 

Viikuna

No Marlo no game.
Reaction score
265
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
 

Lehona

New Member
Reaction score
12
@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.
 

Viikuna

No Marlo no game.
Reaction score
265
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.
 

Lehona

New Member
Reaction score
12
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?
 

Lehona

New Member
Reaction score
12
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: 152

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
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.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Right, noticed the reason. For some unfathomable reason you register then event 16 times, hence the actions fire 16 times.
 

Lehona

New Member
Reaction score
12
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 :/
 

Lehona

New Member
Reaction score
12
I just needed any value that fills the variable first. Will 'null' work or have i to use a dummy unit?
 

RaiJin

New Member
Reaction score
40
leave it alone don't need to set it to anything

oops nvm xD

just leave it as

local unit u
 

Lehona

New Member
Reaction score
12
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.
 

Lehona

New Member
Reaction score
12
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.
  • 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
    +2
  • 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