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

lever removes item and adds another

Spo teh pro

New Member
Joined
Jan 3, 2008
Messages
319
Reaction score
1
Hello everyone

I'm asking for a lever script that removes an item but creates an other item on the same position
for example: removing a stone and creating a ladder that place

Please help me I'm not sure if it's a big deal, thank you.
 
If you search you could find tons of Lever Scripts that can do what you just asked.
But whatever i'll write one real fast

Lua:
local stonePos = {x = 1, y = 1, z = 1} -- Put the stone position here
local stoneId = 1234 -- Put the itemid of the stone here
local ladderId = 4321 -- Put the itemid of the ladder here


function onUse(cid, item, fromPosition, itemEx, toPosition)
  local stone = getTileItemById(stonePos, stoneId) -- Finds the stone (if it's there)
  local ladder = getTileItemById(stonePos, ladderId) -- Finds the ladder (if it's there)

  if stone.itemid == stoneId then -- if stone is there
    doRemoveItem(stone.uid) -- remove stone
    doCreateItem(ladderId, stonePos) -- add ladder
  elseif ladder.itemid == ladderId then -- if ladder is there
    doRemoveItem(ladder.uid) -- remove ladder
    doCreateItem(stoneId, stonePos) -- add stone
  end

  if (item.itemid == 1946) then -- checks lever 
    doTransformItem(item.uid, 1945) -- switches lever
  elseif (item.itemid == 1945) then -- same as above
    doTransformItem(item.uid, 1946) -- same 
  end
  return true
end
 
Last edited:
Hey. thank you for your response. I was checking with the search function trough this forum but couldnt find a script that could have help me
Ive tried your script. everything works expect that the "stone" doesnt disappear.

I use 2 coffins - the one thatll be created is with stairs the other isnt. maybe it helps you when i tell you that :p

Thank you for your effort btw <3
 
This will transform one or more stones into a ladder:

Lua:
local t = {
	{x = 100, y = 100, z = 7}, -- position of the stone
}

local ladder, stone = 428, 1285 -- ladder and stone ID's
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local k = {}
	for _, v in ipairs(t) do
		local st = getTileItemById(v, stone)
		table.insert(k, st)
	end
	
	for _, st in ipairs(k) do
		doTransformItem(st.uid, ladder, 1)
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
And this should transform one stone into a ladder:

Lua:
local t = {x = 100, y = 100, z = 7} -- Position of the stone.
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local st = getTileItemById(t, 1285) -- STONE ID
	if st.uid > 0 then
		doTransformItem(st.uid, 428, 1) -- LADDER ID
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
Last edited:
This will transform one or more stones into a ladder.

Lua:
local t = {
	{x = 100, y = 100, z = 7}, -- position of the stone
}

local ladder, stone = 428, 1285 -- ladder and stone ID's
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local k = {}
	for _, v in ipairs(t) do
		local st = getTileItemById(v, stone)
		table.insert(k, st)
	end
	
	for _, st in ipairs(k) do
		doTransformItem(st.uid, ladder, 1)
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end

Works, though I can't think of a situation where you would need to turn multiple stones into multiple ladders but too much functionality is never a bad thing.
 
Works, though I can't think of a situation where you would need to turn multiple stones into multiple ladders but too much functionality is never a bad thing.

It doesn't have to be only stones to ladders. I can think of other items that this would be more suited for. You can also easily change "doTransformItem" to "doRemoveItem" and you've got a script to remove multiple items.
 
anyone that could rewrite this script

Code:
	local config = {
lever_uid = 1011,
walls = {
[1] = {id = 3766, pos = {x=1912, y=1289, z=9}, relocate = {x=1912, y=1289, z=9}},
[2] = {id = 3766, pos = {x=1923, y=1289, z=9}, relocate = {x=1912, y=1289, z=9}}
}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.uid == 1011 then
if item.itemid == 7568 then
for i = 1, #config.walls do
local getWall = getTileItemById(config.walls[i].pos, config.walls[i].id).uid
if getWall > 0 then
doRemoveItem(getWall)
end
end
doTransformItem(item.uid, item.itemid+1)
return TRUE
elseif item.itemid == 7569 then
for i = 1, #config.walls do
local getWall = getTileItemById(config.walls[i].pos, config.walls[i].id).uid
if getWall == 0 then
doRelocate(config.walls[i].pos, config.walls[i].relocate)
doCreateItem(config.walls[i].id, 1, config.walls[i].pos)
end
end
doTransformItem(item.uid,item.itemid-1)
return TRUE
end
end
return FALSE
end

into a movement script? I mean when you walk over a tile, the walls disappear and as soon as you leave the tile, it closes again
also could anyone explain shortly how to do it ? cus I'm sure I could change that script by myself but I couldn't really figure out how after trying it out several times

thank you in advance =)
 
anyone that could rewrite this script

Code:
	local config = {
lever_uid = 1011,
walls = {
[1] = {id = 3766, pos = {x=1912, y=1289, z=9}, relocate = {x=1912, y=1289, z=9}},
[2] = {id = 3766, pos = {x=1923, y=1289, z=9}, relocate = {x=1912, y=1289, z=9}}
}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.uid == 1011 then
if item.itemid == 7568 then
for i = 1, #config.walls do
local getWall = getTileItemById(config.walls[i].pos, config.walls[i].id).uid
if getWall > 0 then
doRemoveItem(getWall)
end
end
doTransformItem(item.uid, item.itemid+1)
return TRUE
elseif item.itemid == 7569 then
for i = 1, #config.walls do
local getWall = getTileItemById(config.walls[i].pos, config.walls[i].id).uid
if getWall == 0 then
doRelocate(config.walls[i].pos, config.walls[i].relocate)
doCreateItem(config.walls[i].id, 1, config.walls[i].pos)
end
end
doTransformItem(item.uid,item.itemid-1)
return TRUE
end
end
return FALSE
end

into a movement script? I mean when you walk over a tile, the walls disappear and as soon as you leave the tile, it closes again
also could anyone explain shortly how to do it ? cus I'm sure I could change that script by myself but I couldn't really figure out how after trying it out several times

thank you in advance =)

Give this a try: http://otland.net/f132/lever-removes-item-adds-another-196197/index2.html#post1892294 ^_^
 
Last edited:
Code:
[02/08/2013 01:18:43] [Error - MoveEvents Interface] 
[02/08/2013 01:18:43] data/movements/scripts/dhqmove.lua:onStepIn
[02/08/2013 01:18:43] Description: 
[02/08/2013 01:18:43] data/movements/scripts/dhqmove.lua:17: attempt to index field '?' (a nil value)
[02/08/2013 01:18:43] stack traceback:
[02/08/2013 01:18:43] 	data/movements/scripts/dhqmove.lua:17: in function <data/movements/scripts/dhqmove.lua:14>

what does that mean?
Code:
local walls = {
	[1] = {
		1025, 
		{x = 3167, y = 938, z = 8},
		{x = 3167, y = 938, z = 8}
	},
	[2] = {
		1025,
		{x = 3167, y = 939, z = 8},
		{x = 3167, y = 939, z = 8}
	}
}
 
function onStepIn(cid, item, position, fromPosition, toPosition)
	local k = item.actionid == 1020
	if(k and isPlayer(cid)) then
		local wall = getTileItemById(walls[i][2], walls[i][1])
		for i = 1, #walls do
			if wall.uid > 0 then
				doRemoveItem(wall.uid, 1)
			else
				doRelocate(walls[i][2], walls[i][3])
				doCreateItem(walls[i][1], 1, walls[i][2])
			end
		end
	end
	return true
end
 
Hmm, try this one. I fixed a mistake. ^_^

Lua:
local walls = {
	[1] = {
		1025,
		{x = 3167, y = 938, z = 8}, -- position
		{x = 3167, y = 938, z = 8} -- relocate
	},
	[2] = {
		1025,
		{x = 3167, y = 939, z = 8}, -- position
		{x = 3167, y = 939, z = 8} -- relocate
	}
}
 
function onStepIn(cid, item, position, fromPosition, toPosition)
	local k = item.actionid == 1020
	if(k and isPlayer(cid)) then
		for i = 1, #walls do
			local wall = getTileItemById(walls[i][2], walls[i][1]).uid
			if wall > 0 then
				doRemoveItem(wall.uid, 1)
			else
				if wall == 0 then
					local v = getThingFromPos(walls[i][2]).uid
					if v ~= 0 then
						doRelocate(walls[i][2], walls[i][3])
					end
					doCreateItem(walls[i][1], 1, walls[i][2])
				end
			end
		end
	end
	return true
end
Edit: The positions need to be different if you plan to relocate anyone standing on the spot.
 
Last edited:
still doesnt work :eek:

- - - Updated - - -

dunno if you know what I want this script to do but I'll explain it maybe more specific

X = tile
Y1,2 = wands
Z = character

if character (Z) moves on tile (X) walls y1 and y2 get removed and by leaving tile (X) walls y1 and y2 get restored on the SAME place again.

So it's the same script as I've posted, but just as a movement script

Thanks
 
Last edited:
Back
Top