• 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] Lever problem

huhuhuhu

New Member
Joined
May 17, 2008
Messages
38
Reaction score
0
Hello pals! I've a problem with a script i try to make, is just a lever that when is pushed player, object or w/e thing that is place over those tile will teleport to his place, the problem that I found is that give me a error when there isn't place something over the tile something that is bugging me xD, so in conclusion I just want to know if someone is kind enough to give me a help.

This is the script:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

local pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8 = {x=1104,y=948,z=6, stackpos=253}, {x=1105,y=948,z=6, stackpos=253}, {x=1106,y=948,z=6, stackpos=253}, {x=1107,y=948,z=6, stackpos=253}, {x=1109,y=948,z=6, stackpos=253}, {x=1110,y=948,z=6, stackpos=253}, {x=1111,y=948,z=6, stackpos=253}, {x=1112,y=948,z=6, stackpos=253}
local newpos1, newpos2, newpos3, newpos4, newpos5, newpos6, newpos7, newpos8 = {x=1103,y=956,z=7}, {x=1103,y=959,z=7}, {x=1105,y=954,z=7}, {x=1105,y=961,z=7}, {x=1110,y=954,z=7}, {x=1110,y=961,z=7}, {x=1112,y=956,z=7}, {x=1112,y=959,z=7}
local thing = getThingFromPos

if item.itemid == 1945 then
doTeleportThing(thing(pos1).uid, newpos1)
doTeleportThing(thing(pos2).uid, newpos2)
doTeleportThing(thing(pos3).uid, newpos3)
doTeleportThing(thing(pos4).uid, newpos4)
doTeleportThing(thing(pos5).uid, newpos5)
doTeleportThing(thing(pos6).uid, newpos6)
doTeleportThing(thing(pos7).uid, newpos7)
doTeleportThing(thing(pos8).uid, newpos8)
end
return TRUE
end

This work but if one tile dont have player give error:
Code:
[24/7/2011 7:28:21] data/actions/scripts/palanca.lua:onUse
[24/7/2011 7:28:21] Description: 
[24/7/2011 7:28:21] (luaDoTeleportThing) Thing not found

I know that this means that a object/player was not found in the tiles, but i don't know how to solve since i'm not a scripter, just search for some script and try to make this but was not perfect xD

Thanks in advance.

