• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] How to detect campaign mode/which file is currently played?

Status
Not open for further replies.
Level 26
Joined
Feb 2, 2006
Messages
1,690
I have multiple maps for my modification:
  • Chapter 1
  • Chapter 2
  • Chapter 3
  • ...

Every chapter can be played in multiplayer, in single player ("Custom Game" ...) and in the single player campaign. My modification replaces the standard campaign menu of Warcraft III and links it to my maps.
I use basically the same files for the custom game maps and the single player campaign maps but with different names: For a custom Game the map is called "Talras1.0.w3x" and for the single player campaign it is simply called "TL.w3x" but in a folder with the version "10".

How can I detect if I am playing the map from file A or from file B?

In the past I had to add a new custom object to the campaign maps and use:
JASS:
public static method isCampaign takes nothing returns boolean
           // this custom object should only exist in the campaign not in the usual maps
           return GetObjectName('h03V') == "IsCampaign"
endmethod
This solution required modifying the object data. It worked because I used custom campaigns in the past and I had to add the object only once in the object data of my custom campaign. Now, I am not using custom campaigns anymore, so I am looking for an easier way where I won't have to modify every single map for the campaign version.
Is there any way to detect the file name/path of t he currently played map? Otherwise, which attribute of a map can be modified more easily to detect a difference?
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
I don't know where on the scale of ease to do this falls on but you could insert different .wts files. Or use GetLocalizedString with the appropiate file changed. Otherwise i'm not aware of a way to read some mpq specific things via jass.
 
Not sure you technically could filter/seperate them with map names in your case, but if so you might blindly loop through TRIGSTRs and look to find something:
JASS:
library Test initializer Init
    function int_to_TRIGSTR_convention takes integer i returns string
        local string TRIGSTR = "TRIGSTR_"
        if i < 1 then
            set TRIGSTR = TRIGSTR + "000"
        elseif i < 10 then
            set TRIGSTR = TRIGSTR + "00" + I2S(i)
        elseif i < 100 then
            set TRIGSTR = TRIGSTR + "0" + I2S(i)
        else
            set TRIGSTR = TRIGSTR + I2S(i)
        endif
        if StringLength(TRIGSTR) == 0 then
           return ""
        endif
        return TRIGSTR
    endfunction

    private function Test takes nothing returns nothing
        local integer i = 0
        local string name
        loop
            exitwhen i > 100
            set name = int_to_TRIGSTR_convention(i)
            if name != "" then
                call BJDebugMsg(name)
            endif
            set i = i + 1
        endloop
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0, false, function Test)
    endfunction
endlibrary
 
Status
Not open for further replies.
Top