• 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.5] Send SquareColour when equiped a set

Sarah Wesker

ƐƖєgαηт Sуηтαx ❤
Staff member
TFS Developer
Support Team
Joined
Mar 16, 2017
Messages
1,422
Solutions
155
Reaction score
1,986
Location
London
GitHub
MillhioreBT
Twitch
millhiorebt
This system is similar to the [TFS 1.5] Simple Aura System I published some time ago, but this time it's purely cosmetic. Essentially, by equipping certain pre-defined items in the configuration, you will automatically gain a colored square that appears at configurable intervals.
Fully optimized by not using GlobalEvent or addEvent, neither of which was necessary for this case.

fghfdj.gif
data/scripts/square_colour.lua
Lua:
--[[
    Square Colour System
    By: 𝓜𝓲𝓵𝓵𝓱𝓲𝓸𝓻𝓮 𝓑𝓣
    Version: 1.0

    TFS 1.5
]]--

local squareInterval = 5 -- seconds
local squareColour = TEXTCOLOR_SKYBLUE
local equipaments = {
    [CONST_SLOT_HEAD] = 2493,
    [CONST_SLOT_ARMOR] = 2494,
    [CONST_SLOT_LEGS] = 2495,
    [CONST_SLOT_FEET] = 2195
}

local ec = EventCallback

function ec.onInventoryUpdate(player, item, slot, equip)
    local equipamentId = equipaments[slot]
    if not equipamentId then
        return
    end

    if not equip then
        if item:getId() == equipamentId then
            player:unregisterEvent("SquareColour")
        end
        return
    end

    for s, id in pairs(equipaments) do
        if s ~= slot then
            local sItem = player:getSlotItem(s)
            if not sItem or sItem:getId() ~= id then
                player:unregisterEvent("SquareColour")
                return
            end
        end
    end

    player:registerEvent("SquareColour")
end

ec:register()

local intervals = {}

local squareEvent = CreatureEvent("SquareColour")

function squareEvent.onThink(player)
    local playerId = player:getId()
    local timeNow = os.time()
    if not intervals[playerId] then
        intervals[playerId] = timeNow
    end

    if timeNow - intervals[playerId] >= squareInterval then
        intervals[playerId] = timeNow + squareInterval
        for _, p in pairs(Game.getSpectators(player:getPosition(), false, true)) do
            p:sendCreatureSquare(player, squareColour)
        end
    end
    return true
end

squareEvent:register()

You are free to add any benefit or edit it to your liking, use your imagination
I first saw this system on a server called marlborowar.
1073483439946350672.webp
 
Lua:
Lua Script Error: [Scripts Interface]
Release\data\scripts\square_blue.lua
LuaScriptInterface::luaDebugPrint(). [Warning - EventCallback::onInventoryUpdate] is not a valid callback.
stack traceback:
        [C]: in function 'debugPrint'
        ...rl\vc17\x64\Release\data\scripts/lib\event_callbacks.lua:119: in function '__newindex'
        ...arl\vc17\x64\Release\data\scripts\square_blue.lua:17: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:90: in function <data/talkactions/scripts/reload.lua:68>

Lua Script Error: [Scripts Interface]
Release\data\scripts\square_blue.lua
LuaScriptInterface::luaDebugPrint(). [Warning - EventCallback::register] is need to set up a callback before register.
stack traceback:
        [C]: in function 'debugPrint'
        ...rl\vc17\x64\Release\data\scripts/lib\event_callbacks.lua:97: in function 'register'
        ...arl\vc17\x64\Release\data\scripts\square_blue.lua:43: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:90: in function <data/talkactions/scripts/reload.lua:68>

facing these errors ^^"
 
This system is similar to the [TFS 1.5] Simple Aura System I published some time ago, but this time it's purely cosmetic. Essentially, by equipping certain pre-defined items in the configuration, you will automatically gain a colored square that appears at configurable intervals.
Fully optimized by not using GlobalEvent or addEvent, neither of which was necessary for this case.

View attachment 75049
data/scripts/square_colour.lua
Lua:
--[[
    Square Colour System
    By: 𝓜𝓲𝓵𝓵𝓱𝓲𝓸𝓻𝓮 𝓑𝓣
    Version: 1.0

    TFS 1.5
]]--

local squareInterval = 5 -- seconds
local squareColour = TEXTCOLOR_SKYBLUE
local equipaments = {
    [CONST_SLOT_HEAD] = 2493,
    [CONST_SLOT_ARMOR] = 2494,
    [CONST_SLOT_LEGS] = 2495,
    [CONST_SLOT_FEET] = 2195
}

local ec = EventCallback

function ec.onInventoryUpdate(player, item, slot, equip)
    local equipamentId = equipaments[slot]
    if not equipamentId then
        return
    end

    if not equip then
        if item:getId() == equipamentId then
            player:unregisterEvent("SquareColour")
        end
        return
    end

    for s, id in pairs(equipaments) do
        if s ~= slot then
            local sItem = player:getSlotItem(s)
            if not sItem or sItem:getId() ~= id then
                player:unregisterEvent("SquareColour")
                return
            end
        end
    end

    player:registerEvent("SquareColour")
end

ec:register()

local intervals = {}

local squareEvent = CreatureEvent("SquareColour")

function squareEvent.onThink(player)
    local playerId = player:getId()
    local timeNow = os.time()
    if not intervals[playerId] then
        intervals[playerId] = timeNow
    end

    if timeNow - intervals[playerId] >= squareInterval then
        intervals[playerId] = timeNow + squareInterval
        for _, p in pairs(Game.getSpectators(player:getPosition(), false, true)) do
            p:sendCreatureSquare(player, squareColour)
        end
    end
    return true
end

squareEvent:register()

You are free to add any benefit or edit it to your liking, use your imagination
I first saw this system on a server called marlborowar.
1073483439946350672.webp
Nice contribution! :D
OFFTOPIC: I like how it shows the item you're dragging into your slots, default it just shows the mouse! Nice feature!
 
Lua:
Lua Script Error: [Scripts Interface]
Release\data\scripts\square_blue.lua
LuaScriptInterface::luaDebugPrint(). [Warning - EventCallback::onInventoryUpdate] is not a valid callback.
stack traceback:
        [C]: in function 'debugPrint'
        ...rl\vc17\x64\Release\data\scripts/lib\event_callbacks.lua:119: in function '__newindex'
        ...arl\vc17\x64\Release\data\scripts\square_blue.lua:17: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:90: in function <data/talkactions/scripts/reload.lua:68>

Lua Script Error: [Scripts Interface]
Release\data\scripts\square_blue.lua
LuaScriptInterface::luaDebugPrint(). [Warning - EventCallback::register] is need to set up a callback before register.
stack traceback:
        [C]: in function 'debugPrint'
        ...rl\vc17\x64\Release\data\scripts/lib\event_callbacks.lua:97: in function 'register'
        ...arl\vc17\x64\Release\data\scripts\square_blue.lua:43: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:90: in function <data/talkactions/scripts/reload.lua:68>

facing these errors ^^"
Your TFS is probably not up to date.

Nice contribution! :D
OFFTOPIC: I like how it shows the item you're dragging into your slots, default it just shows the mouse! Nice feature!
Cipsoft client.
 
Back
Top