Skip to content

Posts from Scripts for beginners.

4.5 (2 ratings)
User Avatar
8 years ago
Auto-translated
It also works on the test Multiplayer map I created, although for this, it needs to be added to the map itself.
Yes, it also needs to be added to the original Multiplayer maps.
In the NHF mod, scripts in Multiplayer are handled this way. And to add these scripts to fan-made Multiplayer maps, they have a special program for that.
Also, there is another small bug: when a hero captures a dwelling, the recruitment window immediately pops up, but the question about rebuilding appears only after the hero exits this window. Thus, in the case of rebuilding, the hero gets the opportunity to recruit from both the original and the alternative building, and that's exactly what happens. Does anyone have any ideas on how to solve this problem? "Disabling" the buildings until the player touches them is also not an option, because in that case, the AI will ignore these buildings.
And doesn't the function for changing the Value object for the AI work in such cases?
And another question, (probably even more noobish than the others, please forgive me) do all these scripts significantly load the game?
And does it depend on the length of the assigned values, i.e., should I make the assigned names as short as possible, or does it not matter at all?
The names are unlikely to load anything. But in general, scripts do load the game, yes. It depends on the specific case, of course, but in general, you can conduct an experiment by setting up some large cycle and looking at the execution time.
However, without large cycles, you are unlikely to notice that the script takes a long time to execute.
In reply to Ment
User Avatar
8 years ago
Auto-translated
Ment

Doesn't the function for changing the Value of an object work for AI in such cases?

I didn't quite understand this. What do you mean by the "Value of an object"?
And does such a function exist specifically for dwellings on the global map?
User Avatar
8 years ago
Auto-translated
This is available:
void SetAIPlayerAttractor( sObjectName, nPlayerID, nPriority )

Sets an "attraction point" for player nPlayerID on the object with the name sObjectName. The player's heroes will run around the object, periodically returning to it. They will return more frequently the higher the value of nPriority. The last parameter can take values from -1 to 2.

void SetAIHeroAttractor( sObjectName, sHeroName, nPriority )

This function is similar to SetAIPlayerAttractor, but it only works for a single hero with the name sHeroName.
User Avatar
8 years ago
Auto-translated
The whole problem was that the QuestionBox team refers to a new function where 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 location of objects, but maybe there is a more adequate and simpler way to do this?
You are creating difficulties out of thin air. You save the coordinates in global variables, and then access them in the add_alt_dw() function. You could just as easily save the object's name in a global variable and then use it immediately:
function capt_alt_dw (prevowner, newowner, hero, dwell )
alt_dw_dwell = dwell;
QuestionBox("text with a question blah blah blah", "add_alt_dw", nil);
end;

function add_alt_dw ()
ReplaceDwelling(alt_dw_dwell, TOWN_ACADEMY, 991 );
end;
Also, I would advise using more complex names for functions and global variables if you want to embed them in any map. The more complex, the greater the chance that they will not conflict with anything.
in general, do all these scripts significantly load the game?
Don't worry about it. In my map, the trigger for a new day probably processed about a thousand lines of code each turn, and it was barely noticeable. Only working with objects on the map takes a long time - deleting an object, placing a new one, changing the number of creatures - subjectively, each such operation causes the game to lag for about half a second.
In reply to zahar0z
User Avatar
8 years ago
Auto-translated
Thank you, Jack_of_shadows, the name change option works, and I can't believe I didn't figure it out myself; I immediately suspected that I had made the coordinate calculation too complicated.

Ment, thank you for the advice; I tried playing around with SetAIPlayerAttractor, and it seems that the command has no effect if the target object is "disabled."

Added after 5 hours and 39 minutes
Can anyone tell me if there is a command that allows you to find out the rotation angle of an object on the map, or perhaps some clever way to find it out? As far as I understand, GetObjectPosition only finds out the (x, y, "floor") coordinates, or am I misunderstanding?
User Avatar
8 years ago
Auto-translated
How can I change a dwelling so that it can be used to recruit different creatures?
In reply to Андраил
User Avatar
8 years ago
Auto-translated
Here's how.
Jack_of_shadows
Use the following to replace a dwelling with another:
ReplaceDwelling(SCRIPT_NAME, TOWN_ID, CREATURE_1, CREATURE_2, CREATURE_3, CREATURE_4)
The maximum number of creatures available in the new dwelling is equal to the number of creatures that were available in the original dwelling. You can place any creatures, regardless of the dwelling type.
User Avatar
8 years ago
Auto-translated
And what does the city ID look like? And should we place creatures based on their ID, right?
In reply to Андраил
User Avatar
8 years ago
Auto-translated
The town looks like TOWN_HEAVEN and similar, and the creatures are identified by their ID, something like CREATURE_PAESANT or similar. There's an entire Excel spreadsheet listing all these values.
In reply to zahar0z
User Avatar
8 years ago
Auto-translated
Hello everyone, hope you're all doing well.

Does anyone know if it's possible to use a script to limit the number of dwellings that can be built in a town to four? Specifically, all dwellings should be available for construction until four have been built. Once the fourth dwelling is built, the remaining unselected dwellings become unavailable. Importantly, this shouldn't be tied to the level of creatures that can be recruited; the goal is to allow any combination of four dwellings to be built (e.g., a combination of levels 1, 2, 4, and 7, or levels 3, 4, 6, and 7, etc.). Does anyone have any ideas on how to achieve this?

Thank you in advance for any helpful information you can share.
User Avatar
8 years ago
Auto-translated
zahar0z, you can implement a check, for example, in a trigger for a new day. You need to check all possible dwellings, count how many have been built, and when the condition is met, prohibit the construction of those that haven't been built. Here's a description of suitable functions from the Novice's Manual (I haven't personally tested them):
nLevel GetTownBuildingLevel( sTownName, nBuildingID )
nLevel GetTownBuildingLimitLevel( sTownName, nBuildingID )
nLevel GetTownBuildingMaxLevel( sTownName, nBuildingID )

These functions allow you to find out the level/development limit/maximum level of building nBuildingID in a town with the name sTownName. The corresponding TOWN_BUILDING_* constants for nBuildingID can be found in /scripts/advmap-startup.lua. I won't list them here due to their large number.
Level 0 means that the corresponding building is absent.

void SetTownBuildingLimitLevel( sTownName, nBuildingID, nLevel )

This function allows you to set a limit on the development level of building nBuildingID in a town with the name sTownName. Attempting to set a level higher than the maximum possible will cause an error. Level 0 means prohibiting the construction of the building.
In reply to RedHeavenHero
7 years ago
Auto-translated
RedHeavenHero
Ask what you need specifically, and I'll answer. Besides, there are already manuals like "from beginner to beginner," and there's even a huge Excel table with descriptions of all the functions in the game.

Can you provide links to these manuals and Excel tables?
In reply to bonacera
User Avatar
7 years ago
Auto-translated
Good day.

Could anyone tell me if there is a script command that allows you to play a video file? I've been looking through the list of documented commands and couldn't find one. But it should exist, because the video insertion with "evil" Isabel at the end of the original game must be implemented somehow.
User Avatar
7 years ago
Auto-translated
No, there isn't one. The video clip is most likely implemented not within the map itself, but after the map is completed (or am I forgetting something?).

Statistics

Welcome our newest member: recijeb