Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
8 years ago
Auto-translated
Could you explain how the function that triggers a battle works? Why does an error occur when attempting to start a battle with the hero "Nemor," who is a reserve hero placed on the map by a script (a neutral hero, initially yellow), stating that this hero is not a reserve hero...?

Added 5 minutes later
Here is all the script code related to this hero:

DeployReserveHero("Nemor", 111, 121, 1)
sleep(2)
SetObjectOwner("Nemor", 8)
AddHeroCreatures("Nemor", CREATURE_SHADOW_DRAGON, 5 * diff)
AddHeroCreatures("Nemor", CREATURE_BANSHEE, 10 * diff)
AddHeroCreatures("Nemor", CREATURE_LICH_MASTER, 15 * diff)
AddHeroCreatures("Nemor", CREATURE_NOSFERATU, 25 * diff)
AddHeroCreatures("Nemor", CREATURE_GHOST, 30 * diff)
AddHeroCreatures("Nemor", CREATURE_DISEASE_ZOMBIE, 70 * diff)
AddHeroCreatures("Nemor", CREATURE_SKELETON_WARRIOR, 100 * diff)

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "SkullBatttle", "SkullBatttleScript")

function SkullBatttleScript(hero)
StartCombat(hero, "Nemor", 7,
CREATURE_SKELETON_WARRIOR, GetHeroCreatures("Nemor", CREATURE_SKELETON_WARRIOR),
CREATURE_DISEASE_ZOMBIE, GetHeroCreatures("Nemor", CREATURE_DISEASE_ZOMBIE),
CREATURE_GHOST, GetHeroCreatures("Nemor", CREATURE_GHOST),
CREATURE_NOSFERATU, GetHeroCreatures("Nemor", CREATURE_NOSFERATU),
CREATURE_LICH_MASTER, GetHeroCreatures("Nemor", CREATURE_LICH_MASTER),
CREATURE_BANSHEE, GetHeroCreatures("Nemor", CREATURE_BANSHEE),
CREATURE_SHADOW_DRAGON, GetHeroCreatures("Nemor", CREATURE_SHADOW_DRAGON),
nil, "SkullCombatEnd", nil, nil)
end

function SkullCombatEnd(hero, result)
if result then
if IsObjectExists("Nemor") == 0 then
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "SkullBatttle", nil)
MessageBox(path.."necroend.txt")
else
AddHeroCreatures("Nemor", CREATURE_SHADOW_DRAGON, 5 * diff)
AddHeroCreatures("Nemor", CREATURE_BANSHEE, 10 * diff)
AddHeroCreatures("Nemor", CREATURE_LICH_MASTER, 15 * diff)
AddHeroCreatures("Nemor", CREATURE_NOSFERATU, 25 * diff)
AddHeroCreatures("Nemor", CREATURE_GHOST, 30 * diff)
AddHeroCreatures("Nemor", CREATURE_DISEASE_ZOMBIE, 70 * diff)
AddHeroCreatures("Nemor", CREATURE_SKELETON_WARRIOR, 100 * diff)
end
end
end
User Avatar
8 years ago
Auto-translated
It is not recommended to transfer reserved heroes to other players. There are some unclear bugs related to this; for example, after death, the hero will not return to the reserve, and it will not be possible to deploy him.
IsObjectExists("Nemor") == 0
You also shouldn't do this; the IsObjectExists function never returns 0, only 1 and nil.
User Avatar
8 years ago
Auto-translated
How can I create dialogue messages like those found on the "Path of the Hero" map, for example? Specifically, messages with multiple answer options, each with its own unique label, etc.
User Avatar
8 years ago
Auto-translated
How to create dialogue messages like those found on the "Path of the Hero" map, for example.
Here is a quote from one of the Nival forums, where one of the developers discussed the changes in patch 3.1:
TalkBoxForPlayers( playersFilter, iconRef, iconTooltipRef, textRef, addTextRef, callback, mode, titleTextRef, selectTextRef, defaultOption, optionTextRef [, optionTextRef, ...] )
- opens a dialog with multiple answer options (from 1 to 5) for the selected players (playersFilter)
- the function does not output error messages because if the parameters are incorrect, default values are used
- iconRef - a reference to the icon texture
- iconTooltipRef - the path to the icon tooltip text
- textRef - the path to the dialog text
- addTextRef - the path to the dialog text (additional)
- callback - a string with the name of a Lua function, where the first parameter is the player's answer (number: 0 - cancel, -1 - closed by the game, 1.. - the number of the answer selected by the player)
- mode - mode: 0 - with an OK button, 1 - OK/Close
- titleTextRef - the path to the text of the window title
- selectTextRef - the path to the text of the title before the selection options
- defaultOption - the number of the answer that is highlighted by default (number: 0 - none, 1.. - the number of the answer)
- optionTextRef - the path to the text of answer #1
- ... - the path to the text of answer #...

Example:
s = 'Text/Chest/Choose.txt'
TalkBoxForPlayers( PLAYERFLT_1, nil,s, s,s, 'test1', 0, s,s, 0, s,s,s )

Attention! In localized versions of the patch, one necessary text file is missing, which is required for the correct operation of TalkBoxForPlayers. You can simply create it:

File: UI/CommonBoxes/TalkBox/Text.txt
Content: (h5)(color_bright)(value=text) (use angle brackets instead of regular parentheses)
File format: plain Unicode text (save as Unicode in NOTEPAD)

This file is recommended to be distributed as part of map archives that use TalkBoxForPlayers.

