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

CreatureEvent Low Level Death Protection!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
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:
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"/>
for:
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.
 
Very Nice

---Edit //

Can edit the script? :p

If player dead by player the other player get injust, and the protected guy go to temple without the loss of experience and etc~


And if player dead to monster, player will lose EXP, but not items :}


Can you do it please? :D


thx a lot
 
Its good if teleported to temple after a player has killed you, while when being killed by a monster you die and loose stuff like normal.

Could you fix that?
 
Im don't have time to test, can someone?
* Not frag count (BUG - send frag msg)
* Only protect for killers... all/monster/player
* Loss exp (configurate %)

in config add:
PHP:
deadProtection = 20 -- max lvl in protection
deadProtectionBy = "all" -- works when killer: all/monster/players
deadProtectionExpLose = 7 -- % of exp lose

and playerdeath.lua
PHP:
 local config = {
    deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
    sqlType = getConfigInfo('sqlType'),
    maxDeathRecords = getConfigInfo('maxDeathRecords'),
    deadProtection = getConfigInfo('deadProtection'),
    fragTime =  getConfigInfo('timeToDecreaseFrags'),
    deadProtectionBy = getConfigInfo('deadProtectionBy'),
    deadProtectionExpLose = getConfigInfo('deadProtectionExpLose')
}
local prtect = 0
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)) and (string.lower(config.deadProtectionBy) == "all" or (string.lower(config.deadProtectionBy) == "monster" and not(isPlayer(lastHitKiller))) or (string.lower(config.deadProtectionBy) == "player" and isPlayer(lastHitKiller))) then
            protect = 1
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
            doPlayerAddExp(cid, -((getPlayerExperience(cid)/100)*config.deadProtectionExpLose))
            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 and protect == 1) then
                    hitKillerName = getPlayerGUID(lastHitKiller)
                    doPlayerSetRedSkullTicks(lastHitKiller, getPlayerRedSkullTicks(lastHitKiller) - config.fragTime)
                else
                    hitKillerName = getCreatureName(lastHitKiller)
                end

                if(mostDamageKiller ~= FALSE and mostDamageKiller ~= lastHitKiller and getCreatureName(mostDamageKiller) ~= getCreatureName(lastHitKiller)) then
                    if(isPlayer(mostDamageKiller) == TRUE protect == 1) then
                        damageKillerName = getPlayerGUID(mostDamageKiller)
                        doPlayerSetRedSkullTicks(mostDamageKiller, getPlayerRedSkullTicks(mostDamageKiller) - config.fragTime)
                    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
protect = 0
end

I SAID, NOT TESTED! :D
 
Last edited:
but I think, if player kill the noob and dont get injust, all time level 100~200 will kill level 8 and if someone do it a lot, this one will leave server
maybe is better you use to player get frag, be cause if have noob level in trap, the guy can kill this noob, and go to the trap :D
 
A couple flaws in the script like what if there is a group of 50 level 20s Pking, everytime they die they come back at the Same Level with the same stuff 0.0

Sincerely,
Yours Pablol
 
@Azi
I've tested your new script. Only 1 bug in line 8 you've forgotten to add "," :)
Anyway the script is working in 100% (Yes, i've tested it).
Fixed version:
Code:
 local config = {
    deathListEnabled = getBooleanFromString(getConfigInfo('deathListEnabled')),
    sqlType = getConfigInfo('sqlType'),
    maxDeathRecords = getConfigInfo('maxDeathRecords'),
    deadProtection = getConfigInfo('deadProtection'),
    fragTime =  getConfigInfo('timeToDecreaseFrags'),
    deadProtectionBy = getConfigInfo('deadProtectionBy'),
    deadProtectionExpLose = getConfigInfo('deadProtectionExpLose')
}
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)) and (string.lower(config.deadProtectionBy) == "all" or (string.lower(config.deadProtectionBy) == "monster" and not(isPlayer(lastHitKiller))) or (string.lower(config.deadProtectionBy) == "player" and isPlayer(lastHitKiller))) then
            doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
            doPlayerAddExp(cid, -((getPlayerExperience(cid)/100)*config.deadProtectionExpLose))
            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)
                    doPlayerSetRedSkullTicks(lastHitKiller, getPlayerRedSkullTicks(lastHitKiller) - config.fragTime)
                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)
                        doPlayerSetRedSkullTicks(mostDamageKiller, getPlayerRedSkullTicks(mostDamageKiller) - config.fragTime)
                    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
 
Now it works fine for me, without any bugs (YET) :p Good job!
 
Back
Top