• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[8.1]NPC say Random Help

Hekan

New Member
Joined
Jun 14, 2008
Messages
94
Reaction score
0
How can i make NPC random says? Monsters say something righ? How to make NPC random says? Its like in real. Can someon Help me?

Sorry for my bad english :(
 
Code:
function onThink()
	local random = math.random(5)
	if random == 1  then
		selfSay("ho !")
	elseif random == 2 then
		selfSay("ho ho !")
	elseif random == 3 then
		selfSay("ho ho ho!")
	elseif random == 4 then
		selfSay("ho ho ho ho!")
	elseif random == 5 then
		selfSay("ho ho ho ho hohohhhih!")
end
 
Code:
function onThink()
	local random = math.random(5)
	if random == 1  then
		selfSay("ho !")
	elseif random == 2 then
		selfSay("ho ho !")
	elseif random == 3 then
		selfSay("ho ho ho!")
	elseif random == 4 then
		selfSay("ho ho ho ho!")
	elseif random == 5 then
		selfSay("ho ho ho ho hohohhhih!")
end


If you say to ppl how it works.
Then ppl will give you rep+
 
Just copy this, and paste in script you want to have it.

Remember if its NPC with Jiddo system then you need to deleted this part in NPC:
Code:
function onThink() npcHandler:onThink()	end
But now NPC wont farewell : < . I'l try do it in another way.
 
Code:
local something = 0

function onThink()

    if something < 5  then
        something = something + 1
    elseif random == 6 then
        selfSay("Haidihoo")
        something = 0
    end
end
Would make him say Haidihoo at a specific time, once every 6 seconds I believe, can't really remember how often onThink refreshes..
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end

local something = 0

function onThink()

    if something < 5  then
        something = something + 1
    elseif random == 6 then
        selfSay("Haidihoo")
        something = 0
    end
   
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)

     if not npcHandler:isFocused(cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     -- here comes what the NPC should do

     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Why it doesn't work?
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

function onCreatureAppear(cid)       npcHandler:onCreatureAppear(cid)       end
function onCreatureDisappear(cid)     npcHandler:onCreatureDisappear(cid)       end
function onCreatureSay(cid, type, msg)     npcHandler:onCreatureSay(cid, type, msg)     end

local something = 0

function onThink()

    if something < 5  then
        something = something + 1
    elseif random == 6 then
        selfSay("Haidihoo")
        something = 0
    end
  
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)

     if not npcHandler:isFocused(cid) then
         return false
     end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

     -- here comes what the NPC should do

     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Why it doesn't work?
elseif something >= 6 then

You realize this topic is from 2008 right ?
 
Back
Top