• 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 Script problem tfs 0.4

Skaner

New Member
Joined
Feb 9, 2010
Messages
54
Reaction score
0
Hello , how edit script advance level tfs 0.4 messege like this img:


Now i have this:



My script:
local config = {
[0] = { "Fist skill UP", 31},
[1] = { "Club skill UP", 31},
[2] = { "Sword skill UP", 31},
[3] = { "Axe skill UP", 31},
[4] = { "Distance skill UP", 31},
[5] = { "Shield skill UP", 31},
[6] = { "Fishing skill UP", 31},
[7] = { "Magic level UP", 31},
[8] = { "Level UP", 30}
}


function onAdvance(cid, skill, oldlevel, newlevel)

local pos = getPlayerPosition(cid)
local effectPositions = {
{x = pos.x, y = pos.y - 3, z = pos.z},
{x = pos.x, y = pos.y + 3, z = pos.z},
{x = pos.x - 3, y = pos.y, z = pos.z},
{x = pos.x + 3, y = pos.y, z = pos.z},
{x = pos.x - 2, y = pos.y - 2, z = pos.z},
{x = pos.x + 2, y = pos.y - 2, z = pos.z},
{x = pos.x + 2, y = pos.y + 2, z = pos.z},
{x = pos.x - 2, y = pos.y + 2, z = pos.z}
}


for type, variable in pairs(config) do
if skill == type then
doCreatureSay(cid, ""..variable[1].." ["..newlevel.."]", TALKTYPE_ORANGE_1)
for _, ePos in ipairs(effectPositions) do
doSendDistanceShoot(pos, ePos, CONST_ANI_SMALLHOLY)
doSendMagicEffect(ePos, CONST_ME_HOLYAREA)
end


end
end
return TRUE
end
 
I know you don't know the answer to this but I'll ask it anyway, why bother using a for loop to cycle through the config?
When you can just use the skill to reference the index of config..
See this
Code:
if skill == type then
type is an index of config, and your comparing it to skill which is a number... kinda defeats the purpose of using a for loop where you could have just said
Code:
config[skill]
Which would have done the same thing while using less resources.. these little things might not seem to matter but when programs or scripts become larger then they make a huge difference.
So its best to get accustom to writing your code so that it is efficient and makes sense.

Also what is the purpose of the 31 and 30 in the table of each index?
Since 31 & 30 have no use that we can see, they should be removed and the tables within config should be removed as well, so that you can directly reference each string within the corresponding skills to config's index.
 
Last edited:
If you use an old client version like 8.6 you can use animated text (Instead of doCreatureSay).
The function works like this.
Code:
doSendAnimatedText(pos, text, color)
The position should be the position of the player, so you can change that to getThingPosition(cid).
For a yellow color you can use COLOR_YELLOW, you can find other colors in data/lib/000-constant.lua or you can also use other numbers for different colors.
 
Using both @Limos and my advice
Code:
--[[
-- this is here just for reference
COLOR_BLACK = 0
COLOR_BLUE = 5
COLOR_GREEN = 18
COLOR_TEAL = 35
COLOR_LIGHTGREEN = 66
COLOR_DARKBROWN = 78
COLOR_LIGHTBLUE = 89
COLOR_DARKPURPLE = 112
COLOR_BROWN = 120
COLOR_GREY = 129
COLOR_DARKRED = 144
COLOR_DARKPINK = 152
COLOR_PURPLE = 154
COLOR_DARKORANGE = 156
COLOR_RED = 180
COLOR_PINK = 190
COLOR_ORANGE = 192
COLOR_DARKYELLOW = 205
COLOR_YELLOW = 210
COLOR_WHITE = 215
COLOR_NONE = 255

]]

function useRandomColor()
    local colors = {0, 5, 18, 35, 66, 78, 89, 112, 120, 129, 144, 152, 154, 156, 180, 190, 192, 205, 210, 215}
    return colors[math.random(1, #colors)]
end

local config = {
    [0] = "Fist skill UP",
    [1] = "Club skill UP",
    [2] = "Sword skill UP",
    [3] = "Axe skill UP",
    [4] = "Distance skill UP",
    [5] = "Shield skill UP",
    [6] = "Fishing skill UP",
    [7] = "Magic level UP",
    [8] = "Level UP"
}


function onAdvance(cid, skill, oldlevel, newlevel)
    local pos = getThingPosition(cid)
    local effectPositions = {
        {x = pos.x, y = pos.y - 3, z = pos.z},
        {x = pos.x, y = pos.y + 3, z = pos.z},
        {x = pos.x - 3, y = pos.y, z = pos.z},
        {x = pos.x + 3, y = pos.y, z = pos.z},
        {x = pos.x - 2, y = pos.y - 2, z = pos.z},
        {x = pos.x + 2, y = pos.y - 2, z = pos.z},
        {x = pos.x + 2, y = pos.y + 2, z = pos.z},
        {x = pos.x - 2, y = pos.y + 2, z = pos.z}
    }
    doSendAnimatedText(pos, config[skill], useRandomColor())
    for _, ePos in ipairs(effectPositions) do
        doSendDistanceShoot(pos, ePos, CONST_ANI_SMALLHOLY)
        doSendMagicEffect(ePos, CONST_ME_HOLYAREA)
    end
    return true
end
 
Last edited:
Back
Top