• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Spell] Change Weapons(Replace Unit) problem

Status
Not open for further replies.
Level 6
Joined
Aug 14, 2016
Messages
174
Hi, i has my problem with my weapons when change weapons
First, if i change weapons when the stat strength get a bug.
Example:
Before
upload_2018-5-27_13-21-38.png

After
upload_2018-5-27_13-22-16.png

Seconds, if i change weapons when all spell is under cooldown, all spell will reset it when i change.
Example:
Before
upload_2018-5-27_13-23-18.png

After
upload_2018-5-27_13-25-9.png


this is my trigger i make
  • AKM Change
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to AKM
      • (Item-type of (Item being manipulated)) Equal to AKM
      • (Charges remaining in (Item being manipulated)) Greater than 0
      • (Charges remaining in (Item being manipulated)) Less than 30
    • Actions
      • Item - Set charges remaining in (Item being manipulated) to ((Charges remaining in (Item being manipulated)) + 1)
      • Unit - Replace (Triggering unit) with a AKM using The old unit's relative life and mana
      • Selection - Select (Last replaced unit) for (Owner of (Triggering unit))
      • Set RecoilPoint = (Position of (Last replaced unit))
      • Unit - Create 1 Recoil for (Owner of (Last replaced unit)) at RecoilPoint facing RecoilPoint
      • Set RecoilDummy = (Last created unit)
      • Unit - Set level of Recoil for RecoilDummy to 25
      • Unit - Add a 1.00 second Generic expiration timer to RecoilDummy
      • Unit - Order RecoilDummy to Undead Banshee - Curse (Last replaced unit)
 
Level 8
Joined
Mar 19, 2017
Messages
248
Do you use the 1.29 editor version?
If yes, then i suggest you using the new natives (particularly: hero proper name modify, and base/dice damage modify functions) that do the effects your aiming for, without doing a the unit replace thing (since you are effectively removing the previous unit and creating a different one, you encounter the cooldown problem, and i'm pretty sure you can't save the cooldowns, atleast with the ordinary cooldown system of WC3).
 
Level 11
Joined
Jun 2, 2004
Messages
849
Another possibility is using morphs (bear form, metamorphosis, etc). They can be made permanent with some trickery, and retain buffs/cooldowns/etc. The downside is that if you have many different types of units and weapon combinations, you'll need a ton of morph abilities, which can become unmanageable.
 
Level 8
Joined
Mar 19, 2017
Messages
248
My personal stance on Morph abilities is that they have their use to modify features that you otherwise can't modify with anything else, like completely overhauling the unit model (for minor effects i would use attachments), or the attack range (dinamic changes, as you can always modify the attack range with researches). You shouldn't make a real system to track more than 1 data aspect out of Morph abilities as most of them vinculate 2 specific unit ids. If you want ie. modify damage AND attack range via Morphs (ie. a weapon system). Just as you said, this is doable but unmanageable, and kind of restrictive. Instead such system can eaily be made by reserving Morph to track melee/ranged mode, resulting in one Morph ability per desired unit, and modify the damage (and everything else, like animation flags) via triggers (using the new available function or adding item abilities).

I would still recommend using Morph abilities (mostly because his map looks like is revolving around one unit concept), instead of replacing the unit, if the thread starter doesn't have access to the new editor. But you can't modify base damage or armor (not that this is too important tho). Well in fact you can modify base damage it with the Tome of Attack Damage, but casting a Morph ability will undo all these effects, so you will need to delay the effect), and you could actually make a system (not sure if robust enough) to modify base armor using a 0 id Chaos ability. But all these methods are kind of obsolete now, since the 1.29 ver. grants such nice functions.
 
Level 6
Joined
Aug 14, 2016
Messages
174
My personal stance on Morph abilities is that they have their use to modify features that you otherwise can't modify with anything else, like completely overhauling the unit model (for minor effects i would use attachments), or the attack range (dinamic changes, as you can always modify the attack range with researches). You shouldn't make a real system to track more than 1 data aspect out of Morph abilities as most of them vinculate 2 specific unit ids. If you want ie. modify damage AND attack range via Morphs (ie. a weapon system). Just as you said, this is doable but unmanageable, and kind of restrictive. Instead such system can eaily be made by reserving Morph to track melee/ranged mode, resulting in one Morph ability per desired unit, and modify the damage (and everything else, like animation flags) via triggers (using the new available function or adding item abilities).

