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

Trying to Make Function to Get Rid of #0000 on btag

Status
Not open for further replies.
Level 21
Joined
Mar 16, 2008
Messages
955
Doesn't seem to work, I run this by telling another trigger to run it in GUI 1 sec into the game.
JASS:
function Trig_player_names_Actions takes nothing returns nothing
local integer x_red = StringLength(GetPlayerName(Player(0)))
local string name_red = GetPlayerName(Player(0))
    loop
            set x_red = x_red-1
            if SubString(name_red, x_red-1, x_red+1) == "#" then
            call SetPlayerName(Player(0), SubString(name_red, 0, x_red))
            return
        endif
    endloop    
endfunction
 
try this
vJASS:
function removeBnetTag takes player p returns nothing
    local string name = GetPlayerName(p)
    local integer length = StringLength(name)
    local integer index = length - 1
    loop
        exitwhen index < 0
        if SubString(name, index, index+1) == "#" then
            set name = SubString(name, 0, index)
            call SetPlayerName(p, name)
            return
        endif
        set index = index - 1
    endloop
endfunction

function removeBnetTagAll takes nothing returns nothing
    local integer pId = 0
    local player p
    loop
        exitwhen pId >= bj_MAX_PLAYERS
        set p = Player(pId)
        if GetPlayerController(p) == MAP_CONTROL_USER then
            call removeBnetTag(p)
        endif
        set pId = pId + 1
    endloop
endfunction
 
Level 21
Joined
Mar 16, 2008
Messages
955
thanks for help. it works on single player test.

It seems player names aren't loaded until after map initialization. So I called your function in GUI after the "game started" and it worked.
  • Custom script: call removeBnetTagAll()
also these parameters work for the SubString function, this contradicts some guides I've read on strings in WE.
JASS:
        if SubString(name, index, index+1) == "#" then
Based on my understanding of some guides, I thought it would need to be this. . .

. . .this does not work:
JASS:
        if SubString(name, index-1, index+1) == "#" then
 
vJASS:
//===========================================================================
// The parameters for the API Substring function are unintuitive, so this
// merely performs a translation for the starting index.
//
function SubStringBJ takes string source, integer start, integer end returns string
    return SubString(source, start-1, end)
endfunction
the BJ version which is called from GUI handles the start index differently with -1. Maybe the guide meant it
 
Level 21
Joined
Mar 16, 2008
Messages
955
I think this would work if you only want to remove the name off a hero. (I rename the heroes to the playes' names in this map) Based on IcemanBo's post.

JASS:
///removeBnet_hero

function removeBnet_hero takes nothing returns nothing
    local string name = GetHeroProperName(udg_hero_array[1])
    local integer length = StringLength(name)
    local integer index = length - 1
    loop
        exitwhen index < 0
        if SubString(name, index, index+1) == "#" then
                set name = SubString(name, 0, index)
        call BlzSetHeroProperName(udg_hero_array[1], name)
                return
        endif
        set index = index - 1
    endloop
endfunction
 
Status
Not open for further replies.
Top