3 Script questions

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

3 Script questions

Post by [RDH]Zerted »

1. How do you display text to the screen? I've been fiddling with ShowMessageText () and haven't been able to get it to work. I can tell it which side to send the message to, but I can't give it a message. If I try passing in a string (ex: ShowMessageText("Hello", ATT) ) it shows up as "[ null ]" ingame for the attacking team. The other scripts seem to call some ingame text variables. Is there a way to add custom messages or change those ingame values?

2. How do you get a player's name? I want to get a human player's name. I can determine between AI and human players, but I can't get data about the players. What variables does the player objects contain?

3. How are filters applied to events? The scripting document says: "On + Event Name + Filter Name" Does this mean: OnCharacterDeathName function(player, killer)... if so, where does the value of the filter go? I have yet to come across such a filter in the other script files. How do I set the name/team/class value for the filter?

I think I've figured it out by typing this question. Is it: OnCharacterDeathName:"Player 1" function(player, killer)...
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

RE: 3 Script questions

Post by Teancum »

Whoa... Good questions. I don't know that anyone knows well enough to help yet, though. We're all brand new to LUA.
Qdin
Old School Staff
Posts: 2059
Joined: Wed Feb 23, 2005 9:54 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: 3 Script questions

Post by Qdin »

just look at the .lua files which is used by the Training Ground mission (Geonosis). I've been using that to see how to activate some simple objectives. in the beginning, it uses scripts such as OnCharaterSpawn etc. you can simply copy from there and insert in your own map's .lua file(s)
Leviathan
Missing Jedi Admin
Posts: 3277
Joined: Fri Nov 12, 2004 2:54 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: 3 Script questions

Post by Leviathan »

It seems that LUA owns many common bases with other programing languages like C# or C++...
Also, as I can't install Star Wars Battlefront II Modification Tools, I'd like to know whether one helpful GameToast member could post the content of a few *.LUA files calling instructions like the one Zerted mentioned above... ("OnCharacterDeathName function(player, killer)")
Thanks to them, I might figure out how SWBF II scripts really work...

PS : Would you have left LucasForums, Zerted ? :wink:
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

RE: 3 Script questions

Post by [RDH]Zerted »

With the lack of knowledge on the lua scripts, I'll try to document all the different functions. Hopefully, I'll have a lot done by next Saturday. Not counting differences in white sapce, there are 49,876 unique script lines...

I haven't left LucasForums. I spent most of my time after the first patch annoucment on the offical SWBF2 forums. Now that the patch is released and considering there are no search functions, 'Show new posts' functions, and half the posts are people complaining, I'm moving back to LucasForums and GameToast. (sorry to all those on the offical forums who I started giving tech support to and never finished. There is no way I can find all those topics again. )
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

RE: 3 Script questions

Post by [RDH]Zerted »

Answers:
1) ShowMessageText ("message.text", DEF): "message.text" reffers to the language files for the text to display on the screen.

2)Still unknown. Anyone have any ideas on this?

3) OnEnterRegionName( function...end, "regionName" ). The filter goes after the function.
PAN-Fnord

RE: 3 Script questions

Post by PAN-Fnord »

1) For ShowMessageText: If you give it a normal string like "common.no" it will try to translate it through the localize database...if that fails, you get garbage. There's something else that you have to call on the string - like ShowMessageText(Translate("string")) - in order for it to be formatted correctly so the game will print it if it's not in the localize database. It was used a bunch for the PC shell, specifically the Instant Action/Multiplayer options screens. I'll look it up tomorrow.

2) I don't think we have a real complete list of what fields the player tables have. I know name is in there somewhere...in fact, I would suggest looking at the lua for the stats screen (in common/scripts, possibly in shell but I don't think so), since that surely gets units' names.

There are a lot more useful functions in the shell and game-logic scripts than in the mission luas. :^)
Mike Z
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

RE: 3 Script questions

Post by [RDH]Zerted »

Thanks so much. I'll look into it...
PAN-Fnord

RE: 3 Script questions

Post by PAN-Fnord »

