Page 1 of 1

LUA get name function?

Posted: Sun Aug 11, 2013 5:21 pm
by razac920
Is there a way to get the name of an AI character (i.e. Rayce Branigan, Unit 048, Theta 273, TK 421) through a LUA function? Basically whatever replaces "%s" in the "%s killed %s" message? I'd like to have localized messages for all the Imperial troop names, but I don't know which one to show, given the character unit. So is there any LUA functions which input characters and output the name of the character (not the unit class name)? Thanks.

Re: LUA get name function?

Posted: Sun Aug 11, 2013 6:33 pm
by fasty
The only way is by localizing. Impossible with lua as far as I know.

Re: LUA get name function?

Posted: Sun Aug 11, 2013 8:33 pm
by Locutus
The teamstats.lua seems to use ScriptCB_GetTeamstats(team).
Not sure of that can be of any use, though.

I never looked into it but maybe psych0freds most recent lua release contains a function that fills %s with a string so you can display a chat message saying "XXX was infected!".

Re: LUA get name function?

Posted: Sun Aug 11, 2013 9:44 pm
by razac920
Well actually there IS a built-in lua function designed for just that: string.format()
http://lua-users.org/wiki/StringLibraryTutorial
The problem is that for use in, say, ShowMessageText(), you give it a localization key, such as "game.infomsg.killed", and what shows up on the screen is the value "%s killed %s". In LUA you can't actually get the string "%s killed %s" (at least I haven't found any LUA functions that look up the value of a localization key), so you can't edit it directly.