• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[General] how to check if player has unit?

Status
Not open for further replies.
Level 25
Joined
Sep 26, 2009
Messages
2,387
If you want to check if he has hero (a hero that he created, but it does not matter to you if that hero is currently alive or dead), then you can make boolean array check whenever new unit enters area, if unit-type of that unit is your hero, you save "true" into the boolean and as an index you use player's number.

Then it is simply checking if bool for that player == true

Code:
Events
    Unit enters playable map area
Conditions
    Unit-type of triggering unit == your hero
Actions
    Set bool[player number of (triggering player)] = true

------
then you check if bool[X] == true (X is number of player you want to check - e.g. 1 for player 1 (Red) )

----
Alternatively, you can use this trigger as well
Events
    Unit dies
Conditions
    Unit-type of triggering unit == your hero
Actions
    Set bool[player number of (triggering player)] = false

This way it will be false if that hero is dead
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Tell me, how many "unit" that you want to be checked ?
I would suggest a boolean approach in which, whenever a unit that is newly owned by a player, set the boolean to true.
If the unit dies, or whatever, set it to false.

To check, simply check the boolean instead to enumerate all the units in the map, that would be too power-consuming method.
 
Level 25
Joined
Sep 26, 2009
Messages
2,387
afaik the only choices you have are to either
a) use the unit group and iterate through each unit and check if the unit-type is in the group ==> simple trigger (in PoW of the developer), but it's a heavy process, more so if you have many units in game

b) do it via the boolean like I and Defskull wrote... these may seem more complex (requires 3 triggers), but those are simple triggers and way more efficient than iterating through each unit that player has.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
@Nichilus
That only works if you have 1 Hero per Player.
We need to know how many Hero/Unit he intend to allocate per Player first.

But if he only needs one per Player, your trigger would work best.

Because judging by this;
I need to check if player has specific hero type...
I'm sensing that there would be more than 1 check to be done, say, he wants to check from the pool of 6 units.

Either way, we must wait for his more in-depth explanation so that we can adjust our triggering scope to adapt his desired situation.
 
Status
Not open for further replies.
Top