• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Long Story Function For NPC Channel

Rizz

Quited with Tibia/OT
Joined
Jun 16, 2007
Messages
573
Reaction score
4
Location
Stockholm, Sweden
Only works in 0.3.5pl2 or higher.

Lua:
function doCreatureSayWithDelay(cid,text,type,delay,e,pcid)
	if delay<=0 then
		doCreatureSay(cid,text,type, false,pcid)
	else
		local func=function(pars)
			doCreatureSay(pars.cid,pars.text,pars.type, false,pars.pcid)
			pars.e.done=TRUE
		end
		e.done=FALSE
		e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e,pcid=pcid})
	end
end

function doNPCTalkALot(msgs,interval,pcid)
	local e={}
	local ret={}
	if interval==nil then interval=10000 end --10 seconds is default time between messages
		for aux=1,table.getn(msgs) do
		e[aux]={}
		doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux],pcid)
		table.insert(ret,e[aux])
	end
	return(ret)
end

Example Usage:

Lua:
doNPCTalkALot({"Message One...", "Message Two...", "Message 3...", "Last Message."}, 10000, cid)
Can be unlimited amount of msgs. 10000 is time between msgs = 10 seconds, default is 10 seconds as well.


Based it on the other older script. Credits to the creator of that one.


Rizz
 
Last edited:
Well done Rizzy +Repped Ill definitely use this.

But:

Only works in 0.3.5pl2 or higher.

Typo? or how do I find 0.3.5pl2? According to the distro's thread we are currently on pl 1.. or maybe Im missing something or understood the thread wrong or something ;)

Anyways very creative keep it up :thumbup:
 
I don't have pl2, but pl2 will contain a necessary fix.

Here's the fix (0.3.5 and 0.3.5pl1):

luascript.cpp
PHP:
	if(params > 3)
		lua_pushboolean(L, g_game.internalCreatureSay(creature, type, text, ghost, &list, &pos));
	else
		lua_pushboolean(L, g_game.internalCreatureSay(creature, type, text, ghost, &list));

to
PHP:
	if(params > 5)
		lua_pushboolean(L, g_game.internalCreatureSay(creature, type, text, ghost, &list, &pos));
	else
		lua_pushboolean(L, g_game.internalCreatureSay(creature, type, text, ghost, &list));
 
sweet, good job, and chris77 we needed this more than you realize till now ;p
 
somebody explain me how to add this please?
I'm confused >.<
 
Last edited:
BUMP

If you want:

Put this on "data/npc/lib/npc.lua" file:

Code:
function tellHistory(cid,delay,messages)
		for i = 1,#messages do
			addEvent(doCreatureSay,delay * i, getNpcCid(), messages[i], TALKTYPE_PRIVATE_NP, false, cid)
		end
end

HOW TO USE:

Code:
tellHistory(cid,2,{"message 1","message 2"....})

OR

Code:
local messages = {
'Hi',
'How are you today',
'Bye'
}

tellHistory(cid,2,messages)

Delay in seconds please

If you declare "2" as the delay, messages will be shown every 2 seconds
 
Can someone give me an example as to how this is used with the NPC? I'm kinda noobish with this.. But i really want this to work on the server i'm working on.. I'm confused on how i add...

Code:
 local messages = {
'Hi',
'How are you today',
'Bye'
}

tellHistory(cid,2,messages)

Thanks in advance.
 
Can someone give me an example as to how this is used with the NPC? I'm kinda noobish with this.. But i really want this to work on the server i'm working on.. I'm confused on how i add...

Code:
 local messages = {
'Hi',
'How are you today',
'Bye'
}

tellHistory(cid,2,messages)

Thanks in advance.

~/npcs/Unix.xml
Code:
... ~
    <npc name="Unix the OS" script="matlock_marathon.lua" walkinterval="0" floorchange="0" >
    ~ ...

~/npcs/scripts/matlock_marathon.lua
Code:
... ~ 
    function creatureSayCallback(cid, type, msg)
        if (not npcHandler:isFocused(cid)) then return false ; end ; 
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid ; 

        if msgcontains(msg, 'apple') and talkState[cid] == 1 then
            selfSay('Ahh i remember you.. ' .. getCreatureName(cid) .. ', you little pecker. [COLOR=#800080]You fucking misquoted me, saying I didn\'t want to associate with Mac.[/COLOR]', cid) ; 
            selfSay('[COLOR=#800080]God damn kids. Getting me out of my lazyboy while I\'m watching a Matlock marathon. Mac is just an asshole and a corporate tool. Don\'t bother me while I\'m watching a {Matlock} marathon.[/COLOR]', cid) ; 
            selfSay('[COLOR=#800080]I don\'t care if the fucking Russians fire their missiles at us! Don\'t bother me during Matlock![/COLOR]', cid) ; talkState[talkUser] = 2 ; 
        elseif msgcontains (msg, 'matlock') and talkState[talkUser] == 2 then
~ ...

->

Code:
... ~ 
    local [COLOR=#0000ff]Dialogue.AppleMatlock[/COLOR] = { 
         '[COLOR=#800080]You fucking misquoted me, saying I didn\'t want to  associate with Mac.[/COLOR]', 
         '[COLOR=#800080]God damn kids. Getting me out of my lazyboy while I\'m  watching a Matlock marathon. Mac is just an asshole and a corporate  tool.[/COLOR]', 
         '[COLOR=#800080]Don\'t bother me while I\'m watching a {Matlock} marathon.[/COLOR]', 
         '[COLOR=#800080]I don\'t care if the fucking Russians fire their missiles at us! Don\'t bother me during Matlock![/COLOR]' ; 
         } ; 

    function creatureSayCallback(cid, type, msg)
        if (not npcHandler:isFocused(cid)) then return false ; end ; 
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid ; 

        if msgcontains(msg, 'apple') and talkState[cid] == 1 then
            selfSay('Ahh i remember you.. ' .. getCreatureName(cid) .. ',  you little pecker.', cid) ; 
            [COLOR=#ff8c00]tellHistory[/COLOR](cid, 1500, [COLOR=#0000ff]Dialogue.AppleMatlock[/COLOR]) ; talkState[talkUser] = 2 ; 
        elseif msgcontains (msg, 'matlock') and talkState[talkUser] == 2 then
~ ...
 
my example assumes you made the sensible modification to use milliseconds instead for the interval parameter.
 
Back
Top