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

matthewharrison

New Member
Joined
Nov 21, 2011
Messages
42
Reaction score
1
Ok, I made this script for my server, it took me a while to make but it seemed like I finally got it working perfectly. It allows a player to double click a door on a room before even moving and it will teleport them in, then back out (normally with any teleport doors you wouldn't have the time to double click before teleporting, and even if you did it wouldn't teleport you back out).

This is a method of hunting used on my server, the player double clicks the door then hits their attack hotkey once they see themselves inside the room (there's a short delay before you're teleported back out), if done right, the player jumps into the room, attacks, and jumps out quickly.

Here's the problem. Today when I was hunting on my server (using these doors), someone else was using a different door at the same time, when I double clicked and attacked, the other player did the same at the same time, and when we teleported back out the player teleported over on top of me instead of back infront of his own door.

Anyways here's the scripts (won't work without both scripts)


Script 1:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local cidPosition = getPlayerPosition(cid)       
	--config--
	delay = 600
	--endconfig--
	local a = {cid = cid}
	backlocation = {x=cidPosition.x,y=cidPosition.y,z=cidPosition.z}
	if (item.itemid == 1249) then
			if cidPosition.y == toPosition.y and cidPosition.x == toPosition.x-1 then
					doTransformItem(item.uid, item.itemid + 1)
								addEvent(tpback, delay, a)
			elseif cidPosition.y == toPosition.y and cidPosition.x == toPosition.x+1 then
				doTeleportThing(cid, {x=cidPosition.x-2,y=cidPosition.y,z=cidPosition.z}, TRUE)
					doTransformItem(item.uid, item.itemid + 1)
			end
	end
end
 
function tpback(a)
doTeleportThing(a.cid, backlocation, TRUE)
end


Script 2

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local cidPosition = getPlayerPosition(cid)       
	--config--
	delay = 600
	--endconfig--
	local a = {cid = cid}
	backlocation = {x=cidPosition.x,y=cidPosition.y,z=cidPosition.z}
	if (item.itemid == 1250) then
			if cidPosition.y == toPosition.y and cidPosition.x == toPosition.x+1 then
					doTransformItem(item.uid, item.itemid - 1)
								addEvent(tpback, delay, a)
			elseif cidPosition.y == toPosition.y and cidPosition.x == toPosition.x-1 then
				doTeleportThing(cid, {x=cidPosition.x+2,y=cidPosition.y,z=cidPosition.z}, TRUE)
					doTransformItem(item.uid, item.itemid - 1)
			end
	end
end
 
function tpback(a)
doTeleportThing(a.cid, backlocation, TRUE)
end


I'm not completely sure how script functions work, but I'm guessing the server is storing the information of both player positions, and when it goes to perform the second teleport (the one back out the door), it doesn't know which position to use and just picks one.

If anyone understands this, can you please help! I've been working so long on this script and its almost finished!
 
Lua:
local c = {
	[1249] = 1250,
	[1250] = 1249
	delay = 600
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local i = c[item.itemid]
	local cidPos = getPlayerPosition(cid)       
	local pid = cid
	local backPos = cidPos

	if i then
		if cidPos.y == toPosition.y and cidPos.x == toPosition.x - 1 then
			doTransformItem(item.uid, i)
			addEvent(doTeleportThing, delay, pid, backPos, true)

		elseif cidPos.y == toPosition.y and cidPos.x == toPosition.x + 1 then
			doTransformItem(item.uid, i)
			doTeleportThing(pid, {x = cidPos.x - 2, y = cidPos.y, z = cidPos.z}, true)
		end
	end
	return true
end
clean, but not finite because I do not understand why these 2 files, doors
why you do it so complicated?

bugs were:
missing "return true" on the end
and "local" for local variables
 
Lua:
local c = {
	[1249] = 1250,
	[1250] = 1249
	delay = 600
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local i = c[item.itemid]
	local cidPos = getPlayerPosition(cid)       
	local pid = cid
	local backPos = cidPos

	if i then
		if cidPos.y == toPosition.y and cidPos.x == toPosition.x - 1 then
			doTransformItem(item.uid, i)
			addEvent(doTeleportThing, delay, pid, backPos, true)

		elseif cidPos.y == toPosition.y and cidPos.x == toPosition.x + 1 then
			doTransformItem(item.uid, i)
			doTeleportThing(pid, {x = cidPos.x - 2, y = cidPos.y, z = cidPos.z}, true)
		end
	end
	return true
end
clean, but not finite because I do not understand why these 2 files, doors
why you do it so complicated?

bugs were:
missing "return true" on the end
and "local" for local variables



Sorry but this script doesn't work the same

EDIT: NVM, I made it work
 
Last edited:
"clean, but not finite because I do not understand why these 2 files, doors"

i know :p This was an example how you can write this script

Oh, sorry man lol, just seen that you said "bugs were" then listen some and fixed them, so figured that was the problem with my script, I realize now that it wasn't and I'm still having the same problem :/
 
Back
Top