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

Gabriel Tibiano

New Member
Joined
Nov 21, 2009
Messages
420
Reaction score
4
Hey guys, what should i do in this script for
when i get one player or one creature under the gate
the action do not execute and return something like: 'Someone is under the gate and it can not close'

tiles under the gate:
1 = {x=73, y=97, z=7}
2 = {x=74, y=97, z=7}
3 = {x=73, y=96, z=7}
4 = {x=74, y=96, z=7}

LUA:
local config = {
wall1 = {x=73, y=97, z=7, stackpos=1},
wall2 = {x=74, y=97, z=7, stackpos=1},
wall3 = {x=73, y=96, z=7, stackpos=1},
wall4 = {x=74, y=96, z=7, stackpos=1},
}
local message = {
[1] = {x=72, y=96, z=7},
[2] = {x=75, y=98, z=7},
[3] = {x=73, y=97, z=7},
}


function onUse(cid, item, frompos, item2, topos)
local t = message[math.random(1,3)]
getwall1 = getThingfromPos({x=73, y=97, z=7, stackpos=1})
getwall2 = getThingfromPos({x=74, y=97, z=7, stackpos=1})
getwall3 = getThingfromPos({x=73, y=96, z=7, stackpos=1})
getwall4 = getThingfromPos({x=74, y=96, z=7, stackpos=1})

 	if item.itemid == 1945 then  
		doTransformItem(item.uid,item.itemid+1)
    elseif item.itemid == 1946 then
        doTransformItem(item.uid,item.itemid-1)   
    end 

	------------------------------------------------------------------------
	if getwall1.itemid == 9485 then 
			exhaustion.set(cid, storage, 1 * 60 * 1000)
			doRemoveItem(getwall1.uid,1)
			doRemoveItem(getwall2.uid,1)
			doRemoveItem(getwall3.uid,1)
			doRemoveItem(getwall4.uid,1)
				doSendMagicEffect(config.wall1, CONST_ME_POFF)
				doSendMagicEffect(config.wall2, CONST_ME_POFF)
				doSendMagicEffect(config.wall3, CONST_ME_POFF)
				doSendMagicEffect(config.wall4, CONST_ME_POFF)
					doSendAnimatedText(t, "Criiinnkchi!", 193)
		else
			doCreateItem(9485,1,config.wall1)
			doCreateItem(9485,1,config.wall2)
			doCreateItem(9485,1,config.wall3)
			doCreateItem(9485,1,config.wall4) 
		end
	------------------------------------------------------------------------	
return true
end

separador.png
 
LUA:
local config = {
wall1 = {x=73, y=97, z=7, stackpos=1},
wall2 = {x=74, y=97, z=7, stackpos=1},
wall3 = {x=73, y=96, z=7, stackpos=1},
wall4 = {x=74, y=96, z=7, stackpos=1},
}
local message = {
[1] = {x=72, y=96, z=7},
[2] = {x=75, y=98, z=7},
[3] = {x=73, y=97, z=7},
}
local fromPosition = {x=73, y=96, z=7}
local toPosition = {x=74, y=97, z=7}
 
 
function onUse(cid, item, frompos, item2, topos)
local t = message[math.random(1,3)]
getwall1 = getThingfromPos({x=73, y=97, z=7, stackpos=1})
getwall2 = getThingfromPos({x=74, y=97, z=7, stackpos=1})
getwall3 = getThingfromPos({x=73, y=96, z=7, stackpos=1})
getwall4 = getThingfromPos({x=74, y=96, z=7, stackpos=1})
 
 	if item.itemid == 1945 then  
		doTransformItem(item.uid,item.itemid+1)
			elseif item.itemid == 1946 then
				doTransformItem(item.uid,item.itemid-1)   
    end 
 
	if getwall1.itemid == 9485 then 
		exhaustion.set(cid, storage, 1 * 60 * 1000)
		doRemoveItem(getwall1.uid,1)
		doRemoveItem(getwall2.uid,1)
		doRemoveItem(getwall3.uid,1)
		doRemoveItem(getwall4.uid,1)
		doSendMagicEffect(config.wall1, CONST_ME_POFF)
		doSendMagicEffect(config.wall2, CONST_ME_POFF)
		doSendMagicEffect(config.wall3, CONST_ME_POFF)
		doSendMagicEffect(config.wall4, CONST_ME_POFF)
		doSendAnimatedText(t, "Criiinnkchi!", 193)
			elseif getwall1.itemid ~= 9485 and isInRange(getThingPosition(cid), fromPosition, toPosition) then
					doPlayerSendCancel(cid, "Someone is under the gate and it can not close")
						elseif getwall1.itemid ~= 9485 then 
								doCreateItem(9485,1,config.wall1)
								doCreateItem(9485,1,config.wall2)
								doCreateItem(9485,1,config.wall3)
								doCreateItem(9485,1,config.wall4) 
		end	