I would still recommend using Morph abilities (mostly because his map looks like is revolving around one unit concept), instead of replacing the unit, if the thread starter doesn't have access to the new editor. But you can't modify base damage or armor (not that this is too important tho). Well in fact you can modify base damage it with the Tome of Attack Damage, but casting a Morph ability will undo all these effects, so you will need to delay the effect), and you could actually make a system (not sure if robust enough) to modify base armor using a 0 id Chaos ability. But all these methods are kind of obsolete now, since the 1.29 ver. grants such nice functions.
I try using Morph, but dosen't work it, trying many time.
 
Level 8
Joined
Mar 19, 2017
Messages
248
If you don't mind the unit changing it's name (and the fact that you can't modify basedamage easily without a system that revolves around Tomes of Attack) then this "thing" might do the trick.

Has lots of pros, you no longer have to worry about the cooldowns and such.
Can also be expanded to support multiple added effects per weapon (missiles via added abilities, etc).
With a Morph ability it can also be expanded (VERY easily, trust me) to support unit mods (melee/attack), since your map revolves around only 1 unit.
 

Attachments

  • d.w3x
    20.4 KB · Views: 69
Level 8
Joined
Mar 19, 2017
Messages
248
But you were able to test the map in your editor?
I've used normal JASS actually. How you imported this system?
Also, did this system do what you needed, or should it have more features? I made it extremely simple, just to feature a "switch" on item use and 1 ability effect. I'm also thinking on a de-equip (if the weapon is already equipped) on click too.

PD: you need to copy 'n paste the JASS functions that are on the map header (Trigger Editor> Click in the firstmost icon in the menu -it has a icon of a map-). All these functions should compile in the vanilla editor.
 
Last edited:
Level 6
Joined
Aug 14, 2016
Messages
174
But you were able to test the map in your editor?
I've used normal JASS actually. How you imported this system?
Also, did this system do what you needed, or should it have more features? I made it extremely simple, just to feature a "switch" on item use and 1 ability effect. I'm also thinking on a de-equip (if the weapon is already equipped) on click too.

PD: you need to copy 'n paste the JASS functions that are on the map header (Trigger Editor> Click in the firstmost icon in the menu -it has a icon of a map-). All these functions should compile in the vanilla editor.
Yes, i just tested it, it WORKING, but this is a new version, i can't add in my maps because my map is using 1.24e.
 
Level 8
Joined
Mar 19, 2017
Messages
248
If it works in your editor version, my bet is that you get the errors because of bad import.
If you still want to use this little system then make sure to do the following:
Copy the header script and paste all the code unto your map's header script.
Then copy the variables the system uses (see variables, it uses a hashtable variable, and some integers). I should've made a variable creator.
 
Level 6
Joined
Aug 14, 2016
Messages
174
If it works in your editor version, my bet is that you get the errors because of bad import.
If you still want to use this little system then make sure to do the following:
Copy the header script and paste all the code unto your map's header script.
Then copy the variables the system uses (see variables, it uses a hashtable variable, and some integers). I should've made a variable creator.
And how to change another weapons, just change only AKM?
 
Level 8
Joined
Mar 19, 2017
Messages
248
2 questions:
1. Did it work with your map now?
2. Does that system suit your needs at all?

This system only changes damage according to the weapon clicked. In fact, what this system does is adding 1 (can expand it to add more) ability per weapon selected. It could also support more features. It won't bug at all, will save the cooldowns, and can support charges, etc.
To add weapons to the system just follow the instructions of the Init trigger (in order: declare an Item and Ability then copy-paste the custom script).
I said that you could use the system if you didn't mind the name change of the unit. To change a unit name without replacing (very buggy) or morphing (you could argue that you can't make a real system out of this method) is impossible with your current editor version.
What you can do is to change the name of the player.
 
Level 6
Joined
Aug 14, 2016
Messages
174
2 questions:
1. Did it work with your map now?
2. Does that system suit your needs at all?

This system only changes damage according to the weapon clicked. In fact, what this system does is adding 1 (can expand it to add more) ability per weapon selected. It could also support more features. It won't bug at all, will save the cooldowns, and can support charges, etc.
To add weapons to the system just follow the instructions of the Init trigger (in order: declare an Item and Ability then copy-paste the custom script).
I said that you could use the system if you didn't mind the name change of the unit. To change a unit name without replacing (very buggy) or morphing (you could argue that you can't make a real system out of this method) is impossible with your current editor version.
What you can do is to change the name of the player.
I mean, because my map has making some sound weapons and some weapons has multishots and other effect, what i can add on it if they're same?
 
Level 8
Joined
Mar 19, 2017
Messages
248
You didn't answer my questions, but i presume you make it work.
I saw the system again, and it could surely use some more love (i forgot quite a bit of important things).

What about you listing all the exact features needed so i enhance the system enough for you to use?
Sound on equip is no problem, and for multishot i suppose you are talking about adding the Barrage ability, which will only take one additional reference for the register function.
 
Level 6
Joined
Aug 14, 2016
Messages
174
You didn't answer my questions, but i presume you make it work.
I saw the system again, and it could surely use some more love (i forgot quite a bit of important things).

What about you listing all the exact features needed so i enhance the system enough for you to use?
Sound on equip is no problem, and for multishot i suppose you are talking about adding the Barrage ability, which will only take one additional reference for the register function.
1:yes, it working,but how to i reloading weapon,they're change everytime.
2:You know Xeleplant, he making a change weapon without morph and keep all spell, reset cooldown with only this trigger.
  • Change to Bereta 9000S
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Unit-type of (Hero manipulating item)) Not equal to Beretta 9000S
      • (Item-type of (Item being manipulated)) Equal to Beretta 9000S
    • Actions
      • Set effect[(Player number of (Owner of (Triggering unit)))] = pistol2.MDX
      • Set newHero[(Player number of (Owner of (Triggering unit)))] = Beretta 9000S
      • Custom script: set udg_Hero[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))] = ChangeUnit(GetManipulatingUnit(),udg_newHero[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))],udg_effect[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
      • Game - Display to (All players) the text: (|CFFC70000Your Teammate + (ColorStr[(Player number of (Owner of (Hero manipulating item)))] + ((Name of (Owner of (Triggering unit))) + ((|r|CFFC70000 + has equipped ) + (Name of (Item being manipulated))))))
 
Level 8
Joined
Mar 19, 2017
Messages
248
Just saw that map, that function is a modified ReplaceUnit, so naturally cooldowns will not be saved.
Test this map, it features some more things. But my question still remains: it does the job or not.
PD: to recharge ammunition just stack the ammo unto a equipped weapon. Maybe i shoulda make it so you can recharge even unequipped weapons, but that doesn't make sense.
 

Attachments

  • d.w3x
    28 KB · Views: 68
Level 6
Joined
Aug 14, 2016
Messages
174
Have you tried robo goblin ability? you can make as may robo goblin abilities and give them differnt string orders, the make the ability icon buttoon position to 0, -!!. Then when a unit uses the item you order it to cast robo goblin.
Thanks, that easy than trigger, but how i can reload weapon while form "AK-47", because i click again, unit unform into "Fist".
Just saw that map, that function is a modified ReplaceUnit, so naturally cooldowns will not be saved.
Test this map, it features some more things. But my question still remains: it does the job or not.
PD: to recharge ammunition just stack the ammo unto a equipped weapon. Maybe i shoulda make it so you can recharge even unequipped weapons, but that doesn't make sense.
btw disruptive, thank for your help, but i can't using reload like put ammunition into weapon, i need a time of reloading weapon.
 
Level 9
Joined
Sep 20, 2015
Messages
385
Your trigger for reloading weapon should work with the new unit, since with robo goblin both unit should share inventory and cooldown.
Sorry but my previous post was a mess i'll try to explain it better.

So you create two units, one with ak47 one with fist, as you wrote. Give both units the same abilities.

Create robo-goblin ability, starting unit is fist, new unit is ak47.

In data fileds set the icon to (0, -11) so the ability is hidden from the player. (you should give the ability for both units if i recall correctly)

Then you use your trigger but instead of 'replace unit' command you order the unit to use robo goblin.
So the charges are added before the robo goblin ability is casted.

Shoudl look like this.

  • Events
  • Unit - A unit Uses an item
  • Conditions
  • (Unit-type of (Triggering unit)) Not equal to AK47
  • Item-type of (Item being manipulated)) Equal to AKM
  • (Charges remaining in (Item being manipulated)) Greater than 0
  • (Charges remaining in (Item being manipulated)) Less than 30
  • Actions
  • Item - Set charges remaining in (Item being manipulated) to ((Charges remaining in (Item being manipulated)) + 1)
  • Unit - Order (Triggering unit) to Robo-Goblin //(transfom from fist to AK47)
  • //I think you can delete this one
  • Selection - Select (Last replaced unit) for (Owner of (Triggering unit))
  • //Dont know what these triggers do and why.
  • Set RecoilPoint = (Position of (Last replaced unit))
  • Unit - Create 1 Recoil for (Owner of (Last replaced unit)) at RecoilPoint facing RecoilPoint
  • Set RecoilDummy = (Last created unit)
  • Unit - Set level of Recoil for RecoilDummy to 25
  • Unit - Add a 1.00 second Generic expiration timer to RecoilDummy
  • Unit - Order RecoilDummy to Undead Banshee - Curse (Last replaced unit)
So this should work. But its limited for one weapon, if you have multiple weapons, then its more complicated.
 
Level 12
Joined
Nov 3, 2013
Messages
989
You can instantly morph the unit, as if you used the "unit - replace blabla" trigger action, by creating two versions of e.g. bearmorph. One version where the "normal unit" field is put to whatever you want your unit to morph into, and the "alternate unit" field set to the normal unit.

Then what you do is whenever you want to morph your unit, you simply add this ability and then remove it right away; This makes warcraft 3 think that the unit type you want to morph into is the 'normal' unit, so it thinks that it un-morphs your unit, but in reality it actually morphs your unit into the alternative unit.

Then when you want to revert the unit, you simply add & remove the other bear morph ability (which is set to the default) and this time warcraft 3 will correctly un-morph your unit back to its original form.


This way you can keep the cooldowns, no move order interruptions or anything. There shouldn't be any particular con to this besides that you might have to make a lot of custom bear morph abilities.
 
Level 39
Joined
Feb 27, 2007
Messages
5,011
You can instantly morph the unit, as if you used the "unit - replace blabla" trigger action, by creating two versions of e.g. bearmorph. One version where the "normal unit" field is put to whatever you want your unit to morph into, and the "alternate unit" field set to the normal unit.

Then what you do is whenever you want to morph your unit, you simply add this ability and then remove it right away; This makes warcraft 3 think that the unit type you want to morph into is the 'normal' unit, so it thinks that it un-morphs your unit, but in reality it actually morphs your unit into the alternative unit.

Then when you want to revert the unit, you simply add & remove the other bear morph ability (which is set to the default) and this time warcraft 3 will correctly un-morph your unit back to its original form.


This way you can keep the cooldowns, no move order interruptions or anything. There shouldn't be any particular con to this besides that you might have to make a lot of custom bear morph abilities.
@Virus-X Yes do it this way! I love linking this tutorial because it's such an elegant solution to this issue. Hero passive transformation
 
Level 8
Joined
Mar 19, 2017
Messages
248
Bear morph is what i exactly featured in the test map that i upload months ago. I also added examples and damage bonus through abilities (because the recquester said he didn't use the new versions). It is also made kind-of-like-a-system.

So the general solution is clearead enough.

The recquest now is more particular, it is a way to make the reloading triggered in such a way similar to a channeling ability as the system uploaded achieves this with the item stack feature. I have the exact know-how on how to do that but i don't have enough time to do it right now. So maybe one of you guys can help the recquester.
 
Level 6
Joined
Aug 14, 2016
Messages
174
Do not use replace unit action. It basically removes the current unit and makes a half hearted attempt and making a replacement.

If you want to change unit types then use the morph trick.
Then how i can reload weapon?, because if i click that weapon again, unform into Fist
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Then how i can reload weapon?
I do not understand what you mean by this.

Usually ammo systems work by either ordering the unit to stop when trying to attack out of ammo. One could also try using abilities like silence and cloud to disable attacks.

If you want to change unit type, and hence attack type and such properties, you will need to use morph. The replace unit action is fake and is implemented as shown below. Using chaos to morph unit types causes all modifications to be reapplied, including those from hero stats and so is very hard to use and often crash prone.

JASS:
function ReplaceUnitBJ takes unit whichUnit,integer newUnitId,integer unitStateMethod returns unit
    local unit    oldUnit = whichUnit
    local unit    newUnit
    local boolean wasHidden
    local integer index
    local item    indexItem
    local real    oldRatio
    if (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)
    if (newUnitId == 'ugol') then
        set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    else
        set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    endif
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
            call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        endif
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
            call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
        if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
    else
    endif
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))
    if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
        call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)
        set index = 0
        loop
            set indexItem = UnitItemInSlot(oldUnit, index)
            if (indexItem != null) then
                call UnitRemoveItem(oldUnit, indexItem)
                call UnitAddItem(newUnit, indexItem)
            endif
            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY
        endloop
    endif
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif
    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction
 
Status
Not open for further replies.
Top