I saw that some people have problems with this, so I release my version.
I created it some time ago based on a already released script, if the person sees this you can ask me for credits.
In npc/lib/npc.lua add:
In any npc script file you want to use this add this at the top:
That's the basic setup for every NPC.
Everywhere you want the NPC to tell a story now add it like this:
You should also call cancelStory(cid) whenever you use selfStory or selfSay to cancel the previous story.
~Summ
V Dat linkens
I created it some time ago based on a already released script, if the person sees this you can ask me for credits.
In npc/lib/npc.lua add:
Lua:
function npcDelayedTalk(cid, text, player)
if isNpc(cid) and isPlayer(player) then
doCreatureSay(cid, text, TALKTYPE_PRIVATE_NP, false, player, getThingPos(cid))
end
end
function selfStory(msg, player, delay)
local interval, npc = delay or 5000, getNpcCid()
local ret = {}
for i, message in pairs(msg) do
if i == 1 then
doCreatureSay(npc, message, TALKTYPE_PRIVATE_NP, false, player, getThingPos(npc))
else
local r = addEvent(npcDelayedTalk, (i-1)*interval, npc, message, player)
table.insert(ret, r)
end
end
return ret
end
In any npc script file you want to use this add this at the top:
Lua:
local story = {}
local function cancelStory(cid)
if not(story[cid]) then return true end
for _, eventId in pairs(story[cid]) do
stopEvent(eventId)
end
story[cid] = {}
end
function creatureFarewell(cid)
if not(isPlayer(cid)) then return true end
cancelStory(cid)
return true
end
npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
That's the basic setup for every NPC.
Everywhere you want the NPC to tell a story now add it like this:
Lua:
if msgcontains(msg, "story") then
cancelStory(cid)
story[cid] = selfStory({"First message", "Second message", "Third etc.."}, cid, 6000)
return true
end
You should also call cancelStory(cid) whenever you use selfStory or selfSay to cancel the previous story.
~Summ
V Dat linkens