Connection ErrorBad RequestThis page went staleSession 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.
This page went stale
Your security token was rejected, usually because the page sat open too long or you signed in elsewhere. Nothing was saved. Reload the page and try again.
Request Failed
We encountered an issue while processing your request.
Please check your internet connection and try again.
I read somewhere that you should write not startThread( "replacecreature" ) but startThread( replacecreature) I tried this option too, but it didn't work either.
That's right! I already forgot, but the correction is accurate. Did you take into account the subtraction of archers? Well, and please provide what the console writes. How to enable it is in the FAQ.
I fixed the code. I also missed a sleep command, what a klutz.
However, the code I wrote has a weak point. I suspect that you don't actually have 9999 archers. It will throw an error. You need to check the exact number of archers and subtract that exact number! If the point is that there should be no more of them in the army. But for now, just check without subtracting the archers.
It seems that the RemoveHeroCreatures command, if used to remove more creatures than the hero has, or even if used to remove creatures that the hero doesn't have at all, doesn't work. Just in case, I checked without this line, and there is still no result.
function replacecreature()
while (1) do
sleep(2);
local herocr = GetHeroCreatures( "Sarge", CREATURE_ARCHER );
if herocr >= 1 and
GetTownBuildingLevel("cheast_town", TOWN_BUILDING_DWELLING_2 ) == 2 then
RemoveHeroCreatures( "Sarge", CREATURE_ARCHER, herocr );
AddHeroCreatures( "Sarge", CREATURE_LONGBOWMAN, herocr );
sleep(1);
break
end;
end;
end;
startThread(replacecreature);
```
I would write it this way. Unless it's necessary to have only 1 longbowman, then replace herocr in the AddHeroCreatures line with 1.
function replacecreature() while (1) do sleep(2); local herocr = GetHeroCreatures( "Sarge", CREATURE_ARCHER ); if herocr >= 1 and GetTownBuildingLevel("cheast_town", TOWN_BUILDING_DWELLING_2 ) == 2 then RemoveHeroCreatures( "Sarge", CREATURE_ARCHER, herocr ); AddHeroCreatures( "Sarge", CREATURE_LONGBOWMAN, herocr ); sleep(1); break end; end; end;
startThread(replacecreature);
It works great, thank you very much to everyone. I just have a couple of small questions: why is it "==" and not "="? And what needs to be done to make the script run constantly (as long as the building is constructed), and not just once? Do I need to do something with this line "while (1) do"? Am I guessing correctly?
Use = for assigning a value, and == for comparison.
And what needs to be done to make the script run constantly (while the building is constructed), and not just once?
Every day, perhaps? Then you can use Trigger(NEW_DAY_TRIGGER,...). Otherwise, I don't understand. If you need to constantly replace archers with crossbowmen, just remove the break from line 32 of the script.
If you need to constantly replace archers with crossbowmen, just remove the "break" from the 32Metra code.
Yes, that's exactly what needs to be done. I understand. Thank you.)
Added 19 hours 28 minutes later Hello everyone again.
I need to figure out one more thing: is it possible to allow infinite building through scripts or some other way, instead of one building per day (preferably in a specific city, but if that's not possible, it's acceptable for all cities)?
Also, I'm continuing to experiment with scripts and noticed something. The script for adding/removing a creature when a specific building is constructed (as well as other scripts, I assume) only works after exiting the city screen. This creates some inconveniences for my plan.
Is it possible to bypass this in some clever way, for example, by setting a script to quickly exit and re-enter the city (although this seems impossible), but maybe someone has other ideas?
Thank you in advance for your advice; you are very helpful.
We need to figure out one more thing: is it possible to allow infinite building through scripts or some other means, instead of one building per day (preferably in a specific city, but if that's not possible, then it's acceptable for all cities)?
As far as I know, it's not possible, although maybe I just don't know all the tricks. The only thing that comes to mind is to implement it through a custom campaign spell talkbox with building options, but this would require a fairly large script. zahar0z
Is it possible to bypass this limitation in some clever way, for example, by using a script to quickly exit and re-enter the city (although this seems impossible), but maybe someone has other ideas?
The situation is even more dire here. Only general game functions like random, sqrt, etc., work in the city window, as well as 2 functions called when hiring a hero or creatures. So, as far as I can tell, it's impossible to do anything in the city.
Understood, and one more question: is it possible to link the script activation to a custom button? Or does this only work with custom adventure spells?
Hello! Please help me understand how to make it so that when your hero approaches an army (for example, an angel), a message appears, and then they join you? And if possible, have the army (angel) perform the action "Resurrection" or celebrate victory in battle (raising its hand).
How can I make it so that a hero receives a caravan with a message once a week? And also, how can I make it so that a certain building, for example, a peasant's hut, burns down?
Good day. I would like someone to explain how to make it so that when a certain in-game event occurs, player (1) becomes the property of another player (2) (specifically, in my case, when player (1) loses). And how to make player (2) inactive for the duration of player (1)'s existence?
Drmax4, here's an idea you could try (the script won't be simple): 1) Remove quests like "the hero must survive" from the main quests. In this case, if all heroes and Castles are lost, the game shouldn't register it as a loss. (I think there was such an option, if I'm not mistaken). If that doesn't work, then we'll have to come up with another event to transition the player. 2) Detect the player's loss event. For example, using a trigger for the end of a battle (COMBAT_RESULTS_TRIGGER), check how many heroes (GetPlayerHeroes) and Castles (GetObjectOwner for all Castles on the map) the player has left. 3) At the same time, the second player can have their AI disabled (EnableHeroAI), have no Castles, and generally not have their turn displayed at all (DoNotGiveTurnToPlayerAIIfNoTownsAndActiveHeroes). Or simply disable the AI for the heroes, and let the Castle stand idle. You can also place the heroes in reserve (there is such a function in the map editor). I'm not sure what exactly you want to achieve. 4) At the desired event, the heroes, Castles, and anything else needed are transferred to the ownership of player 1 using the SetObjectOwner function.