• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

doubt task script 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
LUA:
local config = {
     ['beholder'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 1}
}
function onKill(player, target)
    local player = type(player) == "userdata" and player or Player(player)
    local target = type(target) == "userdata" and target or Creature(target)
    if target and target:isMonster() then
        local monster = config[target:getName():lower()]
        if target:isPlayer() or not monster or target:getMaster() then
            return true
        end
        local stor = player:getStorageValue(monster.storage)+1
        if stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
            player:setStorageValue(monster.storage, stor)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(stor +1)..' of '..monster.amount..' '..target:getName()..'s killed.')
        end
        if (stor +1) == monster.amount then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(stor +1)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
            player:setStorageValue(monster.storage, stor +1)
        end
    end
    return true
end

i'm trying to configure the npc, but i have a doubt.

startstorage = 5010 npc needs this number to activate my task?
when i finish the task i got automatically storage = 19000 and this to know that I finished the task?
 
Solution
Problem Fixed !!!

The count is working perfectly now


LUA:
local config = {
     ['rat'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 1}
}
function onKill(player, target)
    local player = type(player) == "userdata" and player or Player(player)
    local target = type(target) == "userdata" and target or Creature(target)
    if target and target:isMonster() then
        local monster = config[target:getName():lower()]
        if target:isPlayer() or not monster or target:getMaster() then
            return true
        end
        local stor = player:getStorageValue(monster.storage)+1
        if stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then...
Try this:


Code:
local config = {
     ['beholder'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 0}
}
function onKill(player, target)
    if not player:isPlayer() then
        return false
    end
    if target and target:isMonster() then
        local monster = config[target:getName():lower()]
        if target:isPlayer() or not monster or target:getMaster() then
            return true
        end
        local stor = player:getStorageValue(monster.storage)+1
        if stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
            player:setStorageValue(monster.storage, stor)
            player:setStorageValue(monster.startstorage, stor)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..stor..' of '..monster.amount..' '..target:getName()..'s killed.')
        end
        if stor == monster.amount and startstorage == monster.amount then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..stor..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
            return true
        else
            return true
        end
    end
    return true
end

You should know that you will need a new character to test or to change the storage values.
 
Last edited:
why when i killed the first beholder of my task, i got this msg 23:44 Task message: 2 of 5 beholders killed. is possible fix this for correct count?
 
Yes, change the startvalue from 1 to 0.

If other than that I solved your problem, please mark thread as solved, and mark my answer as best answer.
 
not sure why a completely different storage and start value is necessary, you don't even set the other storage value or anything
LUA:
local config = {
    ['beholder'] = {amount = 5, storage = 19000}
}

function onKill(creature, target)
    local player = Player(creature)
    if not player then
        return false
    end
    if not target:isMonster() then
        return true
    end
    local name = target:getName()
    local monster = config[name:lower()]
    if target:getMaster() or not monster then
        return true
    end
    local storage = player:getStorageValue(monster.storage)
    local newValue = (storage == -1) and 1 or storage + 1
    local msg = ""
    local msgType = 0
    if (newValue < monster.amount) then
        msg = string.format("Task message: %d of %d %ss killed.", newValue, monster.amount, name)
        msgType = MESSAGE_STATUS_CONSOLE_ORANGE
    elseif (newValue == monster.amount) then
        msg = string.format("Congratulations, you have killed %d %ss and completed the %s's mission.", newValue, name, name)
        msgType = MESSAGE_INFO_DESCR
    end
    player:setStorageValue(monster.storage, newValue)
    player:sendTextMessage(msgType, msg)
    return true
end
 
not sure why a completely different storage and start value is necessary, you don't even set the other storage value or anything

I didn't make the script bro, I just edited. From what it sounds like, it's working as intended for him.

As far as change to the start value, that was a count problem, says the start value was 1, but when the function was called it automatically added +1 to that during the creation of the variable stor.

As for different storage value, because the script was giving him the completed value detected by his npc in the beginning, if he used same character and storage he wouldn't be able to tell if the script did anything different.

no work, continue starting with 2 count

Did you try a new character or change the storage value again?
 
Last edited by a moderator:
I didn't make the script bro, I just edited. From what it sounds like, it's working as intended for him.

As far as change to the start value, that was a count problem, says the start value was 1, but when the function was called it automatically added +1 to that during the creation of the variable stor.

As for different storage value, because the script was giving him the completed value detected by his npc in the beginning, if he used same character and storage he wouldn't be able to tell if the script did anything different.
the start value shouldn't have mattered, the problem was the "stor" variable had player:getStorageValue() + 1
and then in every value check statement, it was stor + 1
so it was checking stor + 2 and printing out stor + 2 every time which is the wrong value, it will always show 1 ahead
 
