All times are UTC


Dear guest, welcome to YouTD!



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 11:30 am 
Offline
YouTD Admin
YouTD Admin
User avatar

Joined: Fri Jan 09, 2009 3:02 pm
Posts: 4324
Location: Belgium
YouTD Score: 645
Newbie Guide: Basic Trigger Examples.

Introduction

Hello everyone,

I'm creating this guide for people that know nothing/not much about using triggers for their towers.
In this guide i will give some examples of simple and easy trigger abilities.
First you'll have to create your tower, I already made a guide to help you with that, it's located here.

If something is not clear or you need more info I suggest you look in the "How To", link.
You can always ask questions here on the forum.

If you see a mistake in my guide plz let me know!


The Trigger Editor

To make triggers for your towers we have to use the trigger editor.

Image

Right click on a trigger and enable it if you want to use that specific trigger.

List of Featured Abilities

The abilities are listed from easy to complicated (but still easy)

  • Using native warcraft abilities like shockwave or lightningbolt
  • xx% chance to stun a creep for yy seconds when the tower damages a creep
  • xx% chance to deal yy spelldamage on attack
  • xx% chance to instakill a creep when the tower damages a creep
  • xx% chance to slow a creep by yy% for zz seconds when the tower damages a creep
  • xx% chance to deal yy DPS for zz seconds when the tower damages a creep
  • xx% chance on attack to increase the damage of all towers in yy range by zz% for ww seconds (using an iterate)
  • ...


The Examples

Native Abilities

You can't give native abilities to your tower instead you have to copy them and use those copies in the trigger editor.
We'll create a shockwave spell now that has an xx% chance to be cast on attack.

First we'll have to import the custom shockwave in the header, so enable the header and use this code.

Header
function Header takes Tower tower returns nothing 

globals 

Cast boekie_shockwave_cast // the name of your cast

endglobals

//Do not remove or rename this function! 
//Put your initialization tasks here, this function will be called on map init 

private function init takes nothing returns nothing 

set boekie_shockwave_cast = Cast.create('A000',"shockwave",1.0)  //A000 is the id of your copied spell, shockwave is the name of the cast used by warcraft.



endfunction


Now we'll have to use this custom created cast in the "onAttack" trigger.

onAttack
scope eventOnAttack

globals
    private constant real ONATTACK_chance = xx // replace xx with your own value
    private constant real ONATTACK_chanceLevelAdd = 0.0
endglobals

private function onAttack takes Tower tower returns nothing

local Unit creep = Event.getTarget() // this method is used to get the attacked creep

call boekie_shockwave_cast.pointCastFromCasterOnTarget(tower,creep,1.0,1.0)

endfunction

endscope


Stun

This ability will have a xx% chance to stun a damaged creep for yy seconds.
Because this effect is triggered when the creep is damaged we'll have to put the trigger in the "onDamage" trigger.

onDamage
scope eventOnDamage

globals
    private constant real ONDAMAGE_chance = xx // replace xx with your own value
    private constant real ONDAMAGE_chanceLevelAdd = 0.0
endglobals


private function onDamage takes Tower tower returns nothing

local Unit creep = Event.getTarget() // This method is used to get the damaged creep

call cb_stun.applyOnlyTimed(tower, creep, yy) // replace yy with your own value

endfunction

endscope


Spelldamage

This ability will have a xx% chance to deal yy spelldamage on the attacked creep.
Because this effect is triggered when the creep is attacked we'll have to put the trigger in the "onAttack" trigger.

onAttack

scope eventOnAttack

globals
    private constant real ONATTACK_chance = xx // replace xx with your own value
    private constant real ONATTACK_chanceLevelAdd = 0.0
endglobals

private function onAttack takes Tower tower returns nothing

local Unit creep = Event.getTarget() // this method is used to get the attacked creep 

call tower.doSpellDamage(creep,yy,tower.calcSpellCritNoBonus()) // replace yy with the amount of damage you want to deal
endfunction

endscope


Insta Kill

This ability will have a xx% chance to insta-kill a damaged creep.
Because this effect is triggered when the creep is damaged we'll have to put the trigger in the "onDamage" trigger.

onDamage
scope eventOnDamage

globals
    private constant real ONDAMAGE_chance = xx // replace xx with your own value
    private constant real ONDAMAGE_chanceLevelAdd = 0.0
endglobals


function OnDamage takes Tower tower returns nothing 

local Unit creep = Event.getTarget()  // this method is used to get the attacked creep 

call tower.killInstantly(creep) 

endfunction

endscope

Slow

We'll create an ability that has an xx% chance to slow a creep by yy% for zz seconds.

First create a custom buff in the object editor, choose an icon and name for your custom buff, the rest does not really matter.

Then we'll have to create a buff that slows the creep in the header, so enable the header and use this code.

Header
function Header takes Tower tower returns nothing 

globals 

BuffType boekie_slow_buff // this is used to declare the buff

endglobals

//Do not remove or rename this function!
//Put your initialization tasks here, this function will be called on map init 

