(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Tutorials > JASS/AI Scripts Tutorials

JASS/AI Scripts Tutorials Contains tutorials regarding JASS scripting and the AI editor.
Read the Rules before posting.

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 05-17-2007, 10:09 PM   #1 (permalink)
 
Fulla's Avatar

Chaos Overlord
 
Join Date: Aug 2005
Posts: 748

Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)

Paired Mapping Contest #3 Winner: Warcraft Arena 

Nether Swap

Nether Swap


Instantly swaps location with target unit:

netherswap1.jpg

netherswap2.jpg

Intro
This is a very basic and simplistic spell, which makes it ideal for starting out with jass.
This tutorial does not cover the introduction to jass but rather goes straight into making a spell.
It also has a brief introduction to the Channel ability

Starters
Firstly go into the object editor and create a nether swap ability.
I recommend basing it of Channel, which is found under Neutral Hostile> Hero Abilities

Here is a screenshot to show how you should modify it
ability.jpg

1 & 2 - These are the special effects that will be added to Caster and Target, I chose Blink, its up to you.
3 - Make sure you have the same options.
> Disable other abilities = false
> Follow Through Time = 0.00
> Options = Visible
> Target Type = Unit

Next we need to create the trigger
Go into the Trigger Editor and create a trigger called: Nether Swap
Please Note: NOT NetherSwap or nether swap etc.but Nether Swap

Should look like this:
a2-1.jpg

Next you need to converted it to custom script:
a3.jpg

For now we will skip the Conditions/Actions bit as this is quite boring, Once weve made a few spells I'll explain this to you
So Ill give you a base code to copy paste.

This is what you should currently have:
b1.jpg

Copy Paste this:
function Trig_Nether_Swap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00P'
endfunction

function Trig_Nether_Swap_Actions takes nothing returns nothing

endfunction

//===========================================================================
function InitTrig_Nether_Swap takes nothing returns nothing
    set gg_trg_Nether_Swap = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Nether_Swap, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Nether_Swap, Condition(function Trig_Nether_Swap_Conditions))
    call TriggerAddAction(gg_trg_Nether_Swap, function Trig_Nether_Swap_Actions)
endfunction

So now it should look like this:
b2.jpg

Now we need to make sure the correct ability is in the condition.
For this go back into the Object Editor and click
View > Display Values as Raw Data
c1.jpg

Next we need to get the raw data for the ability
In this case it is A000
c2.jpg

Note: In your map if may differ so make sure to check.
Next go back into the trigger editor and lets alter the condition
c3.jpg

Notice how Ive changed it to 'A000'

Ok we are now ready to start coding the spell :p

Method
This is how we will do the spell:
- Create a local to store: Casting Unit
- Create a local to store: Target Unit of Ability Being Cast Unit
- Create locals to store: Casting Unit's co-ordinates
- Create locals to store: Target Unit of Ability Being Cast's co-ordinates

- Move Casting Unit
- Move Target Unit of ability being cast

- Clean up leaks

Jass Code
The following code will go inside the Actions section:
actions.jpg

Where the cursor is begin typing in there

Firstly we declare the locals

    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()

c = the Casting Unit
t = The Target Unit of ability being cast

Next we create locals for their co-ordinates

    local real xc = GetUnitX(c)
    local real yc = GetUnitY(c)
    local real xt = GetUnitX(t)
    local real yt = GetUnitY(t)

xc & yc = the co-ordinates of the Casting Unit
xt & yt = the co-ordinates of the Target Unit of ability being cast

Now we will set each unit's new position

    call SetUnitX(c, xt)
    call SetUnitY(c, yt)
    call SetUnitX(t, xc)
    call SetUnitY(t, yc)

This will place:
- Casting unit at co-ordinates stored for the Target Unit of ability being cast
- Target Unit of ability being cast at co-ordinates stored for the Casting Unit

Finally we clean up the leaks

    set c = null
    set t = null

This is overall how your code should look

function Trig_Nether_Swap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00P'
endfunction

