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

update script to tfs 1.2

jurass

New Member
Joined
Jul 7, 2015
Messages
98
Reaction score
3
Location
Poland
local config = {
nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
nazwaPotwora = 'Fire Stone' -- nazwa potwora
}
function onKill(cid, target)
if (getCreatureName(target) == config.nazwaPotwora) then
doPlayerAddItem(cid,config.nagroda.id,config.nagroda.ilosc)
doPlayerAddLevel(cid, 2)
doPlayerSendTextMessage(cid, 22, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody
return true
else
return true
end
end

who can help
 
Solution
The error message indicates that the method 'getMonster' does not exist. Add this piece of code to your Lua core library:
Code:
function Creature.getMonster(self)
    return self:isMonster() and self or nil
end
Something like this:
Code:
local config = {
    nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() ~= config.monsterName then
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end

Moved this thread to requests instead of support.
 
@HalfAway dont work
i need scirpt who after kill dragon , give 2 levels and 25 crystal coins , you know?
event boss , all who kill boss event receive 2 lvl and 25 crystail coins
 
Something like this:
Code:
local config = {
    nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() ~= config.monsterName then
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end

Moved this thread to requests instead of support.

The name on the monsterName must be lower.
 
That's one way of solving the issue. The other way would be to not compare lowercased strings and just check input string vs expected string

Code:
local config = {
   nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() ~= config.monsterName:lower() then
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end

^ President vankk told you to do this.

Code:
local config = {
   nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName() ~= config.monsterName then -- This would also work, if and only if config.Monstername == actual monstername(defined one)
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end
 
Last edited:
i have problem :)
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/test.lua:onKill
data/creaturescripts/scripts/custom/test.lua:14: attempt to call method 'getMonster' (a nil value)
stack traceback:
[C]: in function 'getMonster'
data/creaturescripts/scripts/custom/test.lua:14: in function <data/creaturescripts/scripts/custom/test.lua:13>
 
i have problem :)
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/test.lua:eek:nKill
data/creaturescripts/scripts/custom/test.lua:14: attempt to call method 'getMonster' (a nil value)
stack traceback:
[C]: in function 'getMonster'
data/creaturescripts/scripts/custom/test.lua:14: in function <data/creaturescripts/scripts/custom/test.lua:13>
show me the script
 
@tokenzz
Code:
local config = {
   nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName() ~= config.monsterName then -- This would also work, if and only if config.Monstername == actual monstername(defined one)
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end
 
@tokenzz
Code:
local config = {
   nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Rat" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    if targetMonster:getName() ~= config.monsterName then -- This would also work, if and only if config.Monstername == actual monstername(defined one)
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end
and you killed a rat, and did as I said " This would also work, if and only if config.Monstername == actual monstername(defined one)" ?
 
When i killed rat i have bug :
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/test.lua:onKill
data/creaturescripts/scripts/custom/test.lua:14: attempt to call method 'getMonster' (a nil value)
stack traceback:
        [C]: in function 'getMonster'
        data/creaturescripts/scripts/custom/test.lua:14: in function <data/creaturescripts/scripts/custom/test.lua:13>
 
change to:

Code:
local targetMonster = target:getMonster()
if targetMonster == nil then
    return true
end
print(targetMonster)

Code:
if targetMonster:getName() ~= "Rat" then
    print(targetMonster:getName())
    return true
end
print(targetMonster:getName())

try this and tell me what error you get.

If you receive an error, keep the original code and just edit this part + tell me the error

Code:
if targetMonster:getName():lower() ~= config.monsterName:lower() then
    return true
end
 
I now have script :
Code:
local config = {
   nagroda = {id = 12681, ilosc = 2}, -- id, ilosc
    nazwaPotwora = 'Fire Stone', -- nazwa potwora
    level = 2, -- amount of levels you want to gain.
    monsterName = "Cyclops" -- The name of the monster that should trigger the script.
}

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end

function onKill(creature, target)
    if targetMonster:getName() ~= "Cyclops" then
    print(targetMonster:getName())
    return true
end
    if targetMonster:getName() ~= config.monsterName then -- This would also work, if and only if config.Monstername == actual monstername(defined one)
        return true
    end

    local player = creature:getPlayer()

    player:addItem(config.nagroda.id, config.nagroda.ilosc)
    player:addExperience(getExpForLevel(player:getLevel() + config.level) - player:getExperience(), false)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Przyczyniles sie do zabicia Fire Stone! otrzymujesz nagrode, ktora znajdziesz w plecaku i 2 lvle.") -- komunikat pdczas otrzymywania nagrody

    return true
end


and i have bug :
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/test.lua:onKill
data/creaturescripts/scripts/custom/test.lua:14: attempt to index global 'targetMonster' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/custom/test.lua:14: in function <data/creaturescripts/scripts/custom/test.lua:13>






I only want script -
all players who kill boss event receive 2 lvl and 25 crystail coins :)
 
The error message indicates that the method 'getMonster' does not exist. Add this piece of code to your Lua core library:
Code:
function Creature.getMonster(self)
    return self:isMonster() and self or nil
end
 
Solution
Back
Top