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

Coding Help

CesarZ

Well-Known Member
Joined
Sep 20, 2012
Messages
268
Solutions
4
Reaction score
63
Hello guys i'm trying to add the "interval" parameter so they can work with different timing.
this script is the Talk-sings script.


Lua:
--Normal script.

local t = {
    {"", {x = 781, y = 1002, z = 6}, 73},
    {"", {x = 777, y = 995, z = 7}, 73},
    {"", {x = 777, y = 1001, z = 8}, 73},
    {"", {x = 762, y = 1002, z = 7}, 73}
}

function onThink(interval)
    local people = getOnlinePlayers()
    if #people == 0 then
        return true
    end

    for i = 1, #t do
        local v = t[i]
        doCreatureSay(people[1], v[1], TALKTYPE_ORANGE_1, false, 0, v[2])
        doSendMagicEffect(v[2], v[3])
    end
    return true
end

My script that im working on

Lua:
local t = {
    --{"", {x = 781, y = 1002, z = 6}, 73},
   -- {"", {x = 777, y = 995, z = 7}, 73},
    --{"", {x = 777, y = 1001, z = 8}, 73},
    {"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
    {"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
    --{"", {x = 762, y = 1002, z = 7}, 73}
}

function onThink(interval)
    local people = getOnlinePlayers()
    if #people == 0 then
        return true
    end

    for i = 1, #t do
        local v = t[i]
        doCreatureSay(people[1], v[1], TALKTYPE_ORANGE_1, false, 0, v[2], v[4]) -- v[4] added so it work with interval.
        doSendMagicEffect(v[2], v[3], v[4]) -- v[4] added so it can work with interval.
        interval(v[4]) -- interval option added
    end
    return true
end


the result of this one is = one is working but the other talk-sing is giving me a

attempt to call local 'interval' (a number value) error

let me know what i did wrong im pretty new with lua arrays im trying to learn this.
 
Solution
this script working fine.

quick question.

Is the function
Code:
sendAfterDelay(creature, text, position, effect)
was created by you, or it comes with the other functions in the lua source file?
I saw addevent but not this one and i was just wondering how did you get this function.
we are allowed to improvise in these things when it comes to functions?

I created that function, it doesn't exist by default. If you need to create your own functions to organize your code, you can do it.

Lua:
function yourFunctionName(parameter1, parameter2 .. etc)
    -- your code here
end

is there a list other than searching on luascript.cpp for tfs1.3?
Yes, there is: otland/forgottenserver...
Hello guys i'm trying to add the "interval" parameter so they can work with different timing.
this script is the Talk-sings script.

...

the result of this one is = one is working but the other talk-sing is giving me a

attempt to call local 'interval' (a number value) error

let me know what i did wrong im pretty new with lua arrays im trying to learn this.

Are you trying to send text+effect after some time has passed?

The error you're receiving attempt to call local 'interval' (a number value) is telling you that the "function" you're trying to call interval(v[4]) is not a function but a number.

In this script that you have, inside onThink function, interval is a variable which holds a number which is retrieved from globalevents.xml where you have something like interval="1000".
Lua:
function onThink(interval)
Since interval is a number, you can not use it as a function; interval().

What you need to use here is addEvent() function which will allow you to specify what code to execute and when

usage: addEvent(myFunction, delay, parameters)

Lua:
local t = {
    --{"", {x = 781, y = 1002, z = 6}, 73},
   -- {"", {x = 777, y = 995, z = 7}, 73},
    --{"", {x = 777, y = 1001, z = 8}, 73},
    {"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
    {"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
    --{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v[4] doesn't exist, 1000 will be used.

function onThink(interval)
    local people = getOnlinePlayers()
    if #people == 0 then
        return true
    end

    for i = 1, #t do
        local v = t[i]
        local interval = v[4] or defaultInterval

        -- call sendAfterDelay function after _interval_ time
        addEvent(sendAfterDelay, interval, people[1], v[1], v[2], v[3])
    end

    return true
end

function sendAfterDelay(creature, text, position, effect)
    doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
    doSendMagicEffect(position, effect)
end
 
Last edited:
Are you trying to send text+effect after some time has passed?

The error you're receiving attempt to call local 'interval' (a number value) is telling you that the "function" you're trying to call interval(v[4]) is not a function but a number.

In this script that you have, inside onThink function, interval is a variable which holds a number which is retrieved from globalevents.xml where you have something like interval="1000".
Lua:
function onThink(interval)
Since interval is a number, you can not use it as a function; interval().

What you need to use here is addEvent() function which will allow you to specify what code to execute and when

usage: addEvent(myFunction, delay, parameters)

Lua:
local t = {
    --{"", {x = 781, y = 1002, z = 6}, 73},
   -- {"", {x = 777, y = 995, z = 7}, 73},
    --{"", {x = 777, y = 1001, z = 8}, 73},
    {"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
    {"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
    --{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v[4] doesn't exist, 1000 will be used.

function onThink(interval)
    local people = getOnlinePlayers()
    if #people == 0 then
        return true
    end

    for i = 1, #t do
        local v = t[i]
        local interval = v[4] or defaultInterval

        -- call sendAfterDelay function after _interval_ time
        addEvent(sendAfterDelay, interval, people[1], v[1], v[2], v[3])
    end

    return true
end

function sendAfterDelay(creature, text, position, effect)
    doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
    doSendMagicEffect(position, effect)
end

this script working fine.

quick question.

Is the function
Code:
sendAfterDelay(creature, text, position, effect)
was created by you, or it comes with the other functions in the lua source file?

I saw addevent but not this one and i was just wondering how did you get this function.

we are allowed to improvise in these things when it comes to functions?

is there a list other than searching on luascript.cpp for tfs1.3?
 
Last edited:
this script working fine.

quick question.

Is the function
Code:
sendAfterDelay(creature, text, position, effect)
was created by you, or it comes with the other functions in the lua source file?
I saw addevent but not this one and i was just wondering how did you get this function.
we are allowed to improvise in these things when it comes to functions?

I created that function, it doesn't exist by default. If you need to create your own functions to organize your code, you can do it.

Lua:
function yourFunctionName(parameter1, parameter2 .. etc)
    -- your code here
end

is there a list other than searching on luascript.cpp for tfs1.3?
Yes, there is: otland/forgottenserver (https://github.com/otland/forgottenserver/wiki/Script-Interface)
( not sure if they are finished )
 
Solution
Are you trying to send text+effect after some time has passed?

The error you're receiving attempt to call local 'interval' (a number value) is telling you that the "function" you're trying to call interval(v[4]) is not a function but a number.

In this script that you have, inside onThink function, interval is a variable which holds a number which is retrieved from globalevents.xml where you have something like interval="1000".
Lua:
function onThink(interval)
Since interval is a number, you can not use it as a function; interval().

What you need to use here is addEvent() function which will allow you to specify what code to execute and when

usage: addEvent(myFunction, delay, parameters)

Lua:
local t = {
    --{"", {x = 781, y = 1002, z = 6}, 73},
   -- {"", {x = 777, y = 995, z = 7}, 73},
    --{"", {x = 777, y = 1001, z = 8}, 73},
    {"", {x = 742, y = 992, z = 9}, 73, 500}, -- interval setted 4th slot
    {"", {x = 746, y = 992, z = 9}, 73, 900} -- interval setted 4th slot
    --{"", {x = 762, y = 1002, z = 7}, 73}
}

local defaultInterval = 1000 -- if v[4] doesn't exist, 1000 will be used.

function onThink(interval)
    local people = getOnlinePlayers()
    if #people == 0 then
        return true
    end

    for i = 1, #t do
        local v = t[i]
        local interval = v[4] or defaultInterval

        -- call sendAfterDelay function after _interval_ time
        addEvent(sendAfterDelay, interval, people[1], v[1], v[2], v[3])
    end

    return true
end

function sendAfterDelay(creature, text, position, effect)
    doCreatureSay(creature, text, TALKTYPE_ORANGE_1, false, 0, position)
    doSendMagicEffect(position, effect)
end
cute code
 
Back
Top