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

TFS 0.X VIP scroll for Acc

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
Hello people,

I have a VIP Scroll script that works well and suits my needs, however it only makes the player VIP, not the entire account. How to change to my VIP scroll action give vipStorage (30009) for all characters of the same acc? Im using TFS 0.4. Follow my action.

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getPlayerStorageValue(cid, vipStorage)
    setPlayerStorageValue(cid, vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
 
Solution
SQL:
CREATE TABLE `account_storage` (
  `account_id` int(11) NOT NULL,
  `key` varchar(32) NOT NULL DEFAULT '0',
  `value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if...

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,625
Solutions
397
Reaction score
3,735
You'd have to implement an account storage system, as opposed to a regular storage value.
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
You'd have to implement an account storage system, as opposed to a regular storage value.
Sure, added to lib

1628107829941.png

And created table in my database. What i have to do now?
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
Use it like you would a regular storage value.
so, i need to change my code to this? Im really not sure:

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getAccountStorageValue(cid, vipStorage)
    setAccountStorageValue(cid, vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,625
Solutions
397
Reaction score
3,735
so, i need to change my code to this? Im really not sure:

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getAccountStorageValue(cid, vipStorage)
    setAccountStorageValue(cid, vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
Can't use cid, since it wants the accountID.
change cid for getPlayerAccountId(cid)
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
like this?

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(getPlayerAccountId(cid), item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getAccountStorageValue(getPlayerAccountId(cid), vipStorage)
    setAccountStorageValue(getPlayerAccountId(cid), vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(getPlayerAccountId(cid), MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,625
Solutions
397
Reaction score
3,735
like this?

Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(getPlayerAccountId(cid), item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getAccountStorageValue(getPlayerAccountId(cid), vipStorage)
    setAccountStorageValue(getPlayerAccountId(cid), vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(getPlayerAccountId(cid), MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end
looks good.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,625
Solutions
397
Reaction score
3,735
didn't see that you change every cid.. lol
Only those 2 functions need to acountID not every function.

change
Lua:
doPlayerSendTextMessage(getPlayerAccountId(cid), MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
to
Lua:
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")

and
Lua:
function onUse(getPlayerAccountId(cid), item, fromPosition, itemEx, toPosition)
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
Now i not got error in console, but i cant filter who enter in vip area (using account storage) or who can use /autoloot (using storage too):

My VIP Scroll
Lua:
local vipStorage = 30009
local vipDays = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local currentTime, vipStorageValue = os.time(), getAccountStorageValue(cid, vipStorage)
    SetAccountStorageValue(getPlayerAccountId(cid), vipStorage, (vipStorageValue < currentTime and currentTime or vipStorageValue) + (60 * 60 * 24 * vipDays))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. vipDays .. " VIP days to this account!")
    doRemoveItem(item.uid, 1)
    return true
end

Movement to enter in VIP Area

Lua:
function onStepIn(cid, item, pos, fromPos)

local position = {x = 343, y = 155, z = 7} -- edita aqui a posição para qual o player será teleportado

if isPlayer(cid) == true and getAccountStorageValue(cid, 30009) >= os.time() then
doTeleportThing(cid, position)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT,"Welcome to VIP area!")

else

doTeleportThing(cid, fromPos)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT,"You don't have VIP access!")
end
return true
end
Post automatically merged:

And need to change Autoloot to only Account 30009 Storage

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>

<mod name="Perfect Auto Loot" version="2.0" author="Vodkart" contact="none.com" enabled="yes">

<config name="Loot_func"><![CDATA[



info = {

    directory = "data/logs/autoloot",

    Warn_Bp_Slots = 5, -- quando tiver 5 ou menos slots na BP vai avisar o jogador

    Talkaction_delay = 1, -- em segundos // delay para remover e adicionar item

    BlockMonsters = {},

    BlockItemsList = {2515},

    Money_ids = {2160}, -- id das moedas do ot

    Max_Slots = {free = 20, premium = 20},

    Storages = {988801, 988802, 988803, 988804, 988805, 988806, 988807}

}



Color_Loot = {

           [0] = {MESSAGE_EVENT_ORANGE, "Orange"},

           [1] = {MESSAGE_STATUS_CONSOLE_BLUE, "Blue"},

           [2] = {MESSAGE_INFO_DESCR, "Green"},

           [3] = {MESSAGE_STATUS_CONSOLE_RED, "Red"},

           [4] = {MESSAGE_STATUS_SMALL, "White"}

}

function getPlayerColorLootMessage(cid)

    return getPlayerStorageValue(cid, info.Storages[5]) <= 0 and 0 or getPlayerStorageValue(cid, info.Storages[5])

end

function isInTable(cid, item)

    for _,i in pairs(getItensFromAutoloot(cid)) do

        if tonumber(i) == tonumber(item) then

            return true

        end

    end

    return false

end

function doremoveItemFromAutoloot(cid, itemid)

    local file, fileContent = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'r'),{}

    for line in file:lines() do

     if line ~= "" and tonumber(line) ~= tonumber(itemid) then

             fileContent[#fileContent + 1] = line

        end

    end

    io.close(file)

    file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'w')

    for index, value in ipairs(fileContent) do

    file:write(value..'\n')

    end

    io.close(file)

end

function doAddItemFromAutoloot(cid, itemid)

         if not existsAutoloot(cid) then

            doCreateLootUserName(cid, itemid) return true

         end

         local file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "a+")                          

         file:write('\n'..itemid)

         file:close()

end

function existsAutoloot(cid)

  local f = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "rb")

  if f then f:close() end

  return f ~= nil

end

function doCreateLootUserName(cid, itemid)

    newFile = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "w+" )

    newFile:write(itemid)

    newFile:close()

end

function getItensFromAutoloot(cid)

  if not existsAutoloot(cid) then return {} end

  lines = {}

  for line in io.lines(info.directory.."/"..getCreatureName(cid)..".txt") do

      if line ~= "" then

              lines[#lines + 1] = tonumber(line)

      end

  end

  return lines

end

function doCleanAutoloot(cid)

return os.remove(info.directory.."/"..getCreatureName(cid)..".txt")

end

function ShowItemsTabble(cid)

    local auto_list = getItensFromAutoloot(cid)  

    local n,str = 0,"[+] Auto Loot Commands [+]\n\n!autoloot item name --> To add ou Remove item from list.\n!autoloot money --> To collect gold automatically (only for crystal coin).\n!autoloot clear --> To clear the list.\n!autoloot on/off --> To enable or disable the collecting of items in the system.\n!autoloot message --> To enable or disable message from Collect items.\n!autoloot color --> To change Color message in Auto Loot Collect.\n!autoloot warn --> To enable or disable message warning of "..info.Warn_Bp_Slots.." or less slots in the backpack.\n!autoloot deposit --> To enable or disable automatic money deposit at the bank.\n\n[+] Auto Loot Info [+]\n\nSystem: "..(getPlayerStorageValue(cid, info.Storages[1]) <= 0 and "Activated" or "Disabled")..".\nGold Collecting: "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "Disabled")..".\nMessage: "..(getPlayerStorageValue(cid, info.Storages[6]) <= 0 and "Activated" or "Disabled")..".\nColor Message: "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".\nWarn Backpack: "..(getPlayerStorageValue(cid, info.Storages[3]) <= 0 and "Activated" or "Disabled")..".\nAutomatic Gold Deposit: "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "Disabled")..".\nTotal Bank Balance: ["..getPlayerBalance(cid).."]\nMaximum Slots: ["..#auto_list.."/"..(isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free).."]\n\n[+] Auto Loot Slots [+]\n\n"

    if #auto_list > 0 then

        for i = 1, #auto_list do

            n = n + 1

            str = str.."Slot "..n.." - "..getItemNameById(auto_list[i]).."\n"

        end

    end

        doShowTextDialog(cid, 1961, str)

end

function getContainerItems(container, array, haveCap)

    array = array or {}

    haveCap = haveCap or false

    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then

        array[#array +1] = container

    else

        local size = getContainerSize(container.uid)

        haveCap = (getContainerCap(container.uid) -size) > 0

        for slot = 0, (size -1) do

            local item = getContainerItem(container.uid, slot)

            if item.itemid > 1 then

                getContainerItems(item, array, haveCap)

            end

        end

    end

    return #array >= 1 and array, haveCap

end

function getContainerItemsById(container, itemid)

    local founds = {}

    local items = not container.uid and container or getContainerItems(container)

    for index, item in pairs(items) do

        if item.itemid == itemid then

            founds[#founds +1] = item

        end

    end

    return #founds >= 1 and founds

end

function AutomaticDeposit(cid, item, n)

    if isInArray(info.Money_ids, item) and getPlayerStorageValue(cid, info.Storages[4]) > 0 then

        local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n)

        doPlayerDepositMoney(cid, deposit)

    end

    return true

end

function getAllContainerFree(cid) -- by vodka

    local containers,soma = {},0

    for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do

        local sitem = getPlayerSlotItem(cid, i)

        if sitem.uid > 0 then

            if isContainer(sitem.uid) then

                table.insert(containers, sitem.uid)

        soma = soma + getContainerSlotsFree(sitem.uid)

            end

        end

    end

    while #containers > 0 do

        for k = (getContainerSize(containers[1]) - 1), 0, -1 do

            local tmp = getContainerItem(containers[1], k)

            if isContainer(tmp.uid) then

                table.insert(containers, tmp.uid)

                soma = soma + getContainerSlotsFree(tmp.uid)

            end

        end

        table.remove(containers, 1)

    end

    return soma

end

function getContainerSlotsFree(container) -- by vodka

         return getContainerCap(container)-getContainerSize(container)

end

function doPlayerAddItemStackable(cid, itemid, count)

    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)

    if container.itemid > 1 then

        local items = getContainerItemsById(container, itemid)

        if not items then

            return doPlayerAddItem(cid, itemid, count)

        else

            local piles = #items

            for index, item in pairs(items) do

                if item.type < 100 then

                    local sum = item.type + count

                    local result = doTransformItem(item.uid, itemid, sum)

                    if sum <= 100 then

                        return result

                    else

                        return doPlayerAddItem(cid, itemid, sum - 100)

                    end

                else

                    piles = piles - 1

                    if piles == 0 then

                        return doPlayerAddItem(cid, itemid, count)

                    end

                end

            end

        end

    end

    return false

end

function corpseRetireItems(cid, pos)

    local check, slots = false, 0

    for i = 0, 255 do

        pos.stackpos = i

        if getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then

            corpse = getThingFromPos(pos)

            check = true

            break

        end

    end

    if check == true then

        local str, id_list = "", getItensFromAutoloot(cid)

        for _, item in pairs(getContainerItems(corpse)) do

            local id = item.itemid

            if #id_list > 0 and isInArray(id_list, id) or getPlayerStorageValue(cid, info.Storages[2]) > 0 and isInArray(info.Money_ids, id) then

                local amount = isItemStackable(id) and item.type or 1

                local total_cap = getItemWeightById(id, amount)

                slots = getAllContainerFree(cid)

                if slots > 0 and getPlayerFreeCap(cid) >= total_cap then

                    str = str.." " .. getItemInfoLoot(id, amount)

                    if isItemStackable(id) then

                        doPlayerAddItemStackable(cid, id, amount)

                        AutomaticDeposit(cid, id, amount)

                    else

                        doPlayerAddItem(cid, id)

                    end

                    doRemoveItem(item.uid)  

                end

            end

        end

        if str ~= "" and getPlayerStorageValue(cid, info.Storages[6]) <= 0 then

            doPlayerSendTextMessage(cid, Color_Loot[getPlayerColorLootMessage(cid)][1],"[Auto Loot Collect]:"..string.sub(str, 1, -2)..".")

        end

        if getPlayerStorageValue(cid, info.Storages[3]) <= 0 and slots > 0 and slots <= info.Warn_Bp_Slots then

            doPlayerSendTextMessage(cid,18, "[Auto Loot Warn] You only have "..slots.." slots free in your backpack!")

        end

    end

end

function ExistItemByName(name) -- by vodka

    local items = io.open("data/items/items.xml", "r"):read("*all")

    local get = items:lower():match('name="' .. name:lower() ..'"')

    if get == nil or get == "" then

        return false

    end

return true

end

function getItemInfoLoot(id, amount)

    local info = getItemInfo(id)

    return isItemStackable(id) and amount.." "..(amount > 1 and info.plural or info.name).."," or info.article.." " .. info.name ..","

end

]]></config>

<event type="login" name="LootLogin" event="script"><![CDATA[

domodlib('Loot_func')

function onLogin(cid)

    registerCreatureEvent(cid, "LootEventKIll")

    if isPremium(cid) and getPlayerStorageValue(cid, 853608) <= 0 then

        setPlayerStorageValue(cid, 853608, 1)

    elseif getPlayerStorageValue(cid, 853608) > 0 and not isPremium(cid) then

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Auto Loot] You premium is Over, Start a new list!")

        setPlayerStorageValue(cid, 853608, -1)

        doCleanAutoloot(cid)

    end

    return true

end]]></event>

<event type="kill" name="LootEventKIll" event="script"><![CDATA[

domodlib('Loot_func')

function onKill(cid, target, lastHit)

    if isPlayer(cid) and getPlayerStorageValue(cid, 30009) >= os.time() and getPlayerStorageValue(cid, info.Storages[1]) <= 0 and isMonster(target) and not isInArray(info.BlockMonsters, getCreatureName(target):lower()) then

        addEvent(corpseRetireItems, 0, cid ,getThingPos(target))

    end

    return true

end]]></event>

<talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[

domodlib('Loot_func')

if getPlayerStorageValue(cid, 30009) < os.time() then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Only VIP players can use auto loot.") return true end

local param, slots = param:lower(), isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free

if not param or param == "" then

    ShowItemsTabble(cid) return true

elseif tonumber(param) then

    doPlayerSendCancel(cid, "enter commands: !autoloot item name [+] !autoloot clean [+] !autoloot money [+] !autoloot on/off") return true

elseif isInArray({"clean","limpar", "clear"}, param) then

    if existsAutoloot(cid) then doCleanAutoloot(cid) end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Your list has been cleaned.") return true

elseif isInArray({"start","stop","on","off"}, param) then

    setPlayerStorageValue(cid, info.Storages[1], getPlayerStorageValue(cid, info.Storages[1]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot "..(getPlayerStorageValue(cid, info.Storages[1]) > 0 and "Stopped" or "Started")..".") return true

elseif isInArray({"warn","aviso"}, param) then

    setPlayerStorageValue(cid, info.Storages[3], getPlayerStorageValue(cid, info.Storages[3]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Backpack Warn "..(getPlayerStorageValue(cid, info.Storages[3]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"mensagem","message","mensagen","msg"}, param) then

    setPlayerStorageValue(cid, info.Storages[6], getPlayerStorageValue(cid, info.Storages[6]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message "..(getPlayerStorageValue(cid, info.Storages[6]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"cor","color","type"}, param) then

    setPlayerStorageValue(cid, info.Storages[5], getPlayerColorLootMessage(cid) == #Color_Loot and 0 or getPlayerColorLootMessage(cid)+1)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message Color Changed to "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".") return true

elseif isInArray({"money","gold","gps","dinheiro"}, param) then

    setPlayerStorageValue(cid, info.Storages[2], getPlayerStorageValue(cid, info.Storages[2]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Gold Colleting "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "disabled")..".") return true

elseif isInArray({"deposito","bank","gbank","deposit","autodeposit"}, param) then

    setPlayerStorageValue(cid, info.Storages[4], getPlayerStorageValue(cid, info.Storages[4]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Automatic Gold Bank "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "disabled")..".") return true

end

local item = ExistItemByName(tostring(param))

if not item then

    doPlayerSendCancel(cid, "This item does not exist.") return true

end

local item = getItemIdByName(tostring(param))

local var = isInTable(cid, item)

if isInArray(info.Money_ids, item) then

    doPlayerSendTextMessage(cid, MESSAGE_FIRST, "Enter !autoloot money to add money in your list!") return true  

elseif isInArray(info.BlockItemsList, item) then

    doPlayerSendCancel(cid, "You can not add this item in the list!") return true

elseif not var and #getItensFromAutoloot(cid) >= slots then

    doPlayerSendCancel(cid, "max "..slots.." from auto loot") return true

elseif getPlayerStorageValue(cid, info.Storages[7]) - os.time() > 0 then

        doPlayerSendCancel(cid, "wait a second to use this command again") return true

end

if not var then

    doAddItemFromAutoloot(cid, item)

else

    doremoveItemFromAutoloot(cid, item)

end

setPlayerStorageValue(cid, info.Storages[7], os.time()+info.Talkaction_delay)

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,not var and "you added the item "..param.." in the list" or "you removed the item "..param.." from the list, please wait 5 seconds to save the directory.")

return true]]></talkaction>

</mod>
Post automatically merged:

I've got the key in table, have the correct number but cannot jump in TP vip when changed to "GetAccountStorageValue"

1631537803545.png
 
Last edited:

Alberto Cabrera

Active Member
Joined
Sep 17, 2020
Messages
37
Solutions
12
Reaction score
38
Location
México
SQL:
CREATE TABLE `account_storage` (
  `account_id` int(11) NOT NULL,
  `key` varchar(32) NOT NULL DEFAULT '0',
  `value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or 0
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end

Lua:
local days = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
  setAccountVIP(cid, days)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. days .. " VIP days to this account!")
  doRemoveItem(item.uid, 1)
  doPlayerSave(cid)
  return true
end

Lua:
function onStepIn(cid, item, pos, fromPos)
  if not isPlayer(cid) then return doTeleportThing(cid, fromPos) end

  if isVIP(cid) == false then
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You don't have VIP access!")
    doTeleportThing(cid, fromPos)
    return false
  end

  local position = {x = 343, y = 155, z = 7} -- edita aqui a posição para qual o player será teleportado
  doTeleportThing(cid, position)
  doSendMagicEffect(position, CONST_ME_TELEPORT)
  doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT,"Welcome to VIP area!")
  return true
