• 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!

onUse transform item to monster animation

Lucas Durais

New Member
Joined
Jan 13, 2017
Messages
40
Reaction score
1
Hiho guys

I would like to know how can I make one item, like a tree, transform to a monster animation, like a huanted treeling, when I use an item.

Thanks!
 
this is if you clicn item it makes you look like outfit
Code:
local outfits = {5, 6, 7, 8, 9, 15, 18, 23, 24, 25, 29, 33, 37, 40, 48, 50, 53, 54, 57, 58, 59, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 76, 78, 93, 96, 97, 98, 100, 126, 127, 193,
                 194, 195, 196, 203, 214, 215, 216, 229, 232, 235, 237, 246, 249, 253, 254, 255, 259, 260, 264, 281, 282, 287, 296, 297, 298, 300, 301}
local outfit =
    {
        lookType = 2,
        lookHead = 0,
        lookBody = 0,
        lookLegs = 0,
        lookFeet = 0,
        lookAddons = 0
    }
local outfit0 =
    {
        lookType = 2,
        lookHead = 0,
        lookBody = 0,
        lookLegs = 0,
        lookFeet = 0,
        lookAddons = 0
    }
function onUse(cid, item, frompos, item2, topos)
if getPlayerStorageValue(cid,1921) == -1 or getPlayerStorageValue(cid,1921) == #outfits then
setPlayerStorageValue(cid,1921,1)
doSetCreatureOutfit(cid, outfit0, -1)
else
for i=1,#outfits do
if getPlayerStorageValue(cid,1921) == i then
outfit.lookType = outfits[i]
doCreatureSay(cid, "Change!", TALKTYPE_ORANGE_1)
doSetCreatureOutfit(cid, outfit, -1)
setPlayerStorageValue(cid,1921,i+1)
break
end
end
end
end
local outfit- number its LOOktype id of looktype(how it looks , you can delete all leave 1 or add more whatever )
 
For example, I use an item in an especific tile and there is a tree right beside me.
When I use this item, the tree with id x transforms into a animation, like the monster "haunted treeling", for some time, and then returns to the usual tree.
 
