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

[Trigger] Prefix's for heroes?

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
Im looking for a trigger (GUI OR JASS) that when you select a hero, that heroes name is transfered to the player.
Let me elaborate:
1)Player X (color) selects a random hero.
2)Name of unit is transferred to the hero.
3)Player X (color) types a random message: {CrueIIntentions (Lich King): Does anyone know how to do this?}

Basically i want the heroes name beside the Players when he types a message. Possible?
 
Level 6
Joined
Sep 5, 2007
Messages
264
Just use:
JASS:
function SetPlayerPrefix takes unit hero returns nothing
    local string txt
    local player player_owner = GetOwningPlayer(hero)

    set txt = GetPlayerName(player_owner) + " (" + GetUnitName(hero) + ")"
    call SetPlayerName(player_owner, txt)
    set txt = null

    set player_owner = null
endfunction

Just use this in your Hero creation. You can only call this function ONCE per player, unless you want "BoNes (Warrior) (Warrior) (Warrior)" kind of crap happening... :thumbs_up:
 
Level 7
Joined
Jul 20, 2008
Messages
377
Or at map init, just store all the player names in a variable and use that instead of GetPlayerName.
 
Level 9
Joined
Jun 7, 2008
Messages
440
Thanks alot. That helps quite a bit. One question for the variable though. I have close to 100 heros. Since i have no repick option in my map, which way would be the best to go?

"Only one hero per player is allowed, as well, once hero is picked, it is no longer selectable."

EDIT: what did you mean by in hero creation? I didnt understand that part.
 
Level 6
Joined
Sep 5, 2007
Messages
264
By "in hero creation", I'm refering to the hero selection process, the player selects a hero, a duplicate of that hero is created for the player, and the hero is "locked-out" from selection.

At the point of creation, that's when you run my trigger.

JASS:
// Run when the hero is created
function SetPlayerPrefix takes unit hero returns nothing
    local string txt

    // This finds the owner of the hero
    local player player_owner = GetOwningPlayer(hero)

    // This gets the index (0-11) of the owner
    // Player 1 - Red = 0, Player 2 - Blue = 1, etc.
    local integer player_owner_id = GetPlayerId(player_owner)

    set txt = udg_PlayerName[player_owner_id] + " (" + GetUnitName(hero) + ")"
    call SetPlayerName(player_owner, txt)
    set txt = null

    set player_owner = null
endfunction

// Run this function on "Map Initialization"
function StorePlayerNames takes nothing returns nothing
    local integer index = 0
    local player player_check

    loop
        exitwhen (index > 11)
        set player_check = Player(index)
        set udg_PlayerName[index] = GetPlayerName(player_check)
        set player_check = null
        set index = index + 1
    endloop
endfunction
Just make sure that you have a "string" variable array, called "PlayerName".

That should work :thumbs_up:
 
Level 9
Joined
Jun 7, 2008
Messages
440
ok I tried inputting it exactly as you had it ( minus the //"message)
result = did not work.
I also tried to save time to copy and paste
Same result. Am i missing something? Sorry im still new at JASS, despite the tutorials.
 
Level 6
Joined
Sep 5, 2007
Messages
264
Put the code I posted above into the "map header" (In the trigger editor, click on the map name at the top of the list).

Then in your triggers (map init and hero create) put:

In GUI Triggers:
  • Custom Script: call StorePlayerNames()
AND
  • Custom Script: call SetPlayerPrefix(unit)
In JASS Triggers:
JASS:
call StorePlayerNames()
AND
JASS:
call SetPlayerPrefix(unit)

Also, you need to go into the global variable list, and create a "player" type array variable, called PlayerName.

If you follow these directions, then you shouldn't have any troubles. :thumbs_up:
 
Level 9
Joined
Jun 7, 2008
Messages
440
i get an error message,when i try to creat the custom script. Perhaps becuase i have no hero selection event. They enter an area and a random hero is given to them from a cache of hero's
 
Level 6
Joined
Sep 5, 2007
Messages
264
In that function, run the SetPlayerPrefix(unit) using your hero (by whatever means you use to put it into a variable, GetTriggeringUnit(), GetLastCreatedUnit(), etc.) as the parameter.

One last solution is to upload your map, and I'll do it for you. :thumbs_up:
 
Status
Not open for further replies.
Top