1) From ifs_instant_options.lua, I knew I used it somewhere:
ScriptCB_tounicode("string") should give you one properly unicoded that you can use for ShowMessageText. Note that this is untested by me. :^)

2) GetEntityName(entity), says the Lua guy.

Mike Z
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

RE: 3 Script questions

Post by [RDH]Zerted »

I'm still having problems getting this to work. I placed the following code (and other configurations) into an OnCharacterSpawn function and they all displayed "[null]" ingame:
ShowMessageText( ScriptCB_tounicode("Test"), ALL )

textA = ScriptCB_tounicode("TestA")
ShowMessageText( textA, ALL )

textB = ScriptCB_tounicode("TestB")
ShowMessageText( "textB", ALL )

ShowMessageText( (ScriptCB_tounicode("TestD")), ALL )

textE = "TestE"
ShowMessageText( ScriptCB_tounicode( textE ), ALL )
More importantly, I'm not having any luck with GetEntityName too. Is the actor of CharacterSpawn an entity? The following code doesn't work:

spawning = OnCharacterSpawn(
function(character)
if IsCharacterHuman(character) then

ShowMessageText( "message.spawn.human", ALL )
name = GetEntityClassName(character)
--name = "test sgt"
ShowMessageText( "message.spawn.human", ALL )
finding = string.find( name, "sgt", 1, true )
ShowMessageText( "message.spawn.human", ALL )

if finding == nil then
ShowMessageText( "message.cheats.none", ALL )
else
ShowMessageText( "message.cheats.found", ALL )
KillObject(GetCharacterUnit(character))
end

ShowMessageText( "message.spawn.human", ALL )

end
end
)

If I swap in: name = "testing Sgt" then string.find() works and the character is killed when it spawns. If I use GetEntityName, then the string.find() statement seems to terminate the function because none of the ShowMessageText() messages are displayed after it. From the other lua examples, it looks like GetEntityName returns a normal string. Any ideas on why this is failing?
PAN-Fnord

Re: RE: 3 Script questions

Post by PAN-Fnord »

[RDH]Zerted wrote: name = GetEntityClassName(character)
If, say, your character is a rep_inf_sniper and his NAME is "SweetAwesomeDude", then GetEntityClassName(guy) = "rep_inf_sniper", but GetEntityName(guy) = "SweetAwesomeDude".

As well, a Character is not an Entity. A Character is the overarching representation of you (has stats, etc) but is not an individual solider, since a Character can control many soldiers over its life. You can do
myUnit = GetCharacterUnit(character)
GetEntityName(myUnit)

Our Lua guy says we never had to get a player's name. :^)

I'll try some stuff quick,
Mike Z
PAN-Fnord

RE: Re: RE: 3 Script questions

Post by PAN-Fnord »

After much research:

1 - there is Print3D(matrix, string), which you have to pass a UserData of a matrix (can use GetEntityMatrix, I guess - you just need the translation but I don't know the format of a matrix - poke around some) and a string, and it'll print that on a billboarded polygon at some point in space. I think that's as close as you get, but it's a debug function so it may not even work in the released game. :^)

2 - After much research, there is no function to get the name of a Character - which is what you want - anywhere. We never needed it. The unit name is NOT the right thing. There are stats functions that do it, so maybe you could look at the stats screen lua (common/scripts/ifs_stats), and use the auto-fill-in-a-table functions from there to fill in a table after you find out what rank your player is, then get the name from the table...but that's very complicated.

Sorry...
Mike Z
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

RE: Re: RE: 3 Script questions

Post by [RDH]Zerted »

What about ScriptCB_GetCurrentProfileName() ? The only thing I can seem to get from it is nil.
if string.find( ScriptCB_GetCurrentProfileName(), "p", 1, true ) == nil then
ShowMessageText( "message.none", ALL )
else
ShowMessageText( "message.found", ALL )
end
]4N

Post by ]4N »

ouch, Diet Dr. Pepper, nobody knows how to send own made text messages...
I've figured out how to do some multiplayer missions..but without a text message this won't be usable.
Post Reply