MaXwEllDeN

Untitled

May 15th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. local config = {
  2.     deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
  3.     sqlType = getConfigInfo('sqlType'),
  4.     maxDeathRecords = getConfigInfo('maxDeathRecords')
  5. }
  6.  
  7. config.sqlType = config.sqlType == "sqlite" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL
  8.  
  9. function onDeath(cid, corpse, lastHitKiller, mostDamageKiller)
  10.     if(config.deathListEnabled ~= TRUE) then
  11.         return
  12.     end
  13.  
  14.     local hitKillerName = "field item"
  15.     local damageKillerName = ""
  16.  
  17.     if lastHitKiller then
  18.         if isPlayer(lastHitKiller) then
  19.             hitKillerName = getPlayerGUID(lastHitKiller)
  20.         else
  21.             hitKillerName = getCreatureName(lastHitKiller)
  22.         end
  23.  
  24.         if mostDamageKiller and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller) then
  25.             if(isPlayer(mostDamageKiller) == TRUE) then
  26.                 damageKillerName = getPlayerGUID(mostDamageKiller)
  27.             else
  28.                 damageKillerName = getCreatureName(mostDamageKiller)
  29.             end
  30.         end
  31.     end
  32.  
  33.     db.executeQuery("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `altkilled_by`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", " .. db.escapeString(hitKillerName) .. ", " .. db.escapeString(damageKillerName) .. ");")
  34.     local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
  35.     if(rows:getID() ~= -1) then
  36.         local amount = rows:getRows(true) - config.maxDeathRecords
  37.         if(amount > 0) then
  38.             if(config.sqlType == DATABASE_ENGINE_SQLITE) then
  39.                 for i = 1, amount do
  40.                     db.executequery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
  41.                 end
  42.             else
  43.                 db.executequery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
  44.             end
  45.         end
  46.     end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment