Skip to content

Current questions and answers regarding the map editor.

User Avatar
#5606
Auto-translated
}{0TT@6bI4
Jewill, I haven't encountered this function before; I need to test it. The idea is promising, except for one point: why track when the window is closed? If we can't determine which window it is, then there isn't much point in the action...
Let me provide an example, which can be considered pseudocode. I decided not to record specific timestamps, but rather record them conditionally, as absolute time is not really needed here. Correct me if I missed something in the logic – I didn't think through the details too much; this is just a general principle. This isn't the most important task, but if the function that checks for message display works on the principle of "If you see a message, you can't see another one," then it opens up possibilities for writing scripts for the aforementioned mines, garrisons, and factories without any issues. For example, you could check if a particular war machine has been acquired.
-- Define variables somewhere, preferably separately for each player. --

WINDOW_CLOSED = nil;
WINDOW_NAME = "";
-------------------------------------------------------------------------
Trigger(OBJECT_TOUCH_TRIGGER,"mine_name","myCallback")
----------Let's assume we triggered a system message somewhere. -----------------
----------For example, by approaching a mine. In principle, you don't have to attach the trigger to a specific name. -------
----------------- I wrote this just as an example. -------------
--In general, since each building that triggers pop-ups (or any interactive windows) has a TYPE,---------
----you can attach this script to all buildings on the map in a separate file. ----
---- I'm not talking about custom windows; it's obvious how to handle them. ----
---- As for the city, that's a dark forest where I'm not very knowledgeable, and I'm not very interested either. But this principle won't work there. ---.

function myCallback(heroname,obj) -- Callback function, one for any of the buildings, because all it does is start another code.
    local player = detectInteractor(heroname) -- Here, we simply determine the player based on the hero. (I invented the function; it's very easy to implement.)
    WINDOW_NAME = "MINE_WINDOW"
    startThread(checkWindowState,player);
end;

function checkWindowState(player)
    while(CanShowPlayer(player) == nil) do
        sleep(2);
    end;
    WINDOW_CLOSED = not nil;
end;
function windowClosed()
    while(1) do
        sleep(3);
        if(WINDOW_CLOSED ~= nil) then
            --------Iterate through calls based on WINDOW_NAME --------
            if(WINDOW_NAME == 'MINE_WINDOW') then
                --- Call the corresponding function, and start the thread to close the window again in it.----
                --- In this same function, reset our variables before starting the thread. -----
                break;
            end;
        end;
    end;
end;
startThread(windowClosed);


Не уходи безропотно во тьму,
Будь яростней пред ночью всех ночей,
Не дай погаснуть свету своему!

Хоть мудрый знает – не осилишь тьму
Во мгле словами не зажжёшь лучей –
Не уходи безропотно во тьму.