return true
end
not tested.
 
LUA:
local config = {
wall1 = {x=73, y=97, z=7, stackpos=1},
wall2 = {x=74, y=97, z=7, stackpos=1},
wall3 = {x=73, y=96, z=7, stackpos=1},
wall4 = {x=74, y=96, z=7, stackpos=1},
}
local message = {
[1] = {x=72, y=96, z=7},
[2] = {x=75, y=98, z=7},
[3] = {x=73, y=97, z=7},
}
local fromPosition = {x=73, y=96, z=7}
local toPosition = {x=74, y=97, z=7}
 
 
function onUse(cid, item, frompos, item2, topos)
local t = message[math.random(1,3)]
getwall1 = getThingfromPos({x=73, y=97, z=7, stackpos=1})
getwall2 = getThingfromPos({x=74, y=97, z=7, stackpos=1})
getwall3 = getThingfromPos({x=73, y=96, z=7, stackpos=1})
getwall4 = getThingfromPos({x=74, y=96, z=7, stackpos=1})
 
 	if item.itemid == 1945 then  
		doTransformItem(item.uid,item.itemid+1)
			elseif item.itemid == 1946 then
				doTransformItem(item.uid,item.itemid-1)   
    end 
 
	if getwall1.itemid == 9485 then 
		exhaustion.set(cid, storage, 1 * 60 * 1000)
		doRemoveItem(getwall1.uid,1)
		doRemoveItem(getwall2.uid,1)
		doRemoveItem(getwall3.uid,1)
		doRemoveItem(getwall4.uid,1)
		doSendMagicEffect(config.wall1, CONST_ME_POFF)
		doSendMagicEffect(config.wall2, CONST_ME_POFF)
		doSendMagicEffect(config.wall3, CONST_ME_POFF)
		doSendMagicEffect(config.wall4, CONST_ME_POFF)
		doSendAnimatedText(t, "Criiinnkchi!", 193)
			elseif getwall1.itemid ~= 9485 and isInRange(getThingPosition(cid), fromPosition, toPosition) then
					doPlayerSendCancel(cid, "Someone is under the gate and it can not close")
						elseif getwall1.itemid ~= 9485 then 
								doCreateItem(9485,1,config.wall1)
								doCreateItem(9485,1,config.wall2)
								doCreateItem(9485,1,config.wall3)
								doCreateItem(9485,1,config.wall4) 
		end	
return true
end
not tested.
Sup panda, you'll get the hang of it!
LUA:
local config = {
wall1 = {x=73, y=97, z=7, stackpos=1},
wall2 = {x=74, y=97, z=7, stackpos=1},
wall3 = {x=73, y=96, z=7, stackpos=1},
wall4 = {x=74, y=96, z=7, stackpos=1},
}
local message = {
[1] = {x=72, y=96, z=7},
[2] = {x=75, y=98, z=7},
[3] = {x=73, y=97, z=7},
}
local from = {x=73, y=96, z=7}
local to = {x=74, y=97, z=7}
function check()
	for x = from.x, to.x do
		for y = from.y, to.y do
			local thing = getThingfromPosition(x = x, y = y, z = from.z, stackpos = 1)
			if isCreature(thing.uid) or thing.itemid > 0 then
				doPlayerSendCancel(cid, .. isCreature(thing.uid) and "Someone" or "Something" .." is under the gate and it can not close.")
				return false
			else
				return true
			end
		end
	end
end	
 
function onUse(cid, item, frompos, item2, topos)
local t = message[math.random(1,3)]
getwall1 = getThingfromPos({x=73, y=97, z=7, stackpos=1})
getwall2 = getThingfromPos({x=74, y=97, z=7, stackpos=1})
getwall3 = getThingfromPos({x=73, y=96, z=7, stackpos=1})
getwall4 = getThingfromPos({x=74, y=96, z=7, stackpos=1})
 
	doTransformItem(item.uid,(item.itemid == 1945 and item.itemid+1 or item.itemid-1))
	if check() then
		if getwall1.itemid == 9485 then 
			exhaustion.set(cid, storage, 1 * 60 * 1000)
			doRemoveItem(getwall1.uid,1)
			doRemoveItem(getwall2.uid,1)
			doRemoveItem(getwall3.uid,1)
			doRemoveItem(getwall4.uid,1)
			doSendMagicEffect(config.wall1, CONST_ME_POFF)
			doSendMagicEffect(config.wall2, CONST_ME_POFF)
			doSendMagicEffect(config.wall3, CONST_ME_POFF)
			doSendMagicEffect(config.wall4, CONST_ME_POFF)
			doSendAnimatedText(t, "Criiinnkchi!", 193)
		else 
			doCreateItem(9485,1,config.wall1)
			doCreateItem(9485,1,config.wall2)
			doCreateItem(9485,1,config.wall3)
			doCreateItem(9485,1,config.wall4) 
		end	
	end
