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

Donation Castle System [Automatic]

Cornex

Web Developer
Staff member
Global Moderator
Joined
Jun 15, 2008
Messages
3,444
Solutions
5
Reaction score
1,166
Location
Sweden
Hello, like i said i will post an useful script over here.
This script allows you to buy castles, automatic. Any contact with staff is not needed.

I don't take any credits for this script, it is created by Cykotitan so far i know.

First of all, we need an globalevent to make all donation castles owned by admin.
How to do this?

Just do follow:

1: Put this line in Globalevents.xml

Code:
<globalevent name="castles" interval="4000" event="script" value="castles.lua"/>

2: Make an file castles.lua and put this in it:

Code:
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, 5370)
        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

(Yes, on the entry it will show the name of owner. But this can easy be deleted.)

Now we gonna edit this script, first of all we need to look on this part:

Code:
if h.owner == 0 then
            setHouseOwner(hid, 5370)

if h.owner == 0 means that if nobody owns the house, it automatic set owner id 5370. This is the id of the char and should be changed to your admin.

Lets move over to the action part there we gonna set the item to use, to recive your castle.

1: In actions.xml , put in this line:

Code:
<action itemid="11401" event="script" value="castle.lua"/>

2: Make an new file into scripts, name it castle.lua and put this code into it:

Code:
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 == 5370 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 .. '! You can now step into the teleport. 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

Remember, the castle doors should have an own town id.
So when you are in mapeditor, make ctrl+t and create an new town. Name it "castles" and what ever id it got, change:
Code:
SELECT id FROM houses WHERE town=4

To the id of your town.
ALSO REMEMBER, to change the id "5370" in BOTH scripts. To your admin char id.

Hope this help someone out, peace.
 
Last edited:
I need more explain about that so u mean I need put admin id that's maybe no.1 as it's the first account
oki
that's mean if my castle named admin player will get it easy right

so if I have like 10 castles with admin name
and a player have a castle doll
1 from my castle will be his name like Player
and if another one buy another one ?
the next id of house will change from admin to Tester?
 
its not work in tfs 0.3.6 when i use the actionid 02:03 You need Castle Doll to enter on this sqm.
and when i got the doll i can only acces the Sqm and no house buy!
 
[18:26:44.609] [Error - GlobalEvent Interface]
[18:26:44.609] data/globalevents/scripts/castles.lua:eek:nThink
[18:26:44.625] Description:
[18:26:44.625] data/globalevents/scripts/castles.lua:11: attempt to index local
'h' (a boolean value)
[18:26:44.625] stack traceback:
[18:26:44.625] data/globalevents/scripts/castles.lua:11: in function <data/glob
alevents/scripts/castles.lua:1>
[18:26:44.640] [Error - GlobalEvents::think] Couldn't execute event: castles



help
 
[18:26:44.609] [Error - GlobalEvent Interface]
[18:26:44.609] data/globalevents/scripts/castles.lua:eek:nThink
[18:26:44.625] Description:
[18:26:44.625] data/globalevents/scripts/castles.lua:11: attempt to index local
'h' (a boolean value)
[18:26:44.625] stack traceback:
[18:26:44.625] data/globalevents/scripts/castles.lua:11: in function <data/glob
alevents/scripts/castles.lua:1>
[18:26:44.640] [Error - GlobalEvents::think] Couldn't execute event: castles



help
I have the same error and i'm using 0.4 anyone knows whats wrong.
 
If you could show me the script with tab, then i may could help.
 
IR9zvN.png


Code:
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, 5370)
            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
 
Last edited:
Bump please help.

IR9zvN.png


Code:
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, 5370)
            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
 
how can i rep u xD :D

You can't, was in old forum the rep system was there.
In XenForo like my post is same as rep, but I do not really care about that :)
 
[23/02/2015 02:28:03] [Error - Action Interface]
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:eek:nUse
[23/02/2015 02:28:03] Description:
[23/02/2015 02:28:03] (luaGetHouseInfo) House not found

[23/02/2015 02:28:03] [Error - Action Interface]
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:eek:nUse
[23/02/2015 02:28:03] Description:
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:18: attempt to index a boolean value
[23/02/2015 02:28:03] stack traceback:
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:18: in function <data/actions/scripts/other/castle.lua:3>


I've set the right ID too, my gm ID in database in players table is 2, and town ID in map editor is 1 and I have also added that into the scripts, I get these error's as soon as I use the item to buy castle.
 
[23/02/2015 02:28:03] [Error - Action Interface]
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:eek:nUse
[23/02/2015 02:28:03] Description:
[23/02/2015 02:28:03] (luaGetHouseInfo) House not found

[23/02/2015 02:28:03] [Error - Action Interface]
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:eek:nUse
[23/02/2015 02:28:03] Description:
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:18: attempt to index a boolean value
[23/02/2015 02:28:03] stack traceback:
[23/02/2015 02:28:03] data/actions/scripts/other/castle.lua:18: in function <data/actions/scripts/other/castle.lua:3>


I've set the right ID too, my gm ID in database in players table is 2, and town ID in map editor is 1 and I have also added that into the scripts, I get these error's as soon as I use the item to buy castle.
it works will with me tfs 0.3.6
 
Back
Top