• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Search castle system

OK LoOk In data/actions put this
<action itemid="11401" event="script" value="castles.lua"/>

You Can Change The Itemid "11401" To Any Other Item....
Here Is The Script...



local lvl = getConfigInfo('levelToBuyHouse')

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerLevel(cid) < lvl then
return doPlayerSendCancel(cid, 'You have to be at least Level ' .. lvl .. ' to purchase a house.')
elseif isPlayerPzLocked(cid) then
return doPlayerSendCancel(cid, 'You cannot use this while PZlocked.')
end

local castles = db.getResult('SELECT id FROM houses WHERE town=4')
if castles:getID() == -1 then
return true
end

local owners, id, castle = {}, getPlayerGUID(cid), nil
repeat
local hid = castles:getDataInt('id')
local owner = getHouseInfo(hid).owner
if owner == id then
return doPlayerSendCancel(cid, 'Your character already owns a castle.')
elseif owner == 0 or owner == 14 then
if castle == nil then
castle = hid
end
else
table.insert(owners, owner)
end
until not castles:next()
castles:free()

if not castle then
return doPlayerSendCancel(cid, 'There are no castles available at this moment.')
end

local acc = db.getResult('SELECT id FROM players WHERE account_id = '.. getPlayerAccountId(cid) .. ' AND id != ' .. id)
if acc:getID() ~= -1 then
repeat
if table.find(owners, acc:getDataInt('id')) then
return doPlayerSendCancel(cid, 'Your account already owns a castle.')
end
until not acc:next()
acc:free()
end

doRemoveItem(item.uid)

local k = getHouseInfo(castle)
setHouseOwner(castle, id)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Welcome to your new home, ' .. k.name .. '! Congratulations !. To get here again, enter the teleport in Temple +1')
doBroadcastMessage(getCreatureName(cid) .. ' has bought ' .. k.name .. ' using a Castle Box.', MESSAGE_EVENT_ADVANCE)

local old = getThingPos(cid)
doTeleportThing(cid, k.entry)
doSendMagicEffect(old, CONST_ME_TELEPORT)
doSendMagicEffect(k.entry, CONST_ME_TELEPORT)
return true
end



elseif owner == 0 or owner == 14 then <<< CHANGE THIS TO UR OWNER NUMBER ID

local castles = db.getResult('SELECT id FROM houses WHERE town=4') << ANd THIS U MUST HAVE A CITY CALLED CASTLES AND CHANGE THE TOWN ID =4 WITH UR ONE
----------------------------------
IN GLOBALEVENTS FILE PUT THIS
<globalevent name="castles" interval="4000" event="script" value="castles.lua"/>



Here Is The Script also change the City id


function onThink()
local castles = db.getResult('SELECT id FROM houses WHERE town=4')
if castles:getID() == -1 then
return true
end

local p = getPlayersOnline()[1]
repeat
local hid = castles:getDataInt('id')
local h = getHouseInfo(hid)
if h.owner == 0 then
setHouseOwner(hid, 10)
elseif p then
local n = tonumber(h.name:sub(-2)) or 0
h.entry.x = h.entry.x + (n % 2 == 0 and 3 or -3)
doCreatureSay(p, getPlayerNameByGUID(h.owner), TALKTYPE_ORANGE_1, false, 0, h.entry)
end
until not castles:next()
castles:free()

return true
end
 
Back
Top