Zysen
=)
Name: Old Blacksmither
Type: NPC
Author: Oneshot
Information: He exchanges item(s) for some items.
Create a file called blacksmith.lua in data / npc / scripts with the name you want. Put the contents below:
Create an XML file in data/npc:
You can change the look of the NPC by changing the numbers (outfit looktypes,and colors):
To configure the recipes,change the table below:
Always follow table structure by placing a comma at the end key "}" except the last.
Type: NPC
Author: Oneshot
Information: He exchanges item(s) for some items.
Create a file called blacksmith.lua in data / npc / scripts with the name you want. Put the contents below:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local forge = {}
local recipes = {
[2390] = {
{2157, 1},
{2400, 1},
{2149, 100}
}
}
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 onGreetCallback(cid)
talkState[cid] = 0
forge[cid] = {match = nil, recipe = nil}
return true
end
function onCreatureSayCallback(cid, class, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if talkState[talkUser] == 0 then
for itemid, items in pairs(recipes) do
if msgcontains(msg, getItemNameById(itemid)) then
forge[talkUser] = {match = itemid, recipe = items}
break
end
end
if forge[talkUser].match ~= nil then
local str, sep = "Good choice, I will need"
local n = 1
for _, item in ipairs(forge[talkUser].recipe) do
sep = (n == 1) and " " or (n == #forge[talkUser].recipe and " and " or ", ")
str = str .. sep .. (item[2] or 1) .." ".. getItemNameById(item[1])
n = n + 1
end
str = str ..". Agreed?"
npcHandler:say(str, cid)
talkState[talkUser] = 1
else
npcHandler:say("Sorry, I don't know how to forge it.", cid)
end
elseif talkState[talkUser] == 1 then
if msgcontains(msg, "yes") then
local ret = {}
for _, item in ipairs(forge[talkUser].recipe) do
local g = getPlayerItemById(cid, true, item[1])
if g.uid > 0 and math.max(1, g.type) >= item[2] then
table.insert(ret, {g.uid, item[2]})
else
ret = {}
break
end
end
if #ret > 0 then
for _, item in ipairs(ret) do
doRemoveItem(item[1], item[2])
end
doPlayerAddItemEx(cid, doCreateItemEx(forge[talkUser].match, 1))
npcHandler:say("Thank you, heh, here is your ".. getItemNameById(forge[talkUser].match) ..".", cid)
else
npcHandler:say("Sorry, but you don't have all the items I need.", cid)
talkState[talkUser] = 0
forge[talkUser] = {match = nil, recipe = nil}
end
elseif msgcontains(msg, "no") then
npcHandler:say("Alright, do you need anything else?.", cid)
talkState[talkUser] = 0
forge[talkUser] = {match = nil, recipe = nil}
end
end
return true
end
local greet, sep = "Hello, |PLAYERNAME|. Actually I can trade {rare} stuff for some items, pretty, heh? This is what I have:"
local n = 1
for item, recipe in pairs(recipes) do
sep = (n == 1) and " " or (n == #recipes and " and " or ", ")
greet = greet .. sep .. "{".. getItemNameById(item) .."}"
n = n + 1
end
npcHandler:setMessage(MESSAGE_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, onCreatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, onGreetCallback)
npcHandler:addModule(FocusModule:new())
Create an XML file in data/npc:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Old Blacksmither" script="name_of_the_script.lua" walkinterval="0" floorchange="0">
<health now="100" max="100"/>
<look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
</npc>
You can change the look of the NPC by changing the numbers (outfit looktypes,and colors):
XML:
<look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
To configure the recipes,change the table below:
LUA:
local recipes = {
[2390] = {
{2157, 1},
{2400, 1},
{2149, 100}
}
}
Always follow table structure by placing a comma at the end key "}" except the last.
13:44 Zysen: hi
13:45 Old Blacksmither: Hello, Zysen. Actually I can trade rare stuff for some items, pretty, heh? This is what I have: magic longsword
13:45 Zysen: magic longsword
13:45 Old Blacksmither: Good choice, I will need 1 gold nugget, 1 magic sword and 100 small emerald. Agreed?
Yours,
Zysen.
Zysen.
Last edited: