Hello everyone, modified script "playerDeath" and added protection of low-level players before his death. When the low-level player will be put to death, is moved into the his temple, without the loss of experience and items!
replace data/creaturescripts/playerDeath.lua for:
and replace in data/creaturescripts/creaturescripts.xml
for:
and in config.lua add:
Thanks,
Yours, Azi.
replace data/creaturescripts/playerDeath.lua for:
PHP:
local config = {
deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
sqlType = getConfigInfo('sqlType'),
maxDeathRecords = getConfigInfo('maxDeathRecords'),
deadProtection = getConfigInfo('deadProtection')
}
config.sqlType = config.sqlType == "sqlite" and DATABASE_ENGINE_SQLITE or DATABASE_ENGINE_MYSQL
function onPrepareDeath(cid, lastHitKiller, mostDamageKiller)
if(isPlayer(cid))then
if(math.abs(config.deadProtection) >= getPlayerLevel(cid))then
doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
doCreatureAddHealth(cid, getCreatureMaxHealth(cid), TRUE)
doCreatureAddMana(cid, (getCreatureMaxMana(cid) - getCreatureMana(cid)))
doSendMagicEffect(getCreaturePosition(cid), 37)
doRemoveCondition(cid, CONDITION_INFIGHT)
else
if(config.deathListEnabled ~= TRUE) then
return TRUE
end
local hitKillerName = "field item"
local damageKillerName = ""
if(lastHitKiller ~= FALSE) then
if(isPlayer(lastHitKiller) == TRUE) then
hitKillerName = getPlayerGUID(lastHitKiller)
else
hitKillerName = getCreatureName(lastHitKiller)
end
if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
if(isPlayer(mostDamageKiller) == TRUE) then
damageKillerName = getPlayerGUID(mostDamageKiller)
else
damageKillerName = getCreatureName(mostDamageKiller)
end
end
end
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) .. ");")
local rows = db.getResult("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
if(rows:getID() ~= -1) then
local amount = rows:getRows(true) - config.maxDeathRecords
if(amount > 0) then
if(config.sqlType == DATABASE_ENGINE_SQLITE) then
for i = 1, amount do
db.executeQuery("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
end
else
db.executeQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT " .. amount .. ";")
end
end
end
return TRUE
end
end
end
and replace in data/creaturescripts/creaturescripts.xml
PHP:
<event type="death" name="PlayerDeath" event="script" value="playerdeath.lua"/>
PHP:
<event type="preparedeath" name="PlayerDeath" event="script" value="playerdeath.lua"/>
and in config.lua add:
PHP:
deadProtection = 20 -- max lvl in protection
Thanks,
Yours, Azi.