• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[GESIOR AAC] Show if you died with either AOL or BLESS.

Taste

Member
Joined
Apr 6, 2012
Messages
81
Reaction score
5
Hello OTland members,

I would like to request a PHP function that shows if a person died with either AOL or Blessings.

Something like this.

Code:
Taste died at level 99 by a dragon lord [[COLOR="#FFD700"]AOL[/COLOR]].
Taste died at level 100 by a dragon lord [[COLOR="#FF0000"]BLESS[/COLOR]].

Sincerely,
Taste
 
I could help you with the scripts ingame and the queries but I don't know how to call the queries on php (gesior).

deathcheck.lua
LUA:
function onDeath(cid, corpse, deathList)

	local id = getPlayerGUID(cid)
	if(getPlayerSlotItem(cid, 2) == 2173) then
		db.executeQuery("INSERT INTO `deathcheck` (`player_id`, `protection`) VALUES (".. id ..", 'AOL');")
	elseif(getPlayerBlessing(cid) > 1) then
		db.executeQuery("INSERT INTO `deathcheck` (`player_id`, `protection`) VALUES (".. id ..", 'BLESS');")
	elseif(getPlayerSlotItem(cid, 2) == 2173 and getPlayerBlessing(cid) > 1) then
		db.executeQuery("INSERT INTO `deathcheck` (`player_id`, `protection`) VALUES (".. id ..", 'AOL + BLESS');")
	else
		db.executeQuery("INSERT INTO `deathcheck` (`player_id`, `protection`) VALUES (".. id ..", 'NO PROTECTION');")
	end
	
	return true
end

SQL:
CREATE TABLE IF NOT EXISTS `deathcheck` (
  `player_id` int(11) NOT NULL AUTO_INCREMENT,
  `protection` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `protection` (`protection`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
 
Last edited:
I appreciate your contribution.

Though the SQL query should look like this, you probably missed to add it. :p

SQL:
CREATE TABLE IF NOT EXISTS `deathcheck` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `player_id` INT(11) NOT NULL,
  `protection` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `protection` (`protection`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
 
I appreciate your contribution.

Though the SQL query should look like this, you probably missed to add it. :p

SQL:
CREATE TABLE IF NOT EXISTS `deathcheck` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `player_id` INT(11) NOT NULL,
  `protection` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `protection` (`protection`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

What?
The columb 'id' is not in use in the onDeath script... -.- Only 'player_id'...
 
I could help you with the scripts ingame and the queries but I don't know how to call the queries on php (gesior).

I let someone else do it because I don't know how to do it.


and php.?

- - - Updated - - -

elseif(getPlayerBlessing(cid) < 6) then

no?

elseif(getPlayerBlessing(cid) > 1) then

Oh, should edit it.
But: elseif(getPlayerBlessing(cid) < 6) then
works too
 
To make it works like on narvia.eu you must edit source (C++), it's not possible to make it in LUA as it must (should) save AOL/BLESS in table:
player_deaths
(add in it columns `aol`, `bless` to store informations)
and these informations can't be edited from LUA script (no access to last 'DeathID' [`id` added in `player_deaths`] added).
You also should use event prepareDeath, not death.

EDIT:
It's possible to make it in LUA, but much better (and use less CPU, less SQL queries) if you make it in C++.
 
Last edited:
CODE WROTE FOR TFS 0.3.6, SHOULD WORK ON 0.4
CODE NOT TESTED, DO NOT INSTALL ON 'WORKING' SERVER
It can freez server after death with AoL or bless etc. I did not even run it to check if LUA code has proper 'LUA' code format.


To make it works like on narvia you need code like this (what to do and how to install in comments in script):
LUA:
--[[
In PHPMyAdmin:
ALTER TABLE `player_deaths`  ADD `aol` INT(1) NOT NULL DEFAULT '0',  ADD `bless` INT(1) NOT NULL DEFAULT '0'
]]
--[[
In creaturescripts.xml:
	<event type="login" name="deathAolBless_login" event="script" value="deathAolBless.lua"/>
	<event type="preparedeath" name="deathAolBless_preparedeath" event="script" value="deathAolBless.lua"/>
	<event type="logout" name="deathAolBless_logout" event="script" value="deathAolBless.lua"/>
]]

-- file name: data/creaturescripts/scripts/deathAolBless.lua, YES, it's one file, not 3
local storeAOL = 23232
local storeBless = 23233

-- in login we add preparedeath event to 'cid' and set creaturestorages to 0,
-- because we don't want to use old (from deaths before login) informations
function onLogin(cid)
	registerCreatureEvent(cid, "deathAolBless_preparedeath")
	doSetCreatureStorage(cid, storeAOL, 0)
	doSetCreatureStorage(cid, storeBless, 0)
	return true
end

-- in this script we check if player wear AoL in neckles slot and if he has any blessing, and store informations in creaturestorage
function onPrepareDeath(cid)
	if(getPlayerSlotItem(cid, 2) == 2173) then
		doSetCreatureStorage(cid, storeAOL, 1)
	end
	if(getPlayerBlessing(cid) >= 1) then
		doSetCreatureStorage(cid, storeBless, 1)
	end
	return true
end

-- player logout, server executes preparedeath event before logout event (if player died)
-- so values should be in 'storage' if he had aol/bless
-- ONLY PROBLEM with LUA script is when player do 'relog' in 2 seconds [why 2? read script comments] after death:
-- 1. he dies, server executes prepare death and logout events, it saves if he had aol/bless in `player_deaths` table
-- 2. player see on screen button to login again, he press it and login in temple (server executes onLogin)
-- 3. he logouts very fast (less then 2 seconds from death), server executes again onLogout script,
--    but in creaturestorage are values 0 from onLogin script
--
-- that's why I said it will work with 99.9% deaths and you need C++ code to make it work always

function onLogout(cid)
	-- we don't need to run any SQL query if no AoL and no Bless, by default these columns in table contains 0
	if(getCreatureStorage(cid, storeAOL) == 1 OR getCreatureStorage(cid, storeBless) == 1) then
		-- we try to get death of 'this' (cid) player that happend in last 2 seconds
		-- it's must be there (if he died, not just logout) before server logout him
		local lastDeathDB = db.getResult("SELECT `id` FROM `player_deaths` WHERE `player_id` = " .. getPlayerGUID(cid) .. " AND `date` >= " .. (os.time()-2) .. " LIMIT 1;")
		-- if result of query is -1, then there is no result, when it's not equal -1 we can do something with it..
		if(lastDeathDB:getID() ~= -1) then
			-- ..in this case we "SELECT `id`" which is number, so we get it from query result by function getDataInt("id")
			local lastDeath = lastDeathDB:getDataInt("id")
			-- after we did all what we wanted with result of query, we must 'free' memory in which that result is stored
			-- if we don't do it, server will use more and more RAM and work slower and slower, it's called 'memory leak'
			lastDeathDB:free()
			-- REMEMBER that you can't 'free' result that got ID == -1 !!
			db.executeQuery("UPDATE `player_deaths` SET `aol` = " .. getCreatureStorage(cid, storeAOL) .. ", `bless` = " .. getCreatureStorage(cid, storeBless) .. ";")
		end
	end

	return true
end
After I made it and added soo many comments I found out how to make it not possible to remove results by logout in 2 seconds after login [add one more storage for cid and last selected deathID],
but I think that these comments can help a lot to newbie programmers [which want learn LUA and make own scripts], so I don't want rewrite script.

EDIT:
You also need acc. maker script that shows information about aol and bless (load them from `aol` and `bless` columns), but on forum are many PHP programmers and I'm sure someone can edit your lastdeaths.php script. Would be nice if you post it in this thread as there are maany lastdeath.php scripts and if someone post his modified script it can looks diffrent on www or not work with your acc. maker.
 
Last edited:
Back
Top