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

Change Script 0.4 to 1.2

115820

Member
Joined
Feb 27, 2011
Messages
193
Solutions
1
Reaction score
5
Location
London, England
Hi everyone. I need help to change this script 0.4 to 1.2.]
Code:
function onUse (cid, item, fromPosition, itemEx, toPosition)

   -- SFNormal

   if(itemEx.itemid == 2346) and math.random(1,100) >= 15 then
    doSendAnimatedText(toPosition,"ENERGIZED",TEXTCOLOR_LIGHTBLUE)
                  doSendMagicEffect(getPlayerPosition(cid), 52)
   doPlayerRemoveItem(cid, 7760, 1)
    doTransformItem(itemEx.uid, 2349)
   elseif (itemEx.itemid ~= 2346) then
    doPlayerSendCancel(cid, "item inválido")
   elseif math.random(1,100) < 15 then
    doSendAnimatedText(toPosition,"Fail!",TEXTCOLOR_DARKPINK)
   doPlayerRemoveItem(cid, 7760, 1)

return true
   end

UP!
 
Last edited by a moderator:
Lua:
function onUse (cid, item, fromPosition, itemEx, toPosition)

   -- SFNormal
local item = itemEx:getId()
   if item == 2346 and math.random(1,100) >= 15 then
  --  doSendAnimatedText(toPosition,"ENERGIZED",TEXTCOLOR_LIGHTBLUE)
         player:getPosition:sendMagicEffect(100)
         local itemremove = 7760
         itemremove:remove(1)
         item:transform(2349)
        elseif item~= 2346 then
        player:sendTextMessage(MESSAGE_INFO_CANCEL, "item invalido")
        elseif math.random(1,100) < 15 then
 --   doSendAnimatedText(toPosition,"Fail!",TEXTCOLOR_DARKPINK)
   itemremove(1)

return true
   end

Here a base... study about lua, its simple!
 
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- SFNormal
  
    if item.itemid == 2346 and math.random(1,100) >= 15 then
        --doSendAnimatedText(toPosition,"ENERGIZED",TEXTCOLOR_LIGHTBLUE) << there is no such function in tfs 1.2
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "ENERGIZED.")
        toPosition:sendMagicEffect(52)
        item:remove(1)
        --item:transform(2349) ???
    elseif item.itemid ~= 2346 then
        player:sendCancelMessage("item inválido.")
    elseif math.random(1,100) < 15 then
    -- doSendAnimatedText(toPosition,"Fail!",TEXTCOLOR_DARKPINK) << same
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Fail!.")
        item:remove(1)
    end
    return true
end
 
Better would be if you say what u want this script to do. So we could script it.
 
Code:
config = {
    id = 1, -- id of item you are using on target item
    targetid = 2 -- id of item you are using first item on
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if target.itemid == config.targetid then
            item:remove()
            toPosition:sendMagicEffect(CONST_ME_POFF)
            target:transform(newid)
        else
            player:sendCancelMessage("invalid item")
        end
    end
    return true
end

You have to add math.random at your own.
 
Code:
config = {
    id = 1, -- id of item you are using on target item
    targetid = 2 -- id of item you are using first item on
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if target.itemid == config.targetid then
            item:remove()
            toPosition:sendMagicEffect(CONST_ME_POFF)
            target:transform(newid)
        else
            player:sendCancelMessage("invalid item")
        end
    end
    return true
end

You have to add math.random at your own.

Work. But idk how to add math.random
 
Work. But idk how to add math.random
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if target.itemid == config.targetid then
            if math.random(2) == 1 then -- < 50% chance
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
            end
        else
            player:sendCancelMessage("invalid item")
        end
    end
    return true
end
 
Thanks.

@Thexamx Only more question. I want use that script in more items, but use the same STONE, how i put others variant in script?? I try, but dont work.
Code:
config = {
    id = 23723, -- id of item you are using on target item
    targetid = 2346, -- id of item you are using first item on
    target2id = 2349
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if target.itemid == config.targetid then
            if math.random(10) == 1 then -- < 50% chance
                item:remove(1)
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(2349)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
                item:remove(1)
            end
        else
            player:sendCancelMessage("invalid item")
        end
    return true
    end

    if item.itemid == config.id then
        if target.itemid == 2349 then
            if math.random(10) == 1 then -- < 50% chance
                item:remove(1)
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(4848)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
                item:remove(1)
            end
        else
             player:sendCancelMessage("invalid item")
        end
    return true
    end
end
 
Last edited by a moderator:
Code:
config = {
    id = 23723, -- id of item you are using on target item
    targetids = {1111, 2222, 3333} -- ids of items you are using first item on
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if isInArray(config.targetids, target.itemid) then
            if math.random(3) == 1 then -- < 50% chance
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
            end
        else
            player:sendCancelMessage("invalid item")
        end
    end
    return true
end
 
Not Like this. I want change FIRST ID <to> SECOND ID <to> THIRD ID <to> FOURTH ID.

I did it, but when I use a wrong item the phrase does not appear "invalid item".

Code:
config = {
    id = 23723, -- id of item you are using on target item
    targetid = 2346, -- id of item you are using first item on
    target2id = 2349
}
 function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if (target.itemid == 2346) then
            if math.random(10) == 1 then -- < 50% chance
                item:remove(1)
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(2349)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
                item:remove(1)
            end
        else
            player:sendCancelMessage("invalid item")
        end

        if (target.itemid == 2349) then
            if math.random(10) == 1 then -- < 50% chance
                item:remove(1)
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(4848)
            else
                player:sendCancelMessage("You had no luck cause it didnt work")
                item:remove(1)
            end
        else
            player:sendCancelMessage("invalid item")
        end
end
 
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if math.random(3) == 1 then
            if target.itemid == config.targetid then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid)
            elseif target.itemid == config.targetid2 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid2)
            elseif target.itemid == config.targetid3 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid3)
            end
        else
            player:sendCancelMessage("You had no luck cause it didnt work")
        end
    else
        player:sendCancelMessage("invalid item")
    end
    return true
end

Try this then.
 
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if math.random(3) == 1 then
            if target.itemid == config.targetid then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid)
            elseif target.itemid == config.targetid2 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid2)
            elseif target.itemid == config.targetid3 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid3)
            end
        else
            player:sendCancelMessage("You had no luck cause it didnt work")
        end
    else
        player:sendCancelMessage("invalid item")
    end
    return true
end

Try this then.

Can use in all items. ALL.
 
Can use in all items. ALL.
Yeah my bad.

Code:
config = {
    id = 23723, -- id of item you are using on target item
    targetids = {1111, 2222, 3333} -- all ids here you are using in this script.
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == config.id then
        if math.random(3) == 1 then
            if not isInArray(config.targetIds, target.itemid) then
                return player:sendCancelMessage("invalid item")
            end
            if target.itemid == config.targetid then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid)
            elseif target.itemid == config.targetid2 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid2)
            elseif target.itemid == config.targetid3 then
                item:remove()
                toPosition:sendMagicEffect(CONST_ME_POFF)
                target:transform(newid3)
            end
        else
            player:sendCancelMessage("You had no luck cause it didnt work")
        end
    end
    return true
end
 
Back
Top