• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action deleted thread

PHP:
24.08.10
- updated npc, now he sells book and blacksmith hammer
- added 40 new recipes
- added image of all recipes
- made own skill calculator
- minor bug fixes
- changed config.blackSmithing to local 60010 that should not be changed

Updated in first post.
 
Last edited:
based on Alchemy system by Shinmaru and soul4soul.
nothing special
 
based on Alchemy system by Shinmaru and soul4soul.
nothing special

Based on alchemy system? You kiddin' me, right? I made this script from zero and It it based on world of warcraft's blacksmithing system, just like alchemy system. If you're so sure of your view just quote at least one thing from alchemy system that my bs system is based on. No such a thing? I thought so... Make better if you say nothing special. ; )
 
PHP:
Changelog:
24.08.10
- minor bug fixes
- added smithing to the npc
- added jewelcrafting recipes
- added missions for a recipe (give item - > take recipe)

If you want to make people obtain recipe by quest (give item - > take recipe) you have to set recipe["name"].sellable to false and add to recipe["name"] a table called mission. f.e.

Lua:
["demon armor"] = {
	skill = 10,
	storage = 1000,
	price = 7000,
	talkState = 50,
	sellable = false,
	mission = {
		[2160] = 6,
		[5320] = 5
	}
	requiredItems = {
		[2225] = 2,
	}
},

If you don't add a table called "mission" the npc just won't sell it, and then you can make your own quest, npc or box for that recipe.
 
nice script! I'm adding a similar system to my game so this will be a great reference for me to look at if I get lost :)

Ignore muppet or whatever he's called, he flames everything but spams the support thread 'cos he can't get his OTS working. Jealousy of people with talent.
 
Thanks to all who like my scripts. :)

PHP:
Changelog:
26.08.10
- added a recipe scrolls quest

I added this, becouse some ppl would like to make a quest (chest -> get scroll) for a recipe rather than selling it by npc for some items.
All codes for that are added to the first post.
 
Awesome script!!!! and rep 4 u!! You should put all both the profession script and the Blacksmith script together, bundle them, will be sure to test this, btw, what TFS is this for?
 
Awesome script!!!! and rep 4 u!! You should put all both the profession script and the Blacksmith script together, bundle them, will be sure to test this, btw, what TFS is this for?

0.3.6 - yea, i thought to put both scripts together, maybe i will when i have some spare time ;p
 
[26/08/2010 20:26:50] [Error - LuaScriptInterface::loadFile] cannot open data/actions/scripts/blacksmithing.lua: No such file or directory
[26/08/2010 20:26:50] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/blacksmithing.lua)
[26/08/2010 20:26:50] cannot open data/actions/scripts/blacksmithing.lua: No such file or directory
[26/08/2010 20:26:50] [Error - LuaScriptInterface::loadFile] cannot open data/actions/scripts/scroll.lua: No such file or directory
[26/08/2010 20:26:50] [Warning - Event::loadScript] Cannot load script (data/actions/scripts/scroll.lua)
[26/08/2010 20:26:50] cannot open data/actions/scripts/scroll.lua: No such file or directory

how come? <_< awesome script, btw.
 
Idea for you!!!!
You can also make it that depending on the skills of the "Black Smith" has it will add some def and/or attk, using a formula, also it can be made that it randomly selects whether it adds attk, def or attk and def to the item, the folmula can also have a randome variating 5 points.
Example
base attack is 4 so it may variate from 5 to 9 , but that all has to be made with a formula based on his blacksmithing skill.
 
Turned the Blacksmith System into a MOD!

I'm about to test a MOD version of this I'll let you know of the results.
TFS I'm testing on is TFS 0.4!
EDIT:
Success I have placed it on a MOD only the BlackSmithing System and you don't need to place it that huge list on constant, I just placed a "domodlib("blalblabla")" and it will get it from the mod!
UPDATE:
Here, I have added your Profession System too, I changed a little stuff just to avoid the script conflicting

