• 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
 
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.
Still getting debug.. Maybe it's just that lever. Because in my dhq exactly the same thing happened I pulled the lever and i was getting debugged..

You also got a debug when you where using my script right? And you have no errors in console?
No errors in console
 
Try this then.
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 getpos.itemid == 1304 then
	doRemoveItem(getpos.uid,1)
	doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
elseif item.uid == 1500 and getpos.itemid == 0 then
	doCreateItem(1304,1,stonepos)
	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
 
Try this then.
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 getpos.itemid == 1304 then
	doRemoveItem(getpos.uid,1)
	doPlayerSendTextMessage(cid,22,"You can hear that somewhere has change something. It cant be so far.")
elseif item.uid == 1500 and getpos.itemid == 0 then
	doCreateItem(1304,1,stonepos)
	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
Still getting debugged when I pull the lever o_O
 
What about if you place a lever, without unique id or action id, you get a debug too if you use it? if so, look in actions if you have a script with the lever id.
 
To be sure it has nothing to do with the lever, you can also test the script on for example a stone. And else you can try the script with removing some functions, to see if one of them is causing the debug.

For example deleting the textmessage.
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)
elseif item.uid == 1500 and item.itemid == 1946 and getpos.itemid == 0 then
	doCreateItem(1304,1,stonepos)
	doTransformItem(item.uid,item.itemid-1)
	else
		doPlayerSendCancel(cid,"Sorry not possible.")
	end
  return 1
  end
But you can also try the others.
 
To be sure it has nothing to do with the lever, you can also test the script on for example a stone. And else you can try the script with removing some functions, to see if one of them is causing the debug.

For example deleting the textmessage.
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)
elseif item.uid == 1500 and item.itemid == 1946 and getpos.itemid == 0 then
	doCreateItem(1304,1,stonepos)
	doTransformItem(item.uid,item.itemid-1)
	else
		doPlayerSendCancel(cid,"Sorry not possible.")
	end
  return 1
  end
But you can also try the others.
Fuckyeah it works :eek: Thanks bro rep++
 
It's because you are passing 22 as message type to the client. You should use the defined constants in global.lua.
 
Back
Top