Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Vladislav A-V
User Avatar
5 years ago
Auto-translated
Vladislav A-V
Good afternoon, please tell me how I can implement the following idea using a script: There are 2 secondary quests (SO-1), to capture a neutral town and it is initially included in the tasks, and (SO-2), to control the surrounding mines, which is a hidden quest. The goal is to make quest SO-2 visible immediately after capturing the neutral town. I tried to do something similar, but it turned out to be not very good, and is it possible to get a tutorial on this problem?
function detencion()
if GetObjectOwner("Dwarftown")==PLAYER_1 then
SetObjectiveVisible("SO-2", bVisible, "nPlayerID = 1")
Trigger(OBJECT_CAPTURE_TRIGGER,"Dwarftown1", "detencion")
end
end
Trigger(OBJECT_CAPTURE_TRIGGER, "Dwarftown1", nil)

Why is the trigger attached to the object "Dwarftown1", but the player's ownership is checked for the object "Dwarftown"? And what is "nPlayerID = 1"? It is enough to simply put 1 instead of "nPlayerID = 1" if the map is single-player, or PLAYER_1. You also need to add SetObjectiveState("SO-2", 2, 1). The trigger should be attached after the function, and reset within the function body. You have it the other way around.
User Avatar
5 years ago
Auto-translated
Okay, I did everything as you both suggested, and the script works like a Swiss watch: clearly and without any glitches. Thank you very much, Hottabych and Master.
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
}{0TT@6bI4
You could use a variable (R) to generate a random number (random(n)+1, where n is the number of message options). You would also need an array called messages with n elements – each element would be the path to a different message. Then, in the message box, instead of the path to the text, you would use a simple construction like messages[R].
Thank you!
User Avatar
5 years ago
Auto-translated
Good afternoon. Could you please advise me on how to implement army upkeep costs? I'm not sure how to do it. Could you please suggest how to, for example, check the number of peasants in a hero's army each day and then deduct one coin for each peasant? Thank you in advance.
In reply to Casesuro
User Avatar
5 years ago
Auto-translated
Casesuro
Good afternoon. Could you please advise me on how to implement army upkeep costs? I'm not sure how to do it. Could you please tell me, for example, how to make it so that each day the number of peasants in the hero's army is checked, and then one coin is deducted for each peasant. Thank you in advance.
function NewDay()
local peas=GetHeroCreatures(hero name, CREATURE_PEASANT)
local cons=GetHeroCreatures(hero name, CREATURE_CONSCRIPT)
local landl=GetHeroCreatures(hero name, CREATURE_LANDLORD)
sleep(1)
if GetPlayerResource(1,6)>(peas+cons+landl) then
SetPlayerResource(1, GOLD, GetPlayerResource-(peas+cons+landl))
else
Your code for the case when the player doesn't have enough money to pay for the peasants.
end;
end;

Trigger(NEW_DAY_TRIGGER, "NewDay")
However, the coin deducted for each peasant will only negate the Tax Collector ability. Also, at the end of the turn, the player can unload peasants into a sawmill or somewhere else and not pay. The system for paying for troops is very well implemented in Mercenaries; I recommend looking at the script for that map.
User Avatar
5 years ago
Auto-translated
I liked the question because I've long wanted to create a truly strategic map with control zones, army costs, and all that (but doing anything other than scripting is incredibly tedious).
In reply to Ment
User Avatar
5 years ago
Auto-translated
Ment
I liked the question because I've long wanted to create a truly strategic map with control zones, army costs, and all that (but doing anything other than scripting is incredibly tedious).

Good luck with any endeavors!
User Avatar
5 years ago
Auto-translated
I was working with the GetHeroCreaturesType function. The idea is that it should return a table of creature IDs in the hero's army, but in reality, it writes them as a single number (for example, instead of 138, 72, 73, 0, 0, 0, 0, it writes 138727300). Reassigning the result returned by this function to another variable, of course, didn't give any results, and it erased everything except the first value (138). In this regard, the question is: how can I extract these IDs? Thank you in advance.
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
}{0TT@6bI4
I was working with the GetHeroCreaturesType function. The idea is that it should return a table of creature IDs in the hero's army, but in reality, it writes them into a single number (for example, instead of 138, 72, 73, 0, 0, 0, 0, it writes 138727300). Reassigning the result returned by this function to another variable, of course, didn't give any results, erasing everything up to the first value (138). In this regard, the question is: how can I extract these IDs? Thank you in advance.

you can try something like this:
function pack(...)
return arg
end

id_table = pack(GetHeroCreaturesTypes(hero))
User Avatar
5 years ago
Auto-translated
Thank you, I will try.
In reply to Gerter
User Avatar
5 years ago
Auto-translated
Gerter

you can try something like this:
function pack(...)
return arg
end

id_table = pack(GetHeroCreaturesTypes(hero))
It didn't help...
In reply to }{0TT@6bI4
User Avatar
5 years ago
Auto-translated
GetHeroCreaturesTypes returns the result as 7 values, which require 7 variables (or table fields).
An example of its use is shown below:
-- into several variables
local a, b, c, d, e, f, g = GetHeroCreaturesTypes(hero)

-- into a table
local t = {}
t[1], t[2], t[3], t[4], t[5], t[6], t[7] = GetHeroCreaturesTypes(hero)
The method called Gerter should also work. If the code doesn't function with it, then the error lies in something else.
User Avatar
5 years ago
Auto-translated
Thank you very much. I keep forgetting about these functions that return "arrays"... I'll test Gerter's script again. But I'll use your method instead.
User Avatar
5 years ago
Auto-translated
somewhere else, you made a mistake. The simplest test perfectly outputs a table to the console.
function pack(...)
  return arg
end

print(pack(GetHeroCreaturesTypes(GetPlayerHeroes(PLAYER_1)[0])))
User Avatar
5 years ago
Auto-translated
Yes, I've already confirmed it. There seems to be a missing point within the parentheses, which might be the issue... In any case, thank you to both of you, and RedHeavenHero, for your help. As usual, I messed up!

Statistics

Welcome our newest member: recijeb