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

Lua Display effect on client side TFS 1.4

Sprrw

Well-Known Member
Joined
Jun 22, 2021
Messages
100
Reaction score
55
Location
Sweden
Hello otland! I made this NPC that shows you the way using the CONST_ME_TUTORIALARROW effect.
Ex like this :
Lua:
    local passage = {
        x = 1068,
        y = 1010,
        z = 7
    }
    local stairLocations = {
        l = Position({
            x = 1058,
            y = 989,
            z = 6
        }),
        r = Position({
            x = 1059,
            y = 989,
            z = 6
        })
    }

    --Some not important code

    elseif talkState[talkUser] == 3 then
        stairLocations.l:sendMagicEffect(CONST_ME_TUTORIALARROW)
        stairLocations.r:sendMagicEffect(CONST_ME_TUTORIALARROW)

The thing with this is that, well yes it works perfectly when Im the only player talking with the npc, but I asume that this would be terrible with some like 10+ players. Is there something like pos:getMagicEffect(effect)? So that I could check if the effect is already on display putting some sort of delay on it.
 
I don't know if you can check if magic effects exist on tiles, but you can add some delay like this.
Lua:
local lastEffectTime = 0 -- add on the top of NPC file

local currentTime = os.time()
local delay = 2

if currentTime - lastEffectTime >= delay then
    -- your effects here
    lastEffectTime = currentTime
end
 
I don't know if you can check if magic effects exist on tiles, but you can add some delay like this.
Lua:
local lastEffectTime = 0 -- add on the top of NPC file

local currentTime = os.time()
local delay = 2

if currentTime - lastEffectTime >= delay then
    -- your effects here
    lastEffectTime = currentTime
end
Hey you! Thanks a lot for your answer! <3 Well I too thought about something like this but does lua work like that? I mean wont the delay be seperate for every player so this will "only" prevent a single player from spamming the effects but it woulnt prevent multiple from spamming at the same time? I could be wrong here.
 
It's for all players, Just place this local lastEffectTime = 0 on top of NPC so it doesn't reset each time a player says the message or whatever triggers it.
 
Hello otland! I made this NPC that shows you the way using the CONST_ME_TUTORIALARROW effect.
Ex like this :
Lua:
    local passage = {
        x = 1068,
        y = 1010,
        z = 7
    }
    local stairLocations = {
        l = Position({
            x = 1058,
            y = 989,
            z = 6
        }),
        r = Position({
            x = 1059,
            y = 989,
            z = 6
        })
    }

    --Some not important code

    elseif talkState[talkUser] == 3 then
        stairLocations.l:sendMagicEffect(CONST_ME_TUTORIALARROW)
        stairLocations.r:sendMagicEffect(CONST_ME_TUTORIALARROW)

The thing with this is that, well yes it works perfectly when Im the only player talking with the npc, but I asume that this would be terrible with some like 10+ players. Is there something like pos:getMagicEffect(effect)? So that I could check if the effect is already on display putting some sort of delay on it.
Do you need all the players to see it? Or just the person talking to the npc?

If the latter, just send it to the single person.
Lua:
-- everyone can see effect
position:sendMagicEffect(magicEffect)
position:sendDistanceEffect(targetPosition, distanceEffect)
Lua:
-- only a single person can see effect
position:sendMagicEffect(magicEffect, player)
position:sendDistanceEffect(targetPosition, distanceEffect, player)

So even if someone was 'spamming the effect' it'd only be for themselves.
 
Do you need all the players to see it? Or just the person talking to the npc?

If the latter, just send it to the single person.
Lua:
-- everyone can see effect
position:sendMagicEffect(magicEffect)
position:sendDistanceEffect(targetPosition, distanceEffect)
Lua:
-- only a single person can see effect
position:sendMagicEffect(magicEffect, player)
position:sendDistanceEffect(targetPosition, distanceEffect, player)

So even if someone was 'spamming the effect' it'd only be for themselves.
This is beutiful! 🥹 Thanks a lot man!
 
Back
Top