• 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 Premium Points reward per Level (Znote)

Imereth Popis

dopera.sytes.net
Joined
Jan 30, 2017
Messages
111
Solutions
1
Reaction score
12
Location
Spain
Hello guys,

I am using a script modified to the new database from the latest @Znote version and it's not working...

I created at data/creaturescripts/creaturescripts.xml this line:

XML:
<event type="advance" name="pointsforlvl" event="script" value="advance.lua"/>

then I go into data/creaturescripts/scripts and I create a LUA file (advance.lua) with the following code:

Lua:
local t, storage = {
    {90, 100},
    {100, 100},
    {110, 100},
    {120, 100},
    {130, 100},
    {140, 100},
    {150, 100},
}, 256

function onAdvance(cid, skill, oldLevel, newLevel)
    if skill ~= SKILL__LEVEL then
        return true
    end
    for i = 1, #t do
        local v = t[i]
        if newLevel >= v[1] and getStorage(storage) < i then           
db.executeQuery('UPDATE znote_accounts SET points=points+'.. v[2] ..' WHERE account_id=' .. getPlayerAccountId(cid))
            doSetStorage(storage, i)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations! You have advanced to level ' .. v[1] .. ' and you have earned '.. v[2] ..' Premium Points!')
            doBroadcastMessage('Congratulations! ' .. getCreatureName(cid) .. ' advenced to ' .. v[1] .. 'lvl and got ' .. v[2] .. ' ptz to sms shop.')
            break
        end
    end
    return true
end

It is not working (tested). Can somebody explain me why or tell me if something is wrong?

Thanks you in advance!
 
Solution
It's a Virtual Private Server with Linux Ubuntu 16.04. I am using TFS 1.2 do you have some script to give premium points on your AAC?

You could try this, I just wrote it (not a Lua coder so not sure how well it will work):

Add to bottom of login.lua
Lua:
player:registerEvent("pointsforlvl")

creaturescripts.xml
XML:
<event type="advance" name="pointsforlvl" script="pointsforlvl.lua" />

pointsforlvl.lua
Lua:
-- [level] = points
local levelReward = {
    [50] = 20,
    [100] = 60,
    [150] = 100
}

-- Unique storage value to keep track of players highets level record
local uniqueStorage = 22073

function onAdvance(player, skill, oldLevel, newLevel)

    -- We only care if the advanced skill is level
    if skill...
I have registered the event. When I up level 90 servers shutdown... hahaha

Are you using windows?
Run the server through powershell to retrieve crash messages. Although it is likely that your script is not compatible with TFS 1.x+, since I don't see any metatables in it.
 
Are you using windows?
Run the server through powershell to retrieve crash messages. Although it is likely that your script is not compatible with TFS 1.x+, since I don't see any metatables in it.
It's a Virtual Private Server with Linux Ubuntu 16.04. I am using TFS 1.2 do you have some script to give premium points on your AAC?
 
It's a Virtual Private Server with Linux Ubuntu 16.04. I am using TFS 1.2 do you have some script to give premium points on your AAC?

You could try this, I just wrote it (not a Lua coder so not sure how well it will work):

Add to bottom of login.lua
Lua:
player:registerEvent("pointsforlvl")

creaturescripts.xml
XML:
<event type="advance" name="pointsforlvl" script="pointsforlvl.lua" />

pointsforlvl.lua
Lua:
-- [level] = points
local levelReward = {
    [50] = 20,
    [100] = 60,
    [150] = 100
}

-- Unique storage value to keep track of players highets level record
local uniqueStorage = 22073

function onAdvance(player, skill, oldLevel, newLevel)

    -- We only care if the advanced skill is level
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true -- exit script
    end

    -- Load the highest level this character has been
    local highestlevel = player:getStorageValue(uniqueStorage)

    -- If we have a new level record
    if newLevel > highestlevel then
   
        -- Update the storage value to the new level
        player:setStorageValue(uniqueStorage, newLevel)

        -- If newlevel does not match a levelReward index
        local points = levelReward[newLevel]
        if not points then
            return true -- exit script
        end

        -- Give the points to the account
        db.query('UPDATE znote_accounts SET points=points+'.. points ..' WHERE account_id=' .. player:getAccountId() ..' LIMIT 1;')

        -- Congratulate the player of his new points
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have received " .. points .. " shop points for reaching level " .. newLevel .. "!")

        -- Save the character to avoid duplicate rewards
        player:save()
   
    end
    return true
end

Let me know if it works.
 
Last edited:
Solution
You could try this, I just wrote it (not a Lua coder so not sure how well it will work):

Add to bottom of login.lua
Lua:
player:registerEvent("pointsforlvl")

creaturescripts.xml
XML:
<event type="advance" name="pointsforlvl" script="pointsforlvl.lua" />

pointsforlvl.lua
Lua:
-- [level] = points
local levelReward = {
    [50] = 20,
    [100] = 60,
    [150] = 100
}

-- Unique storage value to keep track of players highets level record
local uniqueStorage = 22073

function onAdvance(player, skill, oldLevel, newLevel)
 
    -- We only care if the advanced skill is level
    if skill ~= SKILL_LEVEL or newLevel <= oldLevel then
        return true -- exit script
    end

    -- Load the highest level this character has been
    local highestlevel = player:getStorageValue(uniqueStorage)

    -- If we have a new level record
    if newLevel > highestlevel then
   
        -- Update the storage value to the new level
        player:setStorageValue(uniqueStorage, newLevel)

        -- If newlevel does not match a levelReward index
        local points = levelReward[newLevel]
        if not points then
            return true -- exit script
        end

        -- Give the points to the account
        db.query('UPDATE znote_accounts SET points=points+'.. points ..' WHERE account_id=' .. player:getAccountId() ..' LIMIT 1;')

        -- Save the character to avoid duplicate rewards
        player:save()
   
    end
    return true
end

Let me know if it works.
YES!!!! IT'S WORKING!! Can you add me to this script like a Message that explain you for reached X level you received X points? thanks!!! best answer!
 
Back
Top