function Trig_Nether_Swap_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real xc = GetUnitX(c)
local real yc = GetUnitY(c)
    local real xt = GetUnitX(t)
    local real yt = GetUnitY(t)
    call SetUnitX(c, xt)
    call SetUnitY(c, yt)
    call SetUnitX(t, xc)
    call SetUnitY(t, yc)
    set c = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Nether_Swap takes nothing returns nothing
    set gg_trg_Nether_Swap = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Nether_Swap, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Nether_Swap, Condition(function Trig_Nether_Swap_Conditions))
    call TriggerAddAction(gg_trg_Nether_Swap, function Trig_Nether_Swap_Actions)
endfunction

You can make the code, slightly more efficient by replacing:

    local real xt = GetUnitX(t)
    local real yt = GetUnitY(t)
    call SetUnitX(c, xt)
    call SetUnitY(c, yt)

with:

    call SetUnitX(c, GetUnitX(t))
    call SetUnitY(c, GetUnitY(t))

Your jass spell should now work, have fun and enjoy and stay tuned for more step by step mini jass tuts :)

thx
Fulla

Last edited by Wolverabid; 07-01-2007 at 05:30 AM. Reason: attached images to post.
Fulla is offline  
Old 05-17-2007, 11:03 PM   #2 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,868

PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)

Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

you can skip either (xt,yt) or (xc,yc), since SetUnitX/Y ignore pathing
PurplePoot is offline  
Old 05-30-2007, 12:10 PM   #3 (permalink)
 
Fulla's Avatar

Chaos Overlord
 
Join Date: Aug 2005
Posts: 748

Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)

Paired Mapping Contest #3 Winner: Warcraft Arena 

What do you mean by skip sorry?
Anyways to improve the tut?
__________________
Fulla is offline  
Old 05-30-2007, 01:41 PM   #4 (permalink)
 
Diablo-dk's Avatar

Shifting voidwalker!
 
Join Date: Nov 2004
Posts: 452

Diablo-dk has a spectacular aura about (128)Diablo-dk has a spectacular aura about (128)Diablo-dk has a spectacular aura about (128)Diablo-dk has a spectacular aura about (128)


Use jass tags instead of code tags?
By skipping i think he means that you can shorten it to this:
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    call SetUnitX(c, GetUnitX(t))
    call SetUnitY(c, GetUnitY(t))
    call SetUnitX(t, x)
    call SetUnitY(t, y)
__________________
Need an easy Recipe System for your map?
Wonder what is inside the Spellbook?
Check my Cinematic!

Vote for the hive, the most friendly wc3 website.
Diablo-dk is offline  
Old 05-30-2007, 03:16 PM   #5 (permalink)
 
Fulla's Avatar

Chaos Overlord
 
Join Date: Aug 2005
Posts: 748

Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)

Paired Mapping Contest #3 Winner: Warcraft Arena 

- I intitially used jass tags, but it kept placing the entire code in 1 single line.

- I thought for beginners, would be best to keep it very basic/simple.
__________________
Fulla is offline  
Old 05-30-2007, 08:50 PM   #6 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,868

PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)

Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Yeah, diablo, that's what I meant.

And less variables would be simpler for beginners, I would imagine. However, that's your choice.

And yes, JASS tags are preferrable. try replacing [code][/code] with [jass][/jass] and making no other changes, and seeing if it works. If not, you should probably report it in the bug report forum.
PurplePoot is offline  
Old 05-30-2007, 09:34 PM   #7 (permalink)
 
Fulla's Avatar

Chaos Overlord
 
Join Date: Aug 2005
Posts: 748

Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)Fulla will become famous soon enough (119)

Paired Mapping Contest #3 Winner: Warcraft Arena 

Ok updated, jass tags & added that bit at the end.

Is it possible to get the topic title changed

from: Jass Tut: (Level 1) - Nether Swap
to: Jass Tut: 1.01 - Nether Swap

thx
__________________
Fulla is offline  
Old 05-31-2007, 09:16 PM   #8 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,868

PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)

Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

try double-clicking right beside the name, in the thread list. If a thing pops up where you can change it, change it. Otherwise, PM wolverabid or someone.

I know the double-click thing works on some vBulletin forums, but I'm not sure about THW
PurplePoot is offline  
Old 05-31-2007, 09:41 PM   #9 (permalink)
Overall Site Manager
 
