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

Lua Any can fix my auto gold loot script?

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
someone can arrange for me my script or tell me why you're not working?

It was meant to do: to kill the monsters come to the GPS bp guy who killed


lib/050-funcions.lua

Code:
function autoGP(cid, target, pos)
local itemid = 2148 -- id do gold coin
local function doStack(cid, itemid, new)
local count = getPlayerItemCount(cid, itemid)
if (count > 100) then
count = count - math.floor(count / 100) * 100
end
local newCount = count + new
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
end

login.lua
Code:
registerCreatureEvent(cid, "GP")

gp.lua
Code:
function onKill(cid, target, lastHit)
if not isPlayer(target) then
autoGP(cid, getCreatureName(target), getCreaturePosition(target))
end
return true
end

creatures,xml
Code:
<event type="kill" name="GP" event="script" value="gp.lua"/>
 
Last edited:
How is this person's question in a foreign language?

@Topic
Try this and see how it goes
Code:
function doStack(cid, itemid, new)
    local count = getPlayerItemCount(cid, itemid)
    if (count > 100) then
        count = count - math.floor(count / 100) * 100
    end
    local newCount = count + new
    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)
    return true
end

function autoGP(cid, target, pos)
    local itemid = 2148 -- id do gold coin
    return doStack(cid, itemid, new)
end
 
How is this person's question in a foreign language?

@Topic
Try this and see how it goes
Code:
function doStack(cid, itemid, new)
    local count = getPlayerItemCount(cid, itemid)
    if (count > 100) then
        count = count - math.floor(count / 100) * 100
    end
    local newCount = count + new
    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)
    return true
end

function autoGP(cid, target, pos)
    local itemid = 2148 -- id do gold coin
    return doStack(cid, itemid, new)
end

Thanks for trying to help me, I killed a mouse, fell money and the system did not collect the money for my backpack automatically ;(
 
I am using 8.60, of course, my server is not online, I'm hoping to fix this script can open it

BUMP
 
Last edited by a moderator:
I made this for TFS 1.1, but maybe you can convert it to your version.
I don't like using addEvent like this, but I think it's the only solution if you don't want to use onDeath() and register the event for every monster.

Not tested.
Code:
function autoGP(cid, pos, corpseId)
    local player = Player(cid)
    if not player then
        return
    end
   
    local corpse = Tile(pos):getItemById(corpseId)
    if corpse then
        local container = Container(corpse:getUniqueId())
        if container then
            local gold = 0
            for i = 1, container:getSize() do
                local item = container:getItem(i)
                if item then
                    local id = item:getId()
                    local count = item:getCount()
                    local goldAdded = id == 2148 and count or id == 2152 and count * 100 or id == 2160 and count * 10000 or 0
                    if goldAdded > 0 then
                        gold = gold + goldAdded
                        item:remove(count)
                    end
                else
                    break
                end
            end
           
            player:addMoney(gold)
        end
    end
end

function onKill(creature, target)
    if target:isPlayer() then
        return true
    end
   
    local monsterType = MonsterType(target:getName())
    addEvent(autoGP, 1, creature:getId(), target:getPosition(), monsterType:getCorpseId())
    return true
end
 
Back
Top