PS; Sorry for my english. :(
PS2; Also I don't want to force player to need a team of x player, just push lever and player go tped.
 
Lua:
local pos = {
	{x = 1104, y = 948, z = 6},
	{x = 1105, y = 948, z = 6},
	{x = 1106, y = 948, z = 6},
	{x = 1107, y = 948, z = 6},
	{x = 1109, y = 948, z = 6},
	{x = 1110, y = 948, z = 6},
	{x = 1111, y = 948, z = 6},
	{x = 1112, y = 948, z = 6}
}
local newpos = {
	{x = 1103, y = 956, z = 7},
	{x = 1103, y = 959, z = 7},
	{x = 1105, y = 954, z = 7},
	{x = 1105, y = 961, z = 7},
	{x = 1110, y = 954, z = 7},
	{x = 1110, y = 961, z = 7},
	{x = 1112, y = 956, z = 7},
	{x = 1112, y = 959, z = 7}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	for i = 1, #pos do
		if(getTopCreature(pos[i]).uid > 0) then
			doTeleportThing(getTopCreature(pos[i]).uid, newpos[i])
		end
	end
	return true
end

"Use tables and loops. Be optimized!"
 
Lua:
local pos = {
	{x = 1104, y = 948, z = 6},
	{x = 1105, y = 948, z = 6},
	{x = 1106, y = 948, z = 6},
	{x = 1107, y = 948, z = 6},
	{x = 1109, y = 948, z = 6},
	{x = 1110, y = 948, z = 6},
	{x = 1111, y = 948, z = 6},
	{x = 1112, y = 948, z = 6}
}
local newpos = {
	{x = 1103, y = 956, z = 7},
	{x = 1103, y = 959, z = 7},
	{x = 1105, y = 954, z = 7},
	{x = 1105, y = 961, z = 7},
	{x = 1110, y = 954, z = 7},
	{x = 1110, y = 961, z = 7},
	{x = 1112, y = 956, z = 7},
	{x = 1112, y = 959, z = 7}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	for i = 1, #pos do
		if(getTopCreature(pos[i]).uid > 0) then
			doTeleportThing(getTopCreature(pos[i]).uid, newpos[i])
		end
	end
	return true
end

"Use tables and loops. Be optimized!"

Lua:
local pos = {
	{x = 1104, y = 948, z = 6},
	{x = 1105, y = 948, z = 6},
	{x = 1106, y = 948, z = 6},
	{x = 1107, y = 948, z = 6},
	{x = 1109, y = 948, z = 6},
	{x = 1110, y = 948, z = 6},
	{x = 1111, y = 948, z = 6},
	{x = 1112, y = 948, z = 6}
}
local newpos = {
	{x = 1103, y = 956, z = 7},
	{x = 1103, y = 959, z = 7},
	{x = 1105, y = 954, z = 7},
	{x = 1105, y = 961, z = 7},
	{x = 1110, y = 954, z = 7},
	{x = 1110, y = 961, z = 7},
	{x = 1112, y = 956, z = 7},
	{x = 1112, y = 959, z = 7}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
for i = 1, #pos do
    doTeleportThing(getTopCreature(pos[i]).uid, getTopCreature(pos[i]).uid > 0 and newpos[i] or doPlayerSendCancel(cid, "There's not enough people.")
end
return true
end
 
Lua:
local pos = {
	{x = 1104, y = 948, z = 6},
	{x = 1105, y = 948, z = 6},
	{x = 1106, y = 948, z = 6},
	{x = 1107, y = 948, z = 6},
	{x = 1109, y = 948, z = 6},
	{x = 1110, y = 948, z = 6},
	{x = 1111, y = 948, z = 6},
	{x = 1112, y = 948, z = 6}
}
local newpos = {
	{x = 1103, y = 956, z = 7},
	{x = 1103, y = 959, z = 7},
	{x = 1105, y = 954, z = 7},
	{x = 1105, y = 961, z = 7},
	{x = 1110, y = 954, z = 7},
	{x = 1110, y = 961, z = 7},
	{x = 1112, y = 956, z = 7},
	{x = 1112, y = 959, z = 7}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
for i = 1, #pos do
    doTeleportThing(getTopCreature(pos[i]).uid, getTopCreature(pos[i]).uid > 0 and newpos[i] or doPlayerSendCancel(cid, "There's not enough people.")
end
return true
end

It doesn't change a thing if you do this my way or your.
 
Once you grow up, you'll learn why I did it.

Lua:
for i = 1, #pos do
	if(getTopCreature(pos[i]).uid > 0) then
		doTeleportThing(getTopCreature(pos[i]).uid, newpos[i])
	else
		doPlayerSendCancel(cid, "There's not enough people.")
	end
end
equals

Lua:
for i = 1, #pos do
    doTeleportThing(getTopCreature(pos[i]).uid, getTopCreature(pos[i]).uid > 0 and newpos[i] or doPlayerSendCancel(cid, "There's not enough people.")
end

With the same ram usage and greater transparency, so stfu and learn some things.
 
Last edited:
Lua:
for i = 1, #pos do
	if(getTopCreature(pos[i]).uid > 0) then
		doTeleportThing(getTopCreature(pos[i]).uid, newpos[i])
	else
		doPlayerSendCancel(cid, "There's not enough people.")
	end
end
equals

Lua:
for i = 1, #pos do
    doTeleportThing(getTopCreature(pos[i]).uid, getTopCreature(pos[i]).uid > 0 and newpos[i] or doPlayerSendCancel(cid, "There's not enough people.")
end

With the same ram usage and greater transparency, so stfu and learn some things.

umad bro?
Mine is sexier.
 
Back
Top