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

creating units on player name

Status
Not open for further replies.
Level 9
Joined
Apr 7, 2010
Messages
480
ok so for example, i have a trigger that allows a unit to be created if the player name match the condition.

  • Checking Player Name
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
      • Player - Player 2 (Blue) skips a cinematic sequence
      • Player - Player 3 (Teal) skips a cinematic sequence
      • Player - Player 4 (Purple) skips a cinematic sequence
      • Player - Player 5 (Yellow) skips a cinematic sequence
      • Player - Player 6 (Orange) skips a cinematic sequence
    • Conditions
      • (Name of (Triggering player)) Equal to
    • Actions
      • Unit - Create 1 Unit for (Triggering player) at (Center of (Playable map area)) facing Default building facing degrees
the problem here is that i want it to be created automatically, without the player pressing anything.
 
Level 9
Joined
Apr 7, 2010
Messages
480
well yea. that is just my example, but it wont work for the trigger (for triggering player) if i use map init
 
Level 30
Joined
Nov 29, 2012
Messages
6,637
Try Elapsed Game is 0.10. Map Init I think it wont work so try Elapsed Time and set to 0.10 or 0.1.

That means you will have to change your conditions to:

First put a And Multiple condition and put in it
  • Name of (Player 1 - Red) equal to
like in your condition but do this for each player for the condition.

And in action, Pick every Player and do that Create unit for Picked Player.
 
Level 9
Joined
Apr 7, 2010
Messages
480
@Hell master, but if i have 6 players total and 6 heroes each i would have to create 36 conditions. lol.

@defskull, i dont know actually. i just want the trigger to work. i just want the trigger to check the player name at the start of the game. then if it matches with the condition, then it would create a unit for him.

@Doomlord, let me try

EDIT: problem solved. thanks +rep to Doomlord
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
It is not recommendable to do this as...
1. It encourages spoofing to get the special units.
2. It is the opposite of a "fair" game.

Anyway as for the problem...
For readability and ease of programming what you need to do is store all player names in a string array and then in a matching unit type array (integer array in JASS) you place the corresponding hero type.

At map initialization you pick all human players who are playing (no point picking AI or inactive humans) and then for each picked player you loop through the player name string array checking if their name matches the string in the array at that index. If there is a match, you create the unit of type specified in the unit type array at the index wherever you want. This makes scaling the system and programming it considerably easier as you do not need to handle every case (the script does that for you) but the approach I described will not scale very well and for large numbers of players (100s) you risk a thread crash let alone frame dropping.

Remember that BattleNet allows you to freely change the case of your account name when logging in. You may want to enforce upper or lower case comparisons for player names to take this into account and avoid the embarrassing moments when a player should get something but does not due to a name mismatch.
 
Status
Not open for further replies.
Top