You can custom entity the NPC, it would be the same thing, but you would be allowed to change various parameters suh as his size, bounding box, origin, etc. The best thing about it is that you don't have to find through your game database about the map where the NPC is to change a variant, everything can be done in a single file in /entities. And it doesn't impact any performance.
Not tested, but it act like the build in NPC class. The only thing is that you need to code it's behaviour if you wanna make your NPC more smart.
Remember that size of objects need to be a multiple of 8.
Code (lua) Select
local entity = ...
local game = entity:get_game()
--Shared NPC. The dialog pointer = the name of the entity in the map (in the editor).
--If you want all NPC to have a movement then create the movement in on_created()
function entity:on_created()
-- here, self is the entity
self:set_size(24,24) -- only multiple of 8 are allowed
self:set_traversable_by("hero", false)
end
local hero_facing_npc = false
local action_command_speak = false
-- Hud notification
entity:add_collision_test("facing", function(entity, other)
if other:get_type() == "hero" then
hero_facing_npc = true
if hero_facing_npc then
game:set_custom_command_effect("action", "open")
action_command_npc = true
else
game:set_custom_command_effect("action", nil)
end
end
end)
function entity:on_interaction()
self:set_direction(game:get_hero():get_direction() / 2)
game:start_dialog(self:get_name())
end
function entity:on_update()
if action_command_speak and not hero_facing_npc then
game:set_custom_command_effect("action", nil)
action_command_speak = false
end
hero_facing_npc= false
end
Not tested, but it act like the build in NPC class. The only thing is that you need to code it's behaviour if you wanna make your NPC more smart.
Remember that size of objects need to be a multiple of 8.