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

[Action] Check room

Northnorial

Member
Joined
May 30, 2009
Messages
742
Reaction score
5
Location
Germany
I need an action that checks a room, if there's a player inside you can't use the door, but if the room is free you will be teleported into the training room, which has one tile only.
 
Lua:
-- Training Room by Calum69 v 1.0
-- Credits to Shawak for original script

        -- CONFIG --

        local room = {     -- training room
        fromX = 80,
        fromY = 122,
        fromZ = 7,
        --------------
        toX = 83,
        toY = 126,
        toZ = 7
        }

        local monster_pos = {
        [1] = {pos = {80, 122, 7}, monster = "Training Monk"},
        [2] = {pos = {82, 122, 7}, monster = "Training Monk"},
        }

        local players_pos = {x = 83, y = 136, z = 7, stackpos = 253}

        local new_player_pos = {x = 80, y = 124, z = 7}

        local playersOnly = "yes"
        local trainingroomLevel = 0

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

function onUse(cid, item, fromPosition, itemEx, toPosition)
        local all_ready, monsters, player, level = 0, 0, {}, 0
        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) >= trainingroomLevel 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], FALSE)
                                                doSendMagicEffect(new_player_pos[i], CONST_ME_ENERGYAREA)
                                                doTransformItem(item.uid,1946)
                                        end
                                else
                                        doPlayerSendTextMessage(cid,19,"Only players can use the training rooms.")
                                end
                        else
                                doPlayerSendTextMessage(cid,19,"You have to be level "..trainingroomLevel.." to use the training rooms.")
                        end
                else
                        doPlayerSendTextMessage(cid,19,"You need "..table.getn(players_pos).." player to stand on the switch to enter the room.")
                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 player in the training 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
        return TRUE
end

try this its untested change the area you need and such tell me errors i will fix

same setup as annih, use a lever to enter the training room. you can only enter training rooms if they are empty.
 
DoubleFacepalmRickerPicard.jpg

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

	local pos, door = getThingPos(cid), toPosition
	if isInArray({door.x-1, door.x+1}, pos.x) and pos.y == door.y then
		door.x = door.x + (pos.x < door.x and 1 or -1)
	elseif isInArray({door.y-1, door.y+1}, pos.y) and pos.x == door.x then
		door.y = door.y + (pos.y < door.y and 1 or -1)
	else
		return doPlayerSendCancel(cid, 'You must stand in front of the door!')
	end

	local v = getTopCreature(door).uid
	if isPlayer(v) then
		return doPlayerSendCancel(cid, 'There\'s a player inside.')
	else
		doTeleportThing(cid, door)
		doSendMagicEffect(door, CONST_ME_TELEPORT)
	end
	return true
end
 
Last edited:
Back
Top