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

Script lua tfs 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
How can i do a script like this

Uaing function onUse,

I have a item sequence id 2000 to 2050
When i use this item 2000 will transform to id 2001, when i use this 2001 item transform to 2002, after when i use the last item of sequence 2050, back to first item again 2000
 
I am not sure if I missed any ids but I think this should work.
LUA:
local decayItems = {
    [2000] = 2001, [2001] = 2002, [2002] = 2003, [2003] = 2004, [2004] = 2005, [2006] = 2007, [2007] = 2008, [2008] = 2009, [2009] = 2010,
    [2010] = 2011, [2011] = 2012, [2012] = 2013, [2013] = 2014, [2014] = 2015, [2015] = 2016, [2016] = 2017, [2017] = 2018,
    [2018] = 2019, [2019] = 2020, [2020] = 2021, [2021] = 2022, [2022] = 2023, [2023] = 2024, [2024] = 2025, [2025] = 2026,
    [2026] = 2027, [2027] = 2028, [2028] = 2029, [2029] = 2030, [2030] = 2031, [2031] = 2032, [2032] = 2033, [2033] = 2034,
    [2034] = 2035, [2035] = 2036, [2036] = 2037, [2037] = 2038, [2038] = 2039, [2039] = 2040, [2040] = 2041, [2041] = 2042,
    [2042] = 2043, [2043] = 2044, [2044] = 2045, [2045] = 2046, [2046] = 2047, [2047] = 2048, [2048] = 2049, [2049] = 2050, [2050] = 2000
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local decayItemId = decayItems[item:getId()]
    if not decayItemId then
        return false
    end

    item:transform(decayItemId)
    item:decay()
    return true
end
 
There's no need for a table:
LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local newId = item:getId() + 1
    if newId > 2050 then
        newId = 2000
    end
    item:transform(newId)
    return true
end

XML:
<action fromid="2000" toid="2050" script="xxx.lua" />
 
Back
Top