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

Website monsters kills counter

Victor

New Member
Joined
Feb 1, 2008
Messages
222
Reaction score
1
Hello. I havet o present you my new script(s).

How it work:
- creaturescripts - when player kill monster, script add a record (or change to +1) kills value in database
- globalevents - script looks on globalstorage and reset statistics when they are older than 24hour (configurable)
- php - script show statistics on you webpage

It is compatible with Gesior AAC and TFS 0.3.2+.

DATABASE

Code:
CREATE TABLE IF NOT EXISTS `vorgpl_monsterskills` (
  mid int(4) NOT NULL auto_increment,
  name varchar(30) collate utf8_polish_ci NOT NULL,
  kills int(6) NOT NULL,
  PRIMARY KEY  (mid)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci COMMENT='victor.org.pl';

CREATURESCRIPTS

data/creaturescripts/scripts/vorgpl_monsterskills.lua:
Code:
--	This program is free software: you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation, either version 3 of the License, or
--	(at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--	GNU General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program. If not, see <http://www.gnu.org/licenses/>.


--	vorgpl_monsterskills was wroted by Victor.
--	For help ask at otland.net thread.
--	You can also read my blog at victor.org.pl.
--	Thank you for use it and regarding license.

function onKill(cid, target)
	if(isMonster(target) == TRUE) then
		local name = getCreatureName(target)
		
		local monsterkills = db.getResult("SELECT mid, kills FROM vorgpl_monsterskills WHERE name = '" .. name .. "' LIMIT 1")

		if(monsterkills:getID() ~= -1) then
			db.executeQuery("UPDATE vorgpl_monsterskills SET kills = " .. (monsterkills:getDataInt("kills") + 1) .. " WHERE mid = " .. monsterkills:getDataInt("mid") .. " LIMIT 1")
		else
			db.executeQuery("INSERT INTO vorgpl_monsterskills (name, kills) VALUES ('" .. name .. "', 1)")
		end
	end
	return TRUE
end

data/creaturescripts/creaturescripts.xml:
Code:
<event type="kill" name="MonstersKills" script="vorgpl_monsterskills.lua"/>

data/creaturescripts/scripts/login.lua:
Code:
	registerCreatureEvent(cid, "MonstersKills")

GLOBALEVENTS

data/globalevents/scripts/vorgpl_monsterskills.lua:
Code:
--	This program is free software: you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation, either version 3 of the License, or
--	(at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--	GNU General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program. If not, see <http://www.gnu.org/licenses/>.


--	vorgpl_monsterskills was wroted by Victor.
--	For help ask at otland.net thread.
--	You can also read my blog at victor.org.pl.
--	Thank you for use it and regarding license.

local config = {
	interval = 24 * 60 * 1,
	storage = 24387
}

function onThink(interval, lastExecution)
	local storage = getGlobalStorageValue(config.storage)
	local time = os.time()
	
	if ((storage + config.interval) < time or storage == -1) then
		db.executeQuery("DELETE FROM vorgpl_monsterskills")
		setGlobalStorageValue(config.storage, time)
		broadcastMessage("Monsters kills was reset.")
	end		
	return TRUE
end

data/globalevents/globalevents.xml:
Code:
	<globalevent name="MonstersKills" interval="1800" script="vorgpl_monsterskills.lua"/>

PHP

vorgpl_monsterskills.php:
PHP:
<!--
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
 -->
<!--
	vorgpl_monsterskills was wroted by Victor.
	For help ask at otland.net thread.
	You can also read my blog at victor.org.pl.
	Thank you for use it and regarding license.
 -->
<?php
//PREDEFINED
define('MONSTERLINK', '?subtopic=creatures&creature=');
define('MONSTERSPATH', 'monsters/');

define('IMAGE', TRUE); // images enabled or disabled?
define('IMAGESIZE', '55'); // images size in pixels (width and height in one)
//MONSTERSKILLS
$main_content .= '
	<div style="text-align: center; margin: 20px auto; font-size: 26px; font-weight: bold;">
		<img src="monsters/orc.gif" /><br />
		Monsters kills
	</div>';

//GUILDINWAR - TABLE
$main_content .= '
<table style="width: 100%; border: 0px;" cellpadding="4" cellspacing="1">
	<tbody>
		<tr style="background: #505050; text-align: center; font-weight: bold;">';
			if (IMAGE) {
				$main_content .= '
				<td class="white" style="width: '.IMAGESIZE.'px;">
					Image
				</td>';
			}
			$main_content .= '
			<td class="white" style="width: 45%;">
				Monster
			</td>
			<td class="white" style="width: auto;">
				Kill(s)
			</td>
		</tr>';

//MONSTERSKILLS - TABLE
$mtc = 0;
$monsterskills = $SQL->query('SELECT mid, name, kills FROM vorgpl_monsterskills ORDER BY name ASC');

if ($monsterskills->rowCount() <> 0) {
	foreach ($monsterskills->fetchAll() as $monsterkills) {
			
		if ($mtc % 2) {
			$color = '#f1e0c6';
		}
		else {
			$color = '#d4c0a1';
		}
		
		if (IMAGE) {
			//ucwords not cuz linux...
			$name = $monsterkills['name'];
		
			if (file_exists(MONSTERSPATH.$name.'.gif')) {
				$image = '<img src="'.MONSTERSPATH.$name.'.gif" style="width: '.IMAGESIZE.'px; height: '.IMAGESIZE.'px;" />';
			}
			else {
				$image = '<img src="'.MONSTERSPATH.'nophoto.png" />';
			}
		}

		//ucwords
		$name = ucwords($monsterkills['name']);
		$kills = (int)$monsterkills['kills'];	

		$main_content .= '
		<tr bgcolor="'.$color.'">';
			if (IMAGE) {
				$main_content .= '
				<td style="text-align: center;">
					'.$image.'
				</td>';
			}
			$main_content .= '
			<td style="text-align: center; font-weight: bold;">
				<a href="'.MONSTERLINK.$name.'">'.$name.'</a>
			</td>
			<td style="text-align: center; font-weight: bold;">
				'.$kills.'
			</td>
		</tr>';
	}
}
else {
	$main_content .= '
	<tr style="background: #d4c0a1; text-align: center;">
		<td colspan="3">
			There are not any monster kills today.
		</td>
	</tr>';
}

//MONSTERSKILLS - FINSIH TABLE
$main_content .= '</tbody></table>';

/*COPYRIGHTS
  I think you know don't remove ;). It's under GNU GPL license guy :).
 */
$main_content .= '
	<div style="text-align: right; margin: 20px auto; font-size: 10px;">
		Lua and PHP coded and copyright by <a href="http://www.victor.org.pl/">Victor</a>.
	</div>';
?>

index.php (only in Gesior AAC):
After
PHP:
	case "spells";
		$topic = "Spells";
		$subtopic = "spells";
		include("spells.php");
	break;
Add
PHP:
	case "monsterskills";
		$topic = "Monsters Kills";
		$subtopic = "monsterskills";
		include("vorgpl_monsterskills.php");
	break;

If you wanna add link in layout.php too.

For now, look here:
yourpage.com/index.php?subpage=monsterskills

You can change interval and storage value in globalevent script and size and enable/disable image on website in php script.

All is under GNU GPL, then don't remove copyrights at PHP :).

You see bug or have error? Post it here - I will fix it. All comments are welcome.

Have fun with using this,
Victor ;)
 

Attachments

  • 2009-04-02 17-48-42.jpg
    2009-04-02 17-48-42.jpg
    235.8 KB · Views: 1,745 · VirusTotal
I think it is better to do it with Storages not with updating DB every time u killed something, this might cause some lags on high population servers, anyway if u use DB then u have to make new base, with info about monsters, and what sotrage they got ;p

Anyway good idea, but I have this script for about 3 weeks already on my serv :p


---------

Why use storages? - They are saved just after saving character, eg. Logout.
 
Read my post, imagine 400 people on server, and 250 of them are exping, they kill monsters, and each kill updates data base, that would cause lag.
 
Security attention:
Do not use it on huge servers(!)

Hmm. Then maybe some caching? :)
Writing it in storages and every 15 minutes update database.

There is other storage than int storage?
 
I bet it might work exactly as power gamers script, but each player got storages for monsters, and script once a day adds all them up, and shows on website.
 
Maybe like this:
Code:
local config = {
	updateInterval = 10 --in minutes
}

local m_cache = {}

local function updateEvent()
	for name, kills in pairs(m_cache) do
		db.executeQuery("UPDATE vorgpl_monsterskills SET kills = " .. kills .. " WHERE name = " .. db.escapeString(name) .. " LIMIT 1")
	end

	addEvent(updateEvent, config.updateInterval * 60 * 1000)
end

updateEvent()

function onKill(cid, target)
	if(isMonster(target) ~= TRUE) then
		return TRUE
	end

	local name = getCreatureName(target):lower()
	if(not m_cache[name]) then
		m_cache[name] = 1
	else
		m_cache[name] = m_cache[name] + 1
	end
	return TRUE
end

+ monster names query generator or something
 
I absolutely love that idea, and i tried addin it, added everythin but then when i go to the page, it says this


Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\vorgpl_monsterskills.php on line 57

anyone kno why?
 
You are missing this query on your database:

PHP:
CREATE TABLE IF NOT EXISTS `vorgpl_monsterskills` (
  mid int(4) NOT NULL auto_increment,
  name varchar(30) collate utf8_polish_ci NOT NULL,
  kills int(6) NOT NULL,
  PRIMARY KEY  (mid)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci COMMENT='victor.org.pl';
 
Before:
PHP:
v
if ($monsterskills->rowCount() <> 0) {

Add:
PHP:
print_r($SQL->errorInfo());

And copy the error array.
 
Worked perfectly. Thank you a lot Victor :D I'm not worried if It will lag my server... cuz I don't have so many players on my server(maybe yet?)
 
When i use it I haven't got logo in my acc maker site;/ help please!
 
Back
Top