Skip to content

Posts from How can I prevent monsters from being attacked in scripts?

No ratings yet — be the first to rate!
User Avatar
Auto-translated
I want to implement a system where, when attacking a monster, a dialogue appears, essentially making the monster offer a quest. I need to be able to interact with this monster, but not attack it. That is, I don't just want to block access to it so that I can't even hover the cursor over it, but rather make it so that I can approach it, but combat doesn't start. After all, I need to be able to somehow complete the quest with it later.
User Avatar
Auto-translated
You can attach a trigger to a monster, and then disable the monster itself as an object.
In reply to DarkLordax
User Avatar
Auto-translated
DarkLordax
You can attach a trigger to a monster, and disable the monster itself as an object.
In that case, will it still be possible to interact with it?
In reply to Rasvetribka
User Avatar
Auto-translated
Rasvetribka
In that case, will it be possible to interact with it?
Through a trigger.
In reply to DarkLordax
User Avatar
Auto-translated
DarkLordax
Using a trigger.
Aha, I understand. Thank you.
User Avatar
Auto-translated
From the manual in my signature:

How to execute an action when touching a specific monster?

As a rule, it is better to make a monster with non-standard behavior visually distinct from a
normal one, so as a bonus to the touch trigger, I add a change of the cursor from the
standard sword to a peaceful horse, removing the monster's "skirt," and changing its
name:
-- setting up NPC creatures on the map
-- npc – the monster's name assigned in the editor (string)
-- func – the touch handler function (string)
-- name – the name of the file with the creature's name (string)
-- func and name – optional parameters, they can be omitted
function SetNpcFunc(npc, func, name)
-- disabling the standard monster touch trigger (combat)
SetObjectEnabled(npc, nil);
-- setting a peaceful cursor when hovering over the monster
SetDisabledObjectMode(npc, DISABLED_INTERACT);
sleep(1)
-- disabling the "skirt" (faction symbol under the monster)
SetMonsterSelectionType(npc, 0);
-- setting a custom touch trigger (optional parameter)
if (func ~= nil) then
Trigger(OBJECT_TOUCH_TRIGGER, npc, func);
end
-- setting the monster's name (optional parameter)
if (name ~= nil) then
local full_name = GetMapDataPath()..name;
SetMonsterNames(npc, MONSTER_NAME_SINGLE, full_name);
end
end

-- examples of using the function:
-- the monster simply stops reacting to touches
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’);
-- a touch trigger is assigned to the monster, the name remains the same
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’, ‘NpcTouch’);
-- a touch trigger is assigned to the monster, and it is given a new name
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’, ‘NpcTouch’,
‘FILE_NAME_WITH_NAME’);

-- monster touch handler
-- hero – the script name of the hero who touched the NPC monster
-- npc – the script name of the monster that was touched
function NpcTouch(hero, npc)
YOUR CODE
end
РПГ-сценарий для HoMM5: Путь героя
ЧаВо по созданию карт для HoMM5: ЧаВо
In reply to Jack_of_shadows
User Avatar
Auto-translated
Jack_of_shadows
From the manual in my signature:

How to execute an action when touching a specific monster?

As a rule, it is better to make a monster with non-standard behavior visually different from a
normal one, so as a bonus to the touch trigger, I add a change of the cursor from the
standard sword to a peaceful horse, removing the monster's "skirt" and changing its
name:
-- setting up creatures-NPCs on the map
-- npc – the name of the monster assigned in the editor (string)
-- func – the touch handler function (string)
-- name – the name of the file with the creature's name (string)
-- func and name – optional parameters, they can not be passed
function SetNpcFunc(npc, func, name)
-- disabling the standard touch trigger of the monster (battle)
SetObjectEnabled(npc, nil);
-- setting a peaceful cursor when hovering over the monster
SetDisabledObjectMode(npc, DISABLED_INTERACT);
sleep(1)
-- disabling the "skirt" (faction symbol under the monster)
SetMonsterSelectionType(npc, 0);
-- setting your own touch trigger (optional parameter)
if (func ~= nil) then
Trigger(OBJECT_TOUCH_TRIGGER, npc, func);
end
-- setting the monster's name (optional parameter)
if (name ~= nil) then
local full_name = GetMapDataPath()..name;
SetMonsterNames(npc, MONSTER_NAME_SINGLE, full_name);
end
end

