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

Lua NPC Question...

Zorenia

Hoster of Zorenia
Joined
Jan 21, 2009
Messages
598
Reaction score
64
Location
The Netherlands
Hello people..
The NPC system I'm using (NEW TFS 8.62 client) got default greetings..
If I say hi it says: 22:52 Xaviron: Welcome, Zorenia! I have been expecting you.

but it stays in the Default channel.. and I want to change a couple of things:

*When I say "hi" the npc must answer back into the 'NPCs' channel, because I can't use blue words when the npc speak in default channel, and the script is for a Mission NPC and people don't know what they have to say to continue the conversational when I don't use blue words.
*I want to change the replay.. now the npc got a default replay.. "I've been expecting you.."

Also do anybody knows, how the npc can write a story.. when players enter the server the npc will tell a story about the server. what's the best way to do this?? I need the code
like: (if(msgcontains(msg, 'hiho')) then
selfSay('Please bring me 20 "ham"', cid) <-- but that isn't the best option I guess?


Xaviron XML
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Xaviron" script="data/npc/scripts/missions/beggar.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="153" head="57" body="20" legs="114" feet="116" addons="3"/>
</npc>

Xaviron script:
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
function onThink() 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
if(msgcontains(msg, 'quest')) then
selfSay('Ok, you can started {first mission}?', cid)
end
---------------------------------------------------------
if(msgcontains(msg, 'hiho')) then
selfSay('Please bring me 20 "ham"', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'ham') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,102) > 0) then
selfSay('You finished this mission.', cid)
else
if(doPlayerRemoveItem(cid, 2671, 20) == TRUE) then
setPlayerStorageValue(cid,102,1)
doPlayerAddExperience(cid,1000)
selfSay('Thank you! You finished all missions. (you received 1000 points of experience)', cid)
else
selfSay('You must have more items', cid)
end
end
return true
end


---------------------------------------------------------
if(msgcontains(msg, 'first mission')) then
selfSay('Please bring me 10 "meat"', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'meat') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,100) > 0) then
selfSay('You finished this mission.', cid)
else
if(doPlayerRemoveItem(cid, 2666, 10) == TRUE) then
setPlayerStorageValue(cid,100,1)
doPlayerAddExperience(cid,1000)
selfSay('Thank you! You can started "second mission".. (you received 1000 points of experience)', cid)
else
selfSay('You must have more items', cid)
end
end
return true
end
---------------------------------------------------------
if(msgcontains(msg, 'second mission')) then
selfSay('Please bring me 10 "ham"', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'ham') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,101) > 0) then
selfSay('You finished this mission.', cid)
else
if(doPlayerRemoveItem(cid, 2671, 10) == TRUE) then
setPlayerStorageValue(cid,101,1)
doPlayerAddExperience(cid,1000)
selfSay('Thank you! You can started "third mission".. (you received 1000 points of experience)', cid)
else
selfSay('You must have more items', cid)
end
end
return true
end
---------------------------------------------------------
if(msgcontains(msg, 'third mission')) then
selfSay('Please bring me 20 "ham"', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'ham') and talkState[talkUser] == 1) then
if (getPlayerStorageValue(cid,102) > 0) then
selfSay('You finished this mission.', cid)
else
if(doPlayerRemoveItem(cid, 2671, 20) == TRUE) then
setPlayerStorageValue(cid,102,1)
doPlayerAddExperience(cid,1000)
selfSay('Thank you! You finished all missions. (you received 1000 points of experience)', cid)
else
selfSay('You must have more items', cid)
end
end
return true
end


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


I'll hope anyone can help me soon as possible!
Thanks. yours,
Zorenia.
 
Last edited:
Anyone? :O hehe I tryed to use another NPC system.. but that's not working.
Does anyone have a script? or help me the npc will use NPCs channel and nog deffault?
 
In files data/npc/lib/npcsystem/npcsystem.lua and npchandler.lua, change:
Code:
	NPCHANDLER_CONVBEHAVIOR = CONVERSATION_[B][COLOR="red"]PRIVATE[/COLOR][/B]

To change the greeting response, you can put this line in the Lua script:
LUA:
npcHandler:setMessage(MESSAGE_GREET, "Welcome to my shop, |PLAYERNAME|.")
Or this in the XML file:
XML:
	<parameters>
		<parameter key="message_greet" value="Welcome to my shop, |PLAYERNAME|."/>
	</parameters>
 
Back
Top