Connection ErrorBad RequestSession ExpiredSign in requiredForbiddenNot FoundToo Many RequestsServer ErrorBad GatewayService UnavailableGateway TimeoutHTTP Version Not Supported
Session Expired
Your session has expired. Please log in to continue.
Sign in required
You need an account to do that. Sign in or create one — it only takes a minute.
Request Failed
We encountered an issue while processing your request.
Please check your internet connection and try again.
Hi, I've encountered the need to write a script for the first time, but I'm not very good at programming, and I also don't know the limits of what's possible. Specifically, I need to program a gate so that when the entire army inside it is destroyed, the gate transitions under my control, and the guards inside the gate are revived, doubling in number. Perhaps you already have a similar draft, and I would be very grateful for your help.
Heroist
Auto-translated
What is meant by the word "gate"? A garrison? Then it will become yours anyway after you destroy its entire army.
yes, garrison no, the point isn't that it becomes mine but that the entire army I defeated is reborn but now under my command and, of course, it's non-removable plus, it's doubled.
function capture_gar(hero) local a = {}; a[1], a[3], a[5], a[7], a[9], a[11], a[13] = GetObjectCreaturesTypes("garrison_name"); for i = 1, 7 do if a[i*2-1] ~= 0 then a[i*2] = 2 * GetObjectCreatures("garrison_name", a[i*2-1]); end; end; SetObjectEnabled("garrison_name", 1); Trigger(4, "garrison_name", nil); MakeHeroInteractWithObject(hero, "garrison_name"); local i = GetLastSavedCombatIndex(); while i == GetLastSavedCombatIndex() do sleep(1); end; if not IsHeroAlive(hero) then SetObjectEnabled("garrison_name", nil); Trigger(4, "garrison_name", "capture_gar"); return end; for i = 1, 7 do if a[i*2] then AddObjectCreatures("garrison_name", a[i*2-1], a[i*2]); end; end; DenyGarrisonCreaturesTakeAway("garrison_name", 1); end;
Here, you only need to replace "garrison_name" with the script name of your garrison. In the script, it should be written in quotes, and in the editor (in the Name field in the object's properties) - without quotes.
yes, the garrison no, the point is not that it becomes mine but that the entire army that I defeated is reborn but now under my command naturally, it cannot be taken back plus, it doubles in size
you give your "gates" a name. for example, vorota vorotaF is a function that will be executed when an object is captured then you declare a trigger Trigger(OBJECT_CAPTURE_TRIGGER, "vorota", "vorotaF");
then you write the function itself
vorotaF(nPrevOwnerID, nNewOwnerID, sHeroName, sObjectID) nPrevOwnerID - player number - the former owner nNewOwnerID - the current owner sHeroName - the name of the hero who captured the gates sObjectID - the name of your gates (vorota)
these parameters are passed to the function after the garrison's owner changes. If it doesn't matter who captured the garrison, you can leave the parentheses empty.
to add creatures to the garrison, use the command AddObjectCreatures( sObjectName, nGreatureID, nCount );
where sObjectName is the name of the gates (specified in quotes!!!) nGreatureID is the creature ID (there is a document with all IDs in the editor's documentation) nCount is the number of creatures to be added.
Trigger(OBJECT_CAPTURE_TRIGGER, "vorota", nil ); - resetting the trigger, also in the function body!!!
and don't forget to put end at the end;
that's all. If it is important which player and hero captures, specify all parameters in the function's parentheses and write a conditional statement in the function body if ....... end;
gar="garrison name" gar_army={} for i = 0, 6 do local t, n = GetObjectArmySlotCreature(gar, i) gar_army={t, n} end
Trigger(5, gar, 'capture_gar')
function capture_gar(oldowner, newowner, hero, gar) for i = 0, 6 do if gar_army[1] ~= 0 then AddObjectCreatures(gar, gar_army[1], gar_army[2]*2) end end DenyGarrisonCreaturesTakeAway(gar, 1) Trigger(5, gar, nil) end
What did I do wrong?
I opened the map in the editor.
I found the garrison.
I opened the properties with the spacebar.
I clicked "Edit Script".
I pasted the text.
I clicked "OK".
what did I do wrong?
I opened the map in the editor.
I found a garrison.
I opened its properties by pressing the spacebar.
I clicked "Edit script".
I pasted the text.
I clicked "OK".
To write a script for the map, open Map properties in the editor (you can do this quickly by pressing the M button). In it, select the Scripts tab, click Edit script, and start writing.
Thanks to everyone, I barely found it. It turns out you need to click in the field to the right of the word "name". You can also click on "name" to highlight it and then press the spacebar.
It worked!
Heroist
Auto-translated
Does anyone know how to prevent a super-strong hero-companion from attacking my hero? Judging by the description, the attractor won't help, and I don't want to establish friendship either; I need to be able to attack, but he shouldn't attack back...
Whatever
Ment
Auto-translated
Disable it using `SetObjectEnabled("...",nil);` and move it around the map manually. You'll also need to set up a trigger for when another hero touches it, so they can attack.