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

Upgrading item? ((0.3.6))

xYzPrototype

Just a standard member
Joined
Feb 27, 2015
Messages
49
Reaction score
4
Location
EUW
Hello,
In my donation system there are tier 1 items and tier 2 items, and I need an item that when used with a tier 1 donator item, transforms it into the tier 2 donator item and destroys the upgrading object.
I have some ideas on how to make the script, but how do I make sure that the tier 1 sword upgrades to the tier 2 sword etc?

Thanks
 
You can use any item that has cross hairs on use, I used 2088 as an example, it is a key.

Code:
<action itemid="2088" event="script" value="test/tiers.lua"/>

You can add all your tier1 and tier2 item ids to the table. I gave a small example of how you can set the table up.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tiers = {
    {tier1 = 2376, tier2 = 2408}, -- sword -> warlord sword
    {tier1 = 2386, tier2 = 8924} -- axe -> hellforged axe
}
    for i = 1, #tiers do
    local tier1 = tiers[i].tier1
    local tier2 = tiers[i].tier2
        if itemEx.itemid == tier1 then
            doTransformItem(itemEx.uid, tier2)
            doCreatureSay(cid, "TRANSFORM", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
            doRemoveItem(item.uid)
        end
    end
return true
end
 
You can use any item that has cross hairs on use, I used 2088 as an example, it is a key.

Code:
<action itemid="2088" event="script" value="test/tiers.lua"/>

You can add all your tier1 and tier2 item ids to the table. I gave a small example of how you can set the table up.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tiers = {
    {tier1 = 2376, tier2 = 2408}, -- sword -> warlord sword
    {tier1 = 2386, tier2 = 8924} -- axe -> hellforged axe
}
    for i = 1, #tiers do
    local tier1 = tiers[i].tier1
    local tier2 = tiers[i].tier2
        if itemEx.itemid == tier1 then
            doTransformItem(itemEx.uid, tier2)
            doCreatureSay(cid, "TRANSFORM", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
            doRemoveItem(item.uid)
        end
    end
return true
end

You're a hero bro, thank you so much :)
 
You can use any item that has cross hairs on use, I used 2088 as an example, it is a key.

Code:
<action itemid="2088" event="script" value="test/tiers.lua"/>

You can add all your tier1 and tier2 item ids to the table. I gave a small example of how you can set the table up.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tiers = {
    {tier1 = 2376, tier2 = 2408}, -- sword -> warlord sword
    {tier1 = 2386, tier2 = 8924} -- axe -> hellforged axe
}
    for i = 1, #tiers do
    local tier1 = tiers[i].tier1
    local tier2 = tiers[i].tier2
        if itemEx.itemid == tier1 then
            doTransformItem(itemEx.uid, tier2)
            doCreatureSay(cid, "TRANSFORM", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
            doRemoveItem(item.uid)
        end
    end
return true
end
why do i debug everytime i try using this. using 0.3.6 help please
 
why do i debug everytime i try using this. using 0.3.6 help please

Probably this line:
doCreatureSay(cid, "TRANSFORM", TALKTYPE_MONSTER_SAY)

Change TALKTYPE_MONSTER_SAY to the equal version for TFS 0.3.6
 
how would I add up to tier 8?
You can use the same script for all tiers.
Let's rename the functions to make it more clear. :p

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     local tiers = {
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}  -- Tier 2 -> Tier 3
     }
     for i = 1, #tiers do
     local starting_item = tiers[i].starting_item
     local ending_item = tiers[i].ending_item
         if itemEx.itemid == starting_item then
             doTransformItem(itemEx.uid, ending_item)
             doCreatureSay(cid, "TRANSFORM", TALKTYPE_ORANGE_1)
             doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
             doRemoveItem(item.uid)
         end
     end
     return true
end
 
You can use the same script for all tiers.
Let's rename the functions to make it more clear. :p

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
     local tiers = {
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
         {starting_item = 11111, ending_item = 22222}, -- Tier 1 -> Tier 2
        
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}, -- Tier 2 -> Tier 3
         {starting_item = 22222, ending_item = 33333}  -- Tier 2 -> Tier 3
     }
     for i = 1, #tiers do
     local starting_item = tiers[i].starting_item
     local ending_item = tiers[i].ending_item
         if itemEx.itemid == starting_item then
             doTransformItem(itemEx.uid, ending_item)
             doCreatureSay(cid, "TRANSFORM", TALKTYPE_ORANGE_1)
             doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
             doRemoveItem(item.uid)
         end
     end
     return true
end
just a note, the table should be outside onUse (to avoid creating it every onUse), and i suggest that the format should be like
Code:
local tiers = {
[11111] = 22222
}
then
Code:
     for i = 1, #tiers do
     local starting_item = tiers[i].starting_item
     local ending_item = tiers[i].ending_item
         if itemEx.itemid == starting_item then
can be replaced by
Code:
     local tmp = tiers[itemEx.itemid]
         if tmp then
             doTransformItem(itemEx.uid, tmp)
 
just a note, the table should be outside onUse (to avoid creating it every onUse), and i suggest that the format should be like
Code:
local tiers = {
[11111] = 22222
}
then
Code:
     for i = 1, #tiers do
     local starting_item = tiers[i].starting_item
     local ending_item = tiers[i].ending_item
         if itemEx.itemid == starting_item then
can be replaced by
Code:
     local tmp = tiers[itemEx.itemid]
         if tmp then
             doTransformItem(itemEx.uid, tmp)
You do this a lot. You explain how to create a script properly of scripts that I haven't even created in the first place.
If your going to continue doing this, can you at least not tag me in your reply?

Instead say, here's how I'd script it for myself.
Code:
local tiers = {
     [1] = {starting_item = 11111, ending_item = 22222},
     [2] = {starting_item = 22222, ending_item = 33333},
     [3] = {starting_item = 33333, ending_item = 44444},
     [4] = {starting_item = 44444, ending_item = 55555},
     [5] = {starting_item = 55555, ending_item = 66666},
     [6] = {starting_item = 66666, ending_item = 77777},
     [7] = {starting_item = 77777, ending_item = 88888}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
     for i = 1, #tiers do
         if itemEx.itemid == tiers[i].starting_item then
             doTransformItem(itemEx.uid, tiers[i].ending_item)
             doCreatureSay(cid, "TRANSFORM", TALKTYPE_ORANGE_1)
             doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
             doRemoveItem(item.uid)
         end
     end
     return true
end
Here is another way it could be scripted, however it's less user friendly for people who don't know how to use tables.
Code:
local tiers = {
     [11111] = {transform_into = 22222}, -- 11111 = itemID of item getting transformed
     [22222] = {transform_into = 33333},
     [33333] = {transform_into = 44444},
     [44444] = {transform_into = 55555},
     [55555] = {transform_into = 66666},
     [66666] = {transform_into = 77777},
     [77777] = {transform_into = 88888}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
     if tiers[itemEx.itemid] then
         doTransformItem(itemEx.uid, transform_into)
         doCreatureSay(cid, "TRANSFORM", TALKTYPE_ORANGE_1)
         doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
         doRemoveItem(item.uid)
     end
     return true
end
Letting people decide which one is easier for them to understand, use and possibly learn from is better then vaguely showing people how you think it should have been done.
In the end it doesn't truly matter, but getting tagged to criticizing commentary of a script you didn't make, yet modified slightly to show how something could be accomplished using the already existing script, multiple times over multiple threads, is really annoying.

Cheers, o/
#firsttimeusinghashtags
#gettingannoyedforlittlereason
 
i just mentioned that the example was a badly made piece of code (never said you did something bad), and i dont think people should be learning from code that uses tables completely wrong, because then they'll do it that way when they're making something themselves, then it ends up with people wondering why their servers have issues with lag etc, all because they didn't learn it properly from the beginning

and yes, i do it a lot because i think people should learn how to properly script from the beginning, instead of doing ways that is more code, and less efficient for no reason

and i didnt mean anything against you, it was just general information for anyone trying to actually use the script
 
ok im using a normal table im wondering how to add % chance upgrade and break items?



how to add % chance upgrade to this? i would like it to upgrade or if it fails it either breaks or downgrades maybe a 15% chance fail and 5% chance break on this one 80% chance it would upgrade




Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tiers = {
{tier1 = 2376, tier2 = 2408}, -- sword -> warlord sword
{tier1 = 2386, tier2 = 8924} -- axe -> hellforged axe
}
for i = 1, #tiers do
local tier1 = tiers.tier1
local tier2 = tiers.tier2
if itemEx.itemid == tier1 then
doTransformItem(itemEx.uid, tier2)
doCreatureSay(cid, "TRANSFORM", TALKTYPE_MONSTER_SAY)
doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
doRemoveItem(item.uid)
end
end
return true
end
 
ok im using a normal table im wondering how to add % chance upgrade and break items?
Can you post your current script?

-- Edit

I'l use my preferred method, because it'll be easiest for me.

-- Edit

Untested.

Let's pretend we are attempting to upgrade the first item in the list.

This script will roll a random number out of 100.

Random number chosen is: 5
Since this number is less then or equal to 5 (break_chance), item breaks. (However since downgrade item is set to 0, it simply fails.)

Again we try first item.
Random number chosen is: 17
Since this number is less then or equal to 20 (fail_chance), item downgrades. (However since downgrade item is set to 0, it simply fails.)

Third time is the charm!
Random number chosen is: 96
Since this number is not less then or equal to break_chance or fail_chance, the item is successfully transformed!

Hope you enjoy.

-- Edit

Was removing material item twice.
Code:
local tiers = {
    [1] = {starting_item = 11111, ending_item = 22222, downgrade_item = 0, fail_chance = 20, break_chance = 5},
    [2] = {starting_item = 22222, ending_item = 33333, downgrade_item = 11111, fail_chance = 25, break_chance = 5},
    [3] = {starting_item = 33333, ending_item = 44444, downgrade_item = 22222, fail_chance = 30, break_chance = 6},
    [4] = {starting_item = 44444, ending_item = 55555, downgrade_item = 33333, fail_chance = 40, break_chance = 7},
    [5] = {starting_item = 55555, ending_item = 66666, downgrade_item = 44444, fail_chance = 55, break_chance = 8},
    [6] = {starting_item = 66666, ending_item = 77777, downgrade_item = 55555, fail_chance = 75, break_chance = 9},
    [7] = {starting_item = 77777, ending_item = 88888, downgrade_item = 66666, fail_chance = 95, break_chance = 10}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    for i = 1, #tiers do
        if itemEx.itemid == tiers[i].starting_item then
            doRemoveItem(item.uid, 1)
            local rand = math.random(100)
            print("Random number chosen is: " .. rand .. "")
            if rand <= tiers[i].break_chance then
                doRemoveItem(itemEx.uid)
                doCreatureSay(cid, "Failed! Broken!", TALKTYPE_ORANGE_1)
                return true
            elseif rand <= tiers[i].fail_chance then
                if tiers[i].downgrade_item ~= 0 then
                    doTransformItem(itemEx.uid, tiers[i].downgrade_item)
                    doCreatureSay(cid, "Failed! Downgraded!", TALKTYPE_ORANGE_1)
                    return true
                else
                    -- doRemoveItem(itemEx.uid)
                    doCreatureSay(cid, "Failed!", TALKTYPE_ORANGE_1)
                    return true
                end
            end
            doTransformItem(itemEx.uid, tiers[i].ending_item)
            doCreatureSay(cid, "TRANSFORM", TALKTYPE_ORANGE_1)
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
        end
    end
    return true
end
 
Last edited:
This is my script for tier 1-2 there should be no downgrade only fail upgrade


  • Code:
    function onUse(cid, item, fromPosition, itemEx, toPosition)
    local tiers = {
        {tier1 = 2665, tier2 = 5741}, -- post officers hat -> skull helmet
        {tier1 = 8875, tier2 = 2476}, -- tunic -> knight armor
        {tier1 = 5918, tier2 = 2477}, -- pirate knee breeches -> knight legs
        {tier1 = 2531, tier2 = 2528}, -- viking shield -> tower shield
        {tier1 = 2642, tier2 = 11234} -- sandals -> guardian boots
        }
        for i = 1, #tiers do
        local tier1 = tiers[i].tier1
        local tier2 = tiers[i].tier2
            if itemEx.itemid == tier1 then
                doTransformItem(itemEx.uid, tier2)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Transformation Complete")
                doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
                doRemoveItem(item.uid)
            end
        end
    return true
    end












UPDATE THANKS ALOT FOR THE GUIDANCE but i still need help its not determining which one it upgrades too there all upgrading to the same item


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local tiers = {
    {tier1 = 2665, tier2 = 2476, fail_chance = 8, break_chance = 3}, -- post officers hat -> skull helmet
    {tier1 = 8875, tier2 = 5741, fail_chance = 90, break_chance = 73}, -- tunic -> knight armor
    {tier1 = 5918, tier2 = 2477, fail_chance = 8, break_chance = 3}, -- pirate knee breeches -> knight legs
    {tier1 = 2531, tier2 = 2528, fail_chance = 8, break_chance = 3}, -- viking shield -> tower shield
    {tier1 = 2642, tier2 = 11234, fail_chance = 8, break_chance = 3} -- sandals -> guardian boots
    }
    for i = 1, #tiers do
    local tier1 = tiers[i].tier1
    local tier2 = tiers[i].tier2
        if itemEx.itemid == tier1 then
            local rand = math.random(100)
            print("Random number chosen is: " .. rand .. "")
            if rand <= tiers[i].break_chance then
                doRemoveItem(itemEx.uid, tier1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Failed! Broken!")
                return true
                end
            end
            doTransformItem(itemEx.uid, tier2)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Transformation Complete")
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
            doRemoveItem(item.uid)
        end
    end
 
Last edited:
Code:
local tiers = {
    [2665] = {upgradeTo = 2476, fail_chance = 8, break_chance = 3}, -- post officers hat -> skull helmet
    [8875] = {upgradeTo = 5741, fail_chance = 90, break_chance = 73}, -- tunic -> knight armor
    [5918] = {upgradeTo = 2477, fail_chance = 8, break_chance = 3}, -- pirate knee breeches -> knight legs
    [2531] = {upgradeTo = 2528, fail_chance = 8, break_chance = 3}, -- viking shield -> tower shield
    [2642] = {upgradeTo = 11234, fail_chance = 8, break_chance = 3}, -- sandals -> guardian boots
    }

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local tmp = tiers[itemEx.itemid]
    if tmp then
        local rand = math.random(100)
        print("Random number chosen is: " .. rand .. "")   
        if rand <= tmp.break_chance then
            doRemoveItem(itemEx.uid)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Failed! Broken!")
        elseif rand <= fail_chance then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Failed! Broken!")
        else
            doTransformItem(itemEx.uid, tmp.upgradeTo)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Transformation Complete")
            doSendMagicEffect(getThingPosition(itemEx.uid), CONST_ME_FIREWORK_RED)
        end
        doRemoveItem(item.uid)
    end
    return true
end
try something like this, though im not exactly what you mean is wrong...
if rand < breakchance it will remove item + itemEx, if < fail_chance it will just remove item, else it will update + remove item
 
I was rude the other day. I don't tend to be rude.
I had the choice to not post my comment, yet I did.
It was vindictive, personalized, and not necessary.

I would like to take this opportunity to apologize for my previous actions.
I will not remove or alter my post. While the statements presented do not represent my view at this current moment, altering or removing them would be the same as claiming they never existed.

It is not my intention to further damage our small relationship on these forums.
I just want this forum, and especially yourself to know, I am better then this.
I will better present myself in the future so an occurrence like this will not happen again.

Thanks for your time in reading my apology, and hopefully this doesn't mar your view of me in the future.

Cheers,

Xikini
 
I was rude the other day. I don't tend to be rude.
I had the choice to not post my comment, yet I did.
It was vindictive, personalized, and not necessary.

I would like to take this opportunity to apologize for my previous actions.
I will not remove or alter my post. While the statements presented do not represent my view at this current moment, altering or removing them would be the same as claiming they never existed.

It is not my intention to further damage our small relationship on these forums.
I just want this forum, and especially yourself to know, I am better then this.
I will better present myself in the future so an occurrence like this will not happen again.

Thanks for your time in reading my apology, and hopefully this doesn't mar your view of me in the future.

Cheers,

Xikini
dont worry about it :)
 
Back
Top