• 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 Im learning and i need some help with functin onadditem

megachock

Member
Joined
Mar 12, 2009
Messages
115
Reaction score
7
Hey guys, im learning how to make scripts, i have some doubs
Explained.
I want if some items are in a correct position and you use the lever it will teleport you to a position.
I want to learn if you post the script please teach me how u made it =) i have seen many guides but they dont explain all functions

function onUse(cid, item, frompos, item2, topos)
position={x=200, y=200, z=7, stackpos=0}
position2={x=250 y=250 z=7}
if getThingFromPos(position) and item.itemid == 2828 then
doTeleportThing(cid,position2)

For example if in map is the item 2828 in the pos x=200 y=200 z=7 and 2929 in the pos x=201 y=200 z=7 then
doTeleportThing
for teleporting the player to a position
How i do it? i mean i put the action id in the map tiles right?..
 
Last edited:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
  local thing1 = getThingFromPos({x = 200, y = 200, z = 7, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
  local thing2 = getThingFromPos({x = 201, y = 200, z = 7, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
  if thing1.uid > 0 and thing2.uid > 0 and thing1.itemid == 2828 and thing1.itemid == 2929 then
    doTeleportThing(cid, {x = 250, y = 250, z = 7})
  end
  return true
end

You set the 2 positions where the item has to be, stackpos is important here. STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE equals 255.
Then you check if there are items on the tiles you set and finally check if the itemids are correct.
Script is not tested
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
  local thing1 = getThingFromPos({x = 200, y = 200, z = 7, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
  local thing2 = getThingFromPos({x = 201, y = 200, z = 7, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE})
  if thing1.uid > 0 and thing2.uid > 0 and thing1.itemid == 2828 and thing1.itemid == 2929 then
    doTeleportThing(cid, {x = 250, y = 250, z = 7})
  end
  return true
end

Nice really thanks i think now i understand a bit the scrpt jjeje, what do that stackpos?
and if im not bad this " if thing1.uid > 0" means if the item1 unique id is high to 0
for what is that? and if i put if thing1.uid == 5002 and... this is if thing 1 have the uid 5002 right?

also i made this one: when u pull a lever remove item from a position is it correct?
Thanks a lot for your help :D

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
pos={x = 201, y = 200, z = 7}
wall=2000
         if item.itemid == 1945 and getPlayerLevel(cid) >= 50 then
                doRemoveItem(getTileThingByPos(pos,wall)
                doPlayerSendTextMessage(cid,21,"You removed the tile !")
		doTransformItem(item.uid, item.itemid + 1)
	elseif item.itemid == 1946 and getPlayerLevel(cid) >= 50 then
		doPlayerSendTextMessage(cid,21,"You have closed the pass!")
		doTransformItem(item.uid, item.itemid - 1)
                doCreateItem(wall, 1, pos)
return true
end

- - - Updated - - -

Check please :/
 
Last edited:
Back
Top