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

Lua Why is this simple lever script not working?

Listo

New Member
Joined
Aug 17, 2008
Messages
222
Reaction score
0
Hey guys,
I made a script, the meaning is: Player pulls a lever>stone gets removed.
So this is my script, I am getting debugged if I use the lever :/
Using the latest TFS Mystic Spirit for 9,45

function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos = getThingfromPos(stonepos)
if item.itemid == 1945 and item.uid == 1500 then
doRemoveItem(stonepos.uid,1304)
doTransformItem(item.uid,1946)
doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
elseif(item.itemid == 1946 and item.uid == 1500) then
doCreateItem(stonepos.uid,1304)
doTransformItem(item.uid,1945)
doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
else
doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
end
return 1
end
Thanks in advance
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos1 = getThingfromPos(stonepos)
if item.itemid == 1945 and item.uid == 1500 then
doRemoveItem(stonepos1.uid,1304)
doTransformItem(item.uid,1946)
doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
elseif(item.itemid == 1946 and item.uid == 1500) then
doCreateItem(stonepos1.uid,1304)
doTransformItem(item.uid,1945) 
doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
else
doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
end
return 1
end

Try that, I'm just taking a shot in the dark.
 
This should work now:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos1 = getThingfromPos(stonepos)
	if item.itemid == 1945 and item.uid == 1500 then
		doRemoveItem(stonepos1.uid,1304)
		doTransformItem(item.uid,1946)
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	elseif(item.itemid == 1946 and item.uid == 1500) then
		doCreateItem(1304, stonepos)
		doTransformItem(item.uid,1945) 
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	else
		doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
	end
return 1
end
 
Last edited:
Not sure if it will work, but you can try this.
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)

stonepos = {x=1235, y=1095, z=9, stackpos=1}
getpos = getThingfromPos(stonepos)

if item.uid == 1500 and item.itemid == 1945 and getpos.itemid == 1304 then
	doRemoveItem(getpos.uid,1)
	doTransformItem(item.uid,item.itemid+1)
	doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
elseif item.uid == 1500 and item.itemid == 1946 and getpos.itemid == 0 then
	doCreateItem(1304,1,stonepos)
	doTransformItem(item.uid,item.itemid-1)
	doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	else
		doPlayerSendCancel(cid,"Sorry not possible.")
	end
  return 1
  end
 
Okay, try this then; if it doesn't work, then I have no idea because it is working perfectly fine for me (I'm using 0.3).

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos1 = getThingfromPos(stonepos)
	if item.itemid == 1945 and item.uid == 1500 then
		doRemoveItem(stonepos1.uid,1304)
		doTransformItem(item.uid,1946)
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	elseif(item.itemid == 1946 and item.uid == 1500) then
		doCreateItem(1304, 1, stonepos)
		doTransformItem(item.uid,1945) 
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	else
		doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
	end
return 1
end

Or

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos1 = getThingfromPos(stonepos)
	if item.itemid == 1945 and item.uid == 1500 then
		doRemoveItem(stonepos1.uid)
		doTransformItem(item.uid,1946)
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	elseif(item.itemid == 1946 and item.uid == 1500) then
		doCreateItem(1304, 1, stonepos)
		doTransformItem(item.uid,1945) 
		doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	else
		doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
	end
return 1
end
 
You can try, just make sure your value is correct (script location)

Lua:
<action uniqueid="1500" event="script" value="testlever.lua"/>

The lever has to have uniqueID 1500, the stones have no action/uniqueID
 
Doesn't work.. Too bad. Thanks for your help anyway..
By the way. Should i add an action id to my lever? I've added unique id 1500 action id 0.
And i'm getting 1 warning when starting the server but I dont't know if that matters.
[18/07/2012 23:42:04] Warning: [OTBM loader] This map needs an updated items.otb.
 
If he uses my script, then it would say not possible if the stone isn't located of the stonepos position, same goes for if there would be items under it. Only thing I can think of is that the function might work different.

@up, I doubt it would have influence on it.
 
If he uses my script, then it would say not possible if the stone isn't located of the stonepos position, same goes for if there would be items under it. Only thing I can think of is that the function might work different.

@up, I doubt it would have influence on it.

Hmm do you know how I fix it? Would be awesome
 
We can do some testing.

Instead of removing/adding any item, let's see if it prints anything to the client.
If it does, then we can pinpoint a closer location of the problem.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
stonepos = {x=1235, y=1095, z=9, stackpos=1}
stonepos1 = getThingfromPos(stonepos)
	if item.itemid == 1945 and item.uid == 1500 then
		--doRemoveItem(stonepos1.uid,1304)
		doTransformItem(item.uid,1946)
		doPlayerSendTextMessage(cid,22,"1")
		--doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	elseif(item.itemid == 1946 and item.uid == 1500) then
		--doCreateItem(1304, stonepos)
		doTransformItem(item.uid,1945)
		doPlayerSendTextMessage(cid,22,"2")
		--doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
	else
		doPlayerSendTextMessage(cid,22,"Sorry, not possible.")
	end
return 1
end

Let me know what happens, if it doesn't debug, look for a 1 or a 2 in the server log.
 
Back
Top