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

Trying add new monster task Script Error TFS 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
This is my script of task, is working perfectly. with just one monster in config.

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)+0
        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_STATUS_CONSOLE_ORANGE, '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

My problem is when i try add other monster in script, my script stays like this

LUA:
local config = {
     ['rat'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 1}
     ['troll'] = {amount = 10, storage = 20000, startstorage = 5011, 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)+0
        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_STATUS_CONSOLE_ORANGE, '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 see this error msg in console when i open the server
Code:
[Warning - Event::checkScript] Can not load script: scripts/tasks.lua
data/creaturescripts/scripts/tasks.lua:3: '}' expected (to close '{' at line 1) near '['
 
Solution
X
This is my script of task, is working perfectly. with just one monster in config.

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)+0
        if stor < monster.amount and player:getStorageValue(monster.startstorage) >=...
This is my script of task, is working perfectly. with just one monster in config.

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)+0
        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_STATUS_CONSOLE_ORANGE, '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

My problem is when i try add other monster in script, my script stays like this

LUA:
local config = {
     ['rat'] = {amount = 5, storage = 19000, startstorage = 5010, startvalue = 1}
     ['troll'] = {amount = 10, storage = 20000, startstorage = 5011, 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)+0
        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_STATUS_CONSOLE_ORANGE, '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 see this error msg in console when i open the server
Code:
[Warning - Event::checkScript] Can not load script: scripts/tasks.lua
data/creaturescripts/scripts/tasks.lua:3: '}' expected (to close '{' at line 1) near '['
put a comma at the end of line 2
 
Solution
i need put a comma in the end line of all monster's added?
A table is basically an array.
these two tables are identical, but look different. Both require commas in order to separate each section of the array.
Code:
local table = {[1] = one, [2] = two, [3] = three}
Code:
local table = {
    1 = one, 
    2 = two, 
    3 = three
}
Your table is an array holding arrays, but the same principle applies. Need them commas yo.
 
Back
Top