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

error with donation castle system automatic

7amo

New Member
Joined
Feb 16, 2011
Messages
147
Reaction score
3
Location
egypt
Iam Using
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

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

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

Lua:
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:

Lua:
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:

XML:
<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:

Lua:
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:
Lua:
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.

but it gives me this error
iam using TFS 0.4
Please Help
IR9zvN.png

Bumb!

BumB!
 
Last edited by a moderator:
Back
Top