• 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!

NPC NPC random words problem.

kinglewey1st

Hey Jude.
Joined
Feb 14, 2013
Messages
174
Reaction score
2
Location
Canada
Currently I am trying to make an NPC say a random phrase when you say Hi to him.
But i cannot work it out, could any1 please tell me the error of my ways.
I've got something along the lines of this.. (obviously the rest of the npc is left out, im just looking for how to randomize the command SelfSay)



Code:
 local phrases = {"Damn i suck at scripting", "Help!", "SOME1 PLEASE HELP THIS NAP", "WHY NPCS SO HARD?"}


 selfSay(cid, phrases[math.random(1, #phrases)])

any help would be appreciated.
 
>npc/random.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Random" walkinterval="2000" floorchange="0">
	<health now="150" max="150"/>
	<look type="139" head="132" body="79" legs="97" feet="132" corpse="2212"/>
	<interaction range="3" idletime="30">

    <interact keywords="hi" focus="1">
      <!--These are the keywords will trigger this interaction-->
      <keywords>hello</keywords>
      <keywords>greet</keywords>

      <response>
        <action name="script">
		<![CDATA[
			msg = {
				"msg1", "msg2", "msg3"
				}
				
			selfSay(msg[math.random(1, #msg)], cid)
			_state.topic = 1
		]]>
        </action>
      </response>

      </interact>
	  
	  <interact keywords="bye" focus="0">
      <keywords>farewell</keywords>
		<response text="Good bye then."/>
    </interact>
	  </interaction>
</npc>

edit
XML:
msg = {
				"msg1", "msg2", "msg3"
				}
 
thank you soo much StreamSide, I will test this tomo. But Rep ++ for helping.

- - - Updated - - -
 
Last edited:
Lua:
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
function onThink()					npcHandler:onThink()					end

function greetCallback(cid)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	local msg = {
		"1", 
		"2", 
		"3", 
		"4", 
		"5"
	}
	npcHandler:setMessage(MESSAGE_GREET, msg[math.random(1, #msg)])
	talkState[talkUser] = 0
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())

in lua, what you request
 

Similar threads

Back
Top