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

I am going crazy.. (Revscript) doSendAnimatedText

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,084
Solutions
15
Reaction score
379
Location
Sweden
YouTube
Joriku
Hi,
I had enough and need to head to bed.. this took me a few hours to try and try and try over and over again trying to convert the script.
So far, it seems alright BUT. I can't find an solution for the doSendAnimatedText on line 98 and 49
Asking Otland for help once more while i take a nap to continue once i wake up. If any answer, thank you!
I had lots of guesses, the one's working started with:
Lua:
getTopCreature()

Script:
Lua:
local tiles = {
    {x = 1010, y = 1002, z = 5, stackpos = STACKPOS_TOP_CREATURE},
    {x = 1011, y = 1002, z = 5, stackpos = STACKPOS_TOP_CREATURE},
}

-- [gid] = score
local guildScores = nil

-- gid, time
local counter = nil

local function addBridgeScore(gid, amount)
    local amount = amount or 1
    db.query(string.format("UPDATE `guilds` SET `bridge` = `bridge` + %i WHERE `id` = %i;", amount, gid))
    if guildScores[gid] then
        guildScores[gid] = guildScores[gid] + amount
    else
        guildScores[gid] = amount
    end
end

local function finishCurrentCounter()
    if not(counter) then return true end

    local amount = math.floor(counter[2] / 60)
    if amount > 0 then
        addBridgeScore(counter[1], amount)
    end
    counter = nil
end

local config = {
    convertCounter = function(t) return math.floor(t / 60) end,
    convertScore = function(t) return t end,
    
    color = COLOR_TEAL,
    
    showNoGuild = true
}

local function showCounter(cid, gid)
    local pos = getThingPos(cid)
    local t = config.convertCounter(counter[2])
    if guildScores[gid] then
        t = t + config.convertScore(guildScores[gid])
    end
    
    if t > 0 then
        doSendAnimatedText(pos, t, config.color)
    end
end

local globalevent = GlobalEvent("BridgeScores")

function globalevent.onThink(interval)
    if not guildScores then
        guildScores = { }
        
        local res = db.storeQuery("SELECT `id`, `bridge` FROM `guilds`;")
        if not res then
            repeat
                guildScores[res:getDataInt("id")] = res:getDataInt("bridge")                
            until not(res:next())
        
            res:free()
        end
    end
    
    local things = { }
    for i = 1, #tiles do
        local thing = getTopCreature(tiles[i])
        if thing.uid > 0 and isPlayer(thing.uid) then
            thing = thing.uid
        else
            thing = nil
        end
        table.insert(things, thing)
    end
    
    local lastThing = nil
    for i = #things, 1, -1 do
        local tmp = things[i]
        if tmp then
            lastThing = tmp
            break            
        end
    end
    
    if not lastThing then
        finishCurrentCounter()
        return true
    end
    
    local gid = getPlayerGuildId(lastThing)
    if not gid then
        finishCurrentCounter()
        if config.showNoGuild then
            doSendAnimatedText(getThingPos(lastThing), "No Guild", config.color)
        end        
        return true
    end
    
    if not(counter) then
        counter = {gid, 0}
        showCounter(lastThing, gid)
        return true
    end
    
    if gid ~= counter[1] then
        finishCurrentCounter()
        counter = {gid, 0}
    else
        counter[2] = counter[2] + 1
    end
    
    showCounter(lastThing, gid)
    return true
end

globalevent:interval(2000) -- will be executed every 1000ms
globalevent:register()
 
