• 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.1 - Items Decaying problem

FLE

Member
Joined
Oct 5, 2008
Messages
422
Reaction score
24
Location
Vancouver Canada
Hi, Im using ORTS and tfs 1.1,

I am trying too make some items decay through the items.xml

It's not working properly, does anybody know why?
 
How is the item created?

So I edited the skinning script.. trying too make a mining script from it....

here is what I have so far -
21583 - pick
5880 - reward
8742,8743,8741-rubble (after u mine a rock)

The after item is created with this target:transform(skin.after)

now in my items.xml
I have
8742,
8743,
8741,
8740
all set too decay into a "xxxx" rock.
(i did it this way because I have no idea how too make a script for the rubble too decay into math.random(1,20) rocks)
that would make it so much easier and better. because right now each rubble Id just turns into 1 rock. so they will all look similair after being mined.

Mining.lua
Code:
local config = {
   [21583] = {
        --rocks
        [1285] = {value = 25000, newItem = 5880, after =8742},
        [1295] = {value = 25000, newItem = 5880, after =8742},
        [1356] = {value = 25000, newItem = 5880, after =8742},
        [1357] = {value = 25000, newItem = 5880, after =8743},
        [1358] = {value = 25000, newItem = 5880, after =8743},
        [1359] = {value = 25000, newItem = 5880, after =8743},
        [3607] = {value = 25000, newItem = 5880, after =8743},
        [3608] = {value = 25000, newItem = 5880, after =8741},
        [3615] = {value = 25000, newItem = 5880, after =8741},
        [3616] = {value = 25000, newItem = 5880, after =8741},
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local skin = config[item.itemid][target.itemid]


    if not skin then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    local random, effect, transform = math.random(1, 100000), CONST_ME_MAGIC_GREEN, true
    if type(skin[1]) == 'table' then
        local added = false
        local _skin
        for i = 1, #skin do
            _skin = skin[i]
            if random <= _skin.value then
                if target.itemid == 11343 then
                    effect = CONST_ME_ICEAREA
                    local gobletItem = player:addItem(_skin.newItem, _skin.amount or 1)
                    if gobletItem then
                        gobletItem:setDescription(_skin.desc:gsub('|PLAYERNAME|', player:getName()))
                    end
                    added = true
                elseif isInArray({7441, 7442, 7444, 7445}, target.itemid) then
                    player:addItem(_skin.newItem, _skin.amount or 1)
                    effect = CONST_ME_HITAREA
                    added = true
                else
                    player:addItem(_skin.newItem, _skin.amount or 1)
                    added = true
                end
                break
            end
        end

    elseif random <= skin.value then
        if target.itemid == 11343 then
            effect = CONST_ME_ICEAREA
            local gobletItem = player:addItem(skin.newItem, skin.amount or 1)
            if gobletItem then
                gobletItem:setDescription(skin.desc:gsub('|PLAYERNAME|', player:getName()))
            end
        elseif isInArray({7441, 7442, 7444, 7445}, target.itemid) then
            if skin.newItem == 7446 then
                player:addAchievement('Ice Sculptor')
            end
            player:addItem(skin.newItem, skin.amount or 1)
            effect = CONST_ME_HITAREA
        else
            player:addItem(skin.newItem, skin.amount or 1)
        end
    else
        if isInArray({7441, 7442, 7444, 7445}, target.itemid) then
            player:say('The attempt of sculpting failed miserably.', TALKTYPE_MONSTER_SAY)
            effect = CONST_ME_HITAREA
        else
            effect = CONST_ME_POFF
        end
    end

    toPosition:sendMagicEffect(effect)
    if transform then
        target:transform(skin.after)
    end

    return true
end

P.s. -I dont know how to remove the bottom part of the script so i left it because when i try to remove it returns errors >_<'

Thanks for taking a look,
-Martin
 
I used addEvent all the time before I realized there is function item:decay()

about using random rock.
For loop trough the rocks table and keep count how many loops there was.
Then math random between 1 and totalcount.
next time you use loop, also count until count reaches random count.
 
I used addEvent all the time before I realized there is function item:decay()

about using random rock.
For loop trough the rocks table and keep count how many loops there was.
Then math random between 1 and totalcount.
next time you use loop, also count until count reaches random count.

Hey bro can u show me how to make this loop from the rock table?
i really have no idea :|

thanks,
-Martin
 
local totalID = 0
for k,v in pairs(table) do
totalID = totalID+1
end
i suggest to put that above, out of the function. You only need to use it on startUp

local ID = 0
local randomID = math.random(1,totalID)
for k,v in pairs(table) do
ID = ID+1
if ID = randomID then
Your thing
end
end
 
local totalID = 0
for k,v in pairs(table) do
totalID = totalID+1
end
i suggest to put that above, out of the function. You only need to use it on startUp

local ID = 0
local randomID = math.random(1,totalID)
for k,v in pairs(table) do
ID = ID+1
if ID = randomID then
Your thing
end
end

I still dont know exactly what you mean bro, Im sorry :s
 
local totalID = 0
for k,v in pairs(table) do
totalID = totalID+1
end
i suggest to put that above, out of the function. You only need to use it on startUp

local ID = 0
local randomID = math.random(1,totalID)
for k,v in pairs(table) do
ID = ID+1
if ID = randomID then
Your thing
end
end
This is useless to use
Code:
local totalId = 0
for k,v in pairs(table) do
   totalId = totalId + 1
end
If you want the size of table just use # to return the size

This is also excessive, all your doing here is storing a random number and then incrementing Id, while not using k or v, Id seems to hold no significance other than a counter, when k would have worked just as well which makes this for loop useless
Code:
local Id = 0
local randomId = math.random(1, totalId)
for k, v in pairs(table) do
   Id = Id + 1
   if Id = randomId then
     Your thing
   end
end

When you can just write, this would just return a random number between 1 and the size of the table
Code:
local randomNumber = math.random(1, #table)
-- your code below

Or if you want a random property of the table
Code:
local propertyOfTable = table[math.random(1, #table)]
-- your code below
 
Last edited:
if you did not notice his table was not incrementing (or whatever is this word) from 1, 2,3, etc. if key holds nil value in middle you cant use #table
 
if you did not notice his table was not incrementing (or whatever is this word) from 1, 2,3, etc. if key holds nil value in middle you cant use #table
My response was to your example not to his script, if your example was meant to be apart of his script then you should include it with his code.

The reason I am telling you to include your example with his code is because when you explain things to others you seem to confuse them more than they were before you intervened.

Not only should you include your code with their code but you should also explain how the code works and why those changes were made :)
 
Last edited:
his table:
[21583] = {
--rocks
[1285] = {value = 25000, newItem = 5880, after =8742},
[1295] = {value = 25000, newItem = 5880, after =8742},
[1356] = {value = 25000, newItem = 5880, after =8742},
[1357] = {value = 25000, newItem = 5880, after =8743},
[1358] = {value = 25000, newItem = 5880, after =8743},
[1359] = {value = 25000, newItem = 5880, after =8743},
[3607] = {value = 25000, newItem = 5880, after =8743},
[3608] = {value = 25000, newItem = 5880, after =8741},
[3615] = {value = 25000, newItem = 5880, after =8741},
[3616] = {value = 25000, newItem = 5880, after =8741},
}
and my script. what? now im confused..
 
Back
Top