Skip to content

How can I prevent monsters from being attacked in scripts?

#8
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...