• 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 Task count even if people in party are far away, also only in party..

Hbraveq

Active Member
Joined
Nov 11, 2012
Messages
167
Reaction score
39
TFS 1.5 7.72 by nekiro
Hello, I'm using this script in creaturescripts killtask.lua and problem is you can make party with unlimited people, stay away and make tasks, also tasks count only if player is in party....
function onKill(cid, target, lastHit)
local partyMembers = getPartyMembers(cid)

if not partyMembers or #partyMembers == 0 then
return true
end

local started = getPlayerStartedTasks(cid)

if isPlayer(target) then
return true
end

if started and #started > 0 then
for _, id in ipairs(started) do
if isInArray(tasks[id].creatures, getCreatureName(target):lower()) then
for _, member in ipairs(partyMembers) do
if getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) < 0 then
setPlayerStorageValue(member, KILLSSTORAGE_BASE + id, 0)
end
if getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) < tasks[id].killsRequired then
setPlayerStorageValue(member, KILLSSTORAGE_BASE + id, getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) + 1)
doPlayerSendTextMessage(member, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) .. "/" .. tasks[id].killsRequired .. " " .. tasks[id].raceName .. " already killed.")
end
end
end
end
end

return true
end
 
Last edited:
TFS 1.5 7.72 by nekiro
Hello, I'm using this script in creaturescripts killtask.lua and problem is you can make party with unlimited people, stay away and make tasks.
how u want it to be?
count for every party member in x range?
count for every member if shared exp is active?
count for every player that dealt dmg to the mob?
 
how u want it to be?
count for every party member in x range?
count for every member if shared exp is active?
count for every player that dealt dmg to the mob?
I want to count for party members only that are in 30 sqm range~~
Also to work for ppl in party
And out of party....
 
not tested

Lua:
local config = {
  countInParty = true,
  checkMembersDistance = true,
  maxRange = 30,
  countOnlyIfSharedEnabled = false,
}
local function taskKill(player,monsterName)
  local started = getPlayerStartedTasks(player)
  if started and type(started) == 'table' then
    for _, id in pairs(started) do
      local task = tasks[id]
      if table.contains(task.creatures,monsterName) then
        local current = player:getStorageValue(KILLSSTORAGE_BASE + id)
        curent = current < 0 and 0 or current
        if current < task.killsRequired then
          current = current + 1
          player:setStorageValue(KILLSSTORAGE_BASE + id, current)
        end
        local msg = ("[TASK SYSTEM] %d / %d %s killed."):format(current,task.killsRequired,task.raceName)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE,msg)
      end
    end
  end
end
function onKill(creature,target)
  local player = Player(creature)
  if not player or target:isPlayer() or target:getMaster() then
    return true
  end
  local checked = {}
  local checkParty = {}
  local mName = target:getName():lower()
  for attacker, _ in pairs(target:getDamageMap()) do
    attacker = Creature(attacker)
    if attacker and attacker:isPlayer() then
      table.insert(checked,attacker)
      taskKill(attacker,mName)
      if config.countInParty then
        local party = attacker:getParty()
        if party and not table.contains(checkParty,party) then
          table.insert(checkParty,party)
        end
      end
    end
  end
  if not config.countInParty then
    return true
  end
  local mobPos = target:getPosition()
  for _, party in pairs(checkParty) do
    if not config.countOnlyIfSharedEnabled or party:isSharedExperienceEnabled() then
      for __, member in pairs(party:getMembers()) do
        if not table.contains(checked,member) then
          if not config.checkMembersDistance or getDistanceBetween(mobPos, member:getPosition()) < config.maxRange then
            table.insert(checked,member)
            taskKill(member,mName)
          end
        end
      end
    end
  end
  
  return true
end
 
Last edited:
not tested

Lua:
local config = {
  countInParty = true,
  checkMembersDistance = true,
  maxRange = 30,
  countOnlyIfSharedEnabled = false,
}

local function taskKill(player,monsterName)
  local started = getPlayerStartedTasks(player)
  if started and type(started) == 'table' then
    for _, id in pairs(started) do
      local task = tasks[id]
      if table.find(task.creatures,monsterName) then
        local current = player:getStorageValue(KILLSSTORAGE_BASE + id)
        curent = current < 0 and 0 or current
        if current < task.killsRequired then
          current = current + 1
          player:setStorageValue(current)
        end
        local msg = ("[TASK SYSTEM] %d / %d %s killed."):format(current,task.killsRequired,task.raceName)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE,msg)
      end
    end
  end
