New to GameGuru, was having a hard time finding existing examples of an invulnerable quest npc that just talks to you by cycling through E. Feel free to use, modify, provide tips.
module_quest_npc.lua
-- Quest NPC - Invulnerable with Dialog
local module_quest_npc = {}
function module_quest_npc.init(e, npcName, npcConversation)
i = 0
name = npcName
conversation = npcConversation
end
function module_quest_npc.main(e)
-- invulnerable check
if g_Entity[e]['health'] < 100000 then
SetEntityHealth(e,100000)
end
if GetPlayerDistance(e) < 150 then
-- check a timer so holding down E doesn't advance too quick
if g_KeyPressE == 1 and GetTimer(e) > 500 then
i = i + 1
StartTimer(e)
end
-- restart the conversation if over
if i > #conversation then
i = 0
end
if i == 0 then
Prompt("Press E to talk to " .. name)
animateIdle(e)
else
Prompt(name .. ": " .. conversation[i])
animateConversation(e)
end
else
-- if player walks away, restart conversation and idle animation
i = 0
animateIdle(e)
end
end
function animateConversation(e)
if g_Entity[e]['animating'] == 0 then
SetAnimationFrames(3110,3420)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
end
end
function animateIdle(e)
if g_Entity[e]['animating'] == 0 then
SetAnimationFrames(3000,3100)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
end
end
return module_quest_npc
Attach this to your entity
sample.lua
-- NPC - Sample
module_quest_npc = require "scriptbank\\myscripts\\module_quest_npc"
function npc_sample_init(e)
module_quest_npc.init(e, "MyName", { "Hello 1", "Hello 2" })
end
function npc_sample_main(e)
module_quest_npc.main(e)
end