Solution
Sorry I misunderstood the script, try that:
Line 49:
Lua:
local spectators = Game.getSpectators(pos, false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say(t, TALKTYPE_MONSTER_SAY, false, spectators[i], pos)
    end
end
And line 98:
Lua:
local spectators = Game.getSpectators(getThingPos(lastThing), false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say("No Guild", TALKTYPE_MONSTER_SAY, false, spectators[i], getThingPos(lastThing))
    end
end
Post the doSendAnimatedText() function. (Perhaps its in data/lib/compat/compat.lua)?

Which distro are you using, which downport?
 
Post the doSendAnimatedText() function. (Perhaps its in data/lib/compat/compat.lua)?

Which distro are you using, which downport?
Oh, sorry. Wasn't clear on this..
Using later version than the older 8/9 series so it's not supported.. (OTBR) soon TFS 1.4 trying to change it out to get "TALKTYPE_MONSTER_SAY" to work instead.

Will soon get onto it again but it took me legit 5 hours to realize that i am stuck
 
Does this show any error or just don't work?
The script does load in, the part that's not working is sending out the message.
5903372d6aba93cc2080e58304641752.png
 
Well if you want to change it to "TALKTYPE_MONSTER_SAY" you can do that:
Line 49:
Lua:
doCreatureSay(cid, t, TALKTYPE_MONSTER_SAY)
And line 98 to:
Lua:
doCreatureSay(cid, "No Guild", TALKTYPE_MONSTER_SAY)
Post automatically merged:

The script does load in, the part that's not working is sending out the message.
5903372d6aba93cc2080e58304641752.png
Do you have getTopCreature in compat.lua? If not then try puting it there:

Lua:
function getTopCreature(position)
    local t = Tile(position)
    if t == nil then
        return pushThing(nil)
    end
    return pushThing(t:getTopCreature())
end
 
Well if you want to change it to "TALKTYPE_MONSTER_SAY" you can do that:
Line 49:
Lua:
doCreatureSay(cid, t, TALKTYPE_MONSTER_SAY)
And line 98 to:
Lua:
doCreatureSay(cid, "No Guild", TALKTYPE_MONSTER_SAY)
Here, it gives nothing. No error to nothing in-game on tile either..
Then, how come that doCreatureSay isn't giving out an error in this case?
What makes you want to put that out when it comes to interval onThink?

- Sorry for the "attack", more of an question. Trying badly but still myself no progress.
Console + tile
7cb7f9b4604682d455d03179c3752e91.jpg




Edit for your post above about the function:
It exists already, it solved my last issue to use getTopCreature instead of "getThingPos". + the error that was in the last picture about the getTopCreature is that i tried to use it to locate where the player stands on Row:98
d29da699be4e264cf12dcfff0523935b.png




Edit again:
Another thing: "No Guild" for the no guild player is not printed out, still no error. Will try myself meanwhile.
Took sometime for it to acually print out.. WHAT, could you please explain the lines and try to figure out a way to explain why i should have used "doCreatureSay"?
Would really help me out in the future issues with Interval/onThink

f111e9b1ce20cfd1fed383fafc379436.png
 
Last edited:
Sorry I misunderstood the script, try that:
Line 49:
Lua:
local spectators = Game.getSpectators(pos, false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say(t, TALKTYPE_MONSTER_SAY, false, spectators[i], pos)
    end
end
And line 98:
Lua:
local spectators = Game.getSpectators(getThingPos(lastThing), false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say("No Guild", TALKTYPE_MONSTER_SAY, false, spectators[i], getThingPos(lastThing))
    end
end
 
Solution
Sorry to intrude, but maybe I can bring something to help.
Some days ago was having a problem with a text effect and the one that worked was coded like this:
Lua:
local config = {
    interval = 1000,
    texts = {
      
        { pos = Position(1633, 1530, 6), text = "Test 1"},
        { pos = Position(1637, 1530, 6), text = "Test 2"},
        { pos = Position(1641, 1530, 6), text = "Test 3"}
    }
}

local textOnMap = GlobalEvent("TextOnMap")

function textOnMap.onThink(interval)
    local player = Game.getPlayers()[1]
    if not player then
        return true
    end
    
    if player:getStorageValue(30004) < os.time() then
        for k, info in pairs(config.texts) do
            player:say(info.text, TALKTYPE_MONSTER_SAY, false, nil, info.pos)
            -- info.pos:sendMagicEffect(info.effects[math.random(1, #info.effects)])
            player:setStorageValue(30004, os.time() + 6)
        end
    end
    return true
end

textOnMap:interval(config.interval)
textOnMap:register()
 
Sorry I misunderstood the script, try that:
Line 49:
Lua:
local spectators = Game.getSpectators(pos, false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say(t, TALKTYPE_MONSTER_SAY, false, spectators[i], pos)
    end
end
And line 98:
Lua:
local spectators = Game.getSpectators(getThingPos(lastThing), false, true, 7, 7, 5, 5)
if #spectators > 0 then
    for i = 1, #spectators do
        spectators[i]:say("No Guild", TALKTYPE_MONSTER_SAY, false, spectators[i], getThingPos(lastThing))
    end
end
Thank you,
to be honest. I'd never done it this way, just cus of my lack of knowledge.
Could i ask why:
Lua:
On this line:
local spectators = Game.getSpectators(pos, false, true, 7, 7, 5, 5)
-- Why and where is Game.getSpectators used from and in what situation is it usable? then false, true. 7, 7, 5, 5. What is that about?

Then this line:
spectators[i]:say(t, TALKTYPE_MONSTER_SAY, false, spectators[i], pos)

-- I mostly already know what and why it's used here but, to refresh it (What i tried to learn from an "book" over here on Otland.
When [i] <-- is called, this calls upon the variable i down at: - right?
local things = { }
    for i = 1, #tiles do
Post automatically merged:

Sorry to intrude, but maybe I can bring something to help.
Some days ago was having a problem with a text effect and the one that worked was coded like this:
Lua:
local config = {
    interval = 1000,
    texts = {
    
        { pos = Position(1633, 1530, 6), text = "Test 1"},
        { pos = Position(1637, 1530, 6), text = "Test 2"},
        { pos = Position(1641, 1530, 6), text = "Test 3"}
    }
}

local textOnMap = GlobalEvent("TextOnMap")

function textOnMap.onThink(interval)
    local player = Game.getPlayers()[1]
    if not player then
        return true
    end
  
    if player:getStorageValue(30004) < os.time() then
        for k, info in pairs(config.texts) do
            player:say(info.text, TALKTYPE_MONSTER_SAY, false, nil, info.pos)
            -- info.pos:sendMagicEffect(info.effects[math.random(1, #info.effects)])
            player:setStorageValue(30004, os.time() + 6)
        end
    end
    return true
end

textOnMap:interval(config.interval)
textOnMap:register()
Thank you for the thought, when it comes to effects. It's a different story then trying to calculate onThink to where the player stands. If i am not wrong, onThink does not include any function to locate where the player stands so you have to manually add it in in-order to grab the location of the player.
Love the thought and that you step-in tho!
Post automatically merged:

When it comes to adding the table for this script, I think i did something wrong here aswel..
14700dade784dfecab175476eb4b1bee.png


5e21de6b867aa807dc96cd541ff75dd8.png


Edit: Nevermind, unchecked the "NULL" and it seems to be updating the database, thanks for the help. Really!
 
Last edited:
Back
Top