end

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>

<mod name="Perfect Auto Loot" version="2.0" author="Vodkart" contact="none.com" enabled="yes">

<config name="Loot_func"><![CDATA[



info = {

    directory = "data/logs/autoloot",

    Warn_Bp_Slots = 5, -- quando tiver 5 ou menos slots na BP vai avisar o jogador

    Talkaction_delay = 1, -- em segundos // delay para remover e adicionar item

    BlockMonsters = {},

    BlockItemsList = {2515},

    Money_ids = {2160}, -- id das moedas do ot

    Max_Slots = {free = 20, premium = 20},

    Storages = {988801, 988802, 988803, 988804, 988805, 988806, 988807}

}



Color_Loot = {

           [0] = {MESSAGE_EVENT_ORANGE, "Orange"},

           [1] = {MESSAGE_STATUS_CONSOLE_BLUE, "Blue"},

           [2] = {MESSAGE_INFO_DESCR, "Green"},

           [3] = {MESSAGE_STATUS_CONSOLE_RED, "Red"},

           [4] = {MESSAGE_STATUS_SMALL, "White"}

}

function getPlayerColorLootMessage(cid)

    return getPlayerStorageValue(cid, info.Storages[5]) <= 0 and 0 or getPlayerStorageValue(cid, info.Storages[5])

end

function isInTable(cid, item)

    for _,i in pairs(getItensFromAutoloot(cid)) do

        if tonumber(i) == tonumber(item) then

            return true

        end

    end

    return false

end

function doremoveItemFromAutoloot(cid, itemid)

    local file, fileContent = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'r'),{}

    for line in file:lines() do

     if line ~= "" and tonumber(line) ~= tonumber(itemid) then

             fileContent[#fileContent + 1] = line

        end

    end

    io.close(file)

    file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'w')

    for index, value in ipairs(fileContent) do

    file:write(value..'\n')

    end

    io.close(file)

end

function doAddItemFromAutoloot(cid, itemid)

         if not existsAutoloot(cid) then

            doCreateLootUserName(cid, itemid) return true

         end

         local file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "a+")                        

         file:write('\n'..itemid)

         file:close()

