GetMapName Command? -[SOLVED]-
Moderator: Moderators
-
Aman/Pinguin
- Jedi

- Posts: 1104
- Joined: Tue Jan 30, 2007 6:04 am
- Projects :: Inactive
- Location: Germany
GetMapName Command? -[SOLVED]-
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)
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)
Last edited by Aman/Pinguin on Fri Oct 31, 2008 9:33 am, edited 1 time in total.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: GetMapName Command?
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"
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"
-
Aman/Pinguin
- Jedi

- Posts: 1104
- Joined: Tue Jan 30, 2007 6:04 am
- Projects :: Inactive
- Location: Germany
Re: GetMapName Command?
is it end1g_hunt or end1_hunt?[RDH]Zerted wrote:__thisMapsMode__ = "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__ )
endReadDataFile("ingame.lvl")
I thought it would work like that?
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: GetMapName Command?
__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.
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.
-
Aman/Pinguin
- Jedi

- Posts: 1104
- Joined: Tue Jan 30, 2007 6:04 am
- Projects :: Inactive
- Location: Germany
Re: GetMapName Command?
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
...Code: Select all
if __thisMapsMode__ == "cor, cor1_Conquest" then
...- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: GetMapName Command?
__thisMapsCode__ = "cor"utility_functions2: ReadDataFile(): This map's code, mode: cor cor1_Conquest
__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...
-
Aman/Pinguin
- Jedi

- Posts: 1104
- Joined: Tue Jan 30, 2007 6:04 am
- Projects :: Inactive
- Location: Germany
Re: GetMapName Command?
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- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: GetMapName Command?
Your first print statement will cause a crash if __thisMapsMode__ is nil. You should change that to 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.
Code: Select all
print("user_script_1: Name:", __thisMapsMode__ or "[Oops, I'm nil]")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.
-
Aman/Pinguin
- Jedi

- Posts: 1104
- Joined: Tue Jan 30, 2007 6:04 am
- Projects :: Inactive
- Location: Germany
Re: GetMapName Command?
Nope, it prints nil if __thisMapsMode__ is nil.[RDH]Zerted wrote:Your first print statement will cause a crash if __thisMapsMode__ is nil.
EDIT: YES! It finally works! Thank you Zerted!
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: GetMapName Command? -[SOLVED]-
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.
