• 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] Clueless when it comes to writing JASS, A little help?

Status
Not open for further replies.
Level 2
Joined
Sep 2, 2004
Messages
9
Since I'm not getting much reply on a different forum (Not on this site...) I decided to try here.

I'm very noob when it comes to writing JASS, but not too terrible at implementing it. I need a custom script that ties into Hero abilites. Here goes:

I have a Hero with a few summon abilities. Now every time he uses a different ability to summon a different creature, I want the old creatures that he has previously summoned that are still alive to be destroyed (I.e. For sake of convience we'll say a Beast Master has summoned his Bear. Now when he tries to summon his hawk/quillboar/whatever, It destroys his bear and replaces it with the newly summoned creature).

Any questions post here or PM me. I'd appreciate any feedback.
 
Level 6
Joined
Jun 16, 2004
Messages
237
You can do that without JASS.
- Use a unit array to store pointers to the summoned creatures. Use an integer to count the number of summoned units.
- When the hero summons a creature, add the newly summoned creature to the array. If the summoned unit limit is exceeded, destroy one of the old summoned creatures.
- When a summoned unit dies, remove it from the array and decrease the summoned unit count by one.

If there are more than one such hero, you need to use several arrays.

There are also other ways to implement this behavior, but this one was the first that came to my mind.

Cheers!
 
Level 2
Joined
Sep 2, 2004
Messages
9
Ack, I didn't even think of that. I'll give it a shot, I'll post again if I have any problems. Thanks :D

EDIT - Okay I ran it through, but I might not be understanding something. It won't work (I'm thinking I'm not actually sure :( ) because the hero summons muliple units at the same time, so it eliminates the others. Either that or I did something very very wrong. I'm afraid I need something more step by step to completely implement it.
 
Level 3
Joined
Mar 27, 2004
Messages
70
In the JASS section on this site, there is a set of functions called Local Handle Vars. Find it and copy it into your map header.
Then add this function to your map header below the other functions.
Code:
function GetHandleUnit takes handle h, string name returns unit
    return GetHandleHandle(h, name)
    return null
endfunction
Then make a trigger that fires when your hero summons a unit. Make sure you have added the events and conditions and then convert it to custom text.
Then you add these lines to the actions function (called Trig_(name)_Actions:
Code:
local unit summon = GetSummonedUnit()
local unit hero = GetSummoningUnit()
local unit old = GetHandleUnit(hero, "summon")
if (old != null) then
    call KillUnit(old)
endif
call SetHandleHandle(hero, "summon", summon)
I did this off the top of my head so it may be slightly wrong. Anyway, since you're new at Jass I better explain what it does:
Line #1: This is the unit that was summoned
#2: The hero that summoned the unit
#3: This finds the local called "summon" using the hero's handle.
#4: If there was a local unit called "summon"
#5: -- then kill it
#7: Store this summon as "summon" using the hero's handle, so that line #3 will find it next time the trigger is run.

For many people, this thing about storing/finding locals is hard to understand at first, so don't get knocked about if you don't get it.
 
Level 2
Joined
Sep 2, 2004
Messages
9
I'm getting compiling errors after everything is put in. I copied the Local Handle Vars script exactly, is that supposed to go under Custom Script Code in the trigger section? If so, would it conflict with an already existing Script I have there?
 
Level 2
Joined
Apr 13, 2004
Messages
29
Since you say that some of that summon skills summon more than one unit, KaTTaNas solution needs to be changed to use a unit group instead of a single unit. Also you need some way to determine if the newly summoned unit belongs to the same casting or an old one.
 
Level 2
Joined
Sep 2, 2004
Messages
9
Actually I was thinking something to that effect (I was hoping the script was written that way) but didn't know it was related.
 
Level 2
Joined
Sep 2, 2004
Messages
9
I just realized that I already have KaTTaNa's LocalHandleVars script in my custom text. It's a part of another script I'm running (Vexorian's D2 Style Summons). Putting it in twice wouldn't affect anything would it? Also, ontop of that I think I'm having problem with trigger I'm supposed to convert to custom text. I have the event down, what conditions/actions do I have to include? Lastly, I need to follow AIAndy's advice and figure out how to make it all affect a unit group instead of just a single unit.

Any help on the above will be greatly appreciated. Sorry if I'm asking too much... :cry:
 
Level 3
Joined
Mar 27, 2004
Messages
70
Malkav- said:
Putting it in twice wouldn't affect anything would it?
Yes, the compiler will complain because the function name is already used. Make sure that each function only appears once.

I'm not sure how the event Unit Spawns a Summoned unit works.
I assume that it will fire once for each unit summoned:
JASS:
// Call this when a unit is summoned
local unit summon = GetSummonedUnit()
local unit hero = GetSummoningUnit()
local group summons = GetHandleGroup(hero, "summons")
if (summons == null) then
    set summons = CreateGroup()
    call SetHandleHandle(hero, "summons", summons)
endif
call GroupAddUnit(summons, summon)
JASS:
function KillSummon takes nothing returns nothing
    call KillUnit(GetEnumUnit())
endfunction

// Call this when the unit starts the effect of an ability
local unit caster = GetSpellAbilityUnit()
local integer abil = GetSpellAbilityId()
local group summons
if ( abil == .. ) then // If ability is a summoning ability
    set summons = GetHandleGroup(summons)
    if (summons != null) then
        call ForGroup(summons, function KillSummon)
    endif
endif
Here I just kill all the summons when you start casting a summoning ability and add the summons when they are spawned.
Still I'm not certain that the summon event will fire for each summoned unit, and if it doesn't I actually don't know how to access each summoned unit.
 
Level 2
Joined
Sep 2, 2004
Messages
9
Okay hopefully I don't drag this problem on too long, but I hit a few more things after putting all this in. So let me try and clear things up a bit for myself.

Correct me if I'm wrong on these:

The first set of code (//Call this when a unit is summoned) is a trigger converted to custom text, and not put under the Custom Script Header?

The Second set of code (KillSummon Function) does go under the Custom Script Header?

Lastly (//Call this when a unit is under the effect of an ability) is also a trigger converted to custom text, and not put under the custom script header?

The reason I ask, is after I made the first trigger (Call when summoned) I saved and recieved a compiling error. I shrugged it off and decided to wait and see if I added the rest if it would go away. Well I added the rest and WE crashed. I guess I'm not as good as implamenting as I had previously thought :(.

Again I really appreciate all your help.
 
Level 3
Joined
Mar 27, 2004
Messages
70
Make a new trigger called Detect Summon, add the event Unit spawns a summoned unit.
Then convert it to custom text and DO NOT delete of the text. Find the function called Trig_Detect_Summon_Actions and add the code below that line, like this:
JASS:
function Trig_Detect_Summon_Actions takes nothing returns nothing
    // Insert the code here!
endfunction
The same goes for the other trigger.
 
Level 2
Joined
Sep 2, 2004
Messages
9
Okay... I think I'm done.

I appreciate all you help guys, but I think this is just too big right now for me to understand. Despite your excellent instructions, I still can't get it right. I'll try again on the Warcraft III Campaigns Forums to recruit some trigger/Jass experts to do them for me. I have all these brilliant ideas, just lacking the know-how to piece them together :(.

Anyways, thanks again for your time.
 
Status
Not open for further replies.
Top