end

function existsAutoloot(cid)

  local f = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "rb")

  if f then f:close() end

  return f ~= nil

end

function doCreateLootUserName(cid, itemid)

    newFile = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "w+" )

    newFile:write(itemid)

    newFile:close()

end

function getItensFromAutoloot(cid)

  if not existsAutoloot(cid) then return {} end

  lines = {}

  for line in io.lines(info.directory.."/"..getCreatureName(cid)..".txt") do

      if line ~= "" then

              lines[#lines + 1] = tonumber(line)

      end

  end

  return lines

end

function doCleanAutoloot(cid)

return os.remove(info.directory.."/"..getCreatureName(cid)..".txt")

end

function ShowItemsTabble(cid)

    local auto_list = getItensFromAutoloot(cid)

    local n,str = 0,"[+] Auto Loot Commands [+]\n\n!autoloot item name --> To add ou Remove item from list.\n!autoloot money --> To collect gold automatically (only for crystal coin).\n!autoloot clear --> To clear the list.\n!autoloot on/off --> To enable or disable the collecting of items in the system.\n!autoloot message --> To enable or disable message from Collect items.\n!autoloot color --> To change Color message in Auto Loot Collect.\n!autoloot warn --> To enable or disable message warning of "..info.Warn_Bp_Slots.." or less slots in the backpack.\n!autoloot deposit --> To enable or disable automatic money deposit at the bank.\n\n[+] Auto Loot Info [+]\n\nSystem: "..(getPlayerStorageValue(cid, info.Storages[1]) <= 0 and "Activated" or "Disabled")..".\nGold Collecting: "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "Disabled")..".\nMessage: "..(getPlayerStorageValue(cid, info.Storages[6]) <= 0 and "Activated" or "Disabled")..".\nColor Message: "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".\nWarn Backpack: "..(getPlayerStorageValue(cid, info.Storages[3]) <= 0 and "Activated" or "Disabled")..".\nAutomatic Gold Deposit: "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "Disabled")..".\nTotal Bank Balance: ["..getPlayerBalance(cid).."]\nMaximum Slots: ["..#auto_list.."/"..(isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free).."]\n\n[+] Auto Loot Slots [+]\n\n"

    if #auto_list > 0 then

        for i = 1, #auto_list do

            n = n + 1

            str = str.."Slot "..n.." - "..getItemNameById(auto_list[i]).."\n"

        end

    end

        doShowTextDialog(cid, 1961, str)

