• 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] Request: JASS code that transfer skills to replaced units

Status
Not open for further replies.
Level 9
Joined
Oct 17, 2007
Messages
547
Im not sure if this is the right section for this, but i couldnt find a request section for JASS code.

Im basically making a map with a bunch of custom skills, and i need someone to write a trigger to transfer all the skills the original unit has to the replaced unit.

For example: Unit footman has X, Y, Z skills
When it reaches a certain lv it changes into a knight and still have all the skill the previous version has.

Note: The skills are added by trigger and are all in a skill book, each unit knows a variety of different skills as they lv so they cannot be add to the object editor. Units can learn as much as 4 skill book full of skills (about 44 skills). Some skills do not transfer, so there should be an exception list somewhere on the code so i can add skill id.

And of course i will add rep to show appreciation for all the help.
 
Level 7
Joined
Oct 5, 2007
Messages
118
You could use
JASS:
native UnitMakeAbilityPermanent takes unit whichUnit, boolean permanent, integer abilityId returns boolean
This will keep the choosen ability for the unit when morphed :)
 
Level 9
Joined
Oct 17, 2007
Messages
547
Morph or replace? Because im using a trigger to replace the unit for a different one. And can u demonstrate how to use that line of code? im noob :D
 
Level 7
Joined
Oct 5, 2007
Messages
118
You should morph the units, or you have to save all added abilities and add them after replacing.

And this line can be used quite simple: When you add an ability to your footman just put this line after UnitAddAbility with the same AbilityId and Unit, permanent should be true. Then the ability will be kept when the unit is morphed.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
It would only hold through morph, not replace. For replace, you would have to keep an array of all added abilities.

I suggest you just use the Chaos ability - it acts like a morph ability in some ways, but like Replace in others. There are some bugs with it though, generally when using it on heroes.
 
Level 9
Joined
Oct 17, 2007
Messages
547
Ok so everytime i add an ability it should be similar to this?

  • Events
    • Conditions
    • Actions
      • Unit - Add Cripple to (Triggering unit)
      • Custom script: native UnitMakeAbilityPermanent takes unit N000, true permanent, integer A01P returns boolean
I Can remove specific ability using a trigger later though right?
 
Level 9
Joined
Oct 17, 2007
Messages
547
So the line "native UnitMakeAbilityPermanent takes unit whichUnit, boolean permanent, integer abilityId returns boolean" goes in the map header?
 
Level 7
Joined
Oct 5, 2007
Messages
118
Yes you can...
Why are you asking for JASS-Code, if don't even know the language? If you tell us that you're using GUI, I would've gave you a custom script line :)
 
Level 9
Joined
Oct 17, 2007
Messages
547
Im trying to learn, haven't gotten to that point yet. I try your suggestion, it changes the unit into a diff one, but all the skills that were in the skill book are gone, including the ones that were added in the Object editor (i used disabled spell book skills), how do i fix that?

I basically make a trigger that add a dummy skill to the unit when its level reaches a certain point, when the player cast that skill then then unit gain the Chaos skill which morphed the unit.
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
Don't use chaos. The issues surrounding chaos are massive.

Your best bet would be to find a JASSer to do you a system to do it properly. Or try it yourself.

Are the abilities you want to transfer always the same? Or do some sometimes want to transfer, and sometimes not?
 
Level 9
Joined
Oct 17, 2007
Messages
547
Theres abilities that transfers, mostly active skills that the hero learned, and some passives don't they are like traits, are unique to different types of heroes. If someone can write me a code that has a section of Don't and Do transfer it would make the map a lot smaller.
If i attempt in GUI and make a long trigger that has an array of length 44 and one If/Then/Else action for each skill that are transferable then it looks very ugly and a pain to edit/remove skills and would lag the map as well.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
How about:

  • For each integer A from 1 to 44 do:
    • If level of AbilityId[integer A] on (unit to be replaced) > 0 then:
      • Unit - Add AbilityId[integer A] to (replacing unit)
      • Unit - Set level of AbilityId[integer A] on (replacing unit) to level of AbilityId[integer A] on (unit to be replaced)
 
Level 9
Joined
Oct 17, 2007
Messages
547
Would that work if i use the "Unit - Replace" action? Cus the original unit will be removed from game or do u mean add the skills to be transfer to the variable array first?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
No, you'll have to create another unit first. But if you NEED to replace things, what you COULD do is use a dummy unit...

first create a dummy unit near the unit to be replaced, then transfer all abilities (using that trigger)
Next, replace the unit to be replaced, then transfer all abilities from dummy to replaced unit... If you really want to make the trigger easy.

Alternativelly, you can make 2 arrays: one containing ability id's, one containing the level. The one containing levels will be filled with the levels (ranging from 0 - the unit doesn't have the ability - to 3 ( or more?)) of the unit to be replaced. Next, after replacing the unit, loop through all 44 levels, if the level is more than 0, add the ability in the corresponding ability id index, and change the level.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
You have 2 arrays:

first array: AbilityId array (contains ability types). These are initialized with 44 abilities in a map initialization trigger.
Second array: integer array, will contain the levels of the abilities in the AbilityId array on the same index. For instance:

AbilityId[0] was initialized to be "blink" on map initialization

Level[0] will store the level of "blink" on the unit to be replaced (in the trigger that replaces the unit). This will be 0 if the unit doesn't have blink.
You do this for all 44 abilities (from 0 to 43).
Next, you replace the unit, and loop through all 44 abilities again, adding them if necessary.

An exampletrigger would look like this:
  • Actions
    • for integer A from 0 to 43 do:
      • Set Level[integer A] = level of AbilityId[integer A] on (unit to be replaced)
    • Unit - replace (unit to be replaced) by (unit type of new unit)
    • for integer A from 0 to 43 do:
      • if Level[integer A] > 0 then
        • Unit - add AbilityId[integer A] to last replaced unit
        • Set Level[integer A] = level of AbilityId[integer A] on (last replaced unit)
 
Status
Not open for further replies.
Top