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, 'item 2296') or msgcontains(msg, 'buy 2296')) then
selfSay('To buy one 2296 you need 100 items 9020)', cid)
talkState[talkUser] = 1
end
if(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid,9020,100)
doPlayerAddItem(cid,2296,1)
selfSay('here you go!', cid)
end
else
selfSay('You dont have 100 items of 9020. Come back with everything!', cid)
end
talkState[talkUser] = 0
elseif (msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) ) then
talkState[talkUser] = 0
selfSay('Maybe later?.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
I did not test this script and i dont know if it works cause i edited it with the phone (im on the train) but you can try it!
Edit the texts yourself, i just put the id of the item because right now i dont know which items are
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, 'item 2296') or msgcontains(msg, 'buy 2296')) then selfSay('do you have 100 items 9020)?', cid) talkState[talkUser] = 1 end elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then if(getPlayerItemCount(cid, 9020) <= 99) then doPlayerRemoveItem(cid,9020,100) doPlayerAddItem(cid,2296,1) selfSay('here you go!', cid) end else selfSay('You dont have 100 items of 9020. Come back with everything!', cid) end talkState[talkUser] = 0 elseif (msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) ) then talkState[talkUser] = 0 selfSay('Maybe later?.', cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
If it doesnt work ill post another when im home (if no one gave u a working one)
if(getPlayerItemCount(cid, 9020) <= 99) then
doPlayerRemoveItem(cid,9020,100)
Code:if(getPlayerItemCount(cid, 9020) <= 99) then doPlayerRemoveItem(cid,9020,100)
Should be >= 100
14:58 GOD Drixo [350]: buy 2296
14:58 Drunko: do you have 100 items 9020?
14:58 Drunko: You dont have 100 items of 9020. Come back with everything!
Im at home in 20mins and ill post a working one haha
Or lets see if @WibbenZ or another one can fix it
EDIT: Script not working,
He instantly says the last 2 phrases and doesn't sell me the item
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, "2296")) then
npcHandler:say("To buy one 2296 you need 100 items 9020)", cid)
talkState[talkUser] = 1
end
if(msgcontains(msg, 'yes')) then
if(talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 2296, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You dont have 100 items of 9020. Come back with everything!", cid)
end
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no')) then
if(talkState[talkUser] == 1) then
npcHandler:say("Maybe later?", cid)
end
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Haha took years for me to understand npcs, if you ask me the npc system should be rewritten, atm its abit to hard for new users to understand it.Srry im a noob haha
@Darted450 try it again (i edited my post)
What about if I wanted this NPC to sell a second item? ID 1991, for 100 tokens (9020)
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, "2296")) then
npcHandler:say("To buy one 2296 you need 100 items 9020", cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, "itemname or id")) then
npcHandler:say("To buy one x you need xxx items xxxx", cid)
talkState[talkUser] = 2
end
if(msgcontains(msg, 'yes')) then
if(talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 2296, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You dont have 100 items of 9020. Come back with everything!", cid)
end
elseif(talkState[talkUser] == 2) then
if(getPlayerItemCount(cid, xxxx) >= xxx) then
doPlayerRemoveItem(cid, xxxx, xxx)
doPlayerAddItem(cid, xxxx, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You dont have xxx items of xxxx. Come back with everything!", cid)
end
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no')) then
if(talkState[talkUser] ~= 0) then
npcHandler:say("Maybe later?", cid)
end
talkState[talkUser] = 0
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, "enchantment")) then
npcHandler:say("Would you like to purchase a {rune of enchantment}, for the low price of 100 tokens?", cid)
talkState[talkUser] = 1
end
if(msgcontains(msg, "wares")) then
npcHandler:say("I can sell you an {rune of enchantment}, {godly bags}, or {godly bps}", cid)
talkState[talkUser] = 2
end
if(msgcontains(msg, "godly bags")) then
npcHandler:say("For 100 tokens, I can sell you a {godly bag of distance}, a {godly bag of magic}, a {godly bag of shielding}, a {godly bag of sword fighting}, a {godly bag of axe fighting}, or a {godly bag of club fighting}.", cid)
talkState[talkUser] = 3
end
if(msgcontains(msg, "godly bps")) then
npcHandler:say("For 175 tokens, I can sell you a {godly bp of distance}, a {godly bp of magic}, a {godly bp of shielding}, a {godly bp of sword fighting}, a {godly bp of axe fighting}, or a {godly bp of club fighting}.", cid)
talkState[talkUser] = 4
end
if(msgcontains(msg, "bag of distance")) then
npcHandler:say("Would you like to purchase a godly bag of distance for 100 tokens?", cid)
talkState[talkUser] = 5
end
if(msgcontains(msg, "bag of magic")) then
npcHandler:say("Would you like to purchase a godly bag of magic for 100 tokens?", cid)
talkState[talkUser] = 6
end
if(msgcontains(msg, "bag of shield")) then
npcHandler:say("Would you like to purchase a godly bag of shielding for 100 tokens?", cid)
talkState[talkUser] = 7
end
if(msgcontains(msg, "bag of sword")) then
npcHandler:say("Would you like to purchase a godly bag of sword fighting for 100 tokens?", cid)
talkState[talkUser] = 8
end
if(msgcontains(msg, "bag of axe")) then
npcHandler:say("Would you like to purchase a godly bag of axe fighting for 100 tokens?", cid)
talkState[talkUser] = 9
end
if(msgcontains(msg, "bag of club")) then
npcHandler:say("Would you like to purchase a godly bag of club fighting for 100 tokens?", cid)
talkState[talkUser] = 10
end
if(msgcontains(msg, "bp of distance")) then
npcHandler:say("Would you like to purchase a godly bp of distance for 175 tokens?", cid)
talkState[talkUser] = 11
end
if(msgcontains(msg, "bp of magic")) then
npcHandler:say("Would you like to purchase a godly bp of magic for 175 tokens?", cid)
talkState[talkUser] = 12
end
if(msgcontains(msg, "bp of shield")) then
npcHandler:say("Would you like to purchase a godly bp of shielding for 175 tokens?", cid)
talkState[talkUser] = 13
end
if(msgcontains(msg, "bp of sword")) then
npcHandler:say("Would you like to purchase a godly bp of sword fighting for 175 tokens?", cid)
talkState[talkUser] = 14
end
if(msgcontains(msg, "bp of axe")) then
npcHandler:say("Would you like to purchase a godly bp of axe fighting for 175 tokens?", cid)
talkState[talkUser] = 15
end
if(msgcontains(msg, "bp of club")) then
npcHandler:say("Would you like to purchase a godly bp of club fighting for 175 tokens?", cid)
talkState[talkUser] = 16
end
if(msgcontains(msg, 'yes')) then
if(talkState[talkUser] == 1) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 2296, 1)
npcHandler:say("Enjoy! Remember, these can only be used once.", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 5) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1991, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 6) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1995, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 7) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1993, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 8) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1997, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 9) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1996, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 10) then
if(getPlayerItemCount(cid, 9020) >= 100) then
doPlayerRemoveItem(cid, 9020, 100)
doPlayerAddItem(cid, 1994, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 100 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 11) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 1998, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 12) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 2002, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 13) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 2000, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 14) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 2004, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 15) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 2003, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
elseif(talkState[talkUser] == 16) then
if(getPlayerItemCount(cid, 9020) >= 175) then
doPlayerRemoveItem(cid, 9020, 175)
doPlayerAddItem(cid, 2001, 1)
npcHandler:say("There you go!", cid)
else
npcHandler:say("You don't have 175 tokens. Come back when you have enough!", cid)
end
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no')) then
if(talkState[talkUser] == 1) then
npcHandler:say("Maybe later?", cid)
end
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())