Wolverabid's Avatar

 
Join Date: Oct 2006
Posts: 8,793

Wolverabid has much of which to be proud (1206)Wolverabid has much of which to be proud (1206)

Respected User: This user has been given the respected user award. User of the Year: 2007 

I renamed the thread for you Fulla: Jass Tut: 1.01 - Nether Swap

Before we can approve it you will have to review:
General Tutorial Submitting Rules and Guidelines - Read Before Posting!
and bring the tutorial up to those standards.
Quote:
  • All image files must be attached to your post. We don't wish to be dependent on other sites (to avoid situations in which the server that hosts images fails, thus damaging the tutorial).

  • No signature files may be attached to tutorials. Instead, edit your tutorial to include your signature's contents (no attached or linked images are permitted).
You should detach your siggy from the tut and use the [ATTACH][/ATTACH] tags instead of the [IMG][/IMG] tags.
Wolverabid is offline  
Old 05-31-2007, 10:00 PM   #10 (permalink)
 
paskovich's Avatar

I am ghost
 
Join Date: Jul 2005
Posts: 942

paskovich has a spectacular aura about (124)paskovich has a spectacular aura about (124)paskovich has a spectacular aura about (124)paskovich has a spectacular aura about (124)


IMO, this tutorial is way too long for one spell only. Too detailed, and the main thing (triggering part) is pretty simple.
__________________
Jimmy Eat World - Let It Happen
"I'm the evil one who said.
Gonna let everything just happen
like my chest, my ears are proud
The collision is such an ugly sound."
Vote for the Hive without mercy!
paskovich is offline  
Old 05-31-2007, 11:52 PM   #11 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,868

PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)

Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

It is supposed to be introducing basic concepts, after all
PurplePoot is offline  
Old 06-01-2007, 11:48 AM   #12 (permalink)
 
RedBlade's Avatar

PIVOT !!!
 
Join Date: May 2007
Posts: 411

RedBlade has little to show at this moment (37)RedBlade has little to show at this moment (37)RedBlade has little to show at this moment (37)RedBlade has little to show at this moment (37)


Wait... cant you just do it with GUI ?

Event - Unit castes and ability
Condition - Casting ability equal to Nether Swap
Action - Create Effect over casting unit (an effect)
- Move instantly casting unit to position of (the unit targeted by ability)
- Create Effect over unit targeted by ability (an effect)

I did it, i used it in a map of mine, i played it multiplayer and i had no leaks.
__________________
RedBlade LinksVideosMessages
Vote the hiveU2 - Windows in the Skies-= Peace to ALL =-
Mirage - Realms(MMORPG)-= Welcome to the Hive =-

RedBlade is offline  
Old 06-01-2007, 06:08 PM   #13 (permalink)
 
GST_Nemisis's Avatar

More Than Just A User
 
Join Date: Jan 2005
Posts: 3,632

GST_Nemisis is a jewel in the rough (258)GST_Nemisis is a jewel in the rough (258)GST_Nemisis is a jewel in the rough (258)GST_Nemisis is a jewel in the rough (258)

User of the Year: 2004 

Quote:
Originally Posted by RedBlade View Post
Wait... cant you just do it with GUI?
its not about the spell its about teaching someone to learn jass.
__________________
GST_Nemisis is offline  
Old 06-01-2007, 11:51 PM   #14 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,868

PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)PurplePoot is a name known to all (705)

Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Also, it's a helluva lot harder, due to some *ahem* issues *ahem* with "Move Unit"
PurplePoot is offline  
Old 06-09-2007, 02:47 PM   #15 (permalink)
Overall Site Manager
 
Wolverabid's Avatar

 
Join Date: Oct 2006
Posts: 8,793

Wolverabid has much of which to be proud (1206)Wolverabid has much of which to be proud (1206)

Respected User: This user has been given the respected user award. User of the Year: 2007 

Question Tutorial Submissions

Quote:
Originally Posted by Wolverabid View Post
I renamed the thread for you Fulla: Jass Tut: 1.01 - Nether Swap
[EDIT] ~ Tutorial approved and moved to JASS/AI Scripts Tutorials.

Last edited by Wolverabid; 09-06-2007 at 06:06 PM.
Wolverabid is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump