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

[CREATURESCRIPT] onPrepareDeath 2.0.14

trollebror

Developer
Joined
Aug 8, 2009
Messages
362
Reaction score
57
Location
Sweden, Linköping
Hello folks!
Is there a way to make the following on the 2.0.14 in any other way then the onPrepareDeath - since the onPrepareDeath does not work properly for this distro?
Code:
local EXIT_POS = {x = 1280, y = 686, z = 9}
function onPrepareDeath(cid, deathList)
    doTeleportThing(cid, EXIT_POS)
    return doCreatureAddHealth(cid, getCreatureMaxHealth(cid), 65535, 256, true)
end

The purpose of the above code is to teleport a player to a position and heal him if he faces an attack that would otherwise kill him. I will be using it for arena/event. (where you do not want to lose EQ nor skills if you "die")
 
tell me if this le works

creaturescripts/scripts/fightingzone.lua
Lua:
local teleportpos = {x=60,y=60,z=7} -- position you want the player to go to
local fromposition = {x=70,y=70,z=7} -- where the zone will start
local toposition = {x=100,y=100,z=7} -- where it'll end

	function onPreprareDeath(cid, deathList)
		local pos = getPlayerPosition(cid)
		local helth = getPlayerMaxHealth(cid)
		local manaa = getPlayerMaxMana(cid)
		if isInRange(pos, fromposition, toposition) then
			doTeleportThing(cid, teleportpos)
			doCreatureAddHealth(cid, helth)
			doCreatureAddMana(cid, manaa)
		end
	end
 
Sadly, it does not work. You code is clear to me, it should work! But I think that TFS 2.0.14 have problems with onPrepareDeath, not sure though. Could this be done in some other way? Like set the player death loss rate to 0% (items and experience). I know that this function getPlayerLossPercent(cid) exists in 2.0.14 but not the equivalent set-function.

The code above will teleport the player but he will die just after that.
 
It will still not work. Something that is interesting is that the TFS sometimes crashes if the character dies fast. As stated before, you will get saved if you are lucky and the monster that kills you make low damage. But if you're facing 8 demons that will kill you in an instant the server crashes.
 
Try this:
Lua:
local fromPos = {x=, y=, z=}
local toPos = {x=, y=, z=}
local tpPos = {x=, y=, z=} 
function onPreprareDeath(cid, deathList)
local pos = getCreaturePosition(cid)
if isInRange(pos, fromPos, toPos) then
doTeleportThing(cid, teleportpos)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
return false
end
return true
end

Hope it works...
 
Lua:
local orlend = {
	EXIT_POS = {x=1280,y=686,z=9} -- the position the player will get teleported to.
	from_pos = {x=1,y=1,z=1} -- south west corner.
	to_pos = {x=1,y=1,z=1} -- north east corner.
	}
function onKill(cid, target)
	if isInRange(getCreaturePosition(target), orlend.from_pos, orlend.to_pos) then
		doTeleportThing(target, orlend.EXIT_POS)
			doCreatureAddHealth(target, getCreatureMaxHealth(target),1)
end
	return true
end

Lua:
local orlend = {
	EXIT_POS = {x=1280,y=686,z=9} -- the position the player will get teleported to.
	from_pos = {x=1,y=1,z=1} -- south west corner.
	to_pos = {x=1,y=1,z=1} -- north east corner.
	}
function onDeath(cid, corpse, deathList)
	if isInRange(getCreaturePosition(cid), orlend.from_pos, orlend.to_pos) then
		doTeleportThing(cid, orlend.EXIT_POS)
			doCreatureAddHealth(cid, getCreatureMaxHealth(cid),1)
end
	return true
end

Try both :)
 
Last edited:
Thanks for all the help, still not working as it should. You get telported, you get full HP, but you still die. The character get the "You are dead"- message and loses lever and EQ. It could have something to do with my death.lua, please take a look at it. If you somehow could prevent the death.lua from running if you're in the specific area.

Code:
dofile("./config.lua")

function onDeath(cid, corpse, killer)
	doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You are dead.")
	if deathListEnabled == "yes" then
		local byPlayer = 0
		if killer == 0 then
			killerName = "field item"
		else
			if isPlayer(killer) == TRUE then
				byPlayer = 1
			end
			killerName = getCreatureName(killer)
		end

		db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`) VALUES (" .. getPlayerGUID(cid) .. ", " .. os.time() .. ", " .. getPlayerLevel(cid) .. ", '" .. escapeString(killerName) .. "', " .. byPlayer .. ");")
		local resultId = db.storeQuery("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")

		local deathRecords = 0
		while tmpResultId ~= false do
			tmpResultId = result.next(resultId)
			deathRecords = deathRecords + 1
		end

		if resultId ~= false then
			if sqlType == "mysql" then
				while deathRecords > maxDeathRecords do
					db.query("DELETE FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1;")
					deathRecords = deathRecords - 1
				end
			else
				while deathRecords > maxDeathRecords do
					db.query("DELETE FROM `player_deaths` WHERE `rowid` = (SELECT `rowid` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " ORDER BY `time` LIMIT 1);")
					deathRecords = deathRecords - 1
				end
			end
		end

		if byPlayer == 1 then
			local targetGuild = getPlayerGuildId(cid)
			if targetGuild ~= 0 then
				local killerGuild = getPlayerGuildId(killer)
				if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(cid, killer) == TRUE then
					local warId = false
					resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. ") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. "));")
					if resultId ~= false then
						warId = result.getDataInt(resultId, "id")
						result.free(resultId)
					end

					if warId ~= false then
						db.query("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(getCreatureName(killer)) .. ", " .. db.escapeString(getCreatureName(cid)) .. ", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. warId .. ");")
					end
				end
			end
		end
	end
end
 
Lua:
local corpse_ids = {
        3065, -- female
        3058  -- male
}

---------------------------
local arena = {------------
---------------------------
-- Put your pvp areas here:

{main_pos = {x=x, y=x, z=x}, frompos = {x=x, y=x, z=x}, topos = {x=x, y=x, z=x}},


} ------------------------- main pos is the temple main pos

function onStatsChange(cid, attacker, type, combat, value)
        if combat == COMBAT_HEALING then
                return true
        end

        if getCreatureHealth(cid) > value then
                return true
        end

        local arenaID = 0
        for i = 1, #arena do
                if isInRange(getCreaturePosition(cid), arena[i].frompos, arena[i].topos) then
                        arenaID = i
                        break
                end
                if i == #arena then
                        return true
                end
        end

        local corpse = doCreateItem((corpse_ids[getPlayerSex(cid)+1]), 1, getPlayerPosition(cid))
        doItemSetAttribute(corpse, "description", "You recognize "..getCreatureName(cid)..". He was killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item")..".\n[PvP Arena Kill]")

        doTeleportThing(cid, arena[arenaID].main_pos)
        doSendMagicEffect(getCreaturePosition(cid), 10)

        doRemoveConditions(cid)
        doCreatureAddHealth(cid, getCreatureMaxHealth(cid) - getCreatureHealth(cid))
        doCreatureAddMana(cid, getCreatureMaxMana(cid) - getCreatureMana(cid))

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You got killed by "..(isMonster(attacker) and "a "..string.lower(getCreatureName(attacker)) or isCreature(attacker) and getCreatureName(attacker) or "a field item").." in a pvp arena.")
        if isPlayer(attacker) then
                doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "You killed "..getCreatureName(cid).." in a pvp arena.")
        end
        return false
end

copy-pasted from my pc. dunno the author
 
I am pretty sure that TFS 0.2.14 does not support that function onStatsChange. How does your .xml code look like where you register the .lua file?

edit: what distro are you using Cyro?
 
Last edited:
this is TFS 0.4 rev 3884 maybe not working @ TFS 2.0.14. then I just failed with all ways :D

I hope someone can get the script working for u :) GL
 
Did you tried mine? Cause all make things with onPrepareDeath, but nobody make it return false so players will still die after all....

I will copy paste it here again...

Lua:
local fromPos = {x=, y=, z=}
local toPos = {x=, y=, z=}
local tpPos = {x=, y=, z=} 
function onPreprareDeath(cid, deathList)
local pos = getCreaturePosition(cid)
if isInRange(pos, fromPos, toPos) then
doTeleportThing(cid, teleportpos)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
return false
end
return true
end

@XPRIMEX: Yeah, he said that it doesnt work, but cause players still die... And that is because they dont return false... :/
 
Well now i give to you point
now death that's in C++
is no way to make script on death do that action
because anyways he will dead dead dead
and no way to make it with script
SHOULD EDIT C++ !!
 

Similar threads

Back
Top