private function init takes nothing returns nothing 

local Modifier slow=Modifier.create()
call slow.addModification(MOD_MOVESPEED,-yy,0) // replace yy with your own value
set boekie_slow_buff=BuffType.create(zz,0,false)  //replace zz with your own value
call boekie_slow_buff.setBuffIcon('B000') // this is the id of the buff you have to create in the object editor
call boekie_slow_buff.setBuffModifier(slow)
call boekie_slow_buff.setStackingGroup("boekie_slow_buff") // creates a stacking group so your slow does not stack

endfunction

Now we'll have to use the buff in the "onDamage" event.

onDamage
scope eventOnDamage

globals
    private constant real ONDAMAGE_chance = xx // replace xx with your own value
    private constant real ONDAMAGE_chanceLevelAdd = 0.0
endglobals

function OnDamage takes Tower tower returns nothing 

local Unit creep = Event.getTarget()

call boekie_slow_buff.apply(tower,creep,0) 

endfunction

endscope

DoT

We'll create an ability that has an xx% chance to deal yy DPS for zz seconds to a damaged creep.

First create a custom buff in the object editor, choose an icon and name for your custom buff, the rest does not really matter.

Then we'll have to create a buff in the header that has a periodic event to deal damage to the creep, so enable the header and use this code.

Header
function Header takes Tower tower returns nothing 

globals 

BuffType boekie_dot_buff // this is used to declare the buff

endglobals

function dealDamage takes Buff b returns nothing // we need this function to deal damage to the buffed creep

local Unit creep = b.getBuffedUnit() // this method is used to get the buffed creep
local Tower tower = b.getCaster()  // this method is used to get the caster of the buff

call tower.doSpellDamage(target,yy,tower.calcSpellCritNoBonus()) // replace yy with your own value

endfunction

//Do not remove or rename this function!
//Put your initialization tasks here, this function will be called on map init 

private function init takes nothing returns nothing 

set boekie_dot_buff=BuffType.create(zz,0,false)  //replace zz with your own value
call boekie_dot_buff.setBuffIcon('B000') // this is the id of the buff you have to create in the object editor
call boekie_dot_buff.setStackingGroup("boekie_dot_buff") // creates a stacking group so your dot does not stack
call boekie_dot_buff.addPeriodicEvent(EventHandler.dealDamage,1) // with this we add a periodic event to the buff

endfunction


Now we'll have to use the buff in the "onDamage" event.

onDamage
scope eventOnDamage

globals
    private constant real ONDAMAGE_chance = xx // replace xx with your own value
    private constant real ONDAMAGE_chanceLevelAdd = 0.0
endglobals

function OnDamage takes Tower tower returns nothing 

local Unit creep = Event.getTarget()

call boekie_dot_buff.apply(tower,creep,0) 

endfunction

endscope


Increase damage of all towers in range (using an iterate)

We'll create an ability that has an xx% chance on attack to increase the damage of all towers in yy range by zz% for ww seconds.

First create a custom buff in the object editor, choose an icon and name for your custom buff, the rest does not really matter.

Then we'll have to create a buff that buffs a tower in the header, so enable the header and use this code.

You can use different modifications by replacing "MOD_DAMAGE_ADD_PERC" with something else.

Header
function Header takes Tower tower returns nothing 

globals 

BuffType boekie_damage_buff // this is used to declare the buff

endglobals

//Do not remove or rename this function!
//Put your initialization tasks here, this function will be called on map init 

private function init takes nothing returns nothing 

local Modifier m=Modifier.create()
call m.addModification( MOD_DAMAGE_ADD_PERC, zz, 0) // replace zz with your own value
set boekie_damage_buff=BuffType.create(ww,0,false)  //replace ww with your own value
call boekie_damage_buff.setBuffIcon('B000') // this is the id of the buff you have to create in the object editor
call boekie_damage_buff.setBuffModifier(m)
call boekie_damage_buff.setStackingGroup("boekie_damage_buff") // creates a stacking group so your slow does not stack

endfunction


To apply a buff on all towers in range we'll have to use an iterate.
Because we apply the buff when the tower attack a target we have to use the onAttack trigger.

onAttack

scope eventOnAttack

globals
    private constant real ONATTACK_chance = xx // replace xx with your own value
    private constant real ONATTACK_chanceLevelAdd = 0.0
endglobals

private function onAttack takes Tower tower returns nothing

local Iterate it = Iterate.overUnitsInRangeOfUnit(tower,TARGET_TYPE_TOWERS,tower,zz)
local Unit next // next is the next tower of the iterate

loop
set next = it.next() // this is the loop that iterates over all towers in zz range
call boekie_damage_buff.apply(tower,next,tower.getLevel())
exitwhen next == 0
endloop

endfunction

endscope



Targeting creeps
You can also use this iterate to apply a buff in a zz range around an attacked creep.
Just use this code:


scope eventOnAttack

globals
    private constant real ONATTACK_chance = xx // replace xx with your own value
    private constant real ONATTACK_chanceLevelAdd = 0.0
