All pastes #753945 Raw Edit

Untitled

public lua v1 · immutable
#753945 ·published 2007-10-29 17:42 UTC
rendered paste body
--Crafting Script--Written by Toriad--Included Functions--Function craft(craftTableID, plyr) number, object	--Please do not alter without permission from Toriad		--Please make sure to fill out the following information as it should be specific to your zone	--each value should be in the following format	--	--	--(materialname):(amounttomake)-(nameofitemitmakes)=(number of the item)	--	--For multi component crafting the following format is required	--	--(materialname):(amounttomake):(materialname):(amounttomake)-(nameofitemitmakes)=(number of the item)	--	--	--Example would be Toriadum:15:Toriadium Leggings	--The following array has two examples, just remember that Syconium is ID 2 and Toriadium is ID 1	--		g_craftTable = {'Toriadium:15-Toriadium Leggings', 'Syconium:40:Kickassium:400-Super Chestplate=2'}			function craft(craftTableID, plyr)				--Set craftTableID to a local id for easy reference		local ID = craftTableID				--We are going to use the plyr object for error handling and modification, lets make sure they are valid		if (plyr == nil) then			g_arena:message('An invalid player tried to craft something')			return		end				--Make sure the craftTableID is valid		if (g_craftTable[ID] == nil) then			plyr:message('That is not a valid craftTableID')			return		end				--Declare some variables for useage		local recipe = g_craftTable[ID]		local requiredores = { } --We are going to fill this up with the ores that are required		local requiredamount = { } --We are going to fill this up with the required amount of the ore needed, these will corrospond with requiredore example: requiredamount[1] will be the amount needed of requiredores[1]		local endofrequirements = false -- This will tell us when to stop gatherine requirements		local cursorposition = 0 -- This is for string parsing		-- Isn't used for now local reqstart = 0 -- This is used for string parsing		local reqdivider = 0 --Used for string parsing		local onore = true -- Used for string parsing				while endofrequirements ~= true do			reqdivider = string.find(recipe, ':')			if (reqdivider == nil) then				endofrequirements = true				break			end			if (onore == true) then				table.insert(requiredores, string.sub(recipe, 1, reqdivider - 1))				recipe = string.gsub(recipe, string.sub(recipe, 1, reqdivider), '')				onore = false			else				table.insert(requiredamount, string.sub(recipe, 1, reqdivider - 1))				recipe = string.gsub(recipe, string.sub(recipe, 1, reqdivider), '')				onore = true			end		end		--For referece I will be left with -blah=number				recipe = string.gsub(recipe, string.find('-'), '')		local itemtomake = string.sub(recipe, 1, string.find('=') - 1)		local amounttomake = string.sub(recipe, string.find('=') + 1, string.len(recipe))				--Go through the requirements and see if the player has everything they will need.		local meetsrequirements = true		for i=1, table.getn(requiredores) do			if (plyr:inventory_find(requiredores[i]) < tonumber(requiredamounts[i])) then				meetsrequirements = false			end		end				--If they meet the requirements take the ores and prize them what they need, otherwise say no...		if (meetsrequirements = false) then			plyr:message('You do not have everything needed to craft that.')			return		else			for i=1, table.getn(requiredores) do				plyr:inventory_modify(requiredores[i], tonumber(requiredamount[i]))			end			plyr:inventory_modify(itemtomake, tonumber(amounttomake))		endend