• logo_cipsoft
    Nowe serwery zostały otwarte 19 Lut 2025:
    Noctalia (Open PvP) Ignitera (Open PvP) us_logo Xybra (Open PvP)

AutoLoot

Status
Zamknięty.

Oskar

Forum friend
Dołączył
Styczeń 24, 2009
Posty
2256
Liczba reakcji
331
Skrypt nie zosta? napisany przeze mnie. Ja go tylko naprawi?em usuwaj?c wszelkie b??dy, kt?re znalaz?em.
Link do oryginalnego tematu:

A oto skrypt,
Talkactions:
PHP:
local stor, limit = 7575, 5
 
local allow_container = false
 
function onSay(cid, words, param)
    local expl = param:explode(':')
    local action, rst = expl[1], expl[2]
    if (action:lower() == 'lista') then
        local infos, list = getPlayerStorageValue(cid, stor), {}
        if (infos ~= -1) then
            list = tostring(infos):explode(',')
        end
        local txt = 'Lista:\n'
        if (#list > 0) then
            for k, id in ipairs(list) do
                id = id:gsub('_', '')
                if tonumber(id) then
                    txt = txt .. getItemNameById(tonumber(id)) .. ((k < #list) and '\n' or '')
                end
            end
        else
            txt = 'Pusto'
        end
        doPlayerPopupFYI(cid, txt)
    elseif (action:lower() == 'dodaj') then
        local infos, list = getPlayerStorageValue(cid, stor), {}
        if (infos ~= -1) then
            list = tostring(infos):gsub('_', ''):explode(',')
        end
        if (#list > limit) then
            return doPlayerSendCancel(cid, 'Wykorzystales juz wszytkie ' .. limit .. ' miejsc na liscie.')
        end
        local item = tonumber(rst)
        if not item then
            item = getItemIdByName(rst, false)
            if not item then
                return doPlayerSendCancel(cid, 'Taki przedmiot nie istnieje.')
            end
        end
        if not allow_container and isItemContainer(item) then
            return doPlayerSendCancel(cid, 'Ten przedmiot nie moze byc dodany do listy.')
        end
        local attrs = getItemInfo(item)
        if not attrs then
            return doPlayerSendCancel(cid, 'Taki przedmiot nie istnieje.')
        elseif not attrs.movable or not attrs.pickupable then
            return doPlayerSendCancel(cid, 'Ten przedmiot nie moze byc dodany do listy.')
        end
        if isInArray(list, item) then
            return doPlayerSendCancel(cid, 'Ten przedmiot znajduje sie juz na liscie.')
        end
        table.insert(list, tostring(item))
        local new = ''
        for v, id in ipairs(list) do
            new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
        end
        doPlayerSetStorageValue(cid, stor, tostring(new))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Przedmiot '" .. getItemNameById(item) .. "' zostal dodany do listy.")
    elseif (action:lower() == 'usun') then
        local infos, list = getPlayerStorageValue(cid, stor), {}
        if (infos ~= -1) then
            list = tostring(infos):gsub('_', ''):explode(',')
        end
        if (#list == 0) then
            return doPlayerSendCancel(cid, 'Nie masz dodane zadnego przedmiotu do listy.')
        end
        if (#list > limit) then
            return doPlayerSendCancel(cid, 'Wykorzystales juz wszytkie ' .. limit .. ' miejsc na liscie.')
        end
        local item = tonumber(rst)
        if not item then
            item = getItemIdByName(rst, false)
            if not item then
                return doPlayerSendCancel(cid, 'Taki przedmiot nie istnieje.')
            end
        end
        if not isInArray(list, item) then
            return doPlayerSendCancel(cid, 'Ten przedmiot nie znajduje sie na liscie.')
        end
        local new = ''
        for v, id in ipairs(list) do
            if (tonumber(id) ~= item) then
                new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
            end
        end
        doPlayerSetStorageValue(cid, stor, tostring(new))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Przedmiot '" .. getItemNameById(item) .. "' zostal usuniety z listy.")elseif (action:lower() == 'usun') then
        local infos, list = getPlayerStorageValue(cid, stor), {}
        if (infos ~= -1) then
            list = tostring(infos):gsub('_', ''):explode(',')
        end
        if (#list == 0) then
            return doPlayerSendCancel(cid, 'Nie masz dodane zadnego przedmiotu do listy.')
        end
        local item = tonumber(rst)
        if not item then
            item = getItemIdByName(rst, false)
            if not item then
                return doPlayerSendCancel(cid, 'Taki przedmiot nie istnieje.')
            end
        end
        if not isInArray(list, item) then
            return doPlayerSendCancel(cid, 'Ten przedmiot nie znajduje sie na liscie.')
        end
        local new = ''
        for v, id in ipairs(list) do
            if (tonumber(id) ~= item) then
                new = new .. '_' .. id:gsub('_' ,'') .. ((v < #list) and ',' or '')
            end
        end
        doPlayerSetStorageValue(cid, stor, tostring(new))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Przedmiot '" .. getItemNameById(item) .. "' zostal usuniety z listy.")
	elseif (action:lower() == 'all') then
        local infos = getPlayerStorageValue(cid, stor)
        if (infos ~= -1) then
			doPlayerSetStorageValue(cid, stor, -1)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Lista zostala wyczyszczona.")
		end
    end        
    return true
end
PHP:
<talkaction words="/loot" hide="yes" event="script" value="aloot.lua"/>

Oraz creaturescripts:
PHP:
function onLogin(cid)
    registerCreatureEvent(cid, "aloot_kill")
    return true
end

local stor = 7575

function autoloot(cid, target, pos)
    local function doStack(cid, itemid, new)
        local count = getPlayerItemCount(cid, itemid)
        if (count > 0) then
			local minCount = count - (math.floor(count / 100) * 100)
			count = minCount
				if count + new > 100 then
					local item = doCreateItemEx(itemid, new - (100 - minCount))
					doPlayerAddItemEx(cid, item, true)
				end
			newCount = count + new
		else
			newCount = new
        end
        if (count ~= 0) then
            local find = getPlayerItemById(cid, true, itemid, count).uid
            if (find > 0) then
                doRemoveItem(find)
            else
                newCount = new
            end
        end
        local item = doCreateItemEx(itemid, newCount) 
        doPlayerAddItemEx(cid, item, true) 
    end
 
    local function scanContainer(cid, uid, list)
        for k = (getContainerSize(uid) - 1), 0, -1 do
            local tmp = getContainerItem(uid, k)
            if (isInArray(list, tmp.itemid)) then
                if isItemStackable(tmp.itemid) and (getPlayerItemCount(cid, tmp.itemid) > 0) then
                    doStack(cid, tmp.itemid, tmp.type)
                else
                    local item = doCreateItemEx(tmp.itemid, tmp.type)
                    doPlayerAddItemEx(cid, item, true)
                end
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'Znaleziono ' .. tmp.type .. ' ' .. getItemNameById(tmp.itemid) .. '.')
                doRemoveItem(tmp.uid)
            elseif isContainer(tmp.uid) then
                scanContainer(cid, tmp.uid, list)
            end
        end
    end
 
    local items = {}
    for i = getTileInfo(pos).items, 1, -1 do
        pos.stackpos = i
        table.insert(items, getThingFromPos(pos))
    end
 
    if (#items == 0) then
        return true
    end
 
    local corpse = -1
    for _, item in ipairs(items) do
		if isCorpse(item.uid) then
			corpse = item.uid
		end
    end
 
    if (corpse ~= -1) and isContainer(corpse) then
        scanContainer(cid, corpse, tostring(getPlayerStorageValue(cid, stor)):gsub('_', ''):explode(','))
    end
end
 
function onKill(cid, target, lastHit)
    if not(isPlayer(target)) then
        local infos = getPlayerStorageValue(cid, stor)
        if (infos == -1) then
            return true
        end
        local list = tostring(infos):explode(',')
        if (#list == 0) then
            return true
        end
        addEvent(autoloot, 150, cid, getCreatureName(target), getCreaturePosition(target))
    end
    return true
end
PHP:
<event type="login" name="aloot_reg" event="script" value="aloot.lua"/>
<event type="kill" name="aloot_kill" event="script" value="aloot.lua"/>


/loot dodaj:itemid - dodanie itemu o danym id do listy,
/loot dodaj:nazwa_itemu - dodanie itemu o danej nazwie do listy,
/loot usun:itemid - usuni?cie itemu o danym id z listy,
/loot usun:nazwa_itemu - usuni?cie itemu o danej nazwie z listy,
/loot all - usuni?cie wszystkich item?w z listy,
/loot lista - sprawdzenie listy.
 
Odp: AutoLoot

Zosta? znaleziony b??d, ale zosta? on naprawiony.
 
Status
Zamknięty.
Do góry