• 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.2 Looking for action scrip that gives x item if used on monster

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
989
Solutions
5
Reaction score
54
Hello,
im looking for action script that would give x item if its used on monster with particular name so for example

local config = {
needLevel = 150,
cooldownMin = 5,
chanceForSucces = 35, (it means it has 35% chance to get that item, basically its like pokemon ball you have chance to catch monster and if u get lucky you will get x item)

monsters = {
{name = "Test MVP Quest", addItem = {{id = 778, count = 1},
{name = "Lost Test MVP Quest", addItem = {{id = 788, count = 1},
{name = "Super Test MVP Quest", addItem = {{id = 798, count = 1},
}
}

so if you use this item on a monster that is on this list it would remove the monster and remove the item you just used.
 
Not sure if helpful but u could look on how mounts are obtained and maybe try to rework it a bit? Since In rl tibia u use x item on x monster to get x mount but in ur case u could change it to get x item as reward if success.
 
Not atm sorry, if u don’t have mounts in ur server h could check tfs on GitHub for 1.2 and see their mount files
 
Just register in actions.xml with the itemId's you want to use.
Lua:
local monsters = {
    ["rat"] = {itemToUse = 1111, itemToReceive = {itemId = 2222, amount = 1}},
    ["troll"] = {itemToUse = 3333, itemToReceive = {itemId = 4444, amount = 1}},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm a target exists and is a Monster
    if not target or not target:isMonster() then
        return true
    end
    
    -- confirm it exists in table
    local index = monsters[target:getName():lower()]
    if not index then
        return true
    end
    
    -- confirm correct item is being used on it
    if item:getId() ~= index.itemToUse then
        return true
    end
    
    -- remove item that was used, and give other item
    item:remove(1)
    player:addItem(index.itemToReceive.itemId, index.itemToReceive.amount, true)
    return true
end
 
Just register in actions.xml with the itemId's you want to use.
Lua:
local monsters = {
    ["rat"] = {itemToUse = 1111, itemToReceive = {itemId = 2222, amount = 1}},
    ["troll"] = {itemToUse = 3333, itemToReceive = {itemId = 4444, amount = 1}},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm a target exists and is a Monster
    if not target or not target:isMonster() then
        return true
    end
   
    -- confirm it exists in table
    local index = monsters[target:getName():lower()]
    if not index then
        return true
    end
   
    -- confirm correct item is being used on it
    if item:getId() ~= index.itemToUse then
        return true
    end
   
    -- remove item that was used, and give other item
    item:remove(1)
    player:addItem(index.itemToReceive.itemId, index.itemToReceive.amount, true)
    return true
end
what about success chance rate?
 
what about success chance rate?
You can add a math.random for exemple and create multiples itemToReceive in this case, with chances and Tiers,
This is a simple example, but you can do it in many ways,

Lua:
local monsters = {
    ["rat"] = {itemToUse = 1111, normal = {itemId = 2222, amount = 1}, rare = {itemId = 3333, amount = 1}, epic = {itemId = 4444, amount = 1}},
    ["troll"] = {itemToUse = 3333, normal = {itemId = 4444, amount = 1}, rare = {itemId = 3333, amount = 1}, epic = {itemId = 4444, amount = 1}},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm a target exists and is a Monster
    if not target or not target:isMonster() then
        return true
    end
   
    -- confirm it exists in table
    local index = monsters[target:getName():lower()]
    if not index then
        return true
    end
   
    -- confirm correct item is being used on it
    if item:getId() ~= index.itemToUse then
        return true
    end
   
    -- remove item that was used, and give other item
    local chance = math.random(100)
    if chance < 89 then
      player:addItem(index.normal.itemId, index.normal.amount, true)
    elseif chance > 90 then
      player:addItem(index.rare.itemId, index.rare.amount, true)
    elseif chance > 95 then
      player:addItem(index.epic.itemId, index.epic.amount, true)
    end

    item:remove(1)
    return true
end
 
You can add a math.random for exemple and create multiples itemToReceive in this case, with chances and Tiers,
This is a simple example, but you can do it in many ways,

Lua:
local monsters = {
    ["rat"] = {itemToUse = 1111, normal = {itemId = 2222, amount = 1}, rare = {itemId = 3333, amount = 1}, epic = {itemId = 4444, amount = 1}},
    ["troll"] = {itemToUse = 3333, normal = {itemId = 4444, amount = 1}, rare = {itemId = 3333, amount = 1}, epic = {itemId = 4444, amount = 1}},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm a target exists and is a Monster
    if not target or not target:isMonster() then
        return true
    end
  
    -- confirm it exists in table
    local index = monsters[target:getName():lower()]
    if not index then
        return true
    end
  
    -- confirm correct item is being used on it
    if item:getId() ~= index.itemToUse then
        return true
    end
  
    -- remove item that was used, and give other item
    local chance = math.random(100)
    if chance < 89 then
      player:addItem(index.normal.itemId, index.normal.amount, true)
    elseif chance > 90 then
      player:addItem(index.rare.itemId, index.rare.amount, true)
    elseif chance > 95 then
      player:addItem(index.epic.itemId, index.epic.amount, true)
    end

    item:remove(1)
    return true
end
Okay so how can i make this code a little bit better like adding text if u caught it or not, sending text what item you got
Lua:
local monsters = {
    ["test mvp"] = {itemToUse = 17415, normal = {itemId = 17415, amount = 1}},
    ["rat"] = {itemToUse = 17415, normal = {itemId = 17416, amount = 1}},
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm a target exists and is a Monster
    if not target or not target:isMonster() then
        return true
    end
   
    -- confirm it exists in table
    local index = monsters[target:getName():lower()]
    if not index then
        return true
    end
   
    -- confirm correct item is being used on it
    if item:getId() ~= index.itemToUse then
        return true
    end
   
    -- remove item that was used, and give other item
    local chance = math.random(100)
    if chance < 35 then
      player:addItem(index.normal.itemId, index.normal.amount, true)
      player:sendTextMessage(MESSAGE_EVENT_ORANGE, "You got ".. (amount ~= nil and amount .. ' ' or '') .. ItemType(normal):getName())
    end

    target:remove()
    item:remove(1)
    return true
end
Post automatically merged:

bump
 
Last edited:
Back
Top