endglobals

private function onAttack takes Tower tower returns nothing

local Iterate it = Iterate.overUnitsInRangeOfUnit(tower,TARGET_TYPE_CREEPS,creep,zz)
local Unit next // next is the next creep of the iterate
local Unit creep = Event.getTarget() //attacked creep

loop
set next = it.next() // this is the loop that iterates over all creeps in zz range
call boekie_dot_buff.apply(tower,next,tower.getLevel()) //apply a dot for example (you have to declare it in the header)
exitwhen next == 0
endloop

endfunction

endscope


Attachments:
File comment: trigger editor
Trigger Editor Triggers aangepast.png
Trigger Editor Triggers aangepast.png [ 38.77 KiB | Viewed 26806 times ]


Last edited by boekie on Sun Dec 27, 2009 12:39 pm, edited 7 times in total.
Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 11:33 am 
Offline
Power User
User avatar

Joined: Wed May 27, 2009 6:40 pm
Posts: 2795
Location: Langenfeld Germany
YouTD Score: 434
vote for stickt boekies guides rule

_________________
2000 posts with ancient of wonders


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 11:37 am 
Offline
YouTD Admin
YouTD Admin
User avatar

Joined: Fri Jan 09, 2009 3:02 pm
Posts: 4324
Location: Belgium
YouTD Score: 645
Thanks!

Suggestions for simple abilities are always welcome!


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 12:09 pm 
Offline
Power User
User avatar

Joined: Wed May 27, 2009 6:40 pm
Posts: 2795
Location: Langenfeld Germany
YouTD Score: 434
would add how to slow a creep and how to deal damage to a creep using a dot triggering a periodic event cause this are the most common abilities nearly used in every TD

_________________
2000 posts with ancient of wonders


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 2:49 pm 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Jul 21, 2006 11:31 pm
Posts: 4714
Location: Munich, Germany / Sydney, Australia
YouTD Score: 240
sticky


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Dec 27, 2009 2:51 pm 
Offline
YouTD Admin
YouTD Admin
User avatar

Joined: Fri Jan 09, 2009 3:02 pm
Posts: 4324
Location: Belgium
YouTD Score: 645
geX wrote:
sticky


Thx!


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Tue Dec 29, 2009 11:52 am 
Offline
Light User

Joined: Mon Dec 28, 2009 12:41 pm
Posts: 24
Guide seems pretty cool. I think I have to learn Jass and vJass in the holidays :D


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sat Jan 02, 2010 1:31 pm 
Offline
Power User
User avatar

Joined: Wed May 27, 2009 6:40 pm
Posts: 2795
Location: Langenfeld Germany
YouTD Score: 434
what about an easy iteration and a projectile ?

_________________
2000 posts with ancient of wonders


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Jan 03, 2010 8:47 am 
Offline
Site Admin
Site Admin
User avatar

Joined: Fri Jul 21, 2006 11:31 pm
Posts: 4714
Location: Munich, Germany / Sydney, Australia
YouTD Score: 240
SirCoqaLot. wrote:
what about an easy iteration and a projectile ?

yes, this stuff is quite often used.

And how about putting each example into a hidebox? Then the post isn't so large and a user quickly finds the example he wants.


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Mon Apr 25, 2011 4:35 pm 
Offline
Power User

Joined: Sun Apr 10, 2011 10:34 am
Posts: 543
Location: Ultima Thule
YouTD Score: 30
@boekie_slow_buff

You set it in a stacking group which is fine - but won't that also mean that the buff will not be refreshed on subsequent hits? Atleast gex's documentation seems to say so.

So it that doc outdated or we need to manually handle duration refresh?

Or if it's the same buff being put, duration refresh happens anyways, stacking group or no group?

Excerpt from the doc page:

4.7.2 Stacking Group Refresh Issues

There are some problems that arise from two different buffs not stacking with each other. The first problem: If one buff is on the unit and another buff of the same level wants to be applied to the unit, should the old buff replaced or be kept?

So for buffs that belong to a stacking group, other rules apply:
-If a buff of a stacking group tries to apply to a unit that has a buff of the same level, the old buff will be kept but NOT refreshed. The new buff will just be rejected.
-If a buff of a stacking group tries to apply to a unit that has a buff of a lower level, then the old buff will be removed (so cleanup events will fire on it) and then the new buff will be applied (which fires on creation events for it). No refresh or upgrade events will be fired.


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Tue Apr 26, 2011 11:53 am 
Offline
YouTD Admin
YouTD Admin

Joined: Thu May 20, 2010 8:11 pm
Posts: 1601
Location: Germany
YouTD Score: 48
The buff gets refreshed because they are from the same BuffType. The refresh issues apply if there are 2 different buffs.


Top
 Profile  
 
 Post subject: Re: Newbie Guide: Basic Trigger Examples
PostPosted: Sun Oct 13, 2013 7:17 am 
Offline
User

Joined: Sat Oct 12, 2013 10:43 am
Posts: 74
YouTD Score: 25
Good guide


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group