Code:
local monsters = {
    [itemid] = "monstername",
    [itemid2] = "monstername2"
   ...
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local monster = monsters[item:getId()]
    if monster then
        item:remove()
        Game.createMonster(monster, toPosition)
    end
    return true
end
there's a monsters table for more flexibility between different item ids
should be self explanatory
 
Code:
local monsters = {
    [itemid] = "monstername",
    [itemid2] = "monstername2"
   ...
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local monster = monsters[item:getId()]
    if monster then
        item:remove()
        Game.createMonster(monster, toPosition)
    end
    return true
end
there's a monsters table for more flexibility between different item ids
should be self explanatory
This doesn't accomplish what he's asking to do.
Instead of misleading him you should tell him what the script actually does, and more importantly, it's massive drawbacks compared to his original idea.

If anything, he should make a non-targetable, invulnerable, and passive monster, with a hidden health bar and name, that has the look-type of an item, and when you use his item X on monster Y, it will do a simple outfit change for x seconds.
If you name the creature the same as the object it's representing, and put an invisible wall on the tile the creature is occupying (and maybe a protection tile as well), the player will likely never know that it's a creature at all, which is basically what Lucas is trying to achieve.
 
This doesn't accomplish what he's asking to do.
Instead of misleading him you should tell him what the script actually does, and more importantly, it's massive drawbacks compared to his original idea.

If anything, he should make a non-targetable, invulnerable, and passive monster, with a hidden health bar and name, that has the look-type of an item, and when you use his item X on monster Y, it will do a simple outfit change for x seconds.
If you name the creature the same as the object it's representing, and put an invisible wall on the tile the creature is occupying (and maybe a protection tile as well), the player will likely never know that it's a creature at all, which is basically what Lucas is trying to achieve.
what a loaded paragraph you have composed.
i misunderstood his request, for that i am deeply sorry.
using this: https://otland.net/threads/tfs-1-2-creature-setnomove-bool-creature-canmove.241979/
Code:
local monsters = {
    [itemid] = "monstername"
}

local function replaceCreature(cid, itemid)
    local creature = Creature(cid)
    if not creature then
        return
    end
    Game.createItem(itemid, 1, creature:getPosition())
    creature:remove()
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local name = monsters[item:getId()] -- get monster name by item id through monsters table
    if not name then
        return true
    end
    local monster = Game.createMonster(name, toPosition)
    monster:setHiddenHealth(true)
    monster:setNoMove(true)
    addEvent(replaceCreature, 10000, monster:getId(), item:getId()) -- replace creature with itemid again after 10 seconds
    return true
end
the easiest way to make it untargetable is to make the spawn position a protection zone
 
This doesn't accomplish what he's asking to do.
Instead of misleading him you should tell him what the script actually does, and more importantly, it's massive drawbacks compared to his original idea.

If anything, he should make a non-targetable, invulnerable, and passive monster, with a hidden health bar and name, that has the look-type of an item, and when you use his item X on monster Y, it will do a simple outfit change for x seconds.
If you name the creature the same as the object it's representing, and put an invisible wall on the tile the creature is occupying (and maybe a protection tile as well), the player will likely never know that it's a creature at all, which is basically what Lucas is trying to achieve.

You were right @Xikini , that's exactly what I want.

what a loaded paragraph you have composed.
i misunderstood his request, for that i am deeply sorry.
using this: https://otland.net/threads/tfs-1-2-creature-setnomove-bool-creature-canmove.241979/
Code:
local monsters = {
    [itemid] = "monstername"
}

local function replaceCreature(cid, itemid)
    local creature = Creature(cid)
    if not creature then
        return
    end
    Game.createItem(itemid, 1, creature:getPosition())
    creature:remove()
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local name = monsters[item:getId()] -- get monster name by item id through monsters table
    if not name then
        return true
    end
    local monster = Game.createMonster(name, toPosition)
    monster:setHiddenHealth(true)
    monster:setNoMove(true)
    addEvent(replaceCreature, 10000, monster:getId(), item:getId()) -- replace creature with itemid again after 10 seconds
    return true
end
the easiest way to make it untargetable is to make the spawn position a protection zone



It's not a problem that you miss understood @Xeraphus

I tried your script, but it didn't worked. I get the following error:

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/music.lua:onUse
data/actions/scripts/other/music.lua:81: attempt to index local 'monster' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/other/music.lua:81: in function <data/actions/scripts/other/music.lua:56>

To become more understandable my problem, I will put my entire script here:

Code:
local cursed = Condition(CONDITION_CURSED)
cursed:setParameter(CONDITION_PARAM_DELAYED, true) -- Condition will delay the first damage from when it's added
cursed:setParameter(CONDITION_PARAM_MINVALUE, -100) -- Minimum damage the condition can do at total
cursed:setParameter(CONDITION_PARAM_MAXVALUE, -200) -- Maximum damage
cursed:setParameter(CONDITION_PARAM_STARTVALUE, -20) -- The damage the condition will do on the first hit
cursed:setParameter(CONDITION_PARAM_TICKINTERVAL, 5000) -- Delay between damages
cursed:setParameter(CONDITION_PARAM_FORCEUPDATE, true) -- Re-update condition when adding it(ie. min/max value)



local function replaceCreature(cid, itemid)
    local creature = Creature(cid)
    if not creature then
        return
    end
    Game.createItem(itemid, 1, creature:getPosition())
    creature:remove()
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local monsters = {
    [9758] = "haunted treeling"
}
local player = Player(cid)
local creatureNames, playerPosition = { 'haunted treeling', 'carniphila' }, Position(33298, 31387, 7)
local name = monsters[item:getId()] -- get monster name by item id through monsters table
    if item.itemid == 2070 then
    if isInRange(player:getPosition(), Position(33298, 31387, 7), Position(33298, 31387, 7)) then
    if player:getStorageValue(46128) == 9 and player:getStorageValue(63930) < os.time() then
    local chance = math.random(5)
    if chance == 5 and player:getStorageValue(63930) < os.time() then
    player:setStorageValue(46128, 10)
    doCreatureSay(cid, "The spirit seems less hostile now. It seems you managed to appease him.", TALKTYPE_ORANGE_1)
    elseif chance < 5 and chance >= 3 and player:getStorageValue(63930) < os.time() then
   local monster = Game.createMonster(name, toPosition)
    monster:setHiddenHealth(true)
    monster:setNoMove(true)
    addEvent(replaceCreature, 10000, monster:getId(), item:getId()) -- replace creature with itemid again after 10 seconds
    player:setStorageValue(63930, os.time() + 10)
    player:addCondition(cursed)
    elseif chance < 3 and chance >= 1 and player:getStorageValue(63930) < os.time() then
    player:setStorageValue(63930, os.time() + 10)
    local monster = Game.createMonster(name, toPosition)
    monster:setHiddenHealth(true)
    monster:setNoMove(true)
    addEvent(replaceCreature, 10000, monster:getId(), item:getId()) -- replace creature with itemid again after 10 seconds
    creatures = {
                        "haunted treeling",
                        "carniphila"
                    }
                pos = {x = math.random(33300, 33303), y = math.random(31386, 31389), z = 7}
                addEvent(doSummonCreature, 1 * 1 * 1, creatures[math.random(1, 2)], pos)
                addEvent(doSummonCreature, 1 * 1 * 1, creatures[math.random(1, 2)], pos)
                addEvent(doSummonCreature, 1 * 1 * 1, creatures[math.random(1, 2)], pos)
    end
    end
    end
end


When I use a flute when I am in a specific tile and have a specific storage, I have a random chance of getting a new storage and finish the quest, or I have the chance of getting cursed and start the animation, or I have the chance to summon few creatures and also start the animation.
 
lua-users.org/wiki/LuaStyleGuide
use this instead
Code:
local monster = Game.createMonster(name, toPosition, false, true)
 
lua-users.org/wiki/LuaStyleGuide
use this instead
Code:
local monster = Game.createMonster(name, toPosition, false, true)


It keeps sending the same error:

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/music.lua:onUse
data/actions/scripts/other/music.lua:72: attempt to index local 'monster' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/other/music.lua:72: in function <data/actions/scripts/other/music.lua:56>

But now it's in the line of the: monster:setHiddenHealth(true)
 
Back
Top