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

A small problem with doRemoveItem

m3ssy

New Member
Joined
Feb 19, 2009
Messages
24
Reaction score
0
I'm trying to make a lever which will open and close doors [adding actionID and uniqueID at the same time]

Take a look at my script
Code:
function onUse(cid, item, frompos, item2, topos)

local wallpos    = {x=1053, y=995, z=7, stackpos=1}
local wall    = getThingfromPos(wallpos)

        if item.uid == 7002 and item.itemid == 1945 then
                doRemoveItem(wall.uid,1)
                doCreateItem(5734, 1, wallpos)
                doPlayerSendTextMessage(cid,22,"Something has moved not too far away.")
        elseif item.uid == 7002 and item.itemid == 1946 then 

                doRemoveItem(wall.uid,1)
                doItemSetAttribute(doCreateItem(5732, 1, wallpos), "aid", 666)
                doItemSetAttribute(doCreateItem(5732, 1, wallpos), "uid", 6666)
                doPlayerSendTextMessage(cid,22,"Something has moved not too far away.")
        else
                doPlayerSendCancel(cid,"Sorry, not possible.")
        end
end
The problem is the lever works only 2 times and then its getting fucked up. Its creating opened doors without removing the closed ones :S
What can I do?
 
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 then
		local v = getTileItemById({x=1053, y=995, z=7}, 5732).uid
		doTransformItem(v, 5734)
		doItemSetAttribute(v, 'aid', 0)
		doItemSetAttribute(v, 'uid', 0)
	else
		local v = getTileItemById({x=1053, y=995, z=7}, 5734).uid
		doTransformItem(v, 5732)
		doItemSetAttribute(v, 'aid', 666)
		doItemSetAttribute(v, 'uid', 6666)
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945) and doPlayerSendTextMessage(cid, 22, 'Something has moved not too far away.')
end
 
Yes it was but i tried to make it for 2 doors. Nevermind, I can change it so there will be only 1 doors, but still, the script doesnt change uniqueID..
 
Code:
local t = {
	[{x=1053, y=995, z=7}] = {closed = 5732, open = 5734, aid = 666, uid = 6666},
	[{x=1053, y=995, z=7}] = {closed = 5732, open = 5734, aid = 666, uid = 6666},
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local s, v = item.itemid == 1945, nil
	for pos, k in pairs(t) do
		v = getTileItemById(pos, s and k.closed or k.open).uid
		doTransformItem(v, s and k.open or k.closed)
		if s then
			doItemEraseAttribute(v, 'aid')
			doItemEraseAttribute(v, 'uid')
		else
			doItemSetAttribute(v, 'aid', k.aid)
			doItemSetAttribute(v, 'uid', k.uid)
		end
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945) and doPlayerSendTextMessage(cid, 22, 'Something has moved not too far away.')
end
 
holy shi-
Code:
(luaDoItemEraseAttribute) Attempt to erase protected key "uid".


@edit
okie, i've changed something in my .lua script and now I don't have to change that uid .. I guess so.
 
Code:
local t = {
	[{x=1053, y=995, z=7}] = {closed = 5732, open = 5734, aid = 666, uid = 6666},
	[{x=1053, y=995, z=7}] = {closed = 5732, open = 5734, aid = 666, uid = 6666},
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local s, v = item.itemid == 1945, nil
	for pos, k in pairs(t) do
		doRemoveItem(getTileItemById(pos, s and k.closed or k.open).uid)
		v = doCreateItem(s and k.open or k.closed, 1, pos)
		if not s then
			doItemSetAttribute(v, 'aid', k.aid)
			doItemSetAttribute(v, 'uid', k.uid)
		end
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945) and doPlayerSendTextMessage(cid, 22, 'Something has moved not too far away.')
end
 
Last edited:
Be my mastah :O
It works. Thanks, dude.

@edit ._.
I just noticed there's one moar problem. If you are not pissed off yet..
The script is opening and closing doors perfectly untill I close it manually [ya know, by using them]. It causes the door to close and now when I'm using the lever, script will try to close doors even if they are closed and second doors appears, lol.
Now there are 2 doors at all. One with ID 5733 [those ones I closed manually] and 5732 [those one which script did]
 
Last edited:
Be my mastah :O
It works. Thanks, dude.

@edit ._.
I just noticed there's one moar problem. If you are not pissed off yet..
The script is opening and closing doors perfectly untill I close it manually [ya know, by using them]. It causes the door to close and now when I'm using the lever, script will try to close doors even if they are closed and second doors appears, lol.
Now there are 2 doors at all. One with ID 5733 [those ones I closed manually] and 5732 [those one which script did]
Add an exception in doors.lua for that tile :/
 
Back
Top