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

Add quests onLogin without server freeze

zapo

Member
Joined
Nov 10, 2020
Messages
129
Solutions
3
Reaction score
11
I am using the newest otservbr TFS1.3, freequest.lua script adds tasks if you log in for the first time. They use player: setStorageValue (value.storageId, value.storageValue) to add.
When there are a lot of quests, the first time you log in, the player will freeze the server for 1 second
How to add quests without freezing?
 
Solution
Could you please write this script? :)
Lua:
local playerSetupStorage = 45000

local config = {
    {storage = 45001, value = 1}, -- example table. Use your own list of storages and values
    {storage = 45002, value = 7}
    {storage = 45003, value = 1}
}

local function playerSetup(playerId, index)
    local player = Player(playerId)
    if not player then
        return
    end
    for i = 1, 10 do
        index = index + 1
        if not config[index] then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Player setup is complete.")
            player:setStorageValue(playerSetupStorage, 1)
            return
        end
        if player:getStorageValue(config[index].storage) ~= config[index].value then...
I am using the newest otservbr TFS1.3, freequest.lua script adds tasks if you log in for the first time. They use player: setStorageValue (value.storageId, value.storageValue) to add.
When there are a lot of quests, the first time you log in, the player will freeze the server for 1 second
How to add quests without freezing?
Use a looping addEvent to spread the load over a longer time-frame. (example: set 10 storages per loop, 100 ms delay)

In case of accidental or purposeful player logout, dedicate a single storage to confirm that the process completed successfully, so you can skip it in the future.
 
Użyj pętli addEvent, aby rozłożyć obciążenie na dłuższy okres. (przykład: ustaw 10 pamięci na pętlę, 100 ms opóźnienia)

W przypadku przypadkowego lub celowego wylogowania gracza, przeznacz jedno miejsce, aby potwierdzić, że proces zakończył się pomyślnie, aby móc go pominąć w przyszłości.
Could you please write this script? :)
 
 
Could you please write this script? :)
Lua:
local playerSetupStorage = 45000

local config = {
    {storage = 45001, value = 1}, -- example table. Use your own list of storages and values
    {storage = 45002, value = 7}
    {storage = 45003, value = 1}
}

local function playerSetup(playerId, index)
    local player = Player(playerId)
    if not player then
        return
    end
    for i = 1, 10 do
        index = index + 1
        if not config[index] then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Player setup is complete.")
            player:setStorageValue(playerSetupStorage, 1)
            return
        end
        if player:getStorageValue(config[index].storage) ~= config[index].value then
            player:setStorageValue(config[index].storage, config[index].value)
        end
    end
    addEvent(playerSetup, 100, playerId, index)
end

local loginEvent = CreatureEvent("onLogin_PlayerSetup")
loginEvent:type("login")

function loginEvent.onLogin(player)
    if player:getStorageValue(playerSetupStorage) == 1 then
        return true
    end
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Player setup in progress..")
    addEvent(playerSetup, 100, player:getId(), 0)
    return true
end

loginEvent:register()
 
Solution
Back
Top