MOD:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Profession System" version="1.0" author="teckman" enabled="yes">
	<config name="proinfo"><![CDATA[
recipes = {
	["steel shield"] = {skill = 0, storage = 100, price = 50, talkState = 1, sellable = true, requiredItems = {[2152] = 1, [2225] = 1}},
	["plate shield"] = {skill = 10, storage = 101, price = 100, talkState = 2, sellable = true, requiredItems = {[2152] = 2, [2225] = 2}},
	["brass shield"] = {skill = 25, storage = 102, price = 150, talkState = 3, sellable = true, requiredItems = {[2152] = 3, [2225] = 2}},
	["battle shield"] = {skill = 45, storage = 103, price = 200, talkState = 4, sellable = true, requiredItems = {[2152] = 2, [2225] = 3}},
	["guardian shield"] = {skill = 75, storage = 104, price = 250, talkState = 5, sellable = true, requiredItems = {[2152] = 20, [2225] = 1}},
	["dragon shield"] = {skill = 90, storage = 105, price = 700, talkState = 6, sellable = true, requiredItems = {[2152] = 20, [7399] = 1}},
	["crown shield"] = {skill = 120, storage = 106, price = 1500, talkState = 7, sellable = true, requiredItems = {[5889] = 1, [5882] = 2}},
	["demon shield"] = {skill = 165, storage = 107, price = 1700, talkState = 8, sellable = true, requiredItems = {[5888] = 3, [7393] = 1}},
	["mastermind shield"] = {skill = 190, storage = 108, price = 5000, talkState = 9, sellable = true, requiredItems = {[5892] = 2, [5887] = 1, [5889] = 2, [2150] = 15}},
	["chain legs"] = {skill = 0, storage = 109, price = 50, talkState = 10, sellable = true, requiredItems = {[2152] = 1, [2225] = 1}},
	["brass legs"] = {skill = 25, storage = 110, price = 150, talkState = 11, sellable = true, requiredItems = {[2152] = 2, [2225] = 2}},
	["plate legs"] = {skill = 55, storage = 111, price = 300, talkState = 12, sellable = true, requiredItems = {[2152] = 3, [2225] = 3}},
	["knight legs"] = {skill = 85, storage = 112, price = 1000, talkState = 13, sellable = true, requiredItems = {[2152] = 40, [2225] = 1}},
	["crown legs"] = {skill = 125, storage = 113, price = 1500, talkState = 14, sellable = true, requiredItems = {[5889] = 1, [5882] = 3}},
	["golden legs"] = {skill = 170, storage = 114, price = 20000, talkState = 15, sellable = true, requiredItems = {[5887] = 2, [5892] = 2, [5889] = 2, [5885] = 1, [5884] = 1, [9971] = 2}},
	["brass helmet"] = {skill = 0, storage = 115, price = 50, talkState = 16, sellable = true, requiredItems = {[2225] = 1}},
	["viking helmet"] = {skill = 10, storage = 116, price = 100, talkState = 17, sellable = true, requiredItems = {[2152] = 1, [2225] = 1}},
	["chain helmet"] = {skill = 20, storage = 117, price = 150, talkState = 18, sellable = true, requiredItems = {[2152] = 2, [2225] = 1}},
	["iron helmet"] = {skill = 40, storage = 118, price = 200, talkState = 19, sellable = true, requiredItems = {[2152] = 2, [2225] = 3}},
	["steel helmet"] = {skill = 60, storage = 119, price = 200, talkState = 20, sellable = true, requiredItems = {[2152] = 3, [2225] = 2}},
	["crown helmet"] = {skill = 90, storage = 120, price = 500, talkState = 21, sellable = true, requiredItems = {[5889] = 1, [5882] = 1}},
	["warrior helmet"] = {skill = 120, storage = 121, price = 700, talkState = 22, sellable = true, requiredItems = {[5889] = 1, [5885] = 1}},
	["crusader helmet"] = {skill = 150, storage = 122, price = 750, talkState = 23, sellable = true, requiredItems = {[5889] = 1, [2225] = 5}},
	["royal helmet"] = {skill = 180, storage = 123, price = 1500, talkState = 24, sellable = true, requiredItems = {[5887] = 1, [5892] = 1, [5885] = 1}},
	["skull helmet"] = {skill = 190, storage = 124, price = 2000, talkState = 25, sellable = true, requiredItems = {[5887] = 1, [5892] = 1, [2230] = 3, [2231] = 3, [2229] = 2}},
	["steel boots"] = {skill = 160, storage = 125, price = 5000, talkState = 26, sellable = true, requiredItems = {[5887] = 2, [5892] = 1}},
	["scale armor"] = {skill = 0, storage = 126, price = 50, talkState = 27, sellable = true, requiredItems = {[2152] = 1, [2225] = 1}},
	["brass armor"] = {skill = 10, storage = 127, price = 100, talkState = 28, sellable = true, requiredItems = {[2152] = 2, [2225] = 1}},
	["chain armor"] = {skill = 25, storage = 128, price = 150, talkState = 29, sellable = true, requiredItems = {[2152] = 2, [2225] = 2}},
	["plate armor"] = {skill = 45, storage = 129, price = 250, talkState = 30, sellable = true, requiredItems = {[2152] = 3, [2225] = 3}},
	["noble armor"] = {skill = 75, storage = 130, price = 300, talkState = 31, sellable = true, requiredItems = {[2152] = 10, [2225] = 1, [2147] = 1}},
	["knight armor"] = {skill = 95, storage = 131, price = 400, talkState = 32, sellable = true, requiredItems = {[2152] = 40, [2225] = 1}},
	["crown armor"] = {skill = 125, storage = 132, price = 700, talkState = 33, sellable = true, requiredItems = {[5889] = 1, [5882] = 4}},
	["golden armor"] = {skill = 145, storage = 133, price = 1900, talkState = 34, sellable = true, requiredItems = {[5887] = 1, [5892] = 1, [9971] = 2}},
	["dragon scale mail"] = {skill = 170, storage = 134, price = 2500, talkState = 35, sellable = true, requiredItems = {[5887] = 2, [5892] = 2, [5920] = 5}},
	["magic plate armor"] = {skill = 200, storage = 135, price = 40000, talkState = 36, sellable = true, requiredItems = {[5887] = 8, [2153] = 1, [2154] = 1, [2155] = 1, [2156] = 1, [2158] = 1}},
	["modified crossbow"] = {skill = 140, storage = 136, price = 5000, talkState = 37, sellable = true, requiredItems = {[2455] = 1, [5887] = 1}},
	["royal spear"] = {skill = 80, storage = 137, price = 600, talkState = 38, sellable = true, requiredItems = {[2389] = 1, [2152] = 1}},
	["spear"] = {skill = 30, storage = 138, price = 200, talkState = 39, sellable = true, requiredItems = {[2225] = 1}},
	["throwing knife"] = {skill = 50, storage = 139, price = 250, talkState = 40, sellable = true, requiredItems = {[2225] = 1}},
	["violet gem"] = {skill = 150, storage = 142, price = 2000, talkState = 43, sellable = true, requiredItems = {[2150] = 25}},
	["yellow gem"] = {skill = 150, storage = 143, price = 2000, talkState = 44, sellable = true, requiredItems = {[9970] = 15}},
	["green gem"] = {skill = 150, storage = 144, price = 2000, talkState = 45, sellable = true, requiredItems = {[2149] = 25}},
	["red gem"] = {skill = 150, storage = 145, price = 2000, talkState = 46, sellable = true, requiredItems = {[2147] = 25}},
	["blue gem"] = {skill = 0, storage = 146, price = 2000, talkState = 47, sellable = true, requiredItems = {[2146] = 25}},
}

recipe = {
	-- herbalism (herbs)
	[2740] = {tool = 2550, skill = 0, loot = {{2801, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2767] = {tool = 2550, skill = 20, loot = {{2804, 4}, {2803, 7}, {2799, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2771] = {tool = 2550, skill = 60, loot = {{2801, 4}, {2802, 4}, {2804, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2741] = {tool = 2550, skill = 150, loot = {{2800, 6}, {2802, 4}, {2803, 5}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2768] = {tool = 2550, skill = 250, loot = {{2801, 7}, {2803, 5}, {2799, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2743] = {tool = 2550, skill = 400, loot = {{2798, 4}, {2804, 5}, {2799, 4}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2769] = {tool = 2550, skill = 450, loot = {{2805, 4}, {2802, 5}, {2804, 3}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	[2783] = {tool = 2550, skill = 550, loot = {{2801, 6}, {2800, 7}, {2803, 6}}, effect = CONST_ME_MAGIC_GREEN, profession = "herbalism"},
	--herbalism (mushrooms)
	[4179] = {tool = 2566, skill = 10, loot = {{2794, 2}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4180] = {tool = 2566, skill = 40, loot = {{2792, 3}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4181] = {tool = 2566, skill = 90, loot = {{2794, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4178] = {tool = 2566, skill = 160, loot = {{2792, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4171] = {tool = 2566, skill = 280, loot = {{2787, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4170] = {tool = 2566, skill = 420, loot = {{2791, 5}, {2789, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4179] = {tool = 2566, skill = 510, loot = {{2789, 6}, {2791, 7}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4177] = {tool = 2566, skill = 550, loot = {{2793, 5}, {2787, 7}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	--herbalism (big mushrooms)
	[4167] = {tool = 2550, skill = 50, loot = {{2791, 3}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4168] = {tool = 2550, skill = 150, loot = {{2790, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4169] = {tool = 2550, skill = 250, loot = {{2791, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4174] = {tool = 2550, skill = 350, loot = {{2790, 5}, {2795, 5}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4175] = {tool = 2550, skill = 450, loot = {{2791, 4}, {2796, 6}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4172] = {tool = 2550, skill = 550, loot = {{2791, 5}, {2796, 6}, {2792, 4}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	[4173] = {tool = 2550, skill = 550, loot = {{2795, 5}, {2787, 7}, {2793, 7}}, effect = CONST_ME_MAGIC_RED, profession = "herbalism"},
	--mining (stones)
	[3607] = {tool = 2422, skill = 0, loot = {{2150, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[3608] = {tool = 2422, skill = 10, loot = {{2149, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[3609] = {tool = 2422, skill = 50, loot = {{2150, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[3615] = {tool = 2422, skill = 100, loot = {{2147, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[3616] = {tool = 2422, skill = 130, loot = {{2149, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[1357] = {tool = 2422, skill = 190, loot = {{2146, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[1356] = {tool = 2422, skill = 280, loot = {{9970, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[1285] = {tool = 2422, skill = 320, loot = {{2149, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	--mining (minerals, metals)
	[5868] = {tool = 2553, skill = 100, loot = {{2149, 2}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[5867] = {tool = 2553, skill = 200, loot = {{5889, 1}, {2146, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[5866] = {tool = 2553, skill = 300, loot = {{5892, 1}, {2149, 2}, {2147, 2}, {9970, 2}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[5753] = {tool = 2553, skill = 350, loot = {{5888, 1}, {2150, 2}, {2146,2 }, {9970, 2}, {2156, 1}}, effect = CONST_ME_HITAREA, profession = "mining"},
	[5751] = {tool = 2553, skill = 400, loot = {{5887, 1}, {2149, 2}, {2147, 2}, {9970, 2}, {2158, 1}}, effect = CONST_ME_HITAREA, profession = "mining"}
}

professions = {
	["herbalism"] = {storage = 1030, maxSkill = 550},
	["mining"] = {storage = 1031, maxSkill = 400},
	["skinning"] = {storage = 1032, maxSkill = 500}
}

config = {
	tool = 2422,
	maxSkill = 210,
	actionId = 4500,
}

scrolls = {
	[8000] = {name = "magic plate armor", storage = 8000},
	[8001] = {name = "mastermind shield", storage = 8001}
}

function doPlayerAddOwnSkill(cid, storage, craftValue)
	if getPlayerStorageValue(cid, storage) < 0 then
		skillValue = 0
	else
		skillValue = getPlayerStorageValue(cid, storage)
	end
	if craftValue + 10 > skillValue then
		return setPlayerStorageValue(cid, storage, skillValue + 1)
	elseif craftValue + 20 > skillValue then
		if math.random(1, 2) == 1 then
			return setPlayerStorageValue(cid, storage, skillValue + 1)
		else
			return true
		end
	elseif craftValue + 30 > skillValue then
		if math.random(1, 5) == 1 then
			return setPlayerStorageValue(cid, storage, skillValue + 1)
		else
			return true
		end
	elseif craftValue + 40 > skillValue then
		return true
	end
end
	]]></config>
	<action  itemid="1961"  event="script"><![CDATA[	
function onUse(cid, item, fromPosition, itemEx, toPosition)
domodlib("proinfo")
 
	if getPlayerStorageValue(cid, 60010) < 0 then
		setPlayerStorageValue(cid, 60010, 0)
	end
	show = "The recipe book. Here you can see and update your smithing recipes.\nProperty of ".. getPlayerName(cid) ..".\n\n"
	entries = 0
	allEntries = 0
	for names, values in pairs(recipes) do
		value = ""
		finalItems = ""
		if getPlayerStorageValue(cid, recipes[names].storage) ~= 1 then
			value = ""
			string = ""
			allEntries = allEntries + 1
		else
			for item, count in pairs(recipes[names].requiredItems) do
				items = "                    - ".. count .."x ".. getItemNameById(item)
				finalItems = finalItems .."\n"..items
			end
			value = "       - Required items: ".. finalItems
			string = "     - Recipe name: ".. names .."\n          - Required skill: ".. recipes[names].skill .."\n          ".. value .."\n\n"
			entries = entries + 1
			allEntries = allEntries + 1
		end
		show = show .."".. string
	end
	endLine = show .."     Number of recipe entries: ".. entries .."\n     Number of all known recipes: ".. allEntries .."\n     Unknown recipes: ".. allEntries - entries .."\n     Your blacksmithing skill: ".. getPlayerStorageValue(cid, 60010)
	doShowTextDialog(cid, 1961, endLine)
	return true
end    
	]]></action>
	<action actionid="8000-8001"  event="script"><![CDATA[
function onUse(cid, item, fromPosition, itemEx, toPosition)
domodlib("proinfo")
 
	if item.itemid == 10122 then
		if getPlayerStorageValue(cid, recipes[scrolls[item.actionid].name].storage) ~= 1 then
			setPlayerStorageValue(cid, recipes[scrolls[item.actionid].name].storage, 1)
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
			doCreatureSay(cid, "You've learned how to smith ".. scrolls[item.actionid].name ..".", TALKTYPE_ORANGE_1)
			doRemoveItem(item.uid, 1)
		else
			doCreatureSay(cid, "You already know how to smith ".. scrolls[item.actionid].name ..".", TALKTYPE_ORANGE_1)
		end
	else
		if getPlayerStorageValue(cid, scrolls[item.actionid].storage) ~= 1 then
			scroll = doCreateItemEx(10122, 1)
			doItemSetAttribute(scroll, "aid", item.actionid)
			doItemSetAttribute(scroll, "description", "This scroll contains a recipe for ".. scrolls[item.actionid].name ..".")
			doPlayerAddItemEx(cid, scroll, false)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You've found a recipe scroll.")
			setPlayerStorageValue(cid, scrolls[item.actionid].storage, 1)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It's empty.")
		end
	end
	return true
end  
	]]></action>
	<action itemid="2550;2566;2422;2553"  event="script"><![CDATA[
function onUse(cid, item, fromPosition, itemEx, toPosition)
 domodlib("proinfo")	
	if recipe[itemEx.itemid] then
		if itemEx.actionid > 0 --[[or itemEx.uid > 0]] then -- this part canceled off always!
			doCreatureSay(cid, "You can't do that.", TALKTYPE_ORANGE_1)
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
			return true
		end
		lootTable = {}
		lootName = "You recive: "
		professionSkill = getPlayerStorageValue(cid, professions[recipe[itemEx.itemid].profession].storage)
		itemPos = getThingPos(itemEx.uid)
		if professionSkill < 1 then
			professionSkill = 0
		end
		if item.itemid == recipe[itemEx.itemid].tool then
			if professionSkill >= recipe[itemEx.itemid].skill then
				if item.actionid ~= 5001 then				
					if math.random(1, 3) < 2 then
						doRemoveItem(itemEx.uid, 1)
						doSendMagicEffect(itemPos, recipe[itemEx.itemid].effect)
						if recipe[itemEx.itemid].profession ~= "skinning" then
							addEvent(doCreateItem, 120000, itemEx.itemid, 1, itemPos)
							addEvent(doSendMagicEffect, 120000, itemPos, recipe[itemEx.itemid].effect)
						end
						if math.random(1, 2) < 2 then
							if professionSkill < professions[recipe[itemEx.itemid].profession].maxSkill then
								setPlayerStorageValue(cid, professions[recipe[itemEx.itemid].profession].storage, professionSkill + 1)
								doCreatureSay(cid, "You advanced in "..recipe[itemEx.itemid].profession..". ("..professionSkill..").", TALKTYPE_ORANGE_1)
							end
						end
						repeat
							if #recipe[itemEx.itemid].loot == 0 then
								break
							end
							for i = 1, #recipe[itemEx.itemid].loot do
								if math.random(1, 2) < 2 then
									table.insert(lootTable, (recipe[itemEx.itemid].loot)[i])
								end
							end
						until lootTable ~= {}
						for i = 1, #lootTable do
							lootCount = math.random(1, lootTable[i][2])	
							doPlayerAddItem(cid, lootTable[i][1], lootCount)
							if i == #lootTable then
								lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) .."."
							else
								lootName = lootName..""..lootCount.."x ".. getItemNameById(lootTable[i][1]) ..", "
							end
						end
						if lootName == "You recive: " then
							lootName = "You don't recive any loot."
						end
						doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, lootName)
					else
						doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
					end
				else
					doSendMagicEffect(itemPos, CONST_ME_BLOCKHIT)
					doCreatureSay(cid, "This tree was cut recenlty by someone else!", TALKTYPE_ORANGE_1)
				end
			else
				doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
				doCreatureSay(cid, "You don't have required skill to do that!", TALKTYPE_ORANGE_1)
		end
		else
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_BLOCKHIT)
			doCreatureSay(cid, "This tool doesn't match!", TALKTYPE_ORANGE_1)
		end
	end
	return true
end
	]]></action>
	<talkaction words="!smith"  event="script"><![CDATA[
domodlib("proinfo")		
function onSay(cid, words, param)
 
	if getPlayerStorageValue(cid, 60010) < 0 then
		setPlayerStorageValue(cid, 60010, 0)
	end
	param = string.lower(param)
	if recipes[param] then
		if getPlayerStorageValue(cid, recipes[param].storage) == 1 then
			if getPlayerStorageValue(cid, 60010) >= recipes[param].skill then
				if getPlayerItemCount(cid, config.tool) > 0 then
					smithTile = getPlayerPosition(cid)
					smithTile.stackpos = 0
					if getThingfromPos(smithTile).actionid == config.actionId then
						for items, count in pairs(recipes[param].requiredItems) do
							if getPlayerItemCount(cid, items) < count then
								doCreatureSay(cid, "You don't have required ingredients to craft ".. param .. ".", TALKTYPE_ORANGE_1)
								doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
								return true
							end
						end
						for items, count in pairs(recipes[param].requiredItems) do
							doPlayerRemoveItem(cid, items, count)
						end
						doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
						craftedItem = doCreateItemEx(getItemIdByName(param), 1)
						doItemSetAttribute(craftedItem, "description", "It was crafted by ".. getPlayerName(cid) ..".")
						doPlayerAddItemEx(cid, craftedItem, true)
						doPlayerAddOwnSkill(cid, 60010, recipes[param].skill)
						doCreatureSay(cid, "You've crafted ".. param ..".", TALKTYPE_ORANGE_1)
						return true
					else
						doCreatureSay(cid, "The forge is too far from you.", TALKTYPE_ORANGE_1)
						doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
					end
				else
					doCreatureSay(cid, "You don't have required tools to craft ".. param ..".", TALKTYPE_ORANGE_1)
					doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
				end
			else
				doCreatureSay(cid, "You don't have enought blacksmithing skill to craft ".. param .. ".", TALKTYPE_ORANGE_1)
				doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
			end
		else
			doCreatureSay(cid, "You don't have recipe for that.", TALKTYPE_ORANGE_1)
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
		end
	else
		doCreatureSay(cid, "There is no such a recipe.", TALKTYPE_ORANGE_1)
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
	end
	return true
end
	]]></talkaction>
</mod>

NPC:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Gor'noth" script="blacksmithing.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="160" head="96" body="114" legs="1" feet="76" addons="3"/>
</npc>

NPC Script:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local smelting = {
	["huge chunk of crude iron"] = {[2393] = 1},
	["piece of royal steel"] = {[2487] = 1},
	["piece of hell steel"] = {[2462] = 1},
	["piece of draconian steel"] = {[2516] = 1},
	["piece of iron"] = {[2152] = 1, [2148] = 30}
}
 
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
domodlib("proinfo")
npcHandler:setMessage(MESSAGE_GREET, "Greetings |PLAYERNAME|. If you're looking for either {smelting}, {jewelcrafting} or {smithing recipes}, you found a right person. I can teach you how to smith things for money or some {\"services\"}.")
 
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, "services") then
		npcHandler:say("Sometimes a {recipe} is so precious that it has no price in gold, then the only reasonable price for a recipe is a quest or a service which would cover the price.", cid, 1000)
	elseif msgcontains(msg, "jewelcrafting") then
		npcHandler:say("Jewelcrafting is a part of blacksmithing in which a blacksmith cuts a gem or a jewel.", cid, 1000)
	elseif msgcontains(msg, "smithing") then
		npcHandler:say("Smithing is a part of blacksmithing in which a blacksmith uses a forge.", cid, 1000)
	elseif msgcontains(msg, "smelting") then
		npcHandler:say("I can smelt some metals for you, but only if you have required ingredients.", cid, 1000)
	elseif msgcontains(msg, "recipe") then
		npcHandler:say("I can offer you almost all blacksmithing recipes that are known in the world. Each recipe is unique and represents a process in smithing or crafting in which result a blacksmith recives a various gems or armors.", cid, 1000)
	elseif msgcontains(msg, "blacksmith hammer") or msgcontains(msg, "tool") then
		if doPlayerRemoveMoney(cid, 5000) == true then
			doPlayerAddItem(cid, 2422, 1)
			npcHandler:say("This {blacksmith hammer} is a very high quality item. Use it wisely.", cid, 1000)
		else
			npcHandler:say("You don't have enught money to buy this {tool}.", cid, 1000)
		end
	elseif msgcontains(msg, "book") then
		if doPlayerRemoveMoney(cid, 5000) == true then
			doPlayerAddItem(cid, 1961, 1)
			npcHandler:say("This {recipe book} is a very high quality item. Use it wisely.", cid, 1000)
		else
			npcHandler:say("You don't have enought money to buy this {book}.", cid, 1000)
		end
	end
	for names, values in pairs(recipes) do
		if msg == names then
			if values.sellable == true then
				if getPlayerStorageValue(cid, values.storage) ~= 1 then
					talkState[talkUser] = values.talkState
					npcHandler:say("Do you really want to learn how to smith {".. names .. "}?", cid, 1000)
				else
					npcHandler:say("You already know how to smith that.", cid, 1000)
					talkState[talkUser] = 0
				end
			elseif values.sellable == false and values.mission then
				if getPlayerStorageValue(cid, values.storage) ~= 1 then
					itemList = ""
					for items, count in pairs(values.mission) do
						itemList = itemList .." ".. count .."x ".. getItemNameById(items) ..","
					end	
					talkState[talkUser] = values.talkState
					npcHandler:say("If you want to learn how to smith {".. names .."}, you have to bring me: {".. itemList .." ".. values.price .." and a blacksmith hammer}. Do you have required materials now?", cid, 1000)
				else
					npcHandler:say("You've already completed this task for me.", cid, 1000)
					talkState[talkUser] = 0
				end
			end
		elseif msgcontains(msg, "yes") then
			if talkState[talkUser] > 0 then
				if talkState[talkUser] == values.talkState then
					if values.mission then
						for items, count in pairs(values.mission) do
							if getPlayerItemCount(cid, items) < count then
								npcHandler:say("You don't have required items.", cid, 1000)
								talkState[talkUser] = 0
								return true
							end
						end
						if doPlayerRemoveMoney(cid, values.price) == true then
							for items, count in pairs(values.mission) do
								doPlayerRemoveItem(cid, items, count)
							end
							setPlayerStorageValue(cid, values.storage, 1)
							doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_RED)
							npcHandler:say("Here you are, your ".. names .." recipe. Take care of it, becouse it's one of the rarest recipes in the world!", cid, 1000)
							talkState[talkUser] = 0
						else
							npcHandler:say("You don't have enought cash to buy this recipe.", cid, 1000)
							talkState[talkUser] = 0
						end
						return true
					end
					if doPlayerRemoveMoney(cid, values.price) == true then
						setPlayerStorageValue(cid, values.storage, 1)
						doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
						npcHandler:say("You learned the recipe of smithing {".. names .."}.", cid)
					else
						npcHandler:say("You don't have enought money.", cid)
					end
					talkState[talkUser] = 0
				end
			end
		elseif msgcontains(msg, "no") then
			npcHandler:say("No? Then no...", cid, 1000)
			talkState[talkUser] = 0
		end
	end
	for names, values in pairs(smelting) do
		if msg == names then
			for item, count in pairs(smelting[names]) do
				if doPlayerRemoveItem(cid, item, count) == true then
					doPlayerAddItem(cid, getItemIdByName(names), 1)
					doSendMagicEffect(getPlayerPosition(cid), CONST_ME_HITBYFIRE)
					npcHandler:say("Here you are, a ".. names ..".", cid, 1000)
				else
					npcHandler:say("You don't have required ingredients.", cid, 1000)
				end
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

The NPC could use a better way to interact with players.
 
Last edited:
Back
Top