• 🏆 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!

[Trigger] Replacing a hero

Status
Not open for further replies.
Level 37
Joined
Mar 6, 2006
Messages
9,240
This replaces a hero with another. It works if the player has only one hero. The hero must also be alive.

If you have stored all heroes into an array, skip the set hero = (Random unit...) and replace all udg_hero references with udg_yourarray[player number of triggering player].

You can add unit types like this:
  • Custom script: call SaveInteger(udg_HeroHash, 0, StringHash("paladin"), 'Hpal')
Copy and paste those lines. The paladin there is what you want the players to type to get a paladin. So typing

-paladin

will create a paladin. The Hpal is the unit type of the unit. You can check the unit type by opening object editor and hitting ctrl + D.



  • HC Init Copy
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set HeroHash = (Last created hashtable)
      • Custom script: call SaveInteger(udg_HeroHash, 0, StringHash("paladin"), 'Hpal')
      • Custom script: call SaveInteger(udg_HeroHash, 0, StringHash("mountainking"), 'Hmkg')
      • Custom script: call SaveInteger(udg_HeroHash, 0, StringHash("archmage"), 'Hamg')
      • Custom script: call SaveInteger(udg_HeroHash, 0, StringHash("bloodmage"), 'Hblm')
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to HC Change <gen> the event (Player - (Player((Integer A))) types a chat message containing - as A substring)
  • HC Change
    • Events
    • Conditions
    • Actions
      • Custom script: local boolean b
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Key (Substring((Entered chat string), 2, (Length of (Entered chat string))))) is stored as a Integer of 0 in HeroHash) Equal to True
        • Then - Actions
          • Custom script: set bj_wantDestroyGroup = true
          • Set hero = (Random unit from (Units owned by (Triggering player) matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) is alive) Equal to True))))
          • Custom script: set b = IsUnitSelected(udg_hero, GetTriggerPlayer())
          • Custom script: call ReplaceUnitBJ( udg_hero, LoadInteger(udg_HeroHash, 0, StringHash(SubString(GetEventPlayerChatString(), 1, StringLength(GetEventPlayerChatString())))), bj_UNIT_STATE_METHOD_RELATIVE )
          • Custom script: if b then
          • Selection - Add (Last replaced unit) to selection for (Triggering player)
          • Custom script: endif
        • Else - Actions
          • Set PGroup = (Player group((Triggering player)))
          • Game - Display to PGroup the text: Such hero does not ...
          • Custom script: call DestroyForce(udg_PGroup)


You can add colour codes and additional messages, like if the hero is dead then replacing will fail.

http://www.hiveworkshop.com/forums/pastebin.php?id=hy1txj
 
Status
Not open for further replies.
Top