• 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 Change Loot rates for a player

zexus

Member
Joined
Oct 1, 2016
Messages
133
Reaction score
18
There is a way to change the loot rate for only one player?

I do using this source code:
Fir3element/3777

And i wanna make some items to add more loot chance.

I've search a lot and the only thing i got was this mod with onKill event
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Loot Ring" version="1.0" author="Cykotitan" contact="otland.net" enabled="yes">
<event type="kill" name="lootring" event="script"> <![CDATA[
  local t = {
    item = 11393,
    slot = CONST_SLOT_NECKLACE,
    newRate = 1.5
  }

  local rate = getConfigInfo('rateLoot')

  function getContentDescription(uid, comma)
  local ret, i, containers = '', 0, {}
  while i < getContainerSize(uid) do
  local v, s = getContainerItem(uid, i), ''
  local k = getItemInfo(v.itemid)
  if k.name ~= '' then
  if v.type > 1 and k.stackable and k.showCount then
  s = v.type .. ' ' .. getItemInfo(v.itemid).plural
  else
  local article = k.article
  s = (article == '' and '' or article .. ' ') .. k.name
  end
  ret = ret .. (i == 0 and not comma and '' or ', ') .. s
  if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
  table.insert(containers, v.uid)
  end
  else
  ret = ret .. (i == 0 and not comma and '' or ', ') .. 'an item of type ' .. v.itemid .. ', please report it to gamemaster'
  end
  i = i + 1
  end
  for i = 1, #containers do
  ret = ret .. getContentDescription(containers[i], true)
  end
  return ret
  end

  local function send(cid, pos, corpseid, monster, party)
  local corpse = getTileItemById(pos, corpseid).uid
  local ret = isContainer(corpse) and getContentDescription(corpse)
  doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'))
  if party then
  for _, pid in ipairs(getPartyMembers(party)) do
  doPlayerSendChannelMessage(pid, '', 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'), TALKTYPE_CHANNEL_W, CHANNEL_PARTY)
  end
  end
  end

  local function createLoot(i, ext)
  local item = type(i.id) == 'table' and i.id[math.random(#i.id)] or i.id
  local random = math.ceil(math.random(100000) / (ext and t.newRate or rate))


  local itemInfo = getItemInfo(item)
  if not itemInfo then
  return false
  end


  local tmpItem = false

  if random < i.chance then
  tmpItem = doCreateItemEx(item, itemInfo.stackable and random % i.count + 1 or 1)
  end

  if not tmpItem then
  return false
  end

  if i.subType ~= -1 then
  doItemSetAttribute(tmpItem, 'subType', i.subType)
  end







  if i.actionId ~= -1 then
  doItemSetAttribute(tmpItem, 'aid', i.actionId)
  end

  if i.uniqueId ~= -1 then
  doItemSetAttribute(tmpItem, 'uid', i.uniqueId)
  end

  if i.text ~= '' then
  doItemSetAttribute(tmpItem, 'text', i.text)
  end

  return tmpItem
  end

  local function createChildLoot(parent, i, ext)
  if #i == 0 then
  return true
  end

  local size, cap = 0, getContainerCap(parent)
  for k = 1, #i do
  if size == cap then
  break
  end
  local tmp = createLoot(i[k], ext)
  if tmp then
  if isContainer(tmp) then
  if createChildLoot(tmp, i[k].child, ext) then
  doAddContainerItemEx(parent, tmp)
  size = size + 1
  else
  doRemoveItem(tmp)
  end
  else
  doAddContainerItemEx(parent, tmp)
  size = size + 1
  end
  end
  end

  return size > 0
  end

  local function dropLoot(pos, v, ext)
  local corpse = getTileItemById(pos, v.lookCorpse).uid
  if isContainer(corpse) then
  for i = 1, getContainerSize(corpse) do
  doRemoveItem(getContainerItem(corpse, 0).uid)
  end
  local size, cap = 0, getContainerCap(corpse)
  for i = 1, #v.loot do
  if size == cap then
  break
  end
  local tmp = createLoot(v.loot[i], ext)
  if tmp then
  if isContainer(tmp) then
  if createChildLoot(tmp, v.loot[i].child, ext) then
  doAddContainerItemEx(corpse, tmp)
  size = size + 1
  else
  doRemoveItem(tmp)
  end
  else
  doAddContainerItemEx(corpse, tmp)
  size = size + 1
  end
  end
  end
  end
  end

  function onKill(cid, target, lastHit)
  if lastHit and isMonster(target) then
  local v = getMonsterInfo(getCreatureName(target))
  if v.lookCorpse > 0 then
  local master = getCreatureMaster(target)
  if not master or master == target then
  addEvent(dropLoot, 0, getThingPos(target), v, getPlayerSlotItem(cid, t.slot).itemid == t.item)
  end
  addEvent(send, 100, cid, getThingPos(target), v.lookCorpse, v.description)
  end
  end
  return true
  end
]]></event>
<event type="login" name="Loot Ring" event="buffer"><![CDATA[
  registerCreatureEvent(cid, "lootring")
]]></event>
</mod>

But i got anothers OnKill events and would be better if it was done on real loot, not create another one

Is anybody know something about this?
 
Last edited:
I'm sorry to be a fucking noob, but what are u mean?
Idk something like this
Lua:
<?xml version="1.0" encoding="UTF-8"?>
    <mod name="Loot Ring" version="1.0" author="Cykotitan" contact="otland.net" enabled="yes">
        <event type="kill" name="lootring" event="script"> <![CDATA[
            local t = {
                item = 11393,
                slot = CONST_SLOT_NECKLACE,
                -- newRate = 1.5,
                newRate = {},
                rateStorage = 999999
            }

            local xid = nil

            function setIndividualRate()
                if xid then
                    if not newRate[xid] then
                        newRate[xid] = getPlayerStorageValue(xid, rateStorage)
                    end

                    if newRate[xid] ~= -1 then
                        return newRate[xid]
                    end
                end
                return getConfigInfo('rateLoot')
            end

            function getContentDescription(uid, comma)
                local ret, i, containers = '', 0, {}
                while i < getContainerSize(uid) do
                    local v, s = getContainerItem(uid, i), ''
                    local k = getItemInfo(v.itemid)
                    if k.name ~= '' then
                        if v.type > 1 and k.stackable and k.showCount then
                            s = v.type .. ' ' .. getItemInfo(v.itemid).plural
                        else
                            local article = k.article
                            s = (article == '' and '' or article .. ' ') .. k.name
                        end
                        ret = ret .. (i == 0 and not comma and '' or ', ') .. s
                        if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
                            table.insert(containers, v.uid)
                        end
                    else
                        ret = ret .. (i == 0 and not comma and '' or ', ') .. 'an item of type ' .. v.itemid .. ', please report it to gamemaster'
                    end
                    i = i + 1
                end
                for i = 1, #containers do
                    ret = ret .. getContentDescription(containers[i], true)
                end
                return ret
            end

            local function send(cid, pos, corpseid, monster, party)
                local corpse = getTileItemById(pos, corpseid).uid
                local ret = isContainer(corpse) and getContentDescription(corpse)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'))
                if party then
                    for _, pid in ipairs(getPartyMembers(party)) do
                        doPlayerSendChannelMessage(pid, '', 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'), TALKTYPE_CHANNEL_W, CHANNEL_PARTY)
                    end
                end
            end

            local function createLoot(i, ext)
                local item = type(i.id) == 'table' and i.id[math.random(#i.id)] or i.id
                local random = math.ceil(math.random(100000) / setIndividualRate()


                local itemInfo = getItemInfo(item)
                if not itemInfo then
                    return false
                end


                local tmpItem = false

                if random < i.chance then
                    tmpItem = doCreateItemEx(item, itemInfo.stackable and random % i.count + 1 or 1)
                end

                if not tmpItem then
                    return false
                end

                if i.subType ~= -1 then
                    doItemSetAttribute(tmpItem, 'subType', i.subType)
                end

                if i.actionId ~= -1 then
                    doItemSetAttribute(tmpItem, 'aid', i.actionId)
                end

                if i.uniqueId ~= -1 then
                    doItemSetAttribute(tmpItem, 'uid', i.uniqueId)
                end

                if i.text ~= '' then
                    doItemSetAttribute(tmpItem, 'text', i.text)
                end

                return tmpItem
            end

            local function createChildLoot(parent, i, ext)
                if #i == 0 then
                    return true
                end

                local size, cap = 0, getContainerCap(parent)
                for k = 1, #i do
                    if size == cap then
                        break
                    end
                    local tmp = createLoot(i[k], ext)
                    if tmp then
                        if isContainer(tmp) then
                            if createChildLoot(tmp, i[k].child, ext) then
                                doAddContainerItemEx(parent, tmp)
                                size = size + 1
                            else
                                doRemoveItem(tmp)
                            end
                        else
                            doAddContainerItemEx(parent, tmp)
                            size = size + 1
                        end
                    end
                end
                return size > 0
            end

            local function dropLoot(pos, v, ext)
                local corpse = getTileItemById(pos, v.lookCorpse).uid
                if isContainer(corpse) then
                    for i = 1, getContainerSize(corpse) do
                        doRemoveItem(getContainerItem(corpse, 0).uid)
                    end
                    local size, cap = 0, getContainerCap(corpse)
                    for i = 1, #v.loot do
                        if size == cap then
                            break
                        end
                        local tmp = createLoot(v.loot[i], ext)
                        if tmp then
                            if isContainer(tmp) then
                                if createChildLoot(tmp, v.loot[i].child, ext) then
                                    doAddContainerItemEx(corpse, tmp)
                                    size = size + 1
                                else
                                    doRemoveItem(tmp)
                                end
                            else
                                doAddContainerItemEx(corpse, tmp)
                                size = size + 1
                            end
                        end
                    end
                end
            end

            function onKill(cid, target, lastHit)
                if lastHit and isMonster(target) then
                    local v = getMonsterInfo(getCreatureName(target))
                    if v.lookCorpse > 0 then
                        xid = cid
                        local master = getCreatureMaster(target)
                        if not master or master == target then
                            addEvent(dropLoot, 0, getThingPos(target), v, getPlayerSlotItem(cid, t.slot).itemid == t.item)
                        end
                        addEvent(send, 100, cid, getThingPos(target), v.lookCorpse, v.description)
                    end
                end
                return true
            end
    ]]></event>
    <event type="login" name="Loot Ring" event="buffer"><![CDATA[
    registerCreatureEvent(cid, "lootring")
    ]]></event>
</mod>

You'll need to set the storage value elsewhere for a player's individual loot rates, you can use a quest, an npc or whatever your heart desires to update this storage. If you don't set the storage value then the mod will just use the server's default value.
 
Last edited:
Idk something like this
Lua:
<?xml version="1.0" encoding="UTF-8"?>
    <mod name="Loot Ring" version="1.0" author="Cykotitan" contact="otland.net" enabled="yes">
        <event type="kill" name="lootring" event="script"> <![CDATA[
            local t = {
                item = 11393,
                slot = CONST_SLOT_NECKLACE,
                -- newRate = 1.5,
                newRate = {},
                rateStorage = 999999
            }

            local xid = nil

            function setIndividualRate()
                if xid then
                    if not newRate[xid] then
                        newRate[xid] = getPlayerStorageValue(xid, rateStorage)
                    end

                    if newRate[xid] ~= -1 then
                        return newRate[xid]
                    end
                end
                return getConfigInfo('rateLoot')
            end

            function getContentDescription(uid, comma)
                local ret, i, containers = '', 0, {}
                while i < getContainerSize(uid) do
                    local v, s = getContainerItem(uid, i), ''
                    local k = getItemInfo(v.itemid)
                    if k.name ~= '' then
                        if v.type > 1 and k.stackable and k.showCount then
                            s = v.type .. ' ' .. getItemInfo(v.itemid).plural
                        else
                            local article = k.article
                            s = (article == '' and '' or article .. ' ') .. k.name
                        end
                        ret = ret .. (i == 0 and not comma and '' or ', ') .. s
                        if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
                            table.insert(containers, v.uid)
                        end
                    else
                        ret = ret .. (i == 0 and not comma and '' or ', ') .. 'an item of type ' .. v.itemid .. ', please report it to gamemaster'
                    end
                    i = i + 1
                end
                for i = 1, #containers do
                    ret = ret .. getContentDescription(containers[i], true)
                end
                return ret
            end

            local function send(cid, pos, corpseid, monster, party)
                local corpse = getTileItemById(pos, corpseid).uid
                local ret = isContainer(corpse) and getContentDescription(corpse)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'))
                if party then
                    for _, pid in ipairs(getPartyMembers(party)) do
                        doPlayerSendChannelMessage(pid, '', 'Loot of ' .. monster .. ': ' .. (ret ~= '' and ret or 'nothing'), TALKTYPE_CHANNEL_W, CHANNEL_PARTY)
                    end
                end
            end

            local function createLoot(i, ext)
                local item = type(i.id) == 'table' and i.id[math.random(#i.id)] or i.id
                local random = math.ceil(math.random(100000) / setIndividualRate()


                local itemInfo = getItemInfo(item)
                if not itemInfo then
                    return false
                end


                local tmpItem = false

                if random < i.chance then
                    tmpItem = doCreateItemEx(item, itemInfo.stackable and random % i.count + 1 or 1)
                end

                if not tmpItem then
                    return false
                end

                if i.subType ~= -1 then
                    doItemSetAttribute(tmpItem, 'subType', i.subType)
                end

                if i.actionId ~= -1 then
                    doItemSetAttribute(tmpItem, 'aid', i.actionId)
                end

                if i.uniqueId ~= -1 then
                    doItemSetAttribute(tmpItem, 'uid', i.uniqueId)
                end

                if i.text ~= '' then
                    doItemSetAttribute(tmpItem, 'text', i.text)
                end

                return tmpItem
            end

            local function createChildLoot(parent, i, ext)
                if #i == 0 then
                    return true
                end

                local size, cap = 0, getContainerCap(parent)
                for k = 1, #i do
                    if size == cap then
                        break
                    end
                    local tmp = createLoot(i[k], ext)
                    if tmp then
                        if isContainer(tmp) then
                            if createChildLoot(tmp, i[k].child, ext) then
                                doAddContainerItemEx(parent, tmp)
                                size = size + 1
                            else
                                doRemoveItem(tmp)
                            end
                        else
                            doAddContainerItemEx(parent, tmp)
                            size = size + 1
                        end
                    end
                end
                return size > 0
            end

            local function dropLoot(pos, v, ext)
                local corpse = getTileItemById(pos, v.lookCorpse).uid
                if isContainer(corpse) then
                    for i = 1, getContainerSize(corpse) do
                        doRemoveItem(getContainerItem(corpse, 0).uid)
                    end
                    local size, cap = 0, getContainerCap(corpse)
                    for i = 1, #v.loot do
                        if size == cap then
                            break
                        end
                        local tmp = createLoot(v.loot[i], ext)
                        if tmp then
                            if isContainer(tmp) then
                                if createChildLoot(tmp, v.loot[i].child, ext) then
                                    doAddContainerItemEx(corpse, tmp)
                                    size = size + 1
                                else
                                    doRemoveItem(tmp)
                                end
                            else
                                doAddContainerItemEx(corpse, tmp)
                                size = size + 1
                            end
                        end
                    end
                end
            end

            function onKill(cid, target, lastHit)
                if lastHit and isMonster(target) then
                    local v = getMonsterInfo(getCreatureName(target))
                    if v.lookCorpse > 0 then
                        xid = cid
                        local master = getCreatureMaster(target)
                        if not master or master == target then
                            addEvent(dropLoot, 0, getThingPos(target), v, getPlayerSlotItem(cid, t.slot).itemid == t.item)
                        end
                        addEvent(send, 100, cid, getThingPos(target), v.lookCorpse, v.description)
                    end
                end
                return true
            end
    ]]></event>
    <event type="login" name="Loot Ring" event="buffer"><![CDATA[
    registerCreatureEvent(cid, "lootring")
    ]]></event>
</mod>

You'll need to set the storage value elsewhere for a player's individual loot rates, you can use a quest, an npc or whatever your heart desires to update this storage. If you don't set the storage value then the mod will just use the server's default value.


Thats exactly the script i told i had found here on forum
I can't recreate the loot because i have anothers scripts using the real loot
I have to change the loot rate for one player
 
Thats exactly the script i told i had found here on forum
I can't recreate the loot because i have anothers scripts using the real loot
I have to change the loot rate for one player
I altered the script you posted, I made the changes you requested but I said you need to find a means of setting the storage value for each player which would return their unique loot rate.

This is the additional code which was added to the script.
Lua:
                -- newRate = 1.5,
                newRate = {},
                rateStorage = 999999
            }
            local xid = nil
            function setIndividualRate()
                if xid then
                    if not newRate[xid] then
                        newRate[xid] = getPlayerStorageValue(xid, rateStorage)
                    end
                    if newRate[xid] ~= -1 then
                        return newRate[xid]
                    end
                end
                return getConfigInfo('rateLoot')
            end

Along with a small change here
Lua:
                local random = math.ceil(math.random(100000) / setIndividualRate()

And here
Lua:
xid = cid
 
I altered the script you posted, I made the changes you requested but I said you need to find a means of setting the storage value for each player which would return their unique loot rate.

This is the additional code which was added to the script.
Lua:
                -- newRate = 1.5,
                newRate = {},
                rateStorage = 999999
            }
            local xid = nil
            function setIndividualRate()
                if xid then
                    if not newRate[xid] then
                        newRate[xid] = getPlayerStorageValue(xid, rateStorage)
                    end
                    if newRate[xid] ~= -1 then
                        return newRate[xid]
                    end
                end
                return getConfigInfo('rateLoot')
            end

Along with a small change here
Lua:
                local random = math.ceil(math.random(100000) / setIndividualRate()

And here
Lua:
xid = cid

The point is i can't recreate the loot system because of others systems
There is no way to get loot rates and set in a 0.4?
 
Back
Top