Zombiexon
Member
Witam,
Mam mały problem otóż kiedy pisze do NPC , podczas rozmowy wywala mi 2x komunikat 1
i dostaje tylko 1 platinium coina.
Skrypt:
Wie ktoś może o co be?;p
Mam mały problem otóż kiedy pisze do NPC , podczas rozmowy wywala mi 2x komunikat 1
i dostaje tylko 1 platinium coina.
PHP:
17:16 Tester: hi
17:16 Eva: Welcome Tester! What can I do for you?
17:16 Tester: change gold
17:16 Eva: How many platinum coins would you like to get?
17:16 Tester: 3
17:16 Eva: So you would like me to change 3 of your platinum coins into 300 gold coins?
17:16 Tester: yes
17:16 Eva: So you would like me to change 0 of your platinum coins into 0 gold coins?
17:17 Eva: Good bye.
Skrypt:
PHP:
local difference = 1
local typeToChange = ""
local newType = ""
local multiplier = 1
local count = 0
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)
-- Resetting talkState[talkUser]
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
talkState[talkUser] = 0
return true
end
function getCountChangeGold(msg)
-- made by Jiddo?
local ret = 0
local b, e = string.find(msg, "%d+")
if b ~= nil and e ~= nil then
ret = tonumber(string.sub(msg, b, e))
end
return ret
end
function msgcontains(txt, str)
return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
function creatureSayCallback (cid, type, msg)
if(npcHandler.focus ~= cid) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, 'time') then
selfSay('It is exactly ' .. getWorldTime() .. '.')
end
if(msgcontains(msg, "change gold") or msgcontains(msg, "platinium coin")) then
npcHandler:say("How many platinum coins would you like to get?",cid)
talkState[talkUser] = 1
elseif talkState[talkUser] == 1 then
if talkState[talkUser] == 1 then
count = getCountChangeGold(msg)
typeToChange = "platinum"
newType = "gold"
multiplier = 100
difference = 1
gold1 =count*multiplier
gold2 =count*difference
selfSay('So you would like me to change '.. count*difference ..' of your '.. typeToChange ..' coins into '.. count*multiplier ..' '.. newType ..' coins?')
talkState[talkUser] = 1
if(msgcontains(msg, "yes") and talkState[talkUser] == 1) then
if doPlayerRemoveItem(cid,2148,gold1) == TRUE then -- edit the amount of gold here
doPlayerAddItem(cid,2152,gold2)
talkState[talkUser] = 0
else
selfSay('You don\'t have enough '.. typeToChange ..' coins.')
talkState[talkUser] = 0
end
end
end
elseif(talkState[talkUser] == 1) then
npcHandler:say("Not good enough, eh? What else can I do for you?", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Wie ktoś może o co be?;p