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
local needItems = "one magic plate armor and three crystal coins?"
local idItems = {{2472, 1}, {2160,3}}
if(msgcontains(msg, 'promote') or msgcontains(msg, 'promotion')) then
selfSay('Do you want to buy promotion for '.. needItems ..'?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
for i = 1, #idItems do
if(getPlayerItemCount(cid, idItems[i][1]) >= idItems[i][2]) then
if(getPlayerPromotionLevel(cid) < 0) then
doPlayerSetPromotionLevel(cid, 1)
doPlayerRemoveItem(cid, idItems[i][1], idItems[i][2])
selfSay('Thanks, and here is your reward!', cid)
else
selfSay('Sorry, you have already promoted yourself.', cid)
end
else
selfSay('Sorry, you don\'t have the right items.', cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new()
isnt working `)` expected near eofLua: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 local needItems = "one magic plate armor and three crystal coins?" local idItems = {{2472, 1}, {2160,3}} if(msgcontains(msg, 'promote') or msgcontains(msg, 'promotion')) then selfSay('Do you want to buy promotion for '.. needItems ..'?', cid) talkState[talkUser] = 1 elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then for i = 1, #idItems do if(getPlayerItemCount(cid, idItems[i][1]) >= idItems[i][2]) then if(getPlayerPromotionLevel(cid) < 0) then doPlayerSetPromotionLevel(cid, 1) doPlayerRemoveItem(cid, idItems[i][1], idItems[i][2]) selfSay('Thanks, and here is your reward!', cid) else selfSay('Sorry, you have already promoted yourself.', cid) end else selfSay('Sorry, you don\'t have the right items.', cid) end end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()
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, 'promotion') or msgcontains(msg, 'something')) then
selfSay('Do you want to buy promotion for a magic plate armor and a sword?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerItemCount(cid, 2472) >= 1 and getPlayerItemCount(cid, 2376) >= 1 then
queststatus = getPlayerStorageValue(cid,9869)
if queststatus == -1 then
doPlayerSetPromotionLevel(cid, 1)
doPlayerRemoveItem(cid, 2472, 1)
doPlayerRemoveItem(cid, 2376, 1)
npcHandler:say("You are now promoted.", cid)
else
selfSay('You are already promoted.', cid)
end
else
selfSay('You don\'t have the items!', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Then not...!', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
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 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, 'promotion') or msgcontains(msg, 'something')) then selfSay('Do you want to buy promotion for a magic plate armor and a sword?', cid) talkState[talkUser] = 1 elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then if getPlayerItemCount(cid, 2472) >= 1 and getPlayerItemCount(cid, 2376) >= 1 then queststatus = getPlayerStorageValue(cid,9869) if queststatus == -1 then doPlayerSetPromotionLevel(cid, 1) doPlayerRemoveItem(cid, 2472, 1) doPlayerRemoveItem(cid, 2376, 1) npcHandler:say("You are now promoted.", cid) else selfSay('You are already promoted.', cid) end else selfSay('You don\'t have the items!', cid) end talkState[talkUser] = 0 elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then talkState[talkUser] = 0 selfSay('Then not...!', cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
I did mpa and sword as example.
for my own words?local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
00:20 Johnny: Welcome, Mamado! I have been expecting you.
You can give the NPC a greet message in the XML, if this is what you mean.
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Promoter" script="promote.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150"/>
<look type="136" head="20" body="59" legs="117" feet="92" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I can sell you {promotion}."/>
</parameters>
</npc>
OMG thxxxxxxxxxxI ment jou can just set a greet message in the XML of the NPC, this way you can let it say whatever you want.
Like this
Lua:<?xml version="1.0" encoding="UTF-8"?> <npc name="Promoter" script="promote.lua" walkinterval="2000" floorchange="0"> <health now="150" max="150"/> <look type="136" head="20" body="59" legs="117" feet="92" corpse="2212"/> <parameters> <parameter key="message_greet" value="Hello |PLAYERNAME|. I can sell you {promotion}."/> </parameters> </npc>