Page 1 of 1
GetMapName Command? -[SOLVED]-
Posted: Mon Oct 27, 2008 2:20 pm
by Aman/Pinguin
I need to know if it's possible to detect in the lua which map is running right now.
I need this, because I'm making an custom userscript for Zerted's v1.3 patch and I want the neutral CP's on some maps to have a team right at the beginning. (Shipped maps only)
Re: GetMapName Command?
Posted: Wed Oct 29, 2008 7:59 pm
by [RDH]Zerted
The v1.3 patch r112+ has this ability. It attempts to store the 3-char map code in __thisMapsCode__ and the loaded map layer/game mode in __thisMapsMode__. It gets these values from listening in on ReadDataFile() calls. This isn't a perfect feature. It only works with maps using three letters for its code and if a map uses an uncommon folder structure it may not detect it. If someone uses an uncommon side structure, it may even say that that side is the map. However, I don't think any of the existing maps use such uncommon structures.
Those two variables are nil if the map name could not be detected or if it is just hasn't been detected yet. The ReadDataFile injection happens in utility_functions2.lua, which is in ingame.lvl. All that means is that it won't even start attempting to detect the map name until the ReadDataFile("ingame.lvl") line in ScriptInit().
Example values:
__thisMapsCode__ = "end"
__thisMapsMode__ = "end1_hunt"
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 11:08 am
by Aman/Pinguin
[RDH]Zerted wrote:__thisMapsMode__ = "end1_hunt"
is it
end1g_hunt or
end1_hunt?
EDIT: When I try to print out
__thisMapsMode__ it prints
nil. I tried it with Coruscant Conquest and Mustafar Conquest.
This is how I tried to print it out:
Code: Select all
if ClearWalkers then
print("user_script_1: ", __thisMapsMode__ )
end
since ClearWalkers is on every map AFTER
ReadDataFile("ingame.lvl")
I thought it would work like that?
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 1:21 pm
by [RDH]Zerted
__thisMapsMode__ is the layer configuration in ZeroEdit which is loaded from a ReadDataFile line in ScriptInit. The map variables won't be detected until that ReadDataFile call, since its the new ReadDataFile function that checks for the map fields (I replaced the read ReadDataFile function with a new one I created).
When the values are detected, they are printed to the debug log. Search for utility_functions2 to find it. Also, don't forget you need the v1.3patch r112. That was released last night.
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 2:21 pm
by Aman/Pinguin
utility_functions2: ReadDataFile(): This map's code, mode: cor cor1_Conquest
Okay, I tried it like this before you told me that:
Code: Select all
if __thisMapsMode__ == "cor1_con" then
...
How would that have to look like?
Code: Select all
if __thisMapsMode__ == "cor, cor1_Conquest" then
...
Like this?
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 5:22 pm
by [RDH]Zerted
utility_functions2: ReadDataFile(): This map's code, mode: cor cor1_Conquest
__thisMapsCode__ = "cor"
__thisMapsMode__ = "cor1_Conquest"
Open up cor1g_con.lua (r any other map) and look at the ReadDataFile line which reads in the map itself. The mode is the second parameter to that ReadDataFile.
hmm, I thought I stored those as lowercase...
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 6:07 pm
by Aman/Pinguin
Well, this is what I did now and I added that print function to see if
__thisMapsMode__ is something in that moment already. And nope, it's still nil. So my question: When should I start these if functions? I thought it would be okay when I do this after the ReadDataFile of the layers?
Code: Select all
if AddCameraShot then
print("user_script_1: Name:", __thisMapsMode__)
if __thisMapsMode__ == "cor1_Conquest" then
print("user_script_1: Map is Coruscant")
SetProperty("cp1", "Team", 2)
SetProperty("cp2", "Team", 1)
SetProperty("cp3", "Team", 2)
SetProperty("cp4", "Team", 1)
elseif __thisMapsMode__ == "dag1_conquest" then
print("user_script_1: Map is Dagobah")
SetProperty("cp2", "Team", 1)
SetProperty("cp4", "Team", 1)
SetProperty("cp5", "Team", 2)
SetProperty("cp6", "Team", 2)
elseif __thisMapsMode__ == "tan1_conquest" then
print("user_script_1: Map is Tantive IV")
SetProperty("CP4CON", "Team", 1)
SetProperty("CP5CON", "Team", 2)
elseif __thisMapsMode__ == "uta1_Conquest" then
print("user_script_1: Map is Utapau")
SetProperty("con_CP1a", "Team", 1)
SetProperty("CON_CP2", "Team", 1)
SetProperty("CON_CP6", "Team", 2)
SetProperty("CON_CP7", "Team", 2)
else
print("user_script_1: Map has no neutral command posts or wasn't able to get indentified!")
end
end
Re: GetMapName Command?
Posted: Thu Oct 30, 2008 8:43 pm
by [RDH]Zerted
Your first print statement will cause a crash if __thisMapsMode__ is nil. You should change that to
Code: Select all
print("user_script_1: Name:", __thisMapsMode__ or "[Oops, I'm nil]")
If you where making a map with that code, you would put it in ScriptPostLoad(). So put it inside the ScriptPostLoad in your user_script. Do it right after
print("user_script_1: ScriptPostLoad(): Entered")
Also, I'm not sure why you have that
if AddCameraShot... It is not needed as it doesn't really do anything.
If you where making a normal map, then yes you could print out the values right after the ReadDataFile line. However, in the user_script, you cannot determine when that line was called, so its best to do it in ScriptPostLoad.
Re: GetMapName Command?
Posted: Fri Oct 31, 2008 9:09 am
by Aman/Pinguin
[RDH]Zerted wrote:Your first print statement will cause a crash if __thisMapsMode__ is nil.
Nope, it prints nil if __thisMapsMode__ is nil.
EDIT: YES! It finally works! Thank you Zerted!

Re: GetMapName Command? -[SOLVED]-
Posted: Sat Nov 01, 2008 9:01 pm
by [RDH]Zerted
The v1.3 r117 stores the mode and code in all lower case letters. You will need to update a few of your if statements for that change. Also, I did add in support for getting all of players' ingame names.