• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua If have slots free in backpack

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I have this script to auto cath gold from dead monsters and another to transform golds...
But when i kill a monster and no have slots countainers free all money going to ground...
And it can lag my ot cause so much trash

Someone could help me to fix it?

Auto Get Gold SCRIPT:

Code:
<event type="kill" name="GP" event="script" value="gp.lua"/>

Code:
local function doPlayerAddContainerMoney(cid, container, gold)
local extrac = 0
for slot = (getContainerSize(container) - 1), 0, -1 do
local item = getContainerItem(container, slot)
local amount = (item.itemid == 2148 and item.type or (item.itemid == 2152 and item.type * 100 or (item.itemid == 2160 and item.type * 10000)) or 0)
if item.uid > 0 then
if amount > 0 then
gold = gold + amount
doRemoveItem(item.uid)
end
end
if isContainer(item.uid) then
extrac = item.uid
end
end
if extrac > 0 then
doPlayerAddContainerMoney(cid, extrac, gold)
else
doPlayerAddMoney(cid, gold)
end
end

local function autoloot(cid, position, corpseID)
if not isPlayer(cid) then
return
end

local corpse = getTileItemById(position, corpseID)
if corpse and isContainer(corpse.uid) then
doPlayerAddContainerMoney(cid, corpse.uid, 0)
end
end

function onKill(cid, target)
if isPlayer(target) then
return true
end
local position = getCreaturePosition(target)
local info = getMonsterInfo(getCreatureName(target))
addEvent(autoloot, 100, cid, position, info.lookCorpse)
return true
end
 
Code:
local function doPlayerAddContainerMoney(cid, container, gold)
local extrac = 0
for slot = (getContainerSize(container) - 1), 0, -1 do
local item = getContainerItem(container, slot)
local amount = (item.itemid == 2148 and item.type or (item.itemid == 2152 and item.type * 100 or (item.itemid == 2160 and item.type * 10000)) or 0)
if item.uid > 0 then
if amount > 0 then
gold = gold + amount
doRemoveItem(item.uid)
end
end
if isContainer(item.uid) then
extrac = item.uid
end
end
if extrac > 0 then
doPlayerAddContainerMoney(cid, extrac, gold)
else
doPlayerAddMoney(cid, gold)
end
end

local function autoloot(cid, position, corpseID)
if not isPlayer(cid) then
return
end

local corpse = getTileItemById(position, corpseID)
if corpse and isContainer(corpse.uid) then
doPlayerAddContainerMoney(cid, corpse.uid, 0)
end
end

function onKill(cid, target)
local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid
local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))

if isPlayer(target) then
return true
end
local position = getCreaturePosition(target)
local info = getMonsterInfo(getCreatureName(target))
if freeSlotsInBp > 0 then
addEvent(autoloot, 100, cid, position, info.lookCorpse)
else
return false
end
return true
end

Try this.
 
Code:
local function doPlayerAddContainerMoney(cid, container, gold)
local extrac = 0
for slot = (getContainerSize(container) - 1), 0, -1 do
local item = getContainerItem(container, slot)
local amount = (item.itemid == 2148 and item.type or (item.itemid == 2152 and item.type * 100 or (item.itemid == 2160 and item.type * 10000)) or 0)
if item.uid > 0 then
if amount > 0 then
gold = gold + amount
doRemoveItem(item.uid)
end
end
if isContainer(item.uid) then
extrac = item.uid
end
end
if extrac > 0 then
doPlayerAddContainerMoney(cid, extrac, gold)
else
doPlayerAddMoney(cid, gold)
end
end

local function autoloot(cid, position, corpseID)
if not isPlayer(cid) then
return
end

local corpse = getTileItemById(position, corpseID)
if corpse and isContainer(corpse.uid) then
doPlayerAddContainerMoney(cid, corpse.uid, 0)
end
end

function onKill(cid, target)
local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid
local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))

if isPlayer(target) then
return true
end
local position = getCreaturePosition(target)
local info = getMonsterInfo(getCreatureName(target))
if freeSlotsInBp > 0 then
addEvent(autoloot, 100, cid, position, info.lookCorpse)
else
return false
end
return true
end

Try this.


When my first backpack no have slots free i killed a monster but it still onfoot, not transform to corpse while i dont have slots free in backpack
 
what do you want it to do? give to player if player has cap & space, else drop inside body?
also thexamx, that will only check the first backpack afaik
 
what do you want it to do? give to player if player has cap & space, else drop inside body?
also thexamx, that will only check the first backpack afaik

I cant understand what he wants XD
I made it like that, cause I think thats all he wants
 
Code:
local function doPlayerAddContainerMoney(cid, container, gold)
local extrac = 0
for slot = (getContainerSize(container) - 1), 0, -1 do
local item = getContainerItem(container, slot)
local amount = (item.itemid == 2148 and item.type or (item.itemid == 2152 and item.type * 100 or (item.itemid == 2160 and item.type * 10000)) or 0)
if item.uid > 0 then
if amount > 0 then
gold = gold + amount
doRemoveItem(item.uid)
end
end
if isContainer(item.uid) then
extrac = item.uid
end
end
if extrac > 0 then
doPlayerAddContainerMoney(cid, extrac, gold)
else
doPlayerAddMoney(cid, gold)
end
end

local function autoloot(cid, position, corpseID)
if not isPlayer(cid) then
return
end

local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid
local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))
local corpse = getTileItemById(position, corpseID)
if corpse and isContainer(corpse.uid) then
if freeSlotsInBp > 0 then
doPlayerAddContainerMoney(cid, corpse.uid, 0)
else
return false
end
end
end

function onKill(cid, target)
if isPlayer(target) then
return true
end
local position = getCreaturePosition(target)
local info = getMonsterInfo(getCreatureName(target))
addEvent(autoloot, 100, cid, position, info.lookCorpse)
return true
end
 
Code:
local function doPlayerAddContainerMoney(cid, container, gold)
local extrac = 0
for slot = (getContainerSize(container) - 1), 0, -1 do
local item = getContainerItem(container, slot)
local amount = (item.itemid == 2148 and item.type or (item.itemid == 2152 and item.type * 100 or (item.itemid == 2160 and item.type * 10000)) or 0)
if item.uid > 0 then
if amount > 0 then
gold = gold + amount
doRemoveItem(item.uid)
end
end
if isContainer(item.uid) then
extrac = item.uid
end
end
if extrac > 0 then
doPlayerAddContainerMoney(cid, extrac, gold)
else
doPlayerAddMoney(cid, gold)
end
end

local function autoloot(cid, position, corpseID)
if not isPlayer(cid) then
return
end

local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).uid
local freeSlotsInBp = math.max(0, getContainerCap(bp) - getContainerSize(bp))
local corpse = getTileItemById(position, corpseID)
if corpse and isContainer(corpse.uid) then
if freeSlotsInBp > 0 then
doPlayerAddContainerMoney(cid, corpse.uid, 0)
else
return false
end
end
end

function onKill(cid, target)
if isPlayer(target) then
return true
end
local position = getCreaturePosition(target)
local info = getMonsterInfo(getCreatureName(target))
addEvent(autoloot, 100, cid, position, info.lookCorpse)
return true
end

Ty u so much man!
 
Back
Top