Returning to Jass - check a simple code

MagnaGuard

Active Member
Reaction score
49
So came back after school problems and need someone to look over and tell me why the syntax thingy gave me so many errors

JASS:
scope flame initializer Init

globals
    private constant integer ID = 'A000' //spell rawcode
    private constant string effect = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
    private constant string effect_place = "origin"
endglobals

private function damage takes integer a returns integer //Sets the damage the spell does
    return a * 50
endfunction

private function level takes integer a returns integer //Gets the chance for the spell to work
    return a * 2
endfunction

private function cond takes nothing returns boolean //Checking conditions and returns ture or false
    return IsPlayerEnemy(GetOwningPlayer(GetAttacker()),GetOwningPlayer(GetTriggerUnit())) and GetRandomInt(0,100) <= level(GetUnitAbilityLevel(GetTriggerUnit(), ID))
endfunction

private function Actions takes nothing returns nothing
local unit t = GetTriggerUnit()
local unit a = GetAttacker()
local effect e = AddSpecialEffectTarget(effect, a, effect_place)
    call DestroyEffect(e)
    call UnitDamageTarget(t, a, damage(GetUnitAbilityLevel(t, ID)), true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
  set t=null
  set a=null
  set e=null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
local integer i = 0
local trigger t = CreateTrigger(  )
loop 
 exitwhen i>15
    call TriggerRegisterPlayerEvent(t, Player(i), EVENT_PLAYER_UNIT_ATTACKED)
    
endloop
    call TriggerAddAction( t, Actions )
    call TriggerAddCondition(t, Filter(function cond))
    call TriggerAddAction(t,function action)
endfunction
endscope


Spell is just a passive so if the hero is attacked, theres a chance for the attacker to get damaged.
 

Rushhour

New Member
Reaction score
46
Are you sure that TriggerUnit() isnt the same as Attacker() ? Would be weird if it damages itself ;P
And you should be careful not to create an "infinite loop". That means be sure the actions of the trigger don't make the trigger run again.

You got some syntax errors? Which lines?

And another improvement:
JASS:

does excatly the same thing, and you can remove the local and the set e=null ;)
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
Are you doing this in NewGen WE, or the regular editor? If you are in the regular editor, most of the lines you have will be errors. I don't see any reason this code shouldn't work in NewGen though.

EDIT
JASS:
    call TriggerAddAction(t,function action)

There is no function called action. This line should give an error.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
scope Flame initializer Init

    globals
        private constant integer ID = 'A000' //spell's rawcode
        private constant string FX = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaosTarget.mdl"
        private constant string FX_POINT = "origin"
    endglobals

    private function Damage takes integer lv returns real //Sets the damage the spell does
        return lv * 50.
    endfunction

    private function Chance takes integer lv returns integer //Gets the chance for the spell to work
        return lv * 2
    endfunction

    private function Act takes nothing returns nothing
        call DestroyEffect(AddSpecialEffectTarget(FX, GetAttacker(), FX_POINT))
        call UnitDamageTarget(GetTriggerUnit(), GetAttacker(), Damage(GetUnitAbilityLevel(GetTriggerUnit(), ID)), true, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    endfunction

    private function Cond takes nothing returns boolean //Checking conditions and returns ture or false
        if IsUnitEnemy(GetAttacker(),GetOwningPlayer(GetTriggerUnit())) and GetRandomInt(0,100) <= Chance(GetUnitAbilityLevel(GetTriggerUnit(), ID)) then
            call Act()
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_ATTACKED)
        call TriggerAddCondition(trig,Condition(function Cond))
    endfunction
endscope
 

MagnaGuard

Active Member
Reaction score
49
I think the triggering unit is the one who gets attacked

Forgot to add a counter on the loop :p thanks

And solved the rest myself

There is no function called action. This line should give an error.

Ya i accidentaly made two lines of that

Edit: it does too much damage, much more than it should, doing like 300 dmg at lev 1
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top