return true
end
It may or may not work.
 
Sup panda, you'll get the hang of it!
LUA:
local config = {
wall1 = {x=73, y=97, z=7, stackpos=1},
wall2 = {x=74, y=97, z=7, stackpos=1},
wall3 = {x=73, y=96, z=7, stackpos=1},
wall4 = {x=74, y=96, z=7, stackpos=1},
}
local message = {
[1] = {x=72, y=96, z=7},
[2] = {x=75, y=98, z=7},
[3] = {x=73, y=97, z=7},
}
local from = {x=73, y=96, z=7}
local to = {x=74, y=97, z=7}
function check()
	for x = from.x, to.x do
		for y = from.y, to.y do
			local thing = getThingfromPosition(x = x, y = y, z = from.z, stackpos = 1)
			if isCreature(thing.uid) or thing.itemid > 0 then
				doPlayerSendCancel(cid, .. isCreature(thing.uid) and "Someone" or "Something" .." is under the gate and it can not close.")
				return false
			else
				return true
			end
		end
	end
end	
 
function onUse(cid, item, frompos, item2, topos)
local t = message[math.random(1,3)]
getwall1 = getThingfromPos({x=73, y=97, z=7, stackpos=1})
getwall2 = getThingfromPos({x=74, y=97, z=7, stackpos=1})
getwall3 = getThingfromPos({x=73, y=96, z=7, stackpos=1})
getwall4 = getThingfromPos({x=74, y=96, z=7, stackpos=1})
 
	doTransformItem(item.uid,(item.itemid == 1945 and item.itemid+1 or item.itemid-1))
	if check() then
		if getwall1.itemid == 9485 then 
			exhaustion.set(cid, storage, 1 * 60 * 1000)
			doRemoveItem(getwall1.uid,1)
			doRemoveItem(getwall2.uid,1)
			doRemoveItem(getwall3.uid,1)
			doRemoveItem(getwall4.uid,1)
			doSendMagicEffect(config.wall1, CONST_ME_POFF)
			doSendMagicEffect(config.wall2, CONST_ME_POFF)
			doSendMagicEffect(config.wall3, CONST_ME_POFF)
			doSendMagicEffect(config.wall4, CONST_ME_POFF)
			doSendAnimatedText(t, "Criiinnkchi!", 193)
		else 
			doCreateItem(9485,1,config.wall1)
			doCreateItem(9485,1,config.wall2)
			doCreateItem(9485,1,config.wall3)
			doCreateItem(9485,1,config.wall4) 
		end	
	end
return true
end
It may or may not work.

getting this error when loading script

errorper.png
 
LUA:
function check()
	for x = from.x, to.x do
		for y = from.y, to.y do
			local thing = getThingfromPosition(x = x, y = y, z = from.z, stackpos = 1)
			if isCreature(thing.uid) or thing.itemid > 0 then
				doPlayerSendCancel(cid, .. isCreature(thing.uid) and "Someone" or "Something" .." is under the gate and it can not close.")
				return false
			else
				return true
			end
		end
	end
end
funny how so many people think using return like that in a loop is going to work properly
 
LUA:
local msg = {
	{x=72, y=96, z=7},
	{x=75, y=98, z=7},
	{x=73, y=97, z=7}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1946 then
		for x = 73, 74 do
			for y = 96, 97 do
				local v = getThingfromPos({x=x, y=y, z=7, stackpos=1}).uid
				if v ~= 0 then
					return doCreatureSay(cid, 'Some' .. (isCreature(v) and 'one' or 'thing') .. ' is under the gate and it cannot close.', TALKTYPE_ORANGE_1, false, cid)
				end
			end
		end
	else
		doSendAnimatedText(msg[math.random(#msg)], 'Criiinnkchi!', 193)
	end
	for x = 73, 74 do
		for y = 96, 97 do
			local p = {x=x, y=y, z=7}
			if item.itemid == 1945 then
				doRemoveItem(getTileItemById(p, 9485).uid)
				doSendMagicEffect(p, CONST_ME_POFF)
			else
				doCreateItem(9485, 1, p)
			end
		end
	end
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
@Knight God
You're not authorized to use my thread to ask this! :D

@Cykotitan
It's working perfectly, but when the gate is closed by another lever, it just return the message..
The correctly way would work only with creatures (monsters and players), not with items, etc.

@Santi
Maybe you're right?
 
@Knight God
You're not authorized to use my thread to ask this! :D

@Cykotitan
It's working perfectly, but when the gate is closed by another lever, it just return the message..
The correctly way would work only with creatures (monsters and players), not with items, etc.

@Santi
Maybe you're right?

F*****ng
 
Back
Top