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

How to reffer to Unit(Player number of player) instead of (integer A)

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
So, I need to use the action: call SetUnitAnimationByIndex(udg_yourunit, #)

however I need to reffer to said unit in that way: udg_yourunit[PlayerNumberOfOwnerOfUnit()], #)

how can I reffer to specific player number instead of [GetForLoopIndexA()]

I need it because said unit is set for specific player number, like this :
  • Set UnitHorse[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
I need to set it to player number of owner of Picked Unit
 
Uhm, I'm not entirely sure I understand the problem. In what capacity does (For Loop A) not desirable for you?

JASS:
local integer PlayerNumber = 0

//Pick your unit

set PlayerNumber = GetOwningPlayer(GetEnumUnit())
set udg_UnitHorse[PlayerNumber] = CreateUnit(PlayerNumber, 'hors', x, y, 270.0)

Is that what you were looking for?
 
Level 7
Joined
Oct 19, 2015
Messages
286
If you already have what you need in GUI, then just copy that to a new trigger, convert it to custom text and you'll have what you need in JASS.
 
Level 11
Joined
Oct 9, 2015
Messages
721
I'm using GUI and I reffer to the unit as (example): Unit(player number of owner of picked unit), then I need to use a custom script to set the correct animation ("Play unit animation" glitches the animation) and I need to know how to reffer to "Player number of owner of picked unit" in the custom script instead of "GetForLoopIndexA"
 
Level 7
Joined
Oct 19, 2015
Messages
286
Spellbound said:
well the custom script would be

set udg_YourUnit[GetOwningPlayer(GetEnumUnit())] = bj_lastCreatedUnit
You can't use a player as an array index. You need to convert it to integer first.

Like I already said, take a GUI trigger line that refers to "player number of owner of picked unit", copy that line to a new trigger, convert that trigger to custom text and you will have your answer.
 
Oh, right, that...

*Ahem* it should be:
set udg_YourUnit[GetPlayerId(GetOwningPlayer(GetEnumUnit())) + 1] = bj_lastCreatedUnit

The reason for the +1 is that in JASS, player 1 is actually player 0 (and so all player numbers are back one number), so to adapt it to GUI, you need to add 1 to it to match the integer that will show in the array.

Though for future reference, it's good practice to convert a GUI code and looking at the JASS like Anitarf suggested.
 
Level 11
Joined
Oct 9, 2015
Messages
721
Yeah I put the trigger into text and it worked! thanks all you guys!
It seems I didn't had to put the +1 at the end, because the animation seemed to work.

line: udg_UnitHorse[GetConvertedPlayerId(GetOwningPlayer(GetEnumUnit()))]
PS1: I added the +1 at the end and the animation didn't work, I think it doesn't need it at all because it worked without it.
PS: How do I declare it solved?
 
Last edited:
Level 7
Joined
Oct 19, 2015
Messages
286
Yeah, GUI triggers use GetConvertedPlayerId while Spellbound used GetPlayerId, that's why he needed the +1 and you didn't, because the function you used already has the +1 built into it.
 
Status
Not open for further replies.
Top