• 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 1.X+ Drop Loot getCreatureName(cid)

Status
Not open for further replies.

Svira

Active Member
Joined
Jan 27, 2008
Messages
263
Solutions
11
Reaction score
35
Hello, for some time I have been trying to specify loot for the selected monster "loot chance"

The assumption is that all items from BOSS will have slots not less than 28%

other monsters according to standard calculation.

However, the script does not work as expected without any errors.


Lua:
function getper()
   local n = 1
   for i=1,10 do
     n = n+math.random(0,10)
     if n < 8*i then
       break
     end
   end
   return n
end

function getperchance()
   local n = 1
   for i=1,10 do
     n = n+math.random(1,10)
     if n < 28*i then
       break
     end
   end
   return n
end
  
local lootable_slots = {'hp','mp','ml','melee','shield','dist'}

function assign_loot_Slot(pos)
   local c = Tile(pos):getTopDownItem()
   if c ~= nil then
     if c:isContainer() then
       local h = c:getItemHoldingCount()
       if h > 0 then
         for i = 1, h do
           local i_Ex = c:getItem(i - 1)
           if i_Ex == nil then
       break
     end
           local itemEx = {
             itemid = i_Ex:getId(),
             uid = i_Ex:getUniqueId()
           }
          
           if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
             if math.random(1,5) == 5 then
                if math.random(1, 100) <= 75 then
                 nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
                 nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                 doSetItemSpecialDescription(itemEx.uid, nam)
                 doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYAREA)
                 if math.random(1, 100) <= 50 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_ICETORNADO)
                 end
                  if math.random(1, 100) <= 1 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_PURPLEENERGY)
                   end
                   end
                 end
               end
             end
           end
         end
         return true
       end
     end
    
function assign_loot_chance(pos)
   local c = Tile(pos):getTopDownItem()
   if c ~= nil then
     if c:isContainer() then
       local h = c:getItemHoldingCount()
       if h > 0 then
         for i = 1, h do
           local i_Ex = c:getItem(i - 1)
           if i_Ex == nil then
       break
     end
           local itemEx = {
             itemid = i_Ex:getId(),
             uid = i_Ex:getUniqueId()
           }
          
           if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
                if math.random(1, 100) <= 1 then
                 nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
                 nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                 doSetItemSpecialDescription(itemEx.uid, nam)
                 doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYAREA)
                 if math.random(1, 100) <= 1 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_ICETORNADO)
                 end
                  if math.random(1, 100) <= 1 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_PURPLEENERGY)
                   end
                   end
                 end
             end
           end
         end
         return true
       end
     end


function onKill(cid, target, lastHit)
   if (not isSummon(target)) then
     addEvent(assign_loot_Slot, 2, getThingPos(target))
   end
   local creaturenames = {"Loot Chance"}
            local name = string.lower(getCreatureName(cid))
            if(isInArray(creaturenames, name)) then
            addEvent(assign_loot_chance, 2, getThingPos(target))
            end
return true
end
 
Solution
can I ask you to merge your posts? main can't be marked as "solution"

Correctly working code:

Lua:
function getper()
   local n = 1
   for i=1,10 do
     n = n+math.random(0,10)
     if n < 8*i then
       break
     end
   end
   return n
end

function getperchance()
     local n = 1
   for i=1,10 do
     n = n+math.random(0,10)
     if n >= 28*i then
       break
     end
   end
   return n
end
  
local lootable_slots = {'hp','mp','ml','melee','shield','dist'}

function assign_loot_Slot(pos)
   local c = Tile(pos):getTopDownItem()
   if c ~= nil then
     if c:isContainer() then
       local h = c:getItemHoldingCount()
       if h > 0 then
         for i = 1, h do
           local i_Ex = c:getItem(i - 1)
           if i_Ex == nil then...
can I ask you to merge your posts? main can't be marked as "solution"

Correctly working code:

Lua:
function getper()
   local n = 1
   for i=1,10 do
     n = n+math.random(0,10)
     if n < 8*i then
       break
     end
   end
   return n
end

function getperchance()
     local n = 1
   for i=1,10 do
     n = n+math.random(0,10)
     if n >= 28*i then
       break
     end
   end
   return n
end
  
local lootable_slots = {'hp','mp','ml','melee','shield','dist'}

function assign_loot_Slot(pos)
   local c = Tile(pos):getTopDownItem()
   if c ~= nil then
     if c:isContainer() then
       local h = c:getItemHoldingCount()
       if h > 0 then
         for i = 1, h do
           local i_Ex = c:getItem(i - 1)
           if i_Ex == nil then
       break
     end
           local itemEx = {
             itemid = i_Ex:getId(),
             uid = i_Ex:getUniqueId()
           }
          
           if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
             if math.random(1,5) == 5 then
                if math.random(1, 100) <= 75 then
                 nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
                 nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                 doSetItemSpecialDescription(itemEx.uid, nam)
                 doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYAREA)
                 if math.random(1, 100) <= 50 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_ICETORNADO)
                 end
                  if math.random(1, 100) <= 1 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_PURPLEENERGY)
                   end
                   end
                 end
               end
             end
           end
         end
         return true
       end
     end
    
function assign_loot_chance(pos)
   local c = Tile(pos):getTopDownItem()
   if c ~= nil then
     if c:isContainer() then
       local h = c:getItemHoldingCount()
       if h > 0 then
         for i = 1, h do
           local i_Ex = c:getItem(i - 1)
           if i_Ex == nil then
       break
     end
           local itemEx = {
             itemid = i_Ex:getId(),
             uid = i_Ex:getUniqueId()
           }
          
           if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
                if math.random(1, 100) <= 75 then
                 nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
                 nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                 doSetItemSpecialDescription(itemEx.uid, nam)
                 doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_TUTORIALARROW)
                 if math.random(1, 100) <= 50 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_TUTORIALARROW)
                 end
                  if math.random(1, 100) <= 1 then
                   nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
                   doSetItemSpecialDescription(itemEx.uid, nam)
                   doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_TUTORIALARROW)
                   end
                   end
                 end
             end
           end
         end
         return true
       end
     end

function onKill(cid, target, lastHit)
local targetMonster = target:getMonster()
if(string.lower(getCreatureName(target)) == "loot chance") then
            cid:say('rare?', TALKTYPE_MONSTER_SAY)
            addEvent(assign_loot_chance, 3, getThingPos(target))
            return true
end
if(not isSummon(target)) then
     addEvent(assign_loot_Slot, 2, getThingPos(target))
    end
return true
end
 
Solution
Status
Not open for further replies.
Back
Top