• 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...
changed.

now this in console
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:onKill
data/creaturescripts/scripts/tasks.lua:9: attempt to index local 'monster' (a nil value)
stack traceback:
[C]: in function '__index'
data/creaturescripts/scripts/tasks.lua:9: in function <data/creaturescripts/scripts/tasks.lua:4>
 
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

It's userdata, its an object, and player inherits from creature so if there is still a check to make sure it's a player I don't see it as being used magically like it's something else, I get your point the logic player:isPlayer() doesn't make sense for the variable to be named player but it still keeps me from reconstructing an object.

As for the name thing, I didn't even notice it being called so many times.

Also true that a 1 time small variable to check for monster is better than allocating all the rest of the variables prematurely.

changed.

now this in console
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:eek:nKill
data/creaturescripts/scripts/tasks.lua:9: attempt to index local 'monster' (a nil value)
stack traceback:
[C]: in function '__index'
data/creaturescripts/scripts/tasks.lua:9: in function <data/creaturescripts/scripts/tasks.lua:4>

Goto the beginning of line 9, hit enter and paste this:

Code:
if not monster then return true end
 
Last edited by a moderator:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:onKill
data/creaturescripts/scripts/tasks.lua:13: attempt to perform arithmetic on global 'storage' (a nil value)
stack traceback:
[C]: in function '__add'
data/creaturescripts/scripts/tasks.lua:13: in function <data/creaturescripts/scripts/tasks.lua:4>
 
Updating some informations of my problem.

My database - player_storage, without Talk About "task" with the npc. It's empyt.

WwAuqck

The script don't work. It's perfect.
Imgur: The most awesome images on the Internet
Now, after talk with de npc about task, hi, task, yes. he give for my this storage, now the task script work.
It's perfect.
My database - player_storage.
IOIVQAA

Imgur: The most awesome images on the Internet
Now, i'll kill the "First" Rat in my task... After Kill the "First" Rat, automatically i got this storage in database.

My database - player_storage.
46Ybnrv

Imgur: The most awesome images on the Internet
This is the msg that I received after kill the "First" Rat, "My Problem in "Count wrong" The script is starting with 1 rat killed.
JWtdK5j

Imgur: The most awesome images on the Internet

How can i fix this script, to "correct count" according to my database storage?

The script is working as i need, players without this storage 5010, the script don't work. ok... but my npc give for me 5010 stogage to activate the task. ok.

The Script.
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
            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 Tried change a part of script to test.
LUA:
local config = {
     ['rat'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 1}
To
LUA:
local config = {
     ['rat'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 0}

Now, my script work with 5015 storage in database will work automatically. (unsuccessfully) test.
 
I removed, but the count now is

13:48 Task message: 1 of 5 rats killed.
13:48 Task message: 1 of 5 rats killed.
13:48 Task message: 1 of 5 rats killed.
13:49 Task message: 1 of 5 rats killed.
13:49 Task message: 1 of 5 rats killed.

I killed Five rats, and the count not change stay 1 of 5 forever

in my database player_storage is
Key Value
19000 0
 
when i killed the rat now, task don't work and i saw this error above in console
LUA:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/tasks.lua:onKill
data/creaturescripts/scripts/tasks.lua:12: attempt to perform arithmetic on global 'stor' (a nil value)
stack traceback:
        [C]: in function '__add'
        data/creaturescripts/scripts/tasks.lua:12: in function <data/creaturescripts/scripts/tasks.lua:4>
 
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
            player:setStorageValue(monster.storage, stor)
           player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Task message: '..(stor +0)..' of '..monster.amount..' '..target:getName()..'s killed.')
          end
        if (stor +0) == monster.amount then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'Congratulations, you have killed '..(stor +0)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
            player:setStorageValue(monster.storage, stor +1)
        end
    end
    return true
end

Final Storage no more 19000,5. Now is 19000.6, :)

Thanks for help guys
 
Solution
Back
Top