but this script is automatic? because i killed a beholder without talk with npc, i received this msg Task message: 1 of 5 beholders killed.
 
the start value shouldn't have mattered, the problem was the "stor" variable had player:getStorageValue() + 1
and then in every value check statement, it was stor + 1
so it was checking stor + 2 and printing out stor + 2 every time which is the wrong value, it will always show 1 ahead

I did say that was a possibility.

@OP, updating main code paste.

but this script is automatic? because i killed a beholder without talk with npc, i received this msg Task message: 1 of 5 beholders killed.

No that shouldn't have happened with my original paste or the one I just updated it to. You had to change that startstorage value at some point on that character because the previous script didn't change it at all as @Static_ pointed out, and this new one won't change it unless its already been changed.

  • local player = Player(creature)
  • if not player then
  • return false
  • end
  • if not target:isMonster() then
  • return true
  • end
  • local name = target:getName()
  • local monster = config[name:lower()]
  • if target:getMaster() or not monster then
  • return true
end

Every last bit of that is unnecessary man.

You can still check for player by changing the parameter the way I did, or even doing creature:isPlayer, no point in reconstructing the object again.
You don't need to check if it's a monster because unless the creature's name is in the table it won't execute the magic. Although now I am thinking of it, they would have to block players from picking same names as monsters, or do it your way.

And what is wrong with

local monster = config[target:getName():lower()]

I do like your check to make sure it's not a summon tho! That is dope, and some of the rest of the logic is more well written, but keep in mind I didn't make the code, I just did edits :D

The one thing your script is missing that keeps it from working with his npc is it doesn't check if player has the startvalue assigned by the npc.
 
Last edited by a moderator:
his, yes i'm using new character now

Code:
local config = {
    ['beholder'] = {amount = 5, storage = 19000, startstorage = 5010}
}
function onKill(player, target)
    if not target:isMonster() or target:getMaster()  or (not player:isPlayer()) then
        return true
    end
    local monster = config[target:getName():lower()]
    local storage = player:getStorageValue(monster.storage)
    if not player:getStorageValue(monster.startstorage) >= 0 then
        return true
    end
    local newValue = (storage == -1) and 1 or storage + 1
    local msg = ""
    local msgType = 0
    if (newValue < monster.amount)then
        msg = string.format("Task message: %d of %d %ss killed.", newValue, monster.amount, name)
        msgType = MESSAGE_STATUS_CONSOLE_ORANGE
    elseif (newValue == monster.amount) then
        msg = string.format("Congratulations, you have killed %d %ss and completed the %s's mission.", newValue, name, name)
        msgType = MESSAGE_INFO_DESCR
    end
    player:setStorageValue(monster.storage, newValue)
    player:sendTextMessage(msgType, msg)
    return true
end

That should work. If it works exactly how you wanted and there are no more problems, please change best answer to his post.
 
no point in reconstructing the object again
it's not, a creature userdata is passed through onKill, not player
the argument name was incorrectly named and therefore you had no player object
why do you think you're checking for player:isPlayer()?
doesn't matter if it's "unnecessary", don't name an argument incorrectly and use it like it's magically something else
You don't need to check if it's a monster because unless the creature's name is in the table it won't execute the magic
yes but it doesn't even hurt, why allocate a variable for something that won't be used if it's not a monster?
The one thing your script is missing that keeps it from working with his npc is it doesn't check if player has the startvalue assigned by the npc.
i didn't fully read his post, his npc shouldn't even need a separate storage value anyways but i thought it was completely useless since the script did nothing to change it
And what is wrong with

local monster = config[target:getName():lower()]
nothing is wrong with it, i created a "name" variable to store the name of the target, instead of having to call it 4(?) times to get the name
 
i got this error in console when i killed the beholder

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:onKill
data/creaturescripts/scripts/tasks.lua:10: attempt to compare number with boolean
stack traceback:
[C]: in function '__le'
data/creaturescripts/scripts/tasks.lua:10: in function <data/creaturescripts/scripts/tasks.lua:4>
 
i got this error in console when i killed the beholder

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:eek:nKill
data/creaturescripts/scripts/tasks.lua:10: attempt to compare number with boolean
stack traceback:
[C]: in function '__le'
data/creaturescripts/scripts/tasks.lua:10: in function <data/creaturescripts/scripts/tasks.lua:4>
the "not" logic is applying to player:getStorageValue and returns a boolean
bool >= 0
change line 10 to: if player:getStorageValue(monster.startstorage) == -1 then
 
Back
Top