What's new

PHP Licznik zabitych potwor?w

Status
Not open for further replies.

Thorge D

Advanced User
Joined
Jul 24, 2014
Messages
300
Reaction score
29
Autor: Victor

Jak to dzia?a:
- creaturescripts - kiedy gracz zabije potwora, skrypt dodaje wpis (albo zmienia o +1) zabi? do bazy
- globalevents - skrypt kontroluje globalstorage i resetuje statystki kiedy jest on starszy ni? 24 godziny (do skonfigurowania)
- php - skrypt pokazuje statystyki na stronie


Kompatybilne z G?sior AAC i TFS 0.3.2+.

Baza danych:
[SQL]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';[/SQL]
Creaturescripts:

data/creaturescripts/scripts/vorgpl_monsterskills.lua:
[LUA]-- 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[/LUA]
data/creaturescripts/creaturescripts.xml:
[XML]<event type="kill" name="MonstersKills" script="vorgpl_monsterskills.lua"/>[/XML]
data/creaturescripts/scripts/login.lua:
[LUA]registerCreatureEvent(cid, "MonstersKills")[/LUA]

Globalevents:

data/globalevents/scripts/vorgpl_monsterskills.lua:
[LUA]-- 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[/LUA]
data/globalevents/globalevents.xml:
[XML]<globalevent name="MonstersKills" interval="1800" script="vorgpl_monsterskills.lua"/>[/XML]

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 (tylko w G?sior AAC) pod:
PHP:
case "spells";
        $topic = "Spells";
        $subtopic = "spells";
        include("spells.php");
    break;
dodaj:
PHP:
case "monsterskills";
        $topic = "Monsters Kills";
        $subtopic = "monsterskills";
        include("vorgpl_monsterskills.php");
    break;
Link do tej?e 'opcji':
Code:
twojastrona.pl/index.php?subpage=monsterskills

Mo?na doda? link do layout.php.
Prezentuje si? to tak:
2cynx55.jpg
 

sprytnaaaaa

Advanced User
Joined
Apr 20, 2011
Messages
342
Reaction score
4
Odp: Licznik zabitych potwor?w

zajebisty skrypcik tego w?a?nie szuka?em :] dzi?ki leci rep :]
 

Anakonta

Senior User
Joined
Oct 5, 2010
Messages
536
Reaction score
10
Odp: Licznik zabitych potwor?w

Skrypt rzeczywi?cie fajny ale nie jest a? tak skomplikowany ?eby go nie napisa?. Noobom z pewno?ci? si? przyda.
 

Raa

Senior User
Joined
Aug 9, 2009
Messages
715
Reaction score
50
Age
29
Odp: Licznik zabitych potwor?w

Yhh. ?eby wysy?a? zapytanie do bazy za ka?dym razem jak kto? zabije potwora.
Nie chc? nic pisa?, ale to mo?e naprawd? b. b. obci??y? maszyn?.
 

Placek

Blue Waffle
Joined
Sep 30, 2008
Messages
6,793
Reaction score
672
Age
8
Odp: Licznik zabitych potwor?w

Skrypt prosty. Przyda sie nie tylko noobom, bo po co w ogole sie meczyc 5 minut z pisaniem go jak mozna skopiowac? ;P

Przy okazji podrzuce poprawke jak komus nie dzialaja obrazki i nie chce mu sie meczyc z odpowiednim folderem z obrazkami potworow:
Obrazki nie sa pobierane od nas z serwera tylko zewnetrznie z tibia-wiki.net. Przy okazji nazwy potworow sa poprawione, zeby nie bylo problemow jak potwor ma nazwe dluzsza niz jedno slowo, np demon skeleton.

Caly plik php zmieniamy na:
PHP:
<?php
//PREDEFINED
define('MONSTERSPATH', 'http://www.tibia-wiki.net/images/');
 
define('IMAGE', TRUE); // images enabled or disabled?
define('IMAGESIZE', '32'); // images size in pixels (width and height in one)
//MONSTERSKILLS
 
//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 kills DESC');
 
if ($monsterskills->rowCount() <> 0) {
foreach ($monsterskills->fetchAll() as $monsterkills) {
 
if ($mtc % 2) {
$color = '#f1e0c6';
}
else {
$color = '#d4c0a1';
}
 
if (IMAGE) {
$name = ucwords($monsterkills['name']);
$dname = str_replace(" ","_",$name);

$image = '<img src="'.MONSTERSPATH.$dname.'.gif" style="width: '.IMAGESIZE.'px; height: '.IMAGESIZE.'px;" />';
}
 
//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;">
'.$name.'
</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 Victor.
</div>';
?>

Mozna by to zrobic lepiej, ale tak jest najprosciej wklepane byle by dzialalo. I dziala.
4plzfb.jpg
 
Last edited:
Status
Not open for further replies.
Top