end

function onKill(creature,target)
  local player = Player(creature)
  if not player or target:isPlayer() or target:getMaster() then
    return true
  end

  local checked = {}
  local checkParty = {}
  local mName = target:getName()
  for attacker, _ in pairs(target:getDamageMap()) do
    if attacker:isPlayer() then
      table.insert(checked,attacker)
      taskKill(attacker,mName)
      if config.countInParty then
        local party = attacker:getParty()
        if party and not table.find(checkParty,party) then
          table.insert(checkParty,party)
        end
      end
    end
  end

  if not config.countInParty then
    return true
  end

  local mobPos = target:getPosition()
  for _, party in pairs(checkParty) do
    if not config.countOnlyIfSharedEnabled or party:isSharedExperienceEnabled() then
      for __, member in pairs(party:getMembers()) do
        if not table.find(checked,member) then
          if not config.checkMembersDistance or getDistanceBetween(mobPos, member:getPosition()) < config.maxRange then
            table.insert(checked,member)
            taskKill(member,mName)
          end
        end
      end
    end
  end
 
  return true
end
not workiing


2023-08-25_19-00-30.910142 Lua Script Error: [CreatureScript Interface]
2023-08-25_19-00-30.910161 data/creaturescripts/scripts/killtask.lua:eek:nKill
2023-08-25_19-00-30.910180 data/creaturescripts/scripts/killtask.lua:37: attempt to index local 'attacker' (a number value)
2023-08-25_19-00-30.910202 stack traceback:
2023-08-25_19-00-30.910234 [C]: in function '__index'
2023-08-25_19-00-30.910296 data/creaturescripts/scripts/killtask.lua:37: in function <data/creaturescripts/scripts/killtask.lua:27>
 
Last edited:
Lua:
local config = {
  countInParty = true,
  checkMembersDistance = true,
  maxRange = 30,
  countOnlyIfSharedEnabled = false,
}

local function taskKill(player,monsterName)
  local started = getPlayerStartedTasks(player)
  if started and type(started) == 'table' then
    for _, id in pairs(started) do
      local task = tasks[id]
      if table.find(task.creatures,monsterName) then
        local current = player:getStorageValue(KILLSSTORAGE_BASE + id)
        curent = current < 0 and 0 or current
        if current < task.killsRequired then
          current = current + 1
          player:setStorageValue(current)
        end
        local msg = ("[TASK SYSTEM] %d / %d %s killed."):format(current,task.killsRequired,task.raceName)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE,msg)
      end
    end
  end
end

function onKill(creature,target)
  local player = Player(creature)
  if not player or target:isPlayer() or target:getMaster() then
    return true
  end

  local checked = {}
  local checkParty = {}
  local mName = target:getName()
  for attacker, _ in pairs(target:getDamageMap()) do
    attacker = Creature(attacker)
    if attacker:isPlayer() then
      table.insert(checked,attacker)
      taskKill(attacker,mName)
      if config.countInParty then
        local party = attacker:getParty()
        if party and not table.find(checkParty,party) then
          table.insert(checkParty,party)
        end
      end
    end
  end

  if not config.countInParty then
    return true
  end

  local mobPos = target:getPosition()
  for _, party in pairs(checkParty) do
    if not config.countOnlyIfSharedEnabled or party:isSharedExperienceEnabled() then
      for __, member in pairs(party:getMembers()) do
        if not table.find(checked,member) then
          if not config.checkMembersDistance or getDistanceBetween(mobPos, member:getPosition()) < config.maxRange then
            table.insert(checked,member)
            taskKill(member,mName)
          end
        end
      end
    end
  end
 
  return true
end

error again
2023-08-25_19-28-56.211373 Lua Script Error: [CreatureScript Interface]
2023-08-25_19-28-56.211433 data/creaturescripts/scripts/killtask.lua:eek:nKill
2023-08-25_19-28-56.211471 data/creaturescripts/scripts/killtask.lua:13: attempt to call field 'find' (a nil value)
2023-08-25_19-28-56.211497 stack traceback:
2023-08-25_19-28-56.211518 [C]: in function 'find'
2023-08-25_19-28-56.211539 data/creaturescripts/scripts/killtask.lua:13: in function 'taskKill'
2023-08-25_19-28-56.211571 data/creaturescripts/scripts/killtask.lua:40: in function <data/creaturescripts/scripts/killtask.lua:27>
 
