• 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 Taming System

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
This script dont working correctly

no working: we use on npc with looktype 387 or use in differents monters with looktype 387

this should work when: we use on Donkey mount or use on any monster transformed with looktype 387 or npc transformed with looktype 387

tfs .1.2


LUA:
local TYPE_ITEM, TYPE_MONSTER, TYPE_NPC = 0, 2, 3

local config = {
    [13537]    = {
        mountName = 'Donkey',
        lookType = 387,
        id = 13,
        type = TYPE_MONSTER,
        chance = 40,
        fail = {
            {removeTransformation = true, text = 'The donkey transformation suddenly wears off.'},
            {broke = true, sound = 'Heeee-haaa-haaa-haaw!', text = 'You did not manage to feed the donkey enough apple slices.'}
        },
        success = {sound = 'Heeee-haaaaw!', text = 'Munching a large pile of apple slices tamed the donkey.'}
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local mount = config[item.itemid]
    if not mount then
        return false
    end

    local targetName = target:getName():lower()
    if mount.type ~= target.type
            or (mount.lookType and mount.lookType ~= target:getOutfit().lookType)
            or (mount.name and mount.name ~= targetName) then
        return false
    end

    if player:hasMount(mount.id) then
        player:say('You already tamed a ' .. (mount.mountName or targetName) .. '.', TALKTYPE_MONSTER_SAY)
        return true
    end

    if target.type == TYPE_MONSTER then
        if target:getMaster() then
            return false
        end
    end

    if math.random(100) > mount.chance then
        local action = mount.fail[math.random(#mount.fail)]
        if action.run then
            target:remove()
        elseif action.broke then
            item:remove(1)
        elseif action.destroyObject then
            addEvent(Game.createItem, 60 * 60 * 1000, target.itemid, 1, toPosition)
            target:remove()
        elseif action.removeTransformation then
            target:removeCondition(CONDITION_OUTFIT)
        end

        doCreatureSayWithRadius(player, action.text, TALKTYPE_MONSTER_SAY, 2, 2)
        if action.sound then
            player:say(action.sound, TALKTYPE_MONSTER_SAY, false, 0, toPosition)
        end
        return true
    end

    player:addMount(mount.id)
    doCreatureSayWithRadius(player, mount.success.text, TALKTYPE_MONSTER_SAY, 2, 2)
    player:say(mount.success.sound, TALKTYPE_MONSTER_SAY, false, 0, toPosition)

    target:remove()
    item:remove(1)
    return true
end
 
Solution
I tested it as is and it worked fine for me. Are you sure you registered the item in actions.xml?

Also this line has a typo:
LUA:
or (mount.name and mount.name ~= targetName) then

should be mount.mountName
I tested it as is and it worked fine for me. Are you sure you registered the item in actions.xml?

Also this line has a typo:
LUA:
or (mount.name and mount.name ~= targetName) then

should be mount.mountName
 
Solution
I tested it as is and it worked fine for me. Are you sure you registered the item in actions.xml?

Also this line has a typo:
LUA:
or (mount.name and mount.name ~= targetName) then

should be mount.mountName
You tested using the item on a transformed monster? I mean, use in one monster with name Bear with looktype 387
 
Okay, your problem is that you are lowing the target name but in your config it is not lowered also what imkingran said aswell.

LUA:
local config = {
    [13537]   = {
        mountName = 'Donkey',


local targetName = target:getName():lower()
            or (mount.name and mount.name ~= targetName) then

This is reading:
or Donkey and Donkey ~= donkey then

So you need to change it to
LUA:
mountName="donkey"
or (mount.mountName and mount.mountName ~= targetName) then
 
Last edited:
Back
Top