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

TFS 1.X+ script erro

jel

Member
Joined
Mar 22, 2014
Messages
302
Reaction score
12
hello, I implemented this on my server, but I get this error, any solution?

error:
Code:
[2023-17-03 11:50:09.429] [error] Lua script error:
scriptInterface: [Event Interface]
scriptId: [data/events/scripts/monster.lua:Monster@onDropLoot]
timerEvent: []
 callbackId:[]
function: []
error [data/events/scripts/monster.lua:45: attempt to index local 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/monster.lua:45: in function <data/events/scripts/monster.lua:22>]
line 45: local skillbonus = player:getSkillLevel(SKILL_FISHING)
funcion:
Lua:
-- SkillBonus
local skillbonus = player:getSkillLevel(SKILL_FISHING)

if player and player:getSkillLevel(SKILL_FISHING) >= 0 and player:getSkillLevel(SKILL_FISHING) < 100 then
skillbonus = skillbonus * 0.2
elseif player and player:getSkillLevel(SKILL_FISHING) > 100 then
skillbonus = 100/2
end

for i = 1, #monsterLoot do
monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * skillbonus) --
skill bonus
 
Well the error is pretty explicit..
It doesn't have any reference to the player.

If there is no guarantee that player will exist when this function is being called.. you could wrap the function with an if statement.

Lua:
-- SkillBonus
local skillbonus = 1 -- default skill bonus

if player and player:isPlayer() then
	skillbonus = player:getSkillLevel(SKILL_FISHING)
	
	if player and player:getSkillLevel(SKILL_FISHING) >= 0 and player:getSkillLevel(SKILL_FISHING) < 100 then
		skillbonus = skillbonus * 0.2
	elseif player and player:getSkillLevel(SKILL_FISHING) > 100 then
		skillbonus = 100/2
	end
end

for i = 1, #monsterLoot do
monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * skillbonus)
 
Well the error is pretty explicit..
It doesn't have any reference to the player.

If there is no guarantee that player will exist when this function is being called.. you could wrap the function with an if statement.

Lua:
-- SkillBonus
local skillbonus = 1 -- default skill bonus

if player and player:isPlayer() then
    skillbonus = player:getSkillLevel(SKILL_FISHING)
  
    if player and player:getSkillLevel(SKILL_FISHING) >= 0 and player:getSkillLevel(SKILL_FISHING) < 100 then
        skillbonus = skillbonus * 0.2
    elseif player and player:getSkillLevel(SKILL_FISHING) > 100 then
        skillbonus = 100/2
    end
end

for i = 1, #monsterLoot do
monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * skillbonus)

gave this error:

line 47: if player:isPlayer() then
Code:
[2023-17-03 12:31:25.425] [error] Lua script error:
scriptInterface: [Event Interface]
scriptId: [data/events/scripts/monster.lua:Monster@onDropLoot]
timerEvent: []
 callbackId:[]
function: []
error [data/events/scripts/monster.lua:47: attempt to index local 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/events/scripts/monster.lua:47: in function <data/events/scripts/monster.lua:22>]
 
gave this error:

line 47: if player:isPlayer() then
you must've copied before my edit.

try copying again.

if player:isPlayer() then
if player and player:isPlayer() then
 
Back
Top