change all
table.find to table.contains
in this code

OR

put it in the end of global.lua
table.find = table.contains
```
21:43 [TASK SYSTEM] 7 / 100 Easy Monsters killed.
21:43 [TASK SYSTEM] 7 / 100 Easy Monsters killed.
21:43 [TASK SYSTEM] 7 / 100 Easy Monsters killed.
still same amount of kills :p
 
sorry ^^

change
player:setStorageValue(current)
for
player:setStorageValue(KILLSSTORAGE_BASE + id, current)
Post automatically merged:

edited first post with all fixes
Yh

Idk, but with your killtask.lua it counts only some of tasks lol. For example it count "trolls", not count "cyclops". Maybe my this is bugged?
This is data/lib/grizzlyadams

-- TASK


RANK_NONE = 0
RANK_HUNTSMAN = 1
RANK_RANGER = 2
RANK_BIGGAMEHUNTER = 3
RANK_TROPHYHUNTER = 4
RANK_ELITEHUNTER = 5

REWARD_MONEY = 1
REWARD_EXP = 2
REWARD_ACHIEVEMENT = 3
REWARD_STORAGE = 4
REWARD_POINT = 5
REWARD_ITEM = 6

QUESTSTORAGE_BASE = 71500
KILLSSTORAGE_BASE = 72500
REPEATSTORAGE_BASE = 73500
POINTSSTORAGE = 72500
ONTASKSTORAGE = 74500
tasks =
{
[1] = {killsRequired = 100, raceName = "Easy Monsters", level = {1, 6656}, premium = false, creatures = {"Dwarf", "Dwarf Soldier", "spider", "troll", "bug"}, rewards = {
{type = "exp", value = {5000}},
{type = "money", value = {5000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,1}}
}},
[2] = {killsRequired = 150, raceName = "Vampire", level = {1, 6656}, premium = false, creatures = {"vampire"}, rewards = {
{type = "exp", value = {34000}},
{type = "money", value = {10000}},
{type = "points", value = {1}},
}},
[3] = {killsRequired = 100, raceName = "Ghoul", level = {1, 6656}, premium = false, creatures = {"ghoul", "skeleton"}, rewards = {
{type = "exp", value = {11000}},
{type = "money", value = {7000}},
{type = "points", value = {1}},
}},
[4] = {killsRequired = 350, raceName = "Necromancer", level = {1, 6656}, premium = false, creatures = {"necromancer"}, rewards = {
{type = "exp", value = {50000}},
{type = "item", value = {2195,1}},
{type = "points", value = {1}},
{type = "storage", value = {81500,3}}
}},
[5] = {killsRequired = 400, raceName = "Dragons", level = {1, 6656}, premium = false, creatures = {"Dragon", "Dragon Lord"}, rewards = {
{type = "exp", value = {100000}},
{type = "money", value = {35000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,4}}
}},
[6] = {killsRequired = 300, raceName = "Hydras", level = {1, 6656}, premium = false, creatures = {"hydra"}, rewards = {
{type = "exp", value = {350000}},
{type = "money", value = {50000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,5}}
}},
[7] = {killsRequired = 400, raceName = "Serpent Spawns", level = {1, 6566}, premium = false, creatures = {"serpent spawn"}, rewards = {
{type = "exp", value = {600000}},
{type = "money", value = {80000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,6}}
}},
[8] = {killsRequired = 300, raceName = "Behemoth", level = {1, 6656}, premium = false, creatures = {"behemoth"}, rewards = {
{type = "exp", value = {400000}},
{type = "money", value = {80000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,7}}
}},
[9] = {killsRequired = 500, raceName = "Warlock", level = {1, 6656}, premium = false, creatures = {"warlock"}, rewards = {
{type = "exp", value = {700000}},
{type = "money", value = {100000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,8}}
}},
[10] = {killsRequired = 1500, raceName = "Demon", level = {1, 6566}, premium = false, creatures = {"demon"}, rewards = {
{type = "exp", value = {10000000}},
{type = "item", value = {2357, 1}},
{type = "points", value = {1}},
{type = "storage", value = {81500,9}}
}},
[11] = {killsRequired = 500, raceName = "Mutateds", level = {1, 6656}, premium = false, creatures = {"mutated rat", "mutated bat", "mutated wolf"}, rewards = {
{type = "exp", value = {200000}},
{type = "money", value = {50000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,10}}
}},
[12] = {killsRequired = 400, raceName = "Guzzlemaw", level = {1, 6566}, premium = false, creatures = {"frazzlemaw", "guzzlemaw"}, rewards = {
{type = "exp", value = {900000}},
{type = "money", value = {150000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,11}}
}},
[13] = {killsRequired = 245, raceName = "Undead Gladiator", level = {1, 6656}, premium = false, creatures = {"undead gladiator"}, rewards = {
{type = "exp", value = {250000}},
{type = "money", value = {30000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,12}}
}},
[14] = {killsRequired = 300, raceName = "Worker Golem", level = {1, 6566}, premium = false, creatures = {"worker golem"}, rewards = {
{type = "exp", value = {300000}},
{type = "money", value = {40000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,13}}
}},
[15] = {killsRequired = 200, raceName = "Vampire Bride", level = {1, 6566}, premium = false, creatures = {"vampire bride"}, rewards = {
{type = "exp", value = {400000}},
{type = "money", value = {40000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,14}}
}},
[16] = {killsRequired = 200, raceName = "Ancient Scarab", level = {1, 6665}, premium = false, creatures = {"ancient scarab"}, rewards = {
{type = "exp", value = {200000}},
{type = "money", value = {20000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,15}}
}},
[17] = {killsRequired = 500, raceName = "Heroes", level = {1, 6665}, premium = false, creatures = {"hero", "black knight"}, rewards = {
{type = "exp", value = {450000}},
{type = "money", value = {50000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,17}}
}},
[18] = {killsRequired = 250, raceName = "Orcs", level = {1, 6665}, premium = false, creatures = {"orc", "orc spearman", "orc leader", "orc warlord", "orc berserker", "orc shaman"}, rewards = {
{type = "exp", value = {70000}},
{type = "money", value = {10000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,18}}
}},
[18] = {killsRequired = 250, raceName = "Cyclops", level = {1, 6665}, premium = false, creatures = {"cyclops"}, rewards = {
{type = "exp", value = {100000}},
{type = "money", value = {10000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,19}}
}},
[19] = {killsRequired = 450, raceName = "Strong Minotaurs", level = {1, 6665}, premium = false, creatures = {"mooh tah", "exekutor", "mino hunter"}, rewards = {
{type = "exp", value = {450000}},
{type = "money", value = {50000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,20}}
}},
[20] = {killsRequired = 250, raceName = "Bonebeasts", level = {1, 6665}, premium = false, creatures = {"bonebeast"}, rewards = {
{type = "exp", value = {250000}},
{type = "money", value = {20000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,21}}
}},
[21] = {killsRequired = 200, raceName = "Giant Spiders", level = {1, 6665}, premium = false, creatures = {"giant spider"}, rewards = {
{type = "exp", value = {350000}},
{type = "money", value = {30000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,22}}
}},
[22] = {killsRequired = 200, raceName = "Minotaurs", level = {1, 6665}, premium = false, creatures = {"minotaur", "minotaur archer", "minotaur mage", "minotaur guard"}, rewards = {
{type = "exp", value = {60000}},
{type = "money", value = {8000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,23}}
}},
[23] = {killsRequired = 1500, raceName = "High Warlocks", level = {1, 6665}, premium = false, creatures = {"warlock"}, rewards = {
{type = "exp", value = {1000000}},
{type = "item", value = {2323, 1}},
{type = "points", value = {1}},
{type = "storage", value = {81500,24}}
}}


}

tasksByPlayer = 999999
repeatTimes = 999999

function getPlayerRank(cid)
return (getPlayerStorageValue(cid, POINTSSTORAGE) >= 100 and RANK_ELITEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 70 and RANK_TROPHYHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 40 and RANK_BIGGAMEHUNTER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 20 and RANK_RANGER or getPlayerStorageValue(cid, POINTSSTORAGE) >= 10 and RANK_HUNTSMAN or RANK_NONE)
end

function getTaskByName(name, table)
local t = (table and table or tasks)
for k, v in pairs(t) do
if v.name then
if v.name:lower() == name:lower() then
return k
end
else
if v.raceName:lower() == name:lower() then
return k
end
end
end
return false
end

function getTasksByPlayer(cid)
local canmake = {}
local able = {}
for k, v in pairs(tasks) do
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) < 1 and getPlayerStorageValue(cid, REPEATSTORAGE_BASE + k) < repeatTimes then
able[k] = true
if getPlayerLevel(cid) < v.level[1] or getPlayerLevel(cid) > v.level[2] then
able[k] = false
end
if v.storage and getPlayerStorageValue(cid, v.storage[1]) < v.storage[2] then
able[k] = false
end

if v.rank then
if getPlayerRank(cid) < v.rank then
able[k] = false
end
end

if v.premium then
if not isPremium(cid) then
able[k] = false
end
end

if able[k] then
table.insert(canmake, k)
end
end
end
return canmake
end


function canStartTask(cid, name, table)
local v = ""
local id = 0
local t = (table and table or tasks)
for k, i in pairs(t) do
if i.name then
if i.name:lower() == name:lower() then
v = i
id = k
break
end
else
if i.raceName:lower() == name:lower() then
v = i
id = k
break
end
end
end
if v == "" then
return false
end
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + id) > 0 then
return false
end
if (getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) >= repeatTimes) or (v.norepeatable and getPlayerStorageValue(cid, REPEATSTORAGE_BASE + id) > 0) then
return false
end
if getPlayerLevel(cid) >= v.level[1] and getPlayerLevel(cid) <= v.level[2] then
if v.premium then
if isPremium(cid) then
if v.rank then
if getPlayerRank(cid) >= v.rank then
if v.storage then
if getPlayerStorageValue(cid, v.storage[1]) >= v.storage[2] then
return true
end
else
return true
end
end
else
return true
end
end
else
return true
end
end
return false
end

function getPlayerStartedTasks(cid)

local tmp = {}
for k, v in pairs(tasks) do
if getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) > 0 and getPlayerStorageValue(cid, QUESTSTORAGE_BASE + k) < 2 then
table.insert(tmp, k)
end
end
return tmp
end
 
Yh

Idk, but with your killtask.lua it counts only some of tasks lol. For example it count "trolls", not count "cyclops". Maybe my this is bugged?
This is data/lib/grizzlyadams
change
local mName = target:getName()
to
local mName = target:getName():lower()
Post automatically merged:

but in your config, you have to put all monsters names in lower case
example
WRONG:
[5] = {killsRequired = 400, raceName = "Dragons", level = {1, 6656}, premium = false, creatures = {"Dragon", "Dragon Lord"}, rewards = {
{type = "exp", value = {100000}},
{type = "money", value = {35000}},
{type = "points", value = {1}},
{type = "storage", value = {81500,4}}
}},
 
This is solution.

function onKill(cid, target, lastHit)
local started = getPlayerStartedTasks(cid)
if isPlayer(target) then
return true
end

local player = Player(cid)
if (player == nil) then
return true
end

-- Normal without party
local partyMembers = getPartyMembers(cid)
if not partyMembers or #partyMembers == 0 then
if started and #started > 0 then
for _, id in ipairs(started) do
if isInArray(tasks[id].creatures, getCreatureName(target):lower()) then
if getPlayerStorageValue(cid, KILLSSTORAGE_BASE + id) < 0 then
setPlayerStorageValue(cid, KILLSSTORAGE_BASE + id, 0)
end
if getPlayerStorageValue(cid, KILLSSTORAGE_BASE + id) < tasks[id].killsRequired then
setPlayerStorageValue(cid, KILLSSTORAGE_BASE + id, getPlayerStorageValue(cid, KILLSSTORAGE_BASE + id) + 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerStorageValue(cid, KILLSSTORAGE_BASE + id) .. "/" .. tasks[id].killsRequired .. " " .. tasks[id].raceName .. " already killed.")
end
end
end
end
else
-- Party
local party = player:getParty()
local leader = party:getLeader()
if (getDistanceBetween(leader:getPosition(), player:getPosition()) > 50) then
return true
end

if started and #started > 0 then
for _, id in ipairs(started) do
if isInArray(tasks[id].creatures, getCreatureName(target):lower()) then
for _, member in ipairs(partyMembers) do
if getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) < 0 then
setPlayerStorageValue(member, KILLSSTORAGE_BASE + id, 0)
end
if getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) < tasks[id].killsRequired then
setPlayerStorageValue(member, KILLSSTORAGE_BASE + id, getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) + 1)
doPlayerSendTextMessage(member, MESSAGE_STATUS_CONSOLE_ORANGE, getPlayerStorageValue(member, KILLSSTORAGE_BASE + id) .. "/" .. tasks[id].killsRequired .. " " .. tasks[id].raceName .. " already killed.")
end
end
end
end
end
end

return true
end
 
Back
Top