Skip to content

Scripts for beginners.

User Avatar
#180
Auto-translated
Hello everyone, and once again, I have some questions.

I wrote the following:
function capt_alt_dw (prevowner, newowner, hero, dwell)
alt_dw_x, alt_dw_y, alt_dw_fl = GetObjectPosition(dwell);
QuestionBox("text with a question, blah blah blah", "add_alt_dw", nil);
end;

function add_alt_dw()
for i, pix_dw in allpix_dw do
pix_dw_x, pix_dw_y, pix_dw_fl = GetObjectPosition(pix_dw);
if pix_dw_x == alt_dw_x and
pix_dw_y == alt_dw_y and
pix_dw_fl == alt_dw_fl then
sleep(1);
ReplaceDwelling(pix_dw, TOWN_ACADEMY, 991);
end;
end;
end;

allpix_dw = GetObjectNamesByType("BUILDING_FAIRIE_TREE");
for i, pix_dw in allpix_dw do
Trigger(OBJECT_CAPTURE_TRIGGER, pix_dw, "capt_alt_dw");
end;

Now, when capturing any Fairy dwelling on the map, a question appears. If the answer is positive, the building is rebuilt into an alternative dwelling with creature ID 991.

The problem was that the QuestionBox command refers to a new function, in which the "dwell" value from the "capt_alt_dw" function is lost, so the game cannot determine which dwelling to rebuild at that moment. I have temporarily solved this by comparing the object locations, but perhaps there is a more adequate and simpler way to do this?

And the main question is, why doesn't this script work on the original Multiplayer maps in Multiplayer mode? The script execution is specified in advmap-startup.lua. On the same original Multiplayer maps, in Single mode, the script works. It also works on a test Multiplayer map that I created, but for this, it needs to be specified directly in the map. But on the original maps in Multiplayer, it doesn't work at all. Does anyone know what the reason is and how to fix it?

In addition, there is another small bug: when a hero captures a dwelling, the recruitment window immediately pops up, and the question about rebuilding appears only after the hero exits this window. Thus, in the case of rebuilding, the hero has the opportunity to recruit units from both the original and the alternative building, and he actually does.
Is there anyone who has ideas on how to solve this problem? "Disabling" the buildings until the player touches them is also not an option, because in this case, the AI ignores these buildings.

And one more question (probably even more newbie than the others, please forgive me), do all these scripts heavily load the game? And does this depend on the length of the assigned values, i.e., should I make the assigned names as short as possible, or does this not matter at all?

As always, thank you in advance for your help.