The second option is to create a special mod that contains this file and require the presence of the mod for the map to work (distribute it together).
User Avatar
8 years ago
Auto-translated
How do you determine which answer was selected later?

Added 31 seconds ago
And what is the additional text?

Added 3 minutes ago
My answer options are the choice of a reward for a quest.
User Avatar
8 years ago
Auto-translated
AstralLein, I'm currently working on a small guide about scripts, and I'll post it in a few days. It will describe this in more detail. In short, TalkBox passes 2 parameters to the callback function: the number of the responding player and the number of the selected answer. You don't need to write all the additional text; in "Path of the Hero," I only filled in the title (character name), icon, main text, and text for the answers.
User Avatar
8 years ago
Auto-translated
TalkBoxForPlayers(1, nil, nil, path.."skullfinaltext.txt", nil, "SkullEndFinal", 0, path.."ooo.txt", nil, 0, path.."m.txt", path.."mm.txt", path.."mmm.txt")

Will that work?

Added 44 minutes ago
Hmm... And what should be the path to the standard icon in the corner?

And how do I determine the hero who activated all this and will receive the reward in the final function?

Added 2 minutes ago
I have it like this now:

function SkullEndFinal(player, answer)
if answer == 1 then
Trigger(OBJECT_TOUCH_TRIGGER, "HutSkullQuest", "SkullPusty")
MessageBox (path.."endend.txt")
sleep(2)
RemoveArtefact(???, 83)
ChangeResource(6, 60000, ???)
ChangeResource(2, 50, ???)
sleep(2)
SetObjectiveState("SkullQuest", OBJECTIVE_COMPLETED)
elseif answer == 2 then
Trigger(OBJECT_TOUCH_TRIGGER, "HutSkullQuest", "SkullPusty")
MessageBox (path.."endend.txt")
sleep(2)
RemoveArtefact(???, 83)
ChangeHeroState(???, 4, 5)
sleep(2)
SetObjectiveState("SkullQuest", OBJECTIVE_COMPLETED)
elseif answer == 3 then
Trigger(OBJECT_TOUCH_TRIGGER, "HutSkullQuest", "SkullPusty")
MessageBox (path.."endend.txt")
sleep(2)
RemoveArtefact(???, 83)
AddHeroCreatures(???, CREATURE_DEMILICH, 45)
sleep(2)
SetObjectiveState("SkullQuest", OBJECTIVE_COMPLETED)
end

Added 1 hour 18 minutes ago
GetAttackerCreatures returns the creatures of the attacking side... but how exactly do I use this to refer to a specific stack?
User Avatar
8 years ago
Auto-translated
What should be the path to the standard icon in the corner?
There isn't a standard one, but here's an example, like the one in the MessageBox:
'/UI/MessageBox/Message.xdb#xpointer(/Texture)'
Although, it's nicer to put some faces there, for example, one of the heroes from the Academy:
'/Textures/Icons/Heroes/Academy/Academy_Zehir_128x128.(Texture).xdb#xpointer(/Texture)'
And how do you determine the hero who activated all this and will receive the reward in the final function?
TalkBox is for the player, so the hero's name isn't involved in it. But if it's called when entering a building or interacting with a creature, then all three touch triggers pass the hero's name; you can remember it and use it later.
GetAttackerCreatures returns the creatures on the attacking side... but how exactly do you use this to refer to a specific stack?
local units = GetAttackerCreatures();
for i, unit in units do
local unit_id = GetCreatureType(unit);
-- you can also get the number of creatures, coordinates, etc. using the unit name.
end
User Avatar
8 years ago
Auto-translated
Like, in the touch function, add `hero = name` and then use this `name`?
User Avatar
8 years ago
AstralLein, да.
User Avatar
8 years ago
Auto-translated
Hmm. I'm having trouble understanding the code (related to GetAttackerCreatures). Let's say a Lich is on the attacking side; can I now access it using CREATURE_LICH?
User Avatar
8 years ago
Auto-translated
AstralLein, no, if you need to find all liches among the attacking creatures and make them do something, it will be like this:
local units = GetAttackerCreatures();
for i, unit in units do
  local unit_id = GetCreatureType(unit);
  if (unit_id == CREATURE_LICH) then
    -- do something
  end
end
User Avatar
8 years ago
Auto-translated
I'm starting to understand... but what if something happens when any attacking unit dies? Is it done through the correct Get function (forgot the name) and using the unit's name as the unit identifier?
User Avatar
8 years ago
Auto-translated
Firstly, if a unit dies, GetAttackerCreatures() will no longer return it. As far as I remember, it returns all current units on the battlefield. The moment any creature dies is accompanied by a call to the UnitDeath function, which passes the name of the deceased creature, but I haven't checked what can be done with this name if the creature is already gone.
Secondly,
and as the name of the unit, units?
units is an array of names returned by GetAttackerCreatures(). If you try to output it, for example:
print(units)
You will get something like:
{"creature_0", "creature_1", "creature_2", "creature_3"}
When we iterate through this table with a loop:
for i, unit in units do
then the variable unit already contains the name of one creature, for example, "creature_0". This is an internal name that the game assigned to the unit. In reality, it is slightly different. The best way to see this is to simply open the console during a battle and try the corresponding commands.
User Avatar
8 years ago
Auto-translated
I mean, is it possible to create an event with the condition of any stack from the attacking army being destroyed?

Added 10 minutes later
In general, the idea is to implement two things:

- when the defending side has only one stack, it does something.

- when any stack from the attacking side dies, ghosts appear on the defending side.

Statistics

Welcome our newest member: recijeb