• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Can anyone explain why these two triggers gives an error?

Status
Not open for further replies.
Level 6
Joined
Jul 25, 2005
Messages
221
Can anyone explain why these two triggers give an error message before startup of the map?

First one, checks for attacker if its a hero, if so, add an event regarding the attacked target being damaged, where the second trigger takes final data

JASS:
function CondExp takes nothing returns boolean    
if ( IsUnitType(GetAttacker(),UNIT_TYPE_HERO)) then
    return true
    endif
    return false
endfunction    
function givexp takes nothing returns nothing
    call DisplayTextToForce(GetPlayersAll(), "Lulzor - 1")   
    call TriggerRegisterUnitEvent(gg_trg_dmg, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
endfunction
//===========================================================================
function InitTrig_ExpAtAttack takes nothing returns nothing
local integer u
    set gg_trg_ExpAtAttack = CreateTrigger(  )
    set u=0
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_ExpAtAttack, Player(u), EVENT_PLAYER_UNIT_ATTACKED,null)
        exitwhen u==16
        set u=u+1 
    endloop
    call TriggerAddCondition(gg_trg_ExpAtAttack, Condition( function CondExp))
    call TriggerAddAction( gg_trg_ExpAtAttack, function givexp)
endfunction

Second one, checks if the damage source is the mountain king, if so, add exp to the damage source

JASS:
function CondDmg takes nothing returns boolean    
if (GetUnitTypeId(GetEventDamageSource())!= 'Hmkg') then
    return false
    endif
    return true
endfunction
function dmg takes nothing returns nothing
    call DisplayTextToForce(GetPlayersAll(), "Lulzor - 2")   
    call AddHeroXP(GetEventDamageSource(), 200, true)
endfunction
//===========================================================================
function InitTrig_dmg takes nothing returns nothing
    set gg_trg_dmg = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_dmg, Condition( function CondDmg))
    call TriggerAddAction( gg_trg_dmg, function dmg )
endfunction

Please note that I am lazy, so I didn't have time to add RemoveTriggerAction - that trigger (points to the second one)

Can anyone detect flaws? if so, correct them for me so I may learn from my mistakes, also, any other aspects of the script you'd like to change, please tell me :cute:
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
You want to get experience each time you attack a unit?
The problem is there:
exitwhen u==16
use
exitwhen u==bj_MAX_PLAYERS

Also note that this thing has issues because the event of a unit being damaged is also fired by spells.
 
Last edited:
Level 6
Joined
Jul 25, 2005
Messages
221
the reason why i wanna try this way is because, players can cheat if you use the event for IsAttacked, because then you can engage an enemy but not actually hit him and still get exp, since animation backswings or whatever increases the time between damage and when the unit recieves it. IsAttacked records it when the unit begins attacking, the animation backswing has a delay, during that delay a player can stop attacking and still trigger the trigger....
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
That much I figured.
Anyway was that the error message you got or was is another?
 
Level 6
Joined
Jul 25, 2005
Messages
221
Yes, I noticed that, GhostWolf, any suggestions on how to prevent this? maybe creating a temptrigger would suffice... hm... suggestions?
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
That is not necessary, but it isn't a problem.

As to the code - use a damage detection system (or make one), because this will leak events (when a unit gets hit twice, it will create 2 events etc).

Ok, that is not necessary but then it should be exitwhen u==15.
You know Players are 0-15.
So 16 gives an error.
Didn't get other errors so I thought this was it ;)
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You know Players are 0-15.
So 16 gives an error.

Oh right, forgot it's 0 to 15 and not 1 to 16 :/

Yes, I noticed that, GhostWolf, any suggestions on how to prevent this? maybe creating a temptrigger would suffice... hm... suggestions?

A better solution would be to add the event once a unit enters the map, this will only leak one event once he is dead.

Might want to look at a system, though, and check how they do it (basically making a new function for each unit that enters the map and then when it dies you destroy the function, or trigger, don't remember which one).
 
Status
Not open for further replies.
Top