• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action Item Create Levers (like helmet of the ancients)

bobzero

LUA Scripter
Joined
Dec 7, 2008
Messages
7
Reaction score
0
Location
Brasil
How it Works?
I'm using TFS 0.3.5 PL1

Don't be scared by the huge array. It contais some ready levers.

'leverdata' : contains normal item creating levers.
'leverdataex' : contains levers that creates differents items based in the item you use.

If you want to use one of the made by me levers, just use the actionid I used or change it to the actionid you want in the 'leverdata' or 'leverdataex' array. Remember to change the items potions.

If you want to create your own lever, just add it to the array, following the examples.

Save this file in data/actions/script folder with any name.

Lua:
-- advanced lever item creating system
-- by BobZero

local config = {
	animation_create = CONST_ME_MAGIC_BLUE,
	animation_destroy = CONST_ME_EXPLOSIONHIT,
	sendfail = true
}

local leverdata = {

	[3200] = { -- fire swords into magic sulphur
		{
			{{x=443, y=439, z=6}, 2392},
			{{x=444, y=439, z=6}, 2392},
			{{x=445, y=439, z=6}, 2392}
		},
		{
			{x=444, y=441, z=6}, 5904
		}
	},

	[3201] = { -- warrior helmets into warrior's sweat
		{
			{{x=453, y=447, z=6}, 2475},
			{{x=454, y=447, z=6}, 2475},
			{{x=453, y=449, z=6}, 2475},
			{{x=454, y=449, z=6}, 2475}
		},
		{
			{x=451, y=448, z=6}, 5885
		}	
	},

	[3202] = { -- royal helmets into fighting spirit
		{
			{{x=443, y=457, z=6}, 2498},
			{{x=445, y=457, z=6}, 2498}
		},
		{
			{x=444, y=455, z=6}, 5884
		}
	},

	[3203] = { -- boots of haste into enchanted chicken wing
		{
			{{x=435, y=447, z=6}, 2195}
		},
		{
			{x=437, y=448, z=6}, 5891
		}
	},

	[3204] = { -- green tunics into green piece of cloth
		{
			{{x=454, y=447, z=5}, 2652},
			{{x=453, y=447, z=5}, 2652},
			{{x=453, y=448, z=5}, 2652},
			{{x=453, y=449, z=5}, 2652},
			{{x=454, y=449, z=5}, 2652}
		},
		{
			{x=451, y=448, z=5}, 5910
		}	
	},

	[3205] = { -- red tunic into red piece of cloth
		{
			{{x=443, y=457, z=5}, 2655}
		},
		{
			{x=444, y=455, z=5}, 5911
		}	
	},

	[3206] = { -- mystic turban into blue piece of cloth
		{
			{{x=435, y=447, z=5}, 2663}
		},
		{
			{x=437, y=448, z=5}, 5912
		}
	},
	
	[3208] = { -- helmet of the ancients create
		{
			{{x=300, y=443, z=8}, 2336},
			{{x=301, y=443, z=8}, 2337},
			{{x=302, y=443, z=8}, 2335},
			{{x=303, y=443, z=8}, 2339},
			{{x=304, y=443, z=8}, 2340},
			{{x=305, y=443, z=8}, 2338},
			{{x=306, y=443, z=8}, 2341}
		},
		{
			{x=302, y=441, z=8}, 2342
		}
	}

}

local leverdataex = {
	
	[3207] = { -- metals
		{
			[2487] = {5887,1},
			[2393] = {5892,1},
			[2516] = {5889,1},
			[2462] = {5888,1},
			[5944] = {6529,50}
		},
		{x=443, y=441, z=5},
		{x=444, y=441, z=5}
	}

}

function onUse(cid, item, fromPosition, itemEx, toPosition)

	if (not isInArray(LEVERS, item.itemid)) or (leverdata[item.actionid] == nil and leverdataex[item.actionid] == nil) then
		return false
	end
	
	if isInArray(LEFT_LEVERS, item.itemid) then

		if leverdata[item.actionid] ~= nil then

			local thingstocheck = leverdata[item.actionid][1]
			local itemcheck = true
			local size = table.maxn(thingstocheck)

			-- check things
			for i=1, size do
				local pos = thingstocheck[i][1]
				pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
				local thing = getThingFromPos(pos)
				local thingid = thingstocheck[i][2]
				if thing.itemid ~= thingid then
					itemcheck = false
				end
			end

			if itemcheck then
				-- item removing
				for i=1, size do
					local pos = thingstocheck[i][1]
					pos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
					local thing = getThingFromPos(pos)
					doRemoveItem(thing.uid, 1)
					doSendMagicEffect(pos, config.animation_destroy)
				end
				-- item creating
				local createpos = leverdata[item.actionid][2][1]
				local creatething = leverdata[item.actionid][2][2]
				doCreateItem(creatething, 1, createpos)
				doSendMagicEffect(createpos, config.animation_create)
				--lever increasing
				doTransformItem(item.uid,item.itemid+1)
			else
				doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
				if config.sendfail then
					doSendAnimatedText(fromPosition, "Fail", TEXTCOLOR_RED)
				end
			end

		elseif leverdataex[item.actionid] ~= nil then

			local dataex = leverdataex[item.actionid]
			local itemstable = dataex[1]
			local originpos = dataex[2]
			originpos.stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE
			local originthing = getThingFromPos(originpos)

			if itemstable[originthing.itemid] ~= nil then
				-- item removing
				doRemoveItem(originthing.uid, 1)
				doSendMagicEffect(originpos, config.animation_destroy)				
				-- item creating
				local createitem = itemstable[originthing.itemid][1]
				local createammount = itemstable[originthing.itemid][2]
				local createpos = dataex[3]
				doCreateItem(createitem, createammount, createpos)
				doSendMagicEffect(createpos, config.animation_create)
				--lever increasing
				doTransformItem(item.uid,item.itemid+1)
			else
				doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
				if config.sendfail then
					doSendAnimatedText(fromPosition, "Fail", TEXTCOLOR_RED)
				end				
			end

		end

	else
		doTransformItem(item.uid,item.itemid-1)
	end
	
	return true

end

After giving to the lever the actionid, remember to add it in actions.xml
Code:
	<action actionid="3200" script="other/itemcreatelevers.lua" />

Enjoy =)
And give me some reputation, if you thing i deserve.

BobZero.
 
Last edited:
frits this is not desci

well kinda nice hope you can better

/signed wlj
 
Back
Top