- Joined
- Dec 26, 2013
- Messages
- 1,667
- Solutions
- 11
- Reaction score
- 934
Ok first off credits to respective owners.
@narko for creating original code and solving problem for looking at a player with no deaths.
@Amiroslo for changing mod into creaturescripts in first place
@Elwyn for fixing functions getKillsPlayer(), getDeathsPlayer(), and all other work found here http://otland.net/threads/tfs-1-0-onlook.221582/
Special thanks to Elwyn for taking the time to work with me until we got it right!
Now for the scripts!
/creaturescripts/scripts/onkill.lua
/creaturescripts/scripts/onpd.lua
in creaturescripts.xml add
in /creaturescripts/scripts/login.lua add
in /events/scripts/player.lua add
to the very top !
and in same file: (creaturescripts/scripts/player.lua)
replace the onLook function for this one
Then finally execute this command in sql in phpmyadmin for your database
@narko for creating original code and solving problem for looking at a player with no deaths.
@Amiroslo for changing mod into creaturescripts in first place
@Elwyn for fixing functions getKillsPlayer(), getDeathsPlayer(), and all other work found here http://otland.net/threads/tfs-1-0-onlook.221582/
Special thanks to Elwyn for taking the time to work with me until we got it right!
Now for the scripts!
/creaturescripts/scripts/onkill.lua
Code:
function onKill(cid, target, damage, flags)
if isPlayer(target) == true then
db.query("UPDATE `players` SET `frags` = `frags` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
doCreatureSay(cid, '+1 Kill Point!', TALKTYPE_ORANGE_1)
end
return true
end
/creaturescripts/scripts/onpd.lua
Code:
function onPrepareDeath(cid, deathList, lastHitKiller, mostDamageKiller)
if isPlayer(cid) == true then
db.query("UPDATE `players` SET `deaths` = `deaths` + 1 WHERE id = " .. getPlayerGUID(cid) .. ";")
doCreatureSay(cid, '+1 Death Point!', TALKTYPE_ORANGE_1)
end
return true
end
Code:
<event type="kill" name="killpoint" script="onkill.lua"/>
<event type="preparedeath" name="deathpoint" script="onpd.lua"/>
Code:
player:registerEvent("killpoint")
player:registerEvent("deathpoint")
Code:
function getKillsPlayer(cid)
local Info = db.storeQuery("SELECT `frags` FROM `players` WHERE `id` = " .. cid:getGuid())
local frags = result.getDataInt(Info, 'frags')
result.free(Info)
return frags
end
function getDeathsPlayer(cid)
local Info = db.storeQuery("SELECT `deaths` FROM `players` WHERE `id` = " .. cid:getGuid())
local deaths = result.getDataInt(Info, 'deaths')
result.free(Info)
return deaths
end
and in same file: (creaturescripts/scripts/player.lua)
replace the onLook function for this one
Code:
function Player:onLook(thing, position, distance)
local description = "You see " .. thing:getDescription(distance)
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
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
if thing:isCreature() then
if thing:isPlayer() then
if(getDeathsPlayer(thing)==0)then
kdr = getKillsPlayer(thing)
else
if(getDeathsPlayer(thing)~=0) then
kdr = getKillsPlayer(thing)/getDeathsPlayer(thing)
end
end
description = string.format("%s\nThis player killed %s and died %s times. Their KDR is %s", description, getKillsPlayer(thing), getDeathsPlayer(thing), kdr)
end
end
self:sendTextMessage(MESSAGE_INFO_DESCR, description)
end
Code:
ALTER TABLE `players` ADD `frags` INT( 11 ) NOT NULL DEFAULT '0';
ALTER TABLE `players` ADD `deaths` INT( 11 ) NOT NULL DEFAULT '0';