• 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.

[Solved] Random Unit Changing Ownership

Status
Not open for further replies.
Level 4
Joined
May 17, 2011
Messages
106
Hello! The title isn't so clear so I'll explain here what I want to do.

Players in my map (survival map) have the possibility of making units to gather resources and repair buildings.

I'm adding a custom (triggering ability) that work as follow:

There's a chance that the unit becomes agressive and attack the player (changing ownership of the unit) but the problem is, I want the unit to come back to his ancient owner if its health drops bellow 20.

Here is what I have so far:

  • RageMode
    • Events
      • Time - Every 20.00 seconds of game time
    • Conditions
    • Actions
      • Set RageModeNumber = (Random integer number between 1 and 10)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RageModeNumber Equal to 3
        • Then - Actions
          • Unit - Change ownership of (Random unit from TamedZombies[(Player number of (Random player from PlayingPlayers))]) to Player 12 (Brown) and Change color
        • Else - Actions
  • RageMode2
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) is alive) Equal to True
      • (Life of (Attacked unit)) Less than or equal to 20.00
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Attacked unit)) Equal to Repair Zombie
          • (Unit-type of (Attacked unit)) Equal to Tamed Zombie
    • Actions
      • Unit - Make (Attacked unit) Invulnerable
For the second trigger, I don't know what to add next... I mean... since it's a random unit from a random group... well... you get it... how to change it back to its previous owner?

Thanks!

Edit: Wow... nevermind... I never saw the change to previous owner function... *feeling dumb* -.-
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Use can store the previous player into a hashtable.

set integer = player number of random player from playersPlaying
Custom script: set bj_wantDestroyGroup = true
set unit = (Random unit from TamedZombies[integer])
Custom script: set udg_ID = GetHandleId(udg_unit)
Unit - Change ownership of unit to Player 12 (Brown) and Change color
Hashtable - Save integer as 0 of ID in hashtable


ID is an integer variable
---

In trigger 2
Unit - Change owner of attacked unit to Player(Hashtable - Load 0 of Key(attacked unit) from hashtable) and change color

Remember to initialize the hashtable
 
Level 4
Joined
May 17, 2011
Messages
106
I'll take a look at that but I never used hashtable to I'll have to learn how it works first ^^

Edit: Since I'm changing the whole process, I supose TamedZombies's array is no longer needed? I'm a little bit confused about it... if it's still needed... what is its integer about?
 
Last edited:
Level 4
Joined
May 17, 2011
Messages
106
I don't understand about that last line, about the hashtable. What do I put as the 3 values exactly? And when do I initialize the hashtable?

Edit: Is this normal that I can't find any ''Function'' part under the key handle function? I can only select variable... no functions...
 
Last edited:
Edit: Is this normal that I can't find any ''Function'' part under the key handle function? I can only select variable... no functions...
yes if your using JNGP, you should do it via custom script...

I have this kind of spell in my Field of Conflict map called Mind Control, if you want it I can share with you, it works like what Maker said...
 
Level 4
Joined
May 17, 2011
Messages
106
yes if your using JNGP, you should do it via custom script...

I have this kind of spell in my Field of Conflict map called Mind Control, if you want it I can share with you, it works like what Maker said...

that would be sweet of you :)
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Example, JNGP compatible:

  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set ht = (Last created hashtable)
  • Change To
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Set u = (Triggering unit)
      • Custom script: set udg_id = GetHandleId(udg_u)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (0 is stored as a Integer of id in ht) Equal to False
        • Then - Actions
          • Hashtable - Save (Player number of (Owner of u)) as 0 of id in ht
          • Unit - Change ownership of u to (Player((Random integer number between 5 and 12))) and Change color
          • Selection - Select u for Player 1 (Red)
          • Wait 5.00 seconds
          • Set u = (Triggering unit)
          • Custom script: set udg_id = GetHandleId(udg_u)
          • Unit - Change ownership of u to (Player((Load 0 of id from ht))) and Change color
          • Hashtable - Clear all child hashtables of child id in ht
        • Else - Actions


http://www.hiveworkshop.com/forums/pastebin.php?id=sdq9hk
 
Level 4
Joined
May 17, 2011
Messages
106
So this is going to change someone's unit to be agressive towards him for 5 sec and then going back to normal if I understand it?

I want it to choose a random player and a specific random unit from that random player to be agressive for a short duration, is this doing the job right? I guess I'll just try it out! Thank you Maker :)

To mckill2009 : I'd like GUI since I know how it works (not entirely, but still ^^) and since I don't really know JASS I'll only take it if I have no other choices. Thanks anyway :)
 
Level 4
Joined
May 17, 2011
Messages
106
Heh... that trigger still won't work...

The triggering unit changes ownership but when its hp drops bellow 30 it won't do anything... can someone tell me what's wrong with my triggers?

  • RageMode
    • Events
      • Time - Every 30.00 seconds of game time
    • Conditions
    • Actions
      • Set PickedRandomPlayer = (Player number of (Random player from PlayersPlaying))
      • Set PickedRandomUnit = (Random unit from TamedZombies[PickedRandomPlayer])
      • Custom script: set udg_id = GetHandleId(udg_PickedRandomUnit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (0 is stored as a Integer of id in ragemodehashtable) Equal to False
        • Then - Actions
          • Hashtable - Save PickedRandomPlayer as 0 of id in ragemodehashtable
          • Unit - Change ownership of PickedRandomUnit to Player 12 (Brown) and Change color
          • Selection - Select PickedRandomUnit for (Player(PickedRandomPlayer))
          • Set PickedRandomUnit = (Ownership-changed unit)
          • Trigger - Turn off (This trigger)
        • Else - Actions
  • RageMode2
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) is alive) Equal to True
      • (Life of (Attacked unit)) Less than or equal to 35.00
      • (Attacked unit) Equal to PickedRandomUnit
    • Actions
      • Unit - Make PickedRandomUnit Invulnerable
      • Unit - Set life of PickedRandomUnit to 100.00%
      • Unit - Change ownership of PickedRandomUnit to (Player((Load 0 of id from ragemodehashtable))) and Change color
      • Unit - Make PickedRandomUnit Vulnerable
      • Hashtable - Clear all child hashtables of child id in ragemodehashtable
      • Trigger - Turn on RageMode <gen>
Seriously I don't get it...

Edit: Oops, in the first trigger, I forgot to say that it won't make the selection, so I just changed the next line to something that was hopefully going to work but... well... there it is

Thinking of it... the second trigger won't even go on... that must be a problem with the pickedrandomunit variable in the first trigger... I just don't know what to do with it.

Edit #2: Nevermind! Found a solution and its working well! (Deleted the selection and set variable lines (2 last lines in the first trigger))
 
Last edited:
Status
Not open for further replies.
Top