Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
11 years ago
Auto-translated

function visit_crypt(hero)
QuestionBox(GetMapDataPath() .. 'visit_crypt.txt', 'crypt_ok', 'crypt_cancel')
end

Trigger(4, 'crypt', 'visit_crypt')

function crypt_ok() -- this function is called when the player presses the OK button
-- ...
end

function crypt_cancel() -- this function is called when the player presses the Cancel button
-- ...
end


Added 15 minutes later
You can also create a function that will immediately return the player's answer, instead of calling another function. I think this is a bit more convenient.

function QuestionBoxRef(msg)
question_box_ref_answer = -1
QuestionBox(msg, "question_box_ref_answer=1 --", "question_box_ref_answer=0 --")
while question_box_ref_answer == -1 do
sleep()
end
return question_box_ref_answer == 1
end

-- example of usage

function visit_crypt(hero)
if QuestionBoxRef(GetMapDataPath() .. 'visit_crypt.txt') then
-- the player agrees
else
-- the player declines
end
end

Trigger(4, 'crypt', 'visit_crypt')

User Avatar
11 years ago
Auto-translated
Hello, please list all the tasks that can be assigned using scripts in the standard way. I don't quite understand them, and the documentation is unclear. Or, if anyone has a manual on tasks, please share it.
User Avatar
11 years ago
Auto-translated
What does "quests that can be given in the usual way" mean?
User Avatar
11 years ago
Auto-translated
Just regular quests that can be created in the editor.
Never mind, maybe you can point me to a manual on creating quests?
User Avatar
11 years ago
Auto-translated
Is there a function that allows you to restore a monster's courage and morale on the map?
User Avatar
11 years ago
Auto-translated
There isn't one. It can be emulated for a single map if you modify the map.xdb file.

Added 1 minute ago
What is the goal? Perhaps another solution can be found.
In reply to RedHeavenHero
User Avatar
11 years ago
Auto-translated
RedHeavenHero
There isn't one. It can be emulated for a single map if you process the map.xdb.

Added 1 minute ago
What is the goal? Perhaps there is another solution.

I wanted to create a special ability for a hero that would improve the mood of a hostile mob when attacking it, making it more likely to join.
For now, I've just made it so that there's a chance of a friendly mood appearing (without taking into account what the mood was before) - and that works too.
11 years ago
Auto-translated
Citizens, comrades, ladies and gentlemen, I need your help. I've been struggling with one of the scripts on the map for quite some time, and it just won't let me rest. Here is its full code:
EnableHeroAI('Bersy',nil)
EnableHeroAI('Ingvar', nil)
EnableHeroAI('Vegeyr', nil)
DoNotGiveTurnToPlayerAIIfNoTownsAndActiveHeroes(PLAYER_3,true)


function Mystery_of_mount()
Trigger(OBJECT_TOUCH_TRIGGER, 'Thanes', nil)
MessageBox(dir..'dialog_1.txt')
sleep(5)
SetObjectEnabled('Thanes', true)
sleep(5)
MakeHeroInteractWithObject('Giovanni', 'Thanes')
sleep(3)
if IsObjectExists('Thanes') == not nil then
RemoveObject('Thanes')
sleep(3)
startThread(Thanes_2)
else startThread(Thanes_2)
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, 'Thanes', 'Mystery_of_mount')

function Thanes_2()
if IsObjectExists('Thanes') == nil then
MessageBox(dir..'dialog_2.txt')
sleep(5)
SetObjectiveState('Thun', OBJECTIVE_COMPLETED)
if GetTownHero('Shagarakti') == 'OrnellaNecro' then
flag = 1;
else TeachHeroSpell('OrnellaNecro',SPELL_TOWN_PORTAL)
SetObjectPosition('OrnellaNecro',28,34,0)
flag = 1;
flag3 = GetDate(DAY)
flag4 = flag3 + 3;
print('flag3')
print('flag4')
flag5 = flag3 + 7;
print('flag3')
print('flag5')
flag6 = flag3 + 14;
print('flag3')
print('flag6')
end;
end;
end;

