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

Solved Donation castle error

UchihaClan

Only you can be you
Joined
Oct 25, 2014
Messages
164
Reaction score
33
Hello!

I got a samll problem in my server it´s ain´t so big but it´s anoing, people can buy donation castle with crystal coins, example they can go to a castle house and just write !buyhouse and get the house, and that´s a problem because donation castle in my server is donate so people need to buy it from the shop to get a donation castle.
Here´s my donation castle script:
Code:
__castle = {
    ReqNum = 1,
    ReqLvl = 150,

    StartMins = 2,
    LobbyMins = 5,
    ConquerMins = 60,

    Lobby = {
        Position( 999, 659, 6 ),
        Position(1017, 660, 6 ),
        Position(1007, 674, 6 )
    },

    Temple = {
        Position( 927, 637, 6 ),
        Position( 898, 649, 7 ),
        Position( 951, 641, 7 ),
        Position( 950, 642, 6 )
    },

    Outfit = {
        {lookHead= 75, lookBody=94, lookLegs=113, lookFeet=112},
        {lookHead= 87, lookBody=86, lookLegs=105, lookFeet=106},
        {lookHead=100, lookBody=81, lookLegs=101, lookFeet=120}
    },

    Throne = Position( 927, 634, 6 ),

    key = {
        active = 4500,
        guilds = {},
        damage = {},
        owner = 4510
    },

    Spawn = {
        {30, {'Demon', 'Fury', 'Dark Torturer', 'Plaguesmith', 'Behemoth', 'Nightmare', 'Lost Soul'}, Position(909, 635, 6), Position(945, 644, 6)},
        {10, {'Juggernaut'}, Position(922, 635, 6), Position(932, 642, 6)},
    },

    STATE_INACTIVE = -1,
    STATE_LOBBY = 0,
    STATE_ACTIVE = 1
}

for i = 1, #__castle.Temple do
    __castle.key.guilds[i] = 4500 + i
end

for i = 1, #__castle.Temple do
    __castle.key.damage[i] = 4500 + #__castle.Temple + i
end

__castle.getPlayers = function(guild)
    local s, r = getStorage(key.guilds[guild]), {}
    if s == __castle.STATE_INACTIVE then
        return {}
    end

    s = string.explode(s:sub(2), ',')
    for i = 2, #s do
        table.insert(r, tonumber(s[i]))
    end
    return r
end

__castle.getTeam = function(cid)
    return getCreatureStorage(cid, key.active)
end

__castle.send = function(cid, pos, effect)
    doTeleportThing(cid, pos)
    doRemoveConditions(cid, true)
    doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid), effect or CONST_ME_NONE, 256, true)
    doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid), false)
end

__castle.registerEvents = function(cid)
    registerCreatureEvent(cid, 'CastleDeath')
    registerCreatureEvent(cid, 'CastleCombat')
end

__castle.start = function()
    if getStorage(__castle.key.active) == __castle.STATE_ACTIVE then
        return
    end

    doSetStorage(__castle.key.active, __castle.STATE_ACTIVE)

    doRemoveItem(getTileItemById(Throne, 5915).uid)
    local f = doCreateMonster('Throne', Throne, false, true, true)
    registerCreatureEvent(f, 'CastleDeath')
    registerCreatureEvent(f, 'CastleStats')

    local g, def = getStorage(__castle.key.owner), {}
    if g ~= -1 then
        local t = getPlayersOnline()
        if #t >= ReqNum then
            for i = 1, #t do
                if getPlayerGuildId(t[i]) == g and getPlayerLevel(t[i]) >= __castle.ReqLvl and isPlayerPzLocked(t[i]) == false then
                    table.insert(def, t[i])
                end
            end
        end
    end

    if #def >= __castle.ReqNum then
        for i = 1, #def do
            send(def[i], Temple[0])
            doPlayerSendTextMessage(def[i], MESSAGE_EVENT_ADVANCE, '[Castle - Defense]\n\Protect the Castle\'s throne at all costs for ' .. ConquerMins .. ' minutes!')
            doCreatureSetStorage(def[i], __castle.key.active, 0)
            registerEvents(def[i])
        end
    else
        if g ~= -1 then
            doSetStorage(__castle.key.owner, nil)
        end
        for _, v in ipairs(__castle.Spawn) do
            for i = 1, v[1] do
                doCreateMonster(v[2][math.random(#v[2])], {x=math.random(v[3].x, v[4].x), y=math.random(v[3].y, v[4].y), z=v[3].z == v[4].z and v[3].z or math.random(v[3].z, v[4].z)})
            end
        end
    end

    for n = 1, #__castle.key.guilds do
        local p = getPlayers(n)
        for i = 1, #p do
            __castle.send(p[i], Temple[n])
            doPlayerSendTextMessage(p[i], MESSAGE_EVENT_ADVANCE, '[Castle - Conquest]\n\nYour guild has ' .. ConquerMins .. ' minutes to inflict the most damage to the throne.')
            doCreatureSetStorage(p[i], __castle.key.active, n)
            __castle.registerEvents(p[i])
        end
        doSendMagicEffect(Temple[n], CONST_ME_ENERGYAREA)
        doSetStorage(__castle.key.damage[n], 0)
    end
    addEvent(__castle.finish, __castle.ConquerMins * 60000)
end

__castle.finish = function(kill)
    if getStorage(__castle.key.active) ~= STATE_ACTIVE then
        return
    end

    doSetStorage(__castle.key.active, nil)

    local dmg, s, n = {}
    local holdout = not kill and getStorage(__castle.key.owner) ~= -1

    for n = 1, #__castle.key.guilds do
        local p = getPlayers(n)
        if not holdout then
            dmg[n] = {getStorage(__castle.key.guilds[n]), getStorage(key.damage[n])}
        end
        for i = 1, #p do
            unregisterCreatureEvent(p[i], 'CastleDeath')
            unregisterCreatureEvent(p[i], 'CastleCombat')
            doRemoveCondition(p[i], CONDITION_OUTFIT)
            __castle.send(p[i], getPlayerMasterPos(p[i]))
        end
    end
    if holdout then
        for _, cid in ipairs(getPlayersOnline()) do -- teleport defenders out, need better method
            if __castle.getTeam(cid) == 0 then
                unregisterCreatureEvent(p[i], 'CastleDeath')
                unregisterCreatureEvent(p[i], 'CastleCombat')
                doRemoveCondition(p[i], CONDITION_OUTFIT)
                __castle.send(p[i], getPlayerMasterPos(p[i]))
            end
        end
        doRemoveCreature(getTopCreature(Throne).uid)
        s = 'The guild %s has successfully defended their throne and remains the castle owner for another week!'
        n = getStorage(key.owner)
    else
        table.sort(dmg, function(a, b) return a[2] > b[2] end)
        s = '%s has become the new castle owner, dealing ' .. math.ceil(dmg[1][2] / getMonsterInfo('Throne').healthMax * 100) .. '%% of the damage on the throne.\nThe next conquest will occur in 7 days.'
        n = tonumber(string.explode(dmg[1][1]:sub(2), ',')[1])
        doSetStorage(__castle.key.owner, n)
    end

    local q = db.getResult('SELECT name FROM guilds WHERE id=' .. n)
    local name = q:getDataString('name')
    q:free()
    doBroadcastMessage('[Castle - Endgame]\n\n' .. s:format(name), MESSAGE_EVENT_ADVANCE)
    doCreateItem(5915, 1, __castle.Throne)
    for k, v in ipairs({__castle.key.guilds, __castle.key.damage}) do
        for i = 1, #v do
            doSetStorage(v[i], nil)
        end
    end
end
 
Back
Top