Hey, I am still playing a bit with my OT and now I am creating Smith npc. He basically does same thing as Uzgod in Rashid quest - takes some ore and money and gives a weapon.
So here's a script, pretty obviously, based on A Sweaty Cyclops from some rl map distro.
Thing is that part:
can eat items if player does not have second item. I was thinking about using something like this code...
[lua
if doPlayerRemoveItem(cid, xx, x) then
if doPlayerRemove... then
if do...[/code]
...but its looks quite unoptimized and messy. So could anyone of you guide me on similar script for npc or hint how to do it in less messy way?
So here's a script, pretty obviously, based on A Sweaty Cyclops from some rl map distro.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local done = 'Here you are.'
local miss = 'I\'m afraid, but you don\'t have required items.'
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, 'offer') then
npcHandler:say('I can smelt metals for you and craft fine weapons', cid)
elseif msgcontains(msg, 'weapons') then
npcHandler:say('I can craft nearly every weapon', cid)
elseif msgcontains(msg, 'Blacksteel Sword') then
if getPlayerItemCount(cid, 5880) >= 55 and getPlayerItemCount(cid, 5944) >=2 and getPlayerItemCount(cid, 2144) >= 12 and getPlayerMoney(cid) >= 1500 then
npcHandler:say('Did you bring me 55 oz. of iron ore, 2 soul orbs, 12 black pearls and 1500 gp?', cid)
talk_state = 1
else
npcHandler:say('I need 55 oz. of iron, 2 soul orbs, 12 black pearls. Fee is 1,500 gp', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if doPlayerRemoveItem(cid, 5880, 55) and doPlayerRemoveItem(cid, 5944, 2) and doPlayerRemoveItem(cid, 2144, 12) and getPlayerMoney(cid) >= 1500 then
npcHandler:say(done, cid)
doPlayerBuyItem(cid, 7406, 1, 1500)
else
npcHandler:say(miss, cid)
end
elseif msgcontains(msg, 'no') and talk_state >= 1 then
npcHandler:say('Okay then.')
talk_state = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Lua:
if doPlayerRemoveItem(cid, 5880, 55) and doPlayerRemoveItem(cid, 5944, 2) and doPlayerRemoveItem(cid, 2144, 12) and getPlayerMoney(cid) >= 1500 then
[lua
if doPlayerRemoveItem(cid, xx, x) then
if doPlayerRemove... then
if do...[/code]
...but its looks quite unoptimized and messy. So could anyone of you guide me on similar script for npc or hint how to do it in less messy way?
Last edited: