• 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 check if someone is in the room (SOLVED)

tompan

Member
Joined
Dec 13, 2008
Messages
646
Reaction score
23
Location
Sweden
i have this simple lua script here. but i want it to check if there is players inside this room already before teleporting.. and so you will be kicked from the room after x mins.

Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)


pos =    {x = 98, y = 440, z = 7}
	if
	doTeleportThing(cid,pos)
	      	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "welcome to hell..")
		return true
   	end

so i searched around for simlar codes found one at annihlator quest.
Lua:
-- Annihilator by Shawak v2.1

        -- CONFIG --

        local room = {     -- room with demons
        fromX = 33219,
        fromY = 31657,
        fromZ = 13,
        --------------
        toX = 33222,
        toY = 31661,
        toZ = 13
        }

        local monster_pos = {
        [1] = {pos = {33219, 31657, 13}, monster = "Demon"},
        [2] = {pos = {33221, 31657, 13}, monster = "Demon"},
        [3] = {pos = {33220, 31661, 13}, monster = "Demon"},
        [4] = {pos = {33222, 31661, 13}, monster = "Demon"},
        [5] = {pos = {33223, 31659, 13}, monster = "Demon"},
        [6] = {pos = {33224, 31659, 13}, monster = "Demon"}
        }

        local players_pos = {
        {x = 33222, y =31671, z = 13, stackpos = 253},
        {x = 33223, y =31671, z = 13, stackpos = 253},
        {x = 33224, y =31671, z = 13, stackpos = 253},
        {x = 33225, y =31671, z = 13, stackpos = 253}
        }

        local new_player_pos = {
        {x = 33219, y = 31659, z = 13},
        {x = 33220, y = 31659, z = 13},
        {x = 33221, y = 31659, z = 13},
        {x = 33222, y = 31659, z = 13}
        }

        local playersOnly = "yes"
        local questLevel = 100

        ------------------------------------------------------
        --- CONFIG END ---------------------------------------
        ------------------------------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local all_ready, monsters, player, level = 0, 0, {}, 0
	if item.uid == 10009 then
        if item.itemid == 1945 then
                for i = 1, #players_pos do
                        table.insert(player, 0)
                end
                for i = 1, #players_pos do
                        player[i] = getThingfromPos(players_pos[i])
                        if player[i].itemid > 0 then
                                if string.lower(playersOnly) == "yes" then
                                        if isPlayer(player[i].uid) == TRUE then
                                                all_ready = all_ready+1
                                        else
                                                monsters = monsters+1
                                        end
                                else
                                        all_ready = all_ready+1
                                end
                        end
                end
                if all_ready == #players_pos then
                        for i = 1, #players_pos do
                                player[i] = getThingfromPos(players_pos[i])
                                if isPlayer(player[i].uid) == TRUE then
                                        if getPlayerLevel(player[i].uid) >= questLevel then
                                                level = level+1
                                        end
                                else
                                        level = level+1
                                end
                        end
                        if level == #players_pos then
                                if string.lower(playersOnly) == "yes" and monsters == 0 or string.lower(playersOnly) == "no" then
                                        for _, area in pairs(monster_pos) do
                                                        doSummonCreature(area.monster,{x=area.pos[1],y=area.pos[2],z=area.pos[3]})
                                        end
                                        for i = 1, #players_pos do
                                                doSendMagicEffect(players_pos[i], CONST_ME_POFF)
                                                doTeleportThing(player[i].uid, new_player_pos[i])
                                                doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                                doTransformItem(item.uid,1946)
                                        end
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can do this quest.")
                                end
                        else
                                doPlayerSendTextMessage(cid,19,"All Players have to be level "..questLevel.." to do this quest.")
                        end
                else
                        doPlayerSendCancel(cid,"You need "..table.getn(players_pos).." players to do this quest.")
                end
        elseif item.itemid == 1946 then
                local player_room = 0
                for x = room.fromX, room.toX do
                        for y = room.fromY, room.toY do
                                for z = room.fromZ, room.toZ do
                                        local pos = {x=x, y=y, z=z,stackpos = 253}
                                        local thing = getThingfromPos(pos)
                                        if thing.itemid > 0 then
                                                if isPlayer(thing.uid) == TRUE then
                                                        player_room = player_room+1
                                                end
                                        end
                                end
                        end
                end
                if player_room >= 1 then
                        doPlayerSendTextMessage(cid,19,"There is already a team in the quest room.")          
                elseif player_room == 0 then
                        for x = room.fromX, room.toX do
                                for y = room.fromY, room.toY do
                                        for z = room.fromZ, room.toZ do
                                                local pos = {x=x, y=y, z=z,stackpos = 253}
                                                local thing = getThingfromPos(pos)
                                                if thing.itemid > 0 then
                                                        doRemoveCreature(thing.uid)
                                                end
                                        end
                                end
                        end
                        doTransformItem(item.uid,1945)
                end
        end
	end	
        return TRUE
end

i tried to mix these 2 up but it wont work. :p
 
Lua:
local area = {
	fromPos = {x=123,y=123,z=1},
	toPos = {x=123,y=123,z=1}
	}
for _, pid in ipairs(getPlayersOnline()) do
	if isInRange(pid, area.fromPos, area.toPos) then
		lalalala
	else
		lolololo
	end
end
 
i made it like this, not sure if its right? but i got some errors.

Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)




pos =    {x = 98, y = 440, z = 7}

local area = {
	fromPos = {x=98,y=440,z=8},
	toPos = {x=103,y=445,z=8}
	}
for _, pid in ipairs(getPlayersOnline()) do
	if isInRange(pid, area.fromPos, area.toPos) then
			doTeleportThing(cid,pos)
	      	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "welcome to hell..")
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "someone is already in the room.")
	end
end
return true
end

[error - MoveEvents Interface ]
data/movemens/scrips/team/tpin.lua:eek:nStepIn
Description: data/lib/032-position.lua:2: attemps to index local ´position´ <a number value>
stack traceback: data/lib/032-position.lua:2: in function +isInRange´
dara/movements/scripts/team/tpin.lua:13: in function <data/movements/scripts/team/tpin.lua:1>
 
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
  
local pos = {x = 98, y = 440, z = 7}
 
local area = {
	fromPos = {x=98,y=440,z=8},
	toPos = {x=103,y=445,z=8}
	}

	if not isPlayer(cid) then
		return true
	end

	for _, pid in ipairs(getPlayersOnline()) do
		local xpos = getPlayerPosition(pid)
		if isInRange(xpos, area.fromPos, area.toPos) then
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Someone is already in the room.")
			doTeleportThing(cid,fromPosition)
		else
			doTeleportThing(cid,pos)
	      	        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to hell..")
		end
	end
	return true
end
 
Thank you again for your help!! :)

but some issue.. If i walk in then it doesnt stop other persons from going in only me if im trying to enter again :S
 
Last edited:
Lua:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition)
  
local pos = {x = 98, y = 440, z = 8}

local fromPos = {x = 98, y = 440, z = 8} 
local toPos = {x= 103, y = 445, z = 8}
 
	if not isPlayer(cid) then
		return true
	end

	local amount = 0
	for x = fromPos.x, toPos.x do
		for y = fromPos.y, toPos.y do
			for z = fromPos.z, toPos.z do
				if isPlayer(getTopCreature({x=x,y=y,z=z}).uid) then
					amount = amount+1
				end	
			end
		end
	end
	if amount >= 1 then
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Someone is already in the room.")
		doTeleportThing(cid,fromPosition)
	else
		doTeleportThing(cid,pos)
	      	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Welcome to hell..")
	end
end
 
THANKS!!! Sweet.. at first i didnt think it was going to work because i only saw the scripts with the getPlayersOnline().. lol But it works just fine!!

Added to my Multi Usage Quest lua file.. So far it has cap error msg, keys, books, rewards, rewards in Bag/Backpack, Vocation specific Rewards and now Monsters in area killed.. =)
 
Back
Top