end

function getContainerItems(container, array, haveCap)

    array = array or {}

    haveCap = haveCap or false

    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then

        array[#array +1] = container

    else

        local size = getContainerSize(container.uid)

        haveCap = (getContainerCap(container.uid) -size) > 0

        for slot = 0, (size -1) do

            local item = getContainerItem(container.uid, slot)

            if item.itemid > 1 then

                getContainerItems(item, array, haveCap)

            end

        end

    end

    return #array >= 1 and array, haveCap

end

function getContainerItemsById(container, itemid)

    local founds = {}

    local items = not container.uid and container or getContainerItems(container)

    for index, item in pairs(items) do

        if item.itemid == itemid then

            founds[#founds +1] = item

        end

    end

    return #founds >= 1 and founds

end

function AutomaticDeposit(cid, item, n)

    if isInArray(info.Money_ids, item) and getPlayerStorageValue(cid, info.Storages[4]) > 0 then

        local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n)

        doPlayerDepositMoney(cid, deposit)

    end

    return true

end

function getAllContainerFree(cid) -- by vodka

    local containers,soma = {},0

    for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do

        local sitem = getPlayerSlotItem(cid, i)

        if sitem.uid > 0 then

            if isContainer(sitem.uid) then

                table.insert(containers, sitem.uid)

        soma = soma + getContainerSlotsFree(sitem.uid)

            end

        end

    end

    while #containers > 0 do

        for k = (getContainerSize(containers[1]) - 1), 0, -1 do

            local tmp = getContainerItem(containers[1], k)

            if isContainer(tmp.uid) then

                table.insert(containers, tmp.uid)

                soma = soma + getContainerSlotsFree(tmp.uid)

            end

        end

        table.remove(containers, 1)

    end

    return soma

end

function getContainerSlotsFree(container) -- by vodka

         return getContainerCap(container)-getContainerSize(container)

end

function doPlayerAddItemStackable(cid, itemid, count)

    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)

    if container.itemid > 1 then

        local items = getContainerItemsById(container, itemid)

        if not items then

            return doPlayerAddItem(cid, itemid, count)

        else

            local piles = #items

            for index, item in pairs(items) do

                if item.type < 100 then

                    local sum = item.type + count

                    local result = doTransformItem(item.uid, itemid, sum)

                    if sum <= 100 then

                        return result

                    else

                        return doPlayerAddItem(cid, itemid, sum - 100)

                    end

                else

                    piles = piles - 1

                    if piles == 0 then

                        return doPlayerAddItem(cid, itemid, count)

                    end

                end

            end

        end

    end

    return false