function Attack_1()
if GetDate(DAY) == flag3 + 3 then
SetObjectPosition('Bersy',28,36,0,4)
SetAIHeroAttractor('Shagarakti','Bersy',2)
AddObjectCreatures('Garrison',40,18 +(flag2*5),7)
AddObjectCreatures('Garrison',42,5 +(flag2*5),6)
EnableHeroAI('Bersy',true)
end;
end;
Trigger(NEW_DAY_TRIGGER,'Attack_1')

function Attack_2()
if GetDate(DAY) == flag3 + 7 then
SetObjectPosition('Vegeyr',28,34,0,4)
SetAIHeroAttractor('Shagarakti','Vegeyr',2)
AddObjectCreatures('Shagarakti',40, 16 + (3*flag2))
AddObjectCreatures('Shagarakti',36, 50 +(10*flag2))
EnableHeroAI('Vegeyr',true)
end;
end;
Trigger(NEW_DAY_TRIGGER,'Attack_2')

function Attack_3()
if GetDate(DAY) == flag3 + 14 then
SetObjectPoistion('Ingvar',28,34,0,4)
SetAIHeroAttractor('Shagarakti','Ingvar',2)
TeachHeroSpell('OrnellaNecro',SPELL_SUMMON_HIVE)
AddObjectCreatures('Shagarakti',36, 30 + (flag2*10))
EnableHeroAI('Ingvar',true)
end;
sleep(1)
end;
Trigger(NEW_DAY_TRIGGER,'Attack_3')

function Attack_finished()
while 1 do
if IsHeroAlive('Ingvar') == nil then
MessageBox(dir..'fu.txt')
end;
sleep(1)
end;
end;
startThread(Attack_finished)

The essence of it is as follows: a quest is given to destroy a group of Thanes. After its completion, after a certain amount of time, the heroes, previously deactivated, should appear at a certain point and attack the player's city. However, this does not happen - the map either freezes, or continues to work normally, but the heroes do not appear. The game version is 3.1, and it doesn't work either on a clean version or with mods. Question to the experts: where is the bug?
User Avatar
11 years ago
Auto-translated
I immediately see 2 errors:
1. Several trigger setups, and as a result, it will only work for the last function. Attack_1(2,3) needs to be combined into one function.
2. A break is missing in the Attack_finished function, so messages about Ingvar's death will be displayed infinitely, which may cause the game to freeze.
11 years ago
Auto-translated
Thank you. I've fixed it, and the map has been sent back for testing. Now I'll see if I was able to fix anything.
User Avatar
11 years ago
Auto-translated
There is a function called `StartCombat` that triggers a function at the end of the battle. This function passes the hero and the result of the battle for that hero. How can I add more values to the parameters being passed?
In reply to Dyrman
User Avatar
11 years ago
Auto-translated
Dyrman
There is a StartCombat function that triggers a function at the end of the battle. This function passes the hero and the result of the battle for that hero. How can I add more values to the parameters being passed?
You can redefine the function itself so that it returns the result of the battle:
local wrapStartCombat = StartCombat
function StartCombat(hero, enemy, stacks, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18)
%wrapStartCombat(hero, enemy, stacks, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18)
local combat_index = GetLastSavedCombatIndex()
while GetLastSavedCombatIndex() == combat_index do
sleep()
end
local result = IsHeroAlive(hero)
return result
end
Then, you can avoid passing control to another function and continue executing the current one.
In reply to RedHeavenHero
User Avatar
11 years ago
Auto-translated
RedHeavenHero
You can redefine the function itself so that it returns the result of the battle:
local wrapStartCombat = StartCombat
function StartCombat(hero, enemy, stacks, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18)
%wrapStartCombat(hero, enemy, stacks, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18)
local combat_index = GetLastSavedCombatIndex()
while GetLastSavedCombatIndex() == combat_index do
sleep()
end
local result = IsHeroAlive(hero)
return result
end
Then you don't need to pass control to another function, but continue executing the current one.
Clever. Thanks. Remind me, please, what advantage does using % before a variable give?
User Avatar
11 years ago
Auto-translated
% should always be placed before external local variables.
User Avatar
11 years ago
Auto-translated
It’s a pity that the user script editor throws an error for %.

Statistics

Welcome our newest member: recijeb