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.
Could you please tell me how to check if a creature belongs to a specific castle faction or a player's faction? And after that, how to apply a certain buff to that creature?
I_Am_Walking, as far as I know, there is no function for directly determining a faction. For heroes, you can do this indirectly by checking for faction-specific skills.
So, if you need to check, for example, the faction of a town or a player, is it impossible to do this directly? Can it only be done indirectly, through creatures?
I think that if it's a standard map without any custom elements, you can simply use a script to check all the heroes of all players in one day. If there's necromancy, it means it's a Necromancer; if there's summoning, it means it's a Demon, and so on, and store the results in a global table (key - player number, value - faction). Then you can use it for either heroes or castles.
Guys, help me out. For some reason, after the question (QuestionBox) and the "OK" answer, the battle doesn't start (StartCombat). If I copy StartCombat into the function with the question, then everything works fine. I made a link to another function in the question.
Hello everyone, could you please advise me on something?
Is it possible to configure a function to execute not based on a specific trigger from the list of triggers, but based on something else, such as the construction of a building or the appearance of a specific artifact or creature with a particular hero or player?
It seems that the command that starts a new thread does something similar (although I don't really know what a thread is).
`startThread(fProc, vParam1, vParam2, ...)`
Theoretically, if I understand correctly, it should constantly check for a specific condition, but I can't figure out how to use it.
Specifically, I need to replace one creature with another in a hero's army when a specific building is constructed in a town.
Currently, I have something like this:
```
function replacecreature ();
if GetHeroCreatures( "Sarge", CREATURE_ARCHER ) >= 1
and GetTownBuildingLevel( "cheast_town", TOWN_BUILDING_DWELLING_2 ) = 2;
then AddHeroCreatures( "Sarge", CREATURE_LONGBOWMAN, 1 );
RemoveHeroCreatures( "Sarge", CREATURE_ARCHER, 9999 );
else nil;
end;
end;
startThread( "replacecreature", TOWN_BUILDING_DWELLING_2 );
```
What's wrong with this, and is it even possible to do what I'm describing? If not, is there a similar alternative?
Thank you very much in advance for any advice.
Don't create a trigger. But you can implement a check in an infinite loop. Your code looks fine, but you need to wrap your `if` statement in the following structure:
```
while 1 do
if...
sleep(4);
end;
```
Don't forget about `sleep`, otherwise everything will freeze...
I fixed it like this, but it still doesn't work I must be doing something wrong; if anyone knows exactly where the error is, I would be very grateful if you could let me know
P.S. while I'm at it, I accidentally leaked the mod I'm trying to put together))
function replacecreature()
while 1 do
if GetHeroCreatures("Sarge", CREATURE_ARCHER) >= 1 and GetTownBuildingLevel("cheast_town", TOWN_BUILDING_DWELLING_2) == 2 then
RemoveHeroCreatures("Sarge", CREATURE_ARCHER, 9999);
AddHeroCreatures("Sarge", CREATURE_LONGBOWMAN, 1);
end;
sleep(4);
end;
end;
startThread(replacecreature);
Is this how it should be?
for one, I accidentally revealed the mod I'm trying to put together
You've piqued my interest...
---
However, the code I wrote has a weak point. I suspect 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 goal is to have no more of them in the army. But for now, check it without subtracting the archers.
function replacecreature () while 1 do if GetHeroCreatures( "Sarge", CREATURE_ARCHER ) >= 1 and GetTownBuildingLevel( "cheast_town", TOWN_BUILDING_DWELLING_2 ) = 2 then RemoveHeroCreatures( "Sarge", CREATURE_ARCHER, 9999 ); AddHeroCreatures( "Sarge", CREATURE_LONGBOWMAN, 1 ); end; end; end;
startThread( "replacecreature" );
I checked, it still doesn't work. (It doesn't even start, whether the building is built at the beginning of the map or during the game).
I read somewhere that you should write not startThread( "replacecreature") but startThread( replacecreature) I tried this option too, but it didn't give any results.
In Novik's Manual, there is also this snippet about startThread: while(1) do local heroes = GetPlayerHeroes(PLAYER_1) for i, h in heroes do if.... but I have no idea how to apply it and what it means because I'm a newbie