end

function corpseRetireItems(cid, pos)

    local check, slots = false, 0

    for i = 0, 255 do

        pos.stackpos = i

        if getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then

            corpse = getThingFromPos(pos)

            check = true

            break

        end

    end

    if check == true then

        local str, id_list = "", getItensFromAutoloot(cid)

        for _, item in pairs(getContainerItems(corpse)) do

            local id = item.itemid

            if #id_list > 0 and isInArray(id_list, id) or getPlayerStorageValue(cid, info.Storages[2]) > 0 and isInArray(info.Money_ids, id) then

                local amount = isItemStackable(id) and item.type or 1

                local total_cap = getItemWeightById(id, amount)

                slots = getAllContainerFree(cid)

                if slots > 0 and getPlayerFreeCap(cid) >= total_cap then

                    str = str.." " .. getItemInfoLoot(id, amount)

                    if isItemStackable(id) then

                        doPlayerAddItemStackable(cid, id, amount)

                        AutomaticDeposit(cid, id, amount)

                    else

                        doPlayerAddItem(cid, id)

                    end

                    doRemoveItem(item.uid)

                end

            end

        end

        if str ~= "" and getPlayerStorageValue(cid, info.Storages[6]) <= 0 then

            doPlayerSendTextMessage(cid, Color_Loot[getPlayerColorLootMessage(cid)][1],"[Auto Loot Collect]:"..string.sub(str, 1, -2)..".")

        end

        if getPlayerStorageValue(cid, info.Storages[3]) <= 0 and slots > 0 and slots <= info.Warn_Bp_Slots then

            doPlayerSendTextMessage(cid,18, "[Auto Loot Warn] You only have "..slots.." slots free in your backpack!")

        end

    end

end

function ExistItemByName(name) -- by vodka

    local items = io.open("data/items/items.xml", "r"):read("*all")

    local get = items:lower():match('name="' .. name:lower() ..'"')

    if get == nil or get == "" then

        return false

    end

return true

end

function getItemInfoLoot(id, amount)

    local info = getItemInfo(id)

    return isItemStackable(id) and amount.." "..(amount > 1 and info.plural or info.name).."," or info.article.." " .. info.name ..","

end

]]></config>

<event type="login" name="LootLogin" event="script"><![CDATA[

domodlib('Loot_func')

function onLogin(cid)

    registerCreatureEvent(cid, "LootEventKIll")

    if isPremium(cid) and getPlayerStorageValue(cid, 853608) <= 0 then

        setPlayerStorageValue(cid, 853608, 1)

    elseif getPlayerStorageValue(cid, 853608) > 0 and not isPremium(cid) then

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Auto Loot] You premium is Over, Start a new list!")

        setPlayerStorageValue(cid, 853608, -1)

        doCleanAutoloot(cid)

    end

    return true

end]]></event>

<event type="kill" name="LootEventKIll" event="script"><![CDATA[

domodlib('Loot_func')

function onKill(cid, target, lastHit)
    if isVIP == false then
        return true
    end
   
    if isPlayer(cid) and getPlayerStorageValue(cid, info.Storages[1]) <= 0 and isMonster(target) and not isInArray(info.BlockMonsters, getCreatureName(target):lower()) then

        addEvent(corpseRetireItems, 0, cid ,getThingPos(target))

    end

    return true

end]]></event>

<talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[

domodlib('Loot_func')

if isVIP(cid) == false then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Only VIP players can use auto loot.")
    return true
end

local param, slots = param:lower(), isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free

if not param or param == "" then

    ShowItemsTabble(cid) return true

elseif tonumber(param) then

    doPlayerSendCancel(cid, "enter commands: !autoloot item name [+] !autoloot clean [+] !autoloot money [+] !autoloot on/off") return true

elseif isInArray({"clean","limpar", "clear"}, param) then

    if existsAutoloot(cid) then doCleanAutoloot(cid) end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Your list has been cleaned.") return true

elseif isInArray({"start","stop","on","off"}, param) then

    setPlayerStorageValue(cid, info.Storages[1], getPlayerStorageValue(cid, info.Storages[1]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot "..(getPlayerStorageValue(cid, info.Storages[1]) > 0 and "Stopped" or "Started")..".") return true

elseif isInArray({"warn","aviso"}, param) then

    setPlayerStorageValue(cid, info.Storages[3], getPlayerStorageValue(cid, info.Storages[3]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Backpack Warn "..(getPlayerStorageValue(cid, info.Storages[3]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"mensagem","message","mensagen","msg"}, param) then

    setPlayerStorageValue(cid, info.Storages[6], getPlayerStorageValue(cid, info.Storages[6]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message "..(getPlayerStorageValue(cid, info.Storages[6]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"cor","color","type"}, param) then

    setPlayerStorageValue(cid, info.Storages[5], getPlayerColorLootMessage(cid) == #Color_Loot and 0 or getPlayerColorLootMessage(cid)+1)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message Color Changed to "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".") return true

elseif isInArray({"money","gold","gps","dinheiro"}, param) then

    setPlayerStorageValue(cid, info.Storages[2], getPlayerStorageValue(cid, info.Storages[2]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Gold Colleting "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "disabled")..".") return true

elseif isInArray({"deposito","bank","gbank","deposit","autodeposit"}, param) then

    setPlayerStorageValue(cid, info.Storages[4], getPlayerStorageValue(cid, info.Storages[4]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Automatic Gold Bank "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "disabled")..".") return true

end

local item = ExistItemByName(tostring(param))

if not item then

    doPlayerSendCancel(cid, "This item does not exist.") return true

end

local item = getItemIdByName(tostring(param))

local var = isInTable(cid, item)

if isInArray(info.Money_ids, item) then

    doPlayerSendTextMessage(cid, MESSAGE_FIRST, "Enter !autoloot money to add money in your list!") return true

elseif isInArray(info.BlockItemsList, item) then

    doPlayerSendCancel(cid, "You can not add this item in the list!") return true

elseif not var and #getItensFromAutoloot(cid) >= slots then

    doPlayerSendCancel(cid, "max "..slots.." from auto loot") return true

elseif getPlayerStorageValue(cid, info.Storages[7]) - os.time() > 0 then

        doPlayerSendCancel(cid, "wait a second to use this command again") return true

end

if not var then

    doAddItemFromAutoloot(cid, item)

else

    doremoveItemFromAutoloot(cid, item)

end

setPlayerStorageValue(cid, info.Storages[7], os.time()+info.Talkaction_delay)

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,not var and "you added the item "..param.." in the list" or "you removed the item "..param.." from the list, please wait 5 seconds to save the directory.")

return true]]></talkaction>

</mod>
 
Last edited:
Solution
OP
OP
potinho

potinho

Active Member
Joined
Oct 11, 2009
Messages
418
Solutions
11
Reaction score
38
Location
Brazil
SQL:
CREATE TABLE `account_storage` (
  `account_id` int(11) NOT NULL,
  `key` varchar(32) NOT NULL DEFAULT '0',
  `value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Lua:
VIP_ACCOUNT_STORAGE = 30009

function getAccountStorage(cid, key)
  local ret = db.getResult("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. getPlayerAccountId(cid) .." AND `key` = "..key)
  if ret:getID() == -1 then
    return -1
  end
  return ret:getDataInt("value") or ret:getDataString("value")
end

function setAccountStorage(cid, key, value)
  local func = db.executeQuery or db.query
  local query = db.getResult("SELECT `value` FROM `account_storage` WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
  if query:getID() == -1 then
    return func("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (".. getPlayerAccountId(cid) ..", ".. key ..", ".. value ..")")
  end
  return func("UPDATE `account_storage` SET `value` = ".. value .." WHERE `key` = ".. key .." AND `account_id` = ".. getPlayerAccountId(cid))
end

function isVIP(cid)
  return getAccountVIP(cid) > 0
end

function getAccountVIP(cid)
  return (getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() > 0) and getAccountStorage(cid, VIP_ACCOUNT_STORAGE) - os.time() or false
end

function setAccountVIP(cid, days)
  return setAccountStorage(cid, VIP_ACCOUNT_STORAGE, os.time() + (60 * 60 * 24 * days) + (getAccountVIP(cid) > 0 and  getAccountVIP(cid) or 0))
end

Lua:
local days = 30

function onUse(cid, item, fromPosition, itemEx, toPosition)
  setAccountVIP(cid, days)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations, you've added " .. days .. " VIP days to this account!")
  doRemoveItem(item.uid, 1)
  doPlayerSave(cid)
  return true
end

Lua:
function onStepIn(cid, item, pos, fromPos)
  if not isPlayer(cid) then return doTeleportThing(cid, fromPos) end

  if isVIP(cid) == false then
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You don't have VIP access!")
    doTeleportThing(cid, fromPos)
    return false
  end

  local position = {x = 343, y = 155, z = 7} -- edita aqui a posição para qual o player será teleportado
  doTeleportThing(cid, position)
  doSendMagicEffect(position, CONST_ME_TELEPORT)
  doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT,"Welcome to VIP area!")
  return true
end

XML:
<?xml version="1.0" encoding="ISO-8859-1"?>

<mod name="Perfect Auto Loot" version="2.0" author="Vodkart" contact="none.com" enabled="yes">

<config name="Loot_func"><![CDATA[



info = {

    directory = "data/logs/autoloot",

    Warn_Bp_Slots = 5, -- quando tiver 5 ou menos slots na BP vai avisar o jogador

    Talkaction_delay = 1, -- em segundos // delay para remover e adicionar item

    BlockMonsters = {},

    BlockItemsList = {2515},

    Money_ids = {2160}, -- id das moedas do ot

    Max_Slots = {free = 20, premium = 20},

    Storages = {988801, 988802, 988803, 988804, 988805, 988806, 988807}

}



Color_Loot = {

           [0] = {MESSAGE_EVENT_ORANGE, "Orange"},

           [1] = {MESSAGE_STATUS_CONSOLE_BLUE, "Blue"},

           [2] = {MESSAGE_INFO_DESCR, "Green"},

           [3] = {MESSAGE_STATUS_CONSOLE_RED, "Red"},

           [4] = {MESSAGE_STATUS_SMALL, "White"}

}

function getPlayerColorLootMessage(cid)

    return getPlayerStorageValue(cid, info.Storages[5]) <= 0 and 0 or getPlayerStorageValue(cid, info.Storages[5])

end

function isInTable(cid, item)

    for _,i in pairs(getItensFromAutoloot(cid)) do

        if tonumber(i) == tonumber(item) then

            return true

        end

    end

    return false

end

function doremoveItemFromAutoloot(cid, itemid)

    local file, fileContent = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'r'),{}

    for line in file:lines() do

     if line ~= "" and tonumber(line) ~= tonumber(itemid) then

             fileContent[#fileContent + 1] = line

        end

    end

    io.close(file)

    file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", 'w')

    for index, value in ipairs(fileContent) do

    file:write(value..'\n')

    end

    io.close(file)

end

function doAddItemFromAutoloot(cid, itemid)

         if not existsAutoloot(cid) then

            doCreateLootUserName(cid, itemid) return true

         end

         local file = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "a+")                       

         file:write('\n'..itemid)

         file:close()

end

function existsAutoloot(cid)

  local f = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "rb")

  if f then f:close() end

  return f ~= nil

end

function doCreateLootUserName(cid, itemid)

    newFile = io.open(info.directory.."/"..getCreatureName(cid)..".txt", "w+" )

    newFile:write(itemid)

    newFile:close()

end

function getItensFromAutoloot(cid)

  if not existsAutoloot(cid) then return {} end

  lines = {}

  for line in io.lines(info.directory.."/"..getCreatureName(cid)..".txt") do

      if line ~= "" then

              lines[#lines + 1] = tonumber(line)

      end

  end

  return lines

end

function doCleanAutoloot(cid)

return os.remove(info.directory.."/"..getCreatureName(cid)..".txt")

end

function ShowItemsTabble(cid)

    local auto_list = getItensFromAutoloot(cid)

    local n,str = 0,"[+] Auto Loot Commands [+]\n\n!autoloot item name --> To add ou Remove item from list.\n!autoloot money --> To collect gold automatically (only for crystal coin).\n!autoloot clear --> To clear the list.\n!autoloot on/off --> To enable or disable the collecting of items in the system.\n!autoloot message --> To enable or disable message from Collect items.\n!autoloot color --> To change Color message in Auto Loot Collect.\n!autoloot warn --> To enable or disable message warning of "..info.Warn_Bp_Slots.." or less slots in the backpack.\n!autoloot deposit --> To enable or disable automatic money deposit at the bank.\n\n[+] Auto Loot Info [+]\n\nSystem: "..(getPlayerStorageValue(cid, info.Storages[1]) <= 0 and "Activated" or "Disabled")..".\nGold Collecting: "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "Disabled")..".\nMessage: "..(getPlayerStorageValue(cid, info.Storages[6]) <= 0 and "Activated" or "Disabled")..".\nColor Message: "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".\nWarn Backpack: "..(getPlayerStorageValue(cid, info.Storages[3]) <= 0 and "Activated" or "Disabled")..".\nAutomatic Gold Deposit: "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "Disabled")..".\nTotal Bank Balance: ["..getPlayerBalance(cid).."]\nMaximum Slots: ["..#auto_list.."/"..(isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free).."]\n\n[+] Auto Loot Slots [+]\n\n"

    if #auto_list > 0 then

        for i = 1, #auto_list do

            n = n + 1

            str = str.."Slot "..n.." - "..getItemNameById(auto_list[i]).."\n"

        end

    end

        doShowTextDialog(cid, 1961, str)

end

function getContainerItems(container, array, haveCap)

    array = array or {}

    haveCap = haveCap or false

    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then

        array[#array +1] = container

    else

        local size = getContainerSize(container.uid)

        haveCap = (getContainerCap(container.uid) -size) > 0

        for slot = 0, (size -1) do

            local item = getContainerItem(container.uid, slot)

            if item.itemid > 1 then

                getContainerItems(item, array, haveCap)

            end

        end

    end

    return #array >= 1 and array, haveCap

end

function getContainerItemsById(container, itemid)

    local founds = {}

    local items = not container.uid and container or getContainerItems(container)

    for index, item in pairs(items) do

        if item.itemid == itemid then

            founds[#founds +1] = item

        end

    end

    return #founds >= 1 and founds

end

function AutomaticDeposit(cid, item, n)

    if isInArray(info.Money_ids, item) and getPlayerStorageValue(cid, info.Storages[4]) > 0 then

        local deposit = item == tonumber(2160) and (n*10000) or tonumber(item) == 2152 and (n*100) or (n)

        doPlayerDepositMoney(cid, deposit)

    end

    return true

end

function getAllContainerFree(cid) -- by vodka

    local containers,soma = {},0

    for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do

        local sitem = getPlayerSlotItem(cid, i)

        if sitem.uid > 0 then

            if isContainer(sitem.uid) then

                table.insert(containers, sitem.uid)

        soma = soma + getContainerSlotsFree(sitem.uid)

            end

        end

    end

    while #containers > 0 do

        for k = (getContainerSize(containers[1]) - 1), 0, -1 do

            local tmp = getContainerItem(containers[1], k)

            if isContainer(tmp.uid) then

                table.insert(containers, tmp.uid)

                soma = soma + getContainerSlotsFree(tmp.uid)

            end

        end

        table.remove(containers, 1)

    end

    return soma

end

function getContainerSlotsFree(container) -- by vodka

         return getContainerCap(container)-getContainerSize(container)

end

function doPlayerAddItemStackable(cid, itemid, count)

    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)

    if container.itemid > 1 then

        local items = getContainerItemsById(container, itemid)

        if not items then

            return doPlayerAddItem(cid, itemid, count)

        else

            local piles = #items

            for index, item in pairs(items) do

                if item.type < 100 then

                    local sum = item.type + count

                    local result = doTransformItem(item.uid, itemid, sum)

                    if sum <= 100 then

                        return result

                    else

                        return doPlayerAddItem(cid, itemid, sum - 100)

                    end

                else

                    piles = piles - 1

                    if piles == 0 then

                        return doPlayerAddItem(cid, itemid, count)

                    end

                end

            end

        end

    end

    return false

end

function corpseRetireItems(cid, pos)

    local check, slots = false, 0

    for i = 0, 255 do

        pos.stackpos = i

        if getThingFromPos(pos).uid > 0 and isContainer(getThingFromPos(pos).uid) then

            corpse = getThingFromPos(pos)

            check = true

            break

        end

    end

    if check == true then

        local str, id_list = "", getItensFromAutoloot(cid)

        for _, item in pairs(getContainerItems(corpse)) do

            local id = item.itemid

            if #id_list > 0 and isInArray(id_list, id) or getPlayerStorageValue(cid, info.Storages[2]) > 0 and isInArray(info.Money_ids, id) then

                local amount = isItemStackable(id) and item.type or 1

                local total_cap = getItemWeightById(id, amount)

                slots = getAllContainerFree(cid)

                if slots > 0 and getPlayerFreeCap(cid) >= total_cap then

                    str = str.." " .. getItemInfoLoot(id, amount)

                    if isItemStackable(id) then

                        doPlayerAddItemStackable(cid, id, amount)

                        AutomaticDeposit(cid, id, amount)

                    else

                        doPlayerAddItem(cid, id)

                    end

                    doRemoveItem(item.uid)

                end

            end

        end

        if str ~= "" and getPlayerStorageValue(cid, info.Storages[6]) <= 0 then

            doPlayerSendTextMessage(cid, Color_Loot[getPlayerColorLootMessage(cid)][1],"[Auto Loot Collect]:"..string.sub(str, 1, -2)..".")

        end

        if getPlayerStorageValue(cid, info.Storages[3]) <= 0 and slots > 0 and slots <= info.Warn_Bp_Slots then

            doPlayerSendTextMessage(cid,18, "[Auto Loot Warn] You only have "..slots.." slots free in your backpack!")

        end

    end

end

function ExistItemByName(name) -- by vodka

    local items = io.open("data/items/items.xml", "r"):read("*all")

    local get = items:lower():match('name="' .. name:lower() ..'"')

    if get == nil or get == "" then

        return false

    end

return true

end

function getItemInfoLoot(id, amount)

    local info = getItemInfo(id)

    return isItemStackable(id) and amount.." "..(amount > 1 and info.plural or info.name).."," or info.article.." " .. info.name ..","

end

]]></config>

<event type="login" name="LootLogin" event="script"><![CDATA[

domodlib('Loot_func')

function onLogin(cid)

    registerCreatureEvent(cid, "LootEventKIll")

    if isPremium(cid) and getPlayerStorageValue(cid, 853608) <= 0 then

        setPlayerStorageValue(cid, 853608, 1)

    elseif getPlayerStorageValue(cid, 853608) > 0 and not isPremium(cid) then

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "[Auto Loot] You premium is Over, Start a new list!")

        setPlayerStorageValue(cid, 853608, -1)

        doCleanAutoloot(cid)

    end

    return true

end]]></event>

<event type="kill" name="LootEventKIll" event="script"><![CDATA[

domodlib('Loot_func')

function onKill(cid, target, lastHit)
    if isVIP == false then
        return true
    end
  
    if isPlayer(cid) and getPlayerStorageValue(cid, info.Storages[1]) <= 0 and isMonster(target) and not isInArray(info.BlockMonsters, getCreatureName(target):lower()) then

        addEvent(corpseRetireItems, 0, cid ,getThingPos(target))

    end

    return true

end]]></event>

<talkaction words="!autoloot;/autoloot" event="buffer"><![CDATA[

domodlib('Loot_func')

if isVIP(cid) == false then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Only VIP players can use auto loot.")
    return true
end

local param, slots = param:lower(), isPremium(cid) and info.Max_Slots.premium or info.Max_Slots.free

if not param or param == "" then

    ShowItemsTabble(cid) return true

elseif tonumber(param) then

    doPlayerSendCancel(cid, "enter commands: !autoloot item name [+] !autoloot clean [+] !autoloot money [+] !autoloot on/off") return true

elseif isInArray({"clean","limpar", "clear"}, param) then

    if existsAutoloot(cid) then doCleanAutoloot(cid) end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Your list has been cleaned.") return true

elseif isInArray({"start","stop","on","off"}, param) then

    setPlayerStorageValue(cid, info.Storages[1], getPlayerStorageValue(cid, info.Storages[1]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot "..(getPlayerStorageValue(cid, info.Storages[1]) > 0 and "Stopped" or "Started")..".") return true

elseif isInArray({"warn","aviso"}, param) then

    setPlayerStorageValue(cid, info.Storages[3], getPlayerStorageValue(cid, info.Storages[3]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Backpack Warn "..(getPlayerStorageValue(cid, info.Storages[3]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"mensagem","message","mensagen","msg"}, param) then

    setPlayerStorageValue(cid, info.Storages[6], getPlayerStorageValue(cid, info.Storages[6]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message "..(getPlayerStorageValue(cid, info.Storages[6]) > 0 and "disabled" or "Activated")..".") return true

elseif isInArray({"cor","color","type"}, param) then

    setPlayerStorageValue(cid, info.Storages[5], getPlayerColorLootMessage(cid) == #Color_Loot and 0 or getPlayerColorLootMessage(cid)+1)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Message Color Changed to "..Color_Loot[getPlayerColorLootMessage(cid)][2]..".") return true

elseif isInArray({"money","gold","gps","dinheiro"}, param) then

    setPlayerStorageValue(cid, info.Storages[2], getPlayerStorageValue(cid, info.Storages[2]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"Auto Loot Gold Colleting "..(getPlayerStorageValue(cid, info.Storages[2]) > 0 and "Activated" or "disabled")..".") return true

elseif isInArray({"deposito","bank","gbank","deposit","autodeposit"}, param) then

    setPlayerStorageValue(cid, info.Storages[4], getPlayerStorageValue(cid, info.Storages[4]) <= 0 and 1 or 0)

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"[Auto Loot] Automatic Gold Bank "..(getPlayerStorageValue(cid, info.Storages[4]) > 0 and "Activated" or "disabled")..".") return true

end

local item = ExistItemByName(tostring(param))

if not item then

    doPlayerSendCancel(cid, "This item does not exist.") return true

end

local item = getItemIdByName(tostring(param))

local var = isInTable(cid, item)

if isInArray(info.Money_ids, item) then

    doPlayerSendTextMessage(cid, MESSAGE_FIRST, "Enter !autoloot money to add money in your list!") return true

elseif isInArray(info.BlockItemsList, item) then

    doPlayerSendCancel(cid, "You can not add this item in the list!") return true

elseif not var and #getItensFromAutoloot(cid) >= slots then

    doPlayerSendCancel(cid, "max "..slots.." from auto loot") return true

elseif getPlayerStorageValue(cid, info.Storages[7]) - os.time() > 0 then

        doPlayerSendCancel(cid, "wait a second to use this command again") return true

end

if not var then

    doAddItemFromAutoloot(cid, item)

else

    doremoveItemFromAutoloot(cid, item)

end

setPlayerStorageValue(cid, info.Storages[7], os.time()+info.Talkaction_delay)

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,not var and "you added the item "..param.." in the list" or "you removed the item "..param.." from the list, please wait 5 seconds to save the directory.")

return true]]></talkaction>

</mod>
@Alberto Cabrera Console got error when try to use VIP Scroll:1631562660546.png

1631562636156.png
And TP stop working
 
Top