• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] JASS -> vJASS Help

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I have 'installed' NewGen and tried to save my map it gives me an error. When I saved it with the normal editor it was fine.

One of my heroes, the Priest, has this spell called Replenish:

Replenish
Heals all allied heroes. The amount healed depends on the Priest's intelligence.

Level 1:
Heals by 4x intelligence
Level 2: Heals by 6x intelligence
Level 3: Heals by 8x intelligence
Level 4: Heals by 10x intelligence
Level 5: Heals by 10x intelligence
Here is the script:

JASS:
function Replenish_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit targ = GetEnumUnit()
    local real r = ((2 * GetUnitAbilityLevel(u, 'A014') + 2) * GetHeroInt(u, true))
    local texttag t = CreateTextTag()
    call SetUnitState(targ, UNIT_STATE_LIFE, GetUnitState(targ, UNIT_STATE_LIFE) + r)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", targ, "origin"))
    call SetTextTagText(t, "|cff00ff00+" + I2S(R2I(r)) + "|r", 0.023)
    call SetTextTagPosUnit(t, targ, 50)
    call SetTextTagVelocity(t, 0, 64 * 0.071 / 128)
    call SetTextTagPermanent(t, false)
    call SetTextTagLifespan(t, 2)
    call SetTextTagFadepoint(t, 1)
    call SetTextTagVisibility(t, true)
    set t = null
    set u = null
    set targ = null
endfunction

function Replenish_Conditions takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true and IsPlayerAlly(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit())) == true
endfunction

function act_Replenish takes nothing returns nothing
    local group ug = CreateGroup()
    call GroupEnumUnitsInRect(ug, GetPlayableMapRect(), Condition(function Replenish_Conditions))
    call ForGroup(ug, function Replenish_Actions)
    call DestroyGroup(ug)
    set ug = null
endfunction

function cond_Replenish takes nothing returns boolean
    if (GetSpellAbilityId() == 'A014') then
        return true
    endif
    return false
endfunction

function InitTrig_Replenish takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function cond_Replenish))
    call TriggerAddAction(t, function act_Replenish)
endfunction
What am I doing wrong? Also, if there are aspects that I could improve on, please point them out.

Thanks!
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
JASS:
function Replenish_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit targ = GetEnumUnit()
    local real r = ((2 * GetUnitAbilityLevel(u, 'A014') + 2) * GetHeroInt(u, true))
    local texttag t = CreateTextTag()
    call SetUnitState(targ, UNIT_STATE_LIFE, GetUnitState(targ, UNIT_STATE_LIFE) + r)
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl", targ, "origin"))
    call SetTextTagText(t, "|cff00ff00+" + I2S(R2I(r)) + "|r", 0.023)
    call SetTextTagPosUnit(t, targ, 50)
    call SetTextTagVelocity(t, 0, 64 * 0.071 / 128)
    call SetTextTagPermanent(t, false)
    call SetTextTagLifespan(t, 2)
    call SetTextTagFadepoint(t, 1)
    call SetTextTagVisibility(t, true)
    set t = null
    set u = null
    set targ = null
endfunction

function Replenish_Conditions takes nothing returns boolean
    if IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) and IsPlayerAlly(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit())) then
        call Replenish_Actions()
    endif
    returns false
endfunction

function Replenish takes nothing returns boolean
    if GetSpellAbilityId() == 'A014') then
        call GroupEnumUnitsInRect(bj_lastCreatedGroup, GetPlayableMapRect(), Condition(function Replenish_Conditions))
    endif
    return false
endfunction

function InitTrig_Replenish takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Replenish))
    set t = null
endfunction

I made a few changes. Didn't test whether it compiles. You might have to debug it since I didn't check it thoroughly.

But this is to give you a few ideas about the coding style.
 
Last edited:
Level 17
Joined
Feb 11, 2011
Messages
1,860
Okay, thanks man. Appreciate it.

Another issue: can anyone tell me what this means:

"Syntax Error, unexpected 'takes'"

When I click Syntax Check, it says parse successful, but when saving the map I get this error. This error does not occur for the above script posted by Maker, but for one of my other scripts.

Thanks.
 
That error could have come from your use of a space in a function's name.
It's likely not this snippet of code.

Do you have other scripts in the map?

If so, try finding the cause of the error in them.

Also, you shouldn't use TriggerActions, you can combine the actions and the conditions together and just use the TriggerAddCondition function.

This makes your code faster.

Here's another tip:
If you're going to use a local for storage and the function returns a handle (meaning you're going to have to null the local at the end of the function, then don't create the local because that would actually make you lose performance instead.
Only use locals for handles if you're using the function 3 or more times.

If the function returns an integer/string/boolean/code/real, then only use a local for it if you're using 2 or more times.

That's a jass rule.
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
[embarrassed face]

In one of my lines I misspelled "endfunction" - I put "endfunctioan" :D
Sorry about that guys.

@Mag: Would you mind giving me a simple example of when the function returns a handle, please? I am still learning all this terminology.

Thanks!
 
Level 4
Joined
Mar 27, 2008
Messages
112
This returns a handle:
JASS:
function returnHandle takes nothing returns unit //unit is of type handle
return UnitCreate(Player(0),'hfoo',0,0,0) //parameters and function name might be wrong but I hope you get the idea
endfunction
//so if I now use it in a function
function A takes nothing returns nothing
local unit u = returnHandle()
call KillUnit(u)//kills the footman that is created in the returnHandle() function
//now we must remove the handle we stored on the local variable
set u = null //now the handle is cleared from the variable and we have cleaned a possible leak
endfunction
I think this is what Mag means
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
Question:
Can you guys see where I can improve on this script? It has a slight pause when I cast the spell.
JASS:
function Holy_Blast_Actions takes nothing returns nothing
    local real x = GetUnitX(GetEnumUnit())
    local real y = GetUnitY(GetEnumUnit())
    local unit u = GetTriggerUnit()
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl", GetEnumUnit(), "origin"))
    set bj_lastCreatedUnit = CreateUnit(GetOwningPlayer(u), 'h003', x, y, bj_UNIT_FACING)
    call RemoveGuardPosition(bj_lastCreatedUnit)
    call UnitAddAbility(bj_lastCreatedUnit, 'A03F')
    call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A03F', GetUnitAbilityLevel(u, 'A01J'))
    call IssueTargetOrder(bj_lastCreatedUnit, "curse", GetEnumUnit())
    call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1)
    set u = null
endfunction

function Holy_Blast_Conditions takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit()))
endfunction

function Holy_Blast takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    if (GetSpellAbilityId() == 'A01J') then
        call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 350, Condition(function Holy_Blast_Conditions))
        call ForGroup(bj_lastCreatedGroup, function Holy_Blast_Actions)
    endif
    set u = null
    return false
endfunction

function InitTrig_Holy_Blast takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Holy_Blast))
endfunction
Explanation
This spell is basically like War Stomp, but when you cast it, nearby enemies are blinded for a few seconds, giving them a chance to miss on each attack.
 
Status
Not open for further replies.
Top