• 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!

TalkAction Crafting

Piotrek1447

Member
Joined
Jun 1, 2007
Messages
658
Reaction score
16
Location
Rzeszów, Poland
Here is piece of shit what i latest do for my friend - he don't need it now so i release this.
How it work? You must have a container in arrow slot and put items in it required to craft other things, in this example is spear and wood.
After this, type !craft spear and thats all.
Remember, if put nonStackable item count must be 0!

XML:
<talkaction words="!craft;/craft" event="script" value="craft.lua"/>
Lua:
local crafting =
{
	["spear"] = {requiredItems = {{5880, 1}, {5901, 1}}, createItem = 2389, count = 2},
	["wood"] = {requiredItems = {{8582, 0}, {8582, 0}, {8582, 0}, {8582, 0}}, createItem = 5901, count = 1},
}


function onSay(cid, words, param)
	local craft = crafting[param:lower()]
	if(not craft) then
		return true
	end
	
	local slot = getPlayerSlotItem(cid, CONST_SLOT_AMMO).uid
	if(not isContainer(slot)) then
		doPlayerSendCancel(cid, "Put container with items in ammo slot.")
		return true
	end
	
	local check = false
	for c = 1, getContainerSize(slot) do
		local item = getContainerItem(slot, c - 1)
		for i, req in ipairs(craft.requiredItems) do
			if(item.itemid == req[1] and item.type >= req[2]) then
				if(table.maxn(craft.requiredItems) == getContainerSize(slot)) then
					check = true
				end
			end
		end
	end
	
	if(check) then
		for i, req in ipairs(craft.requiredItems) do
			doPlayerRemoveItem(cid, req[1], req[2] == 0 and 1 or req[2])
		end
		
		doPlayerAddItem(cid, craft.createItem, craft.count)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You succesfully craft " .. getItemInfo(craft.createItem).article .. " " .. craft.count .. " " .. getItemNameById(craft.createItem) .. (craft.count > 1 and "s" or "") .. "!")
	else
		doPlayerSendCancel(cid, "You don't have enough items.")
		return true
	end
	
	return true
end
 
Will be nice if you will change in script that it isn't only showing "You don't have enough items." but items which you are missing and how much you need them.
 
Unfortunately, this won't work in 9.0+.

Made this working on 9.0+ and fixed a spelling bug.

Lua:
local crafting = {
	["spear"] = {requiredItems = {{5880, 1}, {5901, 1}}, createItem = 2389, count = 2},
	["wood"] = {requiredItems = {{8582, 0}, {8582, 0}, {8582, 0}, {8582, 0}}, createItem = 5901, count = 1},
}

function onSay(cid, words, param)
	if(crafting[param.lower(param)]) then
		for j = 1, 2 do
			for i = 1, table.maxn(crafting[param.lower(param)].requiredItems) do
				if(j == 1) then
					if(getPlayerItemCount(cid, (crafting[param.lower(param)].requiredItems)[i][1]) < (crafting[param.lower(param)].requiredItems)[i][2]) then
						return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have required item: " .. getItemNameById((crafting[param.lower(param)].requiredItems)[i][1]))
					end
				else
					doPlayerRemoveItem(cid, (crafting[param.lower(param)].requiredItems)[i][1], (crafting[param.lower(param)].requiredItems)[i][2])
				end
			end
		end
		doPlayerAddItem(cid, crafting[param.lower(param)].createItem, crafting[param.lower(param)].count or 1)
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You've succesfully crafted " .. (crafting[param.lower(param)].count or 1) .. "" .. (crafting[param.lower(param)].count > 1 and "" or (" " and getItemInfo(crafting[param.lower(param)].createItem).article)) .. " " .. getItemNameById(crafting[param.lower(param)].createItem) .. (crafting[param.lower(param)].count > 1 and "s" or "") .. "!")
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There's no such an item.")
	end
	return true
end
 
Back
Top