Skip to content

Current questions and answers regarding the map editor.

User Avatar
#5587
Auto-translated
}{0TT@6bI4
2. Can you write a sample script that works automatically for any mines? That is, if you add a gold mine, the effect is automatically applied to it.
I don't claim this is the absolute truth; there may be errors (I haven't tested it), but the prototype turned out something like this.
There is also an option to disable the mine using a trigger and temporarily enable it upon interaction, but I don't know what happens first:
resource generation or custom triggers.
Regarding the code.
The array can be created manually; it is constant, meaning it will be the same from map to map, unless the map does not contain mines of the required type, in which case the loop
will execute 0 times, and this will not cause any errors. Ah yes, and you need to assign names to all the mines, but they don't necessarily have to be meaningful; you can use any names. As long as the script knows that the mine has a unique name.
minesArray = 
{
{type = "BUILDING_SAWMILL",res = <resource ID>,dailyValue = <how much the mine produces>}
...
{type = <mine type (see types.xml base tables)>,res = <resource ID>,dailyValue = <how much the mine produces>}
}
function checkMines()
local weekMultiplier = 1;
if(GetCurrentMoonWeek() == <union week ID>) then
weekMultiplier = 3;
end;
if(GetCurrentMoonWeek() == <idleness week ID (or whatever it is)>) then
weekMultiplier = 0.5;
end
for i,minesType in minesArray do
local allMines = GetObjectNamesByType(minesType.type);
for ind, mine in allMines do
local owner = GetObjectOwner(mine);
if(owner ~= 0) then
if(GetObjectCreatures(mine,<creature ID>) < value) then
local currentRes = GetPlayerResource(owner,minesType.res)
SetPlayerResource(owner,minesType.res, currentRes - minesType.dailyValue * weekMultiplier);
end;
end;
end;
end;
end;
Trigger(NEW_DAY_TRIGGER,"checkMines");


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

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