-- examples of using the function:
-- the monster simply stops reacting to touches
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’);
-- a touch trigger is assigned to the monster, the name remains the same
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’, ‘NpcTouch’);
-- a touch trigger is assigned to the monster and a new name is given
SetNpcFunc(‘SCRIPT_NAME_OF_THE_MONSTER’, ‘NpcTouch’,
‘FILE_NAME_WITH_NAME’);

-- monster touch handler
-- hero – the script name of the hero who touched the NPC monster
-- npc – the script name of the monster that was touched
function NpcTouch(hero, npc)
YOUR CODE
end

Thank you very much, this is very useful information.
In reply to DarkLordax
Auto-translated
DarkLordax
You can assign a trigger to a monster, and disable the monster itself as an object.
Please, tell me how to disable an object! I understand that 2 years have passed, but I really need to know.

Added 5 minutes later
Jack_of_shadows
From the manual in my signature:

How to perform an action when touching a specific monster?

As a rule, a monster with non-standard behavior should be visually different from a
normal one, so as a bonus to the touch trigger, I add changing the cursor from the
standard sword to a peaceful horse, removing the monster's "skirt", and changing its
name:
-- setting up creatures-NPCs on the map
-- npc – the name of the monster assigned in the editor (string)
-- func – the touch handler function (string)
-- name – the name of the file with the creature's name (string)
-- func and name – optional parameters, they can be omitted
function SetNpcFunc(npc, func, name)
-- disabling the standard monster touch trigger (combat)
SetObjectEnabled(npc, nil);
-- setting a peaceful cursor when hovering over the monster
SetDisabledObjectMode(npc, DISABLED_INTERACT);
sleep(1)
-- disabling the "skirt" (faction symbol under the monster)
SetMonsterSelectionType(npc, 0);
-- setting your own touch trigger (optional parameter)
if (func ~= nil) then
Trigger(OBJECT_TOUCH_TRIGGER, npc, func);
end
-- setting the monster's name (optional parameter)
if (name ~= nil) then
local full_name = GetMapDataPath()..name;
SetMonsterNames(npc, MONSTER_NAME_SINGLE, full_name);
end
end

-- examples of using the function:
-- the monster simply stops reacting to touches
SetNpcFunc('SCRIPTED_MONSTER_NAME');
-- a touch trigger is assigned to the monster, the name remains the same
SetNpcFunc('SCRIPTED_MONSTER_NAME', 'NpcTouch');
-- a touch trigger is assigned to the monster and it is given a new name
SetNpcFunc('SCRIPTED_MONSTER_NAME', 'NpcTouch',
'FILE_NAME_WITH_NAME');

-- monster touch handler
-- hero – the scripted name of the hero who touched the NPC monster
-- npc – the scripted name of the monster that was touched
function NpcTouch(hero, npc)
YOUR CODE
end
Please, tell me what these letters are, and how to change them...
User Avatar
Auto-translated
Jack_of_Shadows seems to have explained everything very clearly. What else can we clarify, especially since there's a comment for each line? The way the question is phrased is also strange: "Explain what those letters mean." Either specify what exactly is unclear in the code, or it will seem like you don't understand Russian.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
Auto-translated
}{0TT@6bI4
Comrade Jack_of_Shadows seems to have explained everything very clearly. What else can I clarify for you if there's a comment for each line? The way the question is phrased is also strange: "Explain what those letters are." Either write what specifically is unclear in the code, or it will seem like you don't understand Russian.

I apologize, but I don't know what a Lua Code Sample is and where to modify it. I've searched online, but I still don't understand. If you know, please answer: 3
User Avatar
Auto-translated
Ah, I think I understand now, sorry. Do you know where to enter the scripts? Map Properties => Map Script => Edit Script. But this method isn't very good; the editor often crashes, erasing the changes. Therefore, I recommend HSerg's script editor. You can find it under this video -> https://www.youtube.com/watch?v=M5_ND_yeSLk; it also explains script examples.

P.S. I don't understand how you couldn't find it on Google. The first few pages contain Ogoi's guide to scripts and Remix's videos.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________

Statistics

Welcome our newest member: Emil