• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Jass starting problems

Status
Not open for further replies.
Level 7
Joined
Aug 31, 2006
Messages
132
Well i was trying jass but the spell i made didnt work at all.
I did read any tutorial but still cant find the error -

JASS:
function Condy takes nothing returns boolean
    return GetSpellAbilityId()=='A000'
endfunction

function MyFuncy takes nothing returns nothing
    local group GroupUnits = CreateGroup()
    local unit caster = GetSpellAbilityUnit()
    local location temploc = GetUnitLoc(caster)
    local unit temp
    local integer tempnumber = 3
    call GroupEnumUnitsInRangeOfLoc(GroupUnits, temploc, 400, null)
    loop
        set temp = FirstOfGroup(GroupUnits)
        exitwhen temp == null or tempnumber == 0
        call UnitDamageTarget(caster, temp, 50, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
        call GroupRemoveUnit(GroupUnits, temp)
        set tempnumber = tempnumber - 1
    endloop
    set GroupUnits = null
    set caster = null
    set temploc = null
    set temp = null
endfunction

function InitTrig takes nothing returns nothing
    local trigger gg_trg_Triggy = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Triggy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Triggy, Condition(function Condy))
    call TriggerAddAction(gg_trg_Triggy, function MyFuncy)
endfunction

The spell is supposed to to remove a % of hp of nearby units of the caster, but when i cast the spell absolutely nothing happens.
 
Last edited by a moderator:
Level 21
Joined
Aug 21, 2005
Messages
3,699
1) nulling a group or location doesn't remove it from the game, thus creating a leak. use
call RemoveLocation(loc) and
call DestroyGroup(group)
2) not entirelly sure, but doesn't "GetSpellAbilityUnit()" return the target, rather than the caster?

other than that, I think it should work...
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You can't use function InitTrig takes nothing returns nothing.

Your init's name should be the name of the trigger (the white page).
So if you white page's name is BLA the init will be named InitTrig_BLA.

If you saw people use only InitTrig its because they use Scopes which give the init their name with this syntax: InitTrig_ScopeName (in this case the Scope's name has to be equal to the white page's name).

Because of all this your trigger is probably disabled so remember to enable it after you fix it.
 
Level 7
Joined
Aug 31, 2006
Messages
132
Ok, thanks. will try.

Edit:

I changed to -
function Condy takes nothing returns boolean
return GetSpellAbilityId()=='A000'
endfunction
function MyFuncy takes nothing returns nothing
local group GroupUnits = CreateGroup()
local unit caster = GetSpellAbilityUnit()
local location temploc = GetUnitLoc(caster)
local unit temp
local integer tempnumber = 3
call GroupEnumUnitsInRangeOfLoc(GroupUnits, temploc, 400, null)
loop
set temp = FirstOfGroup(GroupUnits)
exitwhen temp == null or tempnumber == 0
call UnitDamageTarget(caster, temp, 50, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
call GroupRemoveUnit(GroupUnits, temp)
set tempnumber = tempnumber - 1
endloop
set caster = null
call RemoveLocation(temploc)
call DestroyGroup(GroupUnits)
set temp = null
endfunction
function InitTrig_MyFuncy takes nothing returns nothing
local trigger gg_trg_Triggy = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Triggy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Triggy, Condition(function Condy))
call TriggerAddAction(gg_trg_Triggy, function MyFuncy)
endfunction

but when i save a error message pops up and says that some line "Expected a Name" and lots of following lines "Expected a code statement".

Edit2: Understood what you mean. Changed to

function Trig_Gravita_Condition takes nothing returns boolean
return GetSpellAbilityId()=='A000'
endfunction
function Trig_Gravita_Actions takes nothing returns nothing
local group GroupUnits = CreateGroup()
local unit caster = GetSpellAbilityUnit()
local location temploc = GetUnitLoc(caster)
local unit temp
call GroupEnumUnitsInRangeOfLoc(GroupUnits, temploc, 400, null)
loop
set temp = FirstOfGroup(GroupUnits)
exitwhen temp == null
call UnitDamageTarget(caster, temp, 50, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
call GroupRemoveUnit(GroupUnits, temp)
endloop
set caster = null
set temp = null
call RemoveLocation(temploc)
call DestroyGroup(GroupUnits)
endfunction
function InitTrig_Gravita takes nothing returns nothing
set gg_trg_Gravita = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Gravita, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(gg_trg_Gravita, Condition(function Trig_Gravita_Condition))
call TriggerAddAction(gg_trg_Gravita, function Trig_Gravita_Actions)
endfunction

It finnaly works :D thx.
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
If you happen to read this, please wrap your triggers made in jass in a [code=jass][/code] tag. Also, if you indent your code, it is far easier to read. When I help someone, the first thing I do is indent code because it is a lot easier to find mistakes that way.
 
Level 7
Joined
Aug 31, 2006
Messages
132
Well after that i tried another spell that is more jass dependant.
The spell is supposed to move a shuriken (dummy) forward till it hits an unit.
The spell is not complete but by the "if then else" WE began to say: 'endloop' expected, even if there is already one!

JASS:
function Trig_Shuriken_Condition takes nothing returns boolean
return GetSpellAbilityId()=='A001'
endfunction
//==============================================================================
function Trig_Shuriken_Actions takes nothing returns nothing
local  unit caster = GetSpellAbilityUnit()
local location casterloc = GetUnitLoc(caster)
local location targetloc = GetSpellTargetLoc()
local real angle = AngleBetweenPoints(casterloc, targetloc)
local integer chargez = 0
local unit dummy
local group NearbyUnits = CreateGroup()
local integer counted
local location dummyloc 
set dummy = CreateUnitAtLoc(GetOwningPlayer(caster), 'h000', casterloc, bj_UNIT_FACING )
loop
exitwhen chargez == 100
set dummyloc = GetUnitLoc(dummy)
call GroupEnumUnitsInRangeOfLoc(NearbyUnits, dummyloc, 50, null)
set counted = CountUnitsInGroup(NearbyUnits)
If counted > 0 then
call UnitDamageTarget(caster, GroupPickRandomUnit(NearbyUnits), 100, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, null)
endif
endloop
endfunction
//==============================================================================
function InitTrig_Shuriken takes nothing returns nothing
    set gg_trg_Shuriken = CreateTrigger()
    call TriggerAddCondition(gg_trg_Shuriken, Condition(function Trig_Shuriken_Condition))
    call TriggerAddAction(gg_trg_Shuriken, function Trig_Shuriken_Actions )
endfunction
 
Level 7
Joined
Aug 31, 2006
Messages
132
I have a jass new gen pack but if i use syntax check it says that a dll file is missing even if its there.

EDIT: If then else works now, but how do i make the check for units near the dummy only pick enemy units?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
call GroupEnumUnitsInRangeOfLoc(NearbyUnits, dummyloc, 50, null)

instead of using "null", you need to use Condition(function myfilter)

my filter is a function (without parameters) that checks if GetEnumUnit is enemy of owner of triggering unit. If you don't know how it works, I think it's easiest to create such an action in GUI, then convert to jass and see how it works.
 
Status
Not open for further replies.
Top