- Joined
- Dec 26, 2013
- Messages
- 1,665
- Solutions
- 11
- Reaction score
- 928
Hello Otland. I have been trying to convert over @narko 's KDR for TFS 1.0 and been having some problems. I understand that onLook is done in events now and not creaturescripts. So I have tried altering my onLook function in players.lua file to look like this
and I get this error
The error only happens if I am on GM Character which is already one prolbem because I was trying for my bit of code to work for all players not just GM... second is obviously its not working because of a problem in the getDeathsPlayer function but doesn't seem to have a problem with the getKillsPlayer function.... Any help guys? Yes my database has deaths and frags and I have tried with characters set up with 0 3 4 and 2 deaths, all with 4 or more frags....
Code:
function Player:onLook(thing, position, distance)
local description = "You see " .. thing:getDescription(distance)
function getKillsPlayer(cid)
local Info = db.getResult("SELECT `frags` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
local frags= Info:getDataInt("frags")
return frags
end
function getDeathsPlayer(cid)
local Info = db.getResult("SELECT `deaths` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
local deaths = Info:getDataInt("deaths")
return deaths
end
if self:getGroup():getAccess() then
if thing:isItem() then
description = string.format("%s\nItemID: [%d]", description, thing:getId())
local actionId = thing:getActionId()
if actionId ~= 0 then
description = string.format("%s, ActionID: [%d]", description, actionId)
end
local uniqueId = thing:getAttribute(ITEM_ATTRIBUTE_UNIQUEID)
if uniqueId > 0 and uniqueId < 65536 then
description = string.format("%s, UniqueId: [%d]", description, uniqueId)
end
description = description .. "."
local itemType = thing:getType()
local transformEquipId = itemType:getTransformEquipId()
local transformDeEquipId = itemType:getTransformDeEquipId()
if transformEquipId ~= 0 then
description = string.format("%s\nTransformTo: [%d] (onEquip).", description, transformEquipId)
elseif transformDeEquipId ~= 0 then
description = string.format("%s\nTransformTo: [%d] (onDeEquip).", description, transformDeEquipId)
end
local decayId = itemType:getDecayId()
if decayId ~= -1 then
description = string.format("%s\nDecayTo: [%d]", description, decayId)
end
elseif thing:isCreature() then
if isPlayer(thing.uid) then
if(getDeathsPlayer(cid)==0)then
kdr = getKillsPlayer(cid)
else
if(getDeathsPlayer(cid)~=0) then
kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
end
end
doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Killed: ["..getKillsPlayer(thing.uid).."] Players."..(getPlayerSex(thing.uid) == 0 and "\nShe" or "\nHe") .. " has Died: ["..getDeathsPlayer(thing.uid).."] Times."..(getPlayerSex(thing.uid) == 0 and "\nHer" or "\nHis") .. " Kill Death Ratio is: ["..kdr.."].")
end
if(thing.uid == cid) then
if(getDeathsPlayer(cid)==0)then
kdr = getKillsPlayer(cid)
else
if(getDeathsPlayer(cid)~=0) then
kdr = getKillsPlayer(thing.uid)/getDeathsPlayer(thing.uid)
end
doPlayerSetSpecialDescription(thing.uid, "\nYou have Killed: ["..getKillsPlayer(thing.uid).."] Players.\nYou have Died: ["..getDeathsPlayer(thing.uid).."] Times.\nYour Kill Death Ratio is: ["..kdr.."].")
end
return true
end
local str = "%s\nHealth: [%d / %d]"
if thing:getMaxMana() > 0 then
str = string.format("%s, Mana: [%d / %d]", str, thing:getMana(), thing:getMaxMana())
end
description = string.format(str, description, thing:getHealth(), thing:getMaxHealth()) .. "."
end
local position = thing:getPosition()
description = string.format(
"%s\nPosition: [X: %d] [Y: %d] [Z: %d].",
description, position.x, position.y, position.z
)
-- if thing:isCreature() then
--- if thing:isPlayer() then
--- description = string.format("%s\nIP: [%s].", description, Game.convertIpToString(thing:getIp()))
--- end
--- end
end
self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
and I get this error
Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onLook
data/events/scripts/player.lua:14: attempt to concatenate a boolean value
stack traceback:
[C]: ?
data/events/scripts/player.lua:14: in function 'getDeathsPlayer'
data/events/scripts/player.lua:59: in function <data/events/scripts/play
er.lua:5>
The error only happens if I am on GM Character which is already one prolbem because I was trying for my bit of code to work for all players not just GM... second is obviously its not working because of a problem in the getDeathsPlayer function but doesn't seem to have a problem with the getKillsPlayer function.... Any help guys? Yes my database has deaths and frags and I have tried with characters set up with 0 3 4 and 2 deaths, all with 4 or more frags....