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

TFS 1.X+ Daily task event problem tfs 0.4 to 1.5

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
929
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
hello i'm trying to adapt a daily task npc tfs 0.4 in my new tfs 1.5 nekiro. Can anyone tell me why these 2 errors happen?

WhatsApp Image 2022-10-14 at 12.16.24.jpeg

creaturescript
XML:
    <event type="login" name="DailyTaskLogin" script="dailytask.lua"/>
    <event type="death" name="DailyTaskDeath" script="dailytask.lua"/>
    <event type="target" name="DailyTaskTarget" script="dailytask.lua"/>
    <event type="combat" name="DailyTaskCombat" script="dailytask.lua"/>

creaturescripts/scripts/task.lua
Lua:
function onLogin(cid)
    registerCreatureEvent(cid, "DailyTask")
    registerCreatureEvent(cid, "DailyTaskTarget")
    registerCreatureEvent(cid, "DailyTaskCombat")
    return true
end    

function onTarget(cid, target)
    if isPlayer(cid) and isMonster(target) and not isSummon(target) then
        registerCreatureEvent(target, "DailyTaskDeath")
    end
    return true
end

function onCombat(cid, target)
    if isPlayer(cid) and isMonster(target) and not isSummon(target) then
        registerCreatureEvent(target, "DailyTaskDeath")
    end
    return true
end
 
Solution
the functions you're trying to use either doesn't exist or has been rewritten in some other way, so you could try to recreate it for newer tfs in revscriptsys instead

this is not complete code, just a base for you to start working with

onLogin
data/scripts/creaturescripts/loginEventNameHere.lua
Lua:
local creatureevent = CreatureEvent("loginEventNameHere")
function creatureevent.onLogin(player)
    -- more code here
    return true
end

creatureevent:register()

onTargetCombat
data/events/events.xml
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
scripts/eventcallbacks/creature/default_onTargetCombat.lua
Lua:
local ec = EventCallback

ec.onTargetCombat =...
my guess is that 'combat', 'target' events and 'onCombat', 'onTarget' functions is custom and nekiro's archived repository don't have those, so you will have to implement them yourself from that 0.4 distro

here you can see all event types:
 
Last edited:
I tried but the error remains the same
<event type="onTarget" name="DailyTaskTarget" script="dailytask.lua"/>
<event type="onCombat" name="DailyTaskCombat" script="dailytask.lua"/>
 
creaturescript

Lua:
function onLogin(cid)
    registerCreatureEvent(cid, "DailyTask")
    registerCreatureEvent(cid, "DailyTaskTarget")
    registerCreatureEvent(cid, "DailyTaskCombat")
    return true
end     

function onTarget(cid, target)
    if isPlayer(cid) and isMonster(target) and not isSummon(target) then
        registerCreatureEvent(target, "DailyTaskDeath")
    end
    return true
end

function onCombat(cid, target)
    if isPlayer(cid) and isMonster(target) and not isSummon(target) then
        registerCreatureEvent(target, "DailyTaskDeath")
    end
    return true
end

function onDeath(cid, corpse, deathList)
    if (not isMonster(cid)) or getCreatureMaster(cid) then return true end
    local check, races = false, ""
    local monster_name = getCreatureName(cid):lower()
    local tab_monsters = DAILY_TASKS.monsters
    local monster = tab_monsters[monster_name]
    if monster then check = true end
    if not check then
        for race, v in pairs(tab_monsters) do
            if v.races then
                if isInArray(v.races, monster_name) then
                    monster = tab_monsters[race]
                    races = race
                    break
                end
            end
        end
    end
    local killer = #deathList == 1 and deathList[1] or deathList[2]
    if isPlayer(killer) then
        if not monster then return true end
        local info = races ~= "" and capitalizeAll(races) or getCreatureName(cid)
        local task_name = info..addPlural(2,"s", info)
        local stor = getPlayerStorageValue(killer, monster.mstorage) + 1
        if getPlayerStorageValue(killer, monster.storage) == 1 then
            if stor < monster.amount then
                setPlayerStorageValue(killer, monster.mstorage, stor)
                doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_ORANGE, "Task message: " .. (stor + 1).." of "..monster.amount.." "..task_name.." killed.")
            end
            if (stor + 1) == monster.amount then
                doPlayerSendTextMessage(killer, MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have killed "..(stor+1).." "..task_name.." and completed the "..task_name.." mission.")
                setPlayerStorageValue(killer, monster.mstorage, stor+1)
            end
        end
    end
    return true
end

LIB
Lua:
DAILY_TASKS = {
    time_to_finish = {24, "hour"},
    storage = {global = 67998, time = 67999},
    monsters = {
        ["troll"] = {storage = 68000, mstorage = 68500, amount = 10, experience = 1000, races = {"troll champion"}},
        ["orc"] = {storage = 68001, mstorage = 68501, amount = 10, experience = 1000, races = {"orc warrior", "orc spearman"}},
        ["rotworm"] = {storage = 68002, mstorage = 68502, amount = 10, experience = 1000, races = {"carrion worm"}},
        ["cyclops"] = {storage = 68003, mstorage = 68503, amount = 10, experience = 1000, races = {"cyclops drone", "cyclops smith"}}
    }
}




function getRandomDailyTask(except)
    local tasks, choices, tab = {}, {}, DAILY_TASKS.monsters
    for task, info in pairs(tab) do
        if not except then
            table.insert(tasks, task)
        else
            if task:lower() ~= except:lower() then
                table.insert(tasks, task)
            end
        end
    end
    return tasks[math.random(1, #tasks)]
end

function addPlural(counter, windup, word)
    if counter <= 1 then return "" end
    return not word and windup or (word:sub(-1,-1) ~= windup and windup or "")
end

function capitalizeAll(str)
    return str:lower():gsub("%w+",
        function(w)
          return w:sub(1,1):upper() .. w:sub(2)
    end)
end


function mathtime(table)
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end
 
the functions you're trying to use either doesn't exist or has been rewritten in some other way, so you could try to recreate it for newer tfs in revscriptsys instead

this is not complete code, just a base for you to start working with

onLogin
data/scripts/creaturescripts/loginEventNameHere.lua
Lua:
local creatureevent = CreatureEvent("loginEventNameHere")
function creatureevent.onLogin(player)
    -- more code here
    return true
end

creatureevent:register()

onTargetCombat
data/events/events.xml
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
scripts/eventcallbacks/creature/default_onTargetCombat.lua
Lua:
local ec = EventCallback

ec.onTargetCombat = function(self, target)
    -- more code here
    return RETURNVALUE_NOERROR
end

ec:register()

onDeath
data/scripts/creaturescripts/deathEventNameHere.lua
Lua:
local creatureevent = CreatureEvent("deathEventNameHere")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    -- more code here
    return true
end

creatureevent:register()
data/monster/rat.xml
XML:
<script>
    <event name="deathEventNameHere" />
</script>
 
Solution
Back
Top