Castle Control Script

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
trellos
Posts: 1
Joined: Thu May 08, 2008 11:25 am

Re: Castle Control Script

Post by trellos » Mon Nov 28, 2011 6:01 pm

I have the same issue regarding downloading the file. Could you please upload again the file ?



Thank you

User avatar
DareStrike
Posts: 376
Joined: Sun May 01, 2011 1:20 pm

Re: Castle Control Script

Post by DareStrike » Mon Dec 05, 2011 10:26 am

Code: Select all

 <?php //---------------// Made by Daedalus email : daedalus at hotmail dot fr//--------------- $db_serv = 'x';         //the address of the database goes here $db_user = 'x';             //your sql username goes here$db_pass = 'x';                 //your sql password goes here $db_name = 'l2jgs';             //your database name goes here $filename = './helios.js';      //generated javascript file you need to put attribute 777 in your folder 

this problem :S

Code: Select all

 $filename = './helios.js';      //generated javascript file you need to put attribute 777 in your folder$filename = '7777./helios.js';      //generated javascript file you need to put attribute 777 in your folder 

darknessneo
Posts: 196
Joined: Mon Apr 26, 2010 11:00 pm

Re: Castle Control Script

Post by darknessneo » Mon Jan 30, 2012 11:03 pm

hello,
i added this features for my website, but i needed to edit a little the generator:

here is my patch

Code: Select all

   $req =  @mysql_query("SELECT `name`, `seed_price` FROM `etcitem`, `castle_manor_production` WHERE `seed_id` = `item_id` AND `castle_id` = '$castle[id]' UNION (SELECT `name`, `c`.`price` FROM `etcitem` e, `castle_manor_procure` c WHERE `crop_id` = `item_id` AND `castle_id` = '$castle[id]') ORDER BY `name`");     $i = 1;    while ($row = mysql_fetch_array($req, MYSQL_NUM)) {        $gen .= '<tr>';        $gen .= '<td style="background-color: #'.( ($i % 2) ? 'EEE' : 'DDD' ).'">'.$row[0].'</td>';        $gen .= '<td style="background-color: #'.( ($i % 2) ? 'EEE' : 'DDD' ).'">'.$row[1].'</td>';        $gen .= '</tr>';        $i++;    }
what i edited?

'$castle[id]' in the sql request.

without this edit, i eat a Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given.....

Oh, and, ofc, i needed to reput the table etcitem in the database with a old backup, cuz now, l2jserver use xml.

Eray
Posts: 10
Joined: Tue Apr 17, 2012 4:30 pm

Re: Castle Control Script

Post by Eray » Wed Apr 18, 2012 12:21 pm

thanks.

VeNoML2
Posts: 2
Joined: Sun Sep 09, 2012 11:54 pm

Re: Castle Control Script

Post by VeNoML2 » Sun Sep 09, 2012 11:59 pm

so i have 1 problem

i have my server on my PC and if i make this script on my pc with Xampp work fine
and if i add script on website host say this "Coudn't connect to host"


anyone can help me pls

VeNoML2
Posts: 2
Joined: Sun Sep 09, 2012 11:54 pm

Re: Castle Control Script

Post by VeNoML2 » Mon Sep 10, 2012 10:04 am

someone?

User avatar
gmakhs
Posts: 215
Joined: Sat Apr 14, 2007 12:00 pm

Re: Castle Control Script

Post by gmakhs » Sun Oct 28, 2012 5:34 pm

you have to give remote acces on your database

busta
Posts: 17
Joined: Tue May 24, 2011 7:56 pm

Re: Castle Control Script

Post by busta » Tue Feb 12, 2013 2:19 pm

Does any php guru know why the script doesnt rewrite the helios.js again, after the sieges timestamp change in mysql table castle on column siegeDate ?
For example I have this problem:
the generator writen once the siege date and time first time, but after the time expire, it didnt rewrite with the new timestamp for the next siege. I think it doesnt check MySQL anymore.
2 castles which has not been sieged Gludio and Schuttgart get new timestamp same as all the rest in MySQL, but in the website I still see them with the same old date Feb 9, all others are Feb 23. All others were Feb 23 before too, only Gludio and Schuttgart were on Feb 9 for siege. Why is this happening?

xban1x
L2j Veteran
L2j Veteran
Posts: 1228
Joined: Thu Jan 17, 2013 9:46 am

Re: Castle Control Script

Post by xban1x » Wed Feb 13, 2013 10:11 pm

Post the code that was "supposed to rewrite helios.js"

busta
Posts: 17
Joined: Tue May 24, 2011 7:56 pm

Re: Castle Control Script

Post by busta » Thu Feb 14, 2013 2:02 pm

This is the script I use:

Code: Select all

<?php //---------------// Made by Daedalus email : daedalus at hotmail dot fr//--------------- $db_serv = '****';          //the address of the database goes here $db_user = 'root';              //your sql username goes here$db_pass = '****';              //your sql password goes here $db_name = 'l2jgs';             //your database name goes here $filename = './gen/helios.js';          //generated javascript file you need to put attribute 777 in your folder //----------------------------------------------------------------------------------------------- mysql_connect ( $db_serv, $db_user, $db_pass ) or die ('Coudn\'t connect to host');mysql_select_db( $db_name ) or die ('Couldn\'t select database'); $sql = mysql_query('SELECT id,name,taxPercent,siegeDate FROM `castle`') or die('Query failed!'); $gen = "\n"; while ($castle = mysql_fetch_array($sql)){    $gen .= "\n".strtolower($castle['name']) . 'info = \'<div class="castleWrapper">';    $gen .= '<div class="castlePic" id="' . ucfirst(strtolower($castle['name'])) . 'Pic"></div>';    $gen .= '<div class="castleInfo">';    $gen .= '<div class="castleName"><strong>' . ucfirst(strtolower($castle['name'])) . ' Castle</strong></div>';        $clan = mysql_fetch_array(mysql_query('SELECT clan_name,hasCastle FROM `clan_data` WHERE hasCastle = ' . $castle['id']));    $clan_name = (isset($clan['clan_name'])) ? htmlspecialchars($clan['clan_name'], ENT_QUOTES) : '<font color="22FF22">Unclaimed</font>';        $gen .= '<div><strong>Controlled by:</strong> ' . $clan_name . '</div>';        if (isset($clan['clan_name'])) $gen .= '<div><strong>Tax Rate:</strong> ' . $castle['taxPercent'] . '%</div>';        $gen .= '<div><strong>Next Siege:</strong> ' . date('M d Y ',$castle['siegeDate']/1000) . '</div>';    $gen .= '</div></div>\';'."\n\n";} $handle = fopen($filename, 'w+');fwrite($handle, $gen);fclose($handle); ?>
I believe the last 3 rows do the rewrite, but it seems that somehow they dont rewrite it.

Code: Select all

$handle = fopen($filename, 'w+');fwrite($handle, $gen);fclose($handle);
./gen/ is the location of generator.php and helios.js in my site.

P.S. I try to make a cronjob on 1 hours for this castle manager, but I cant really make it work. Dont know how to setup it correctly.

xban1x
L2j Veteran
L2j Veteran
Posts: 1228
Joined: Thu Jan 17, 2013 9:46 am

Re: Castle Control Script

Post by xban1x » Fri Feb 15, 2013 8:17 pm

cron job on linux ?

Tell me which linux

busta
Posts: 17
Joined: Tue May 24, 2011 7:56 pm

Re: Castle Control Script

Post by busta » Fri Feb 15, 2013 8:47 pm

I cant see from the cPanel which version is Linux.
How to define the cronjob command so to be able to refresh the content of helios.js?

P.S. Nevermind, I figured it out and it works.

Now I will explain where I was wrong.
First I have put a path for $filename which was wrong. My folder containing generator.php and helios.js is /gen just like I mention. So inside $filename must be writen this:

Code: Select all

$filename = 'helios.js';
Second and very important just like deadalus said, you must put attribute to helios.js, but the attribute must be 755. You dont need to make it 777. This can be done by clicking in your cPannel on file helios.js and clicking the key icon "Change Permissions", or by right mouse click and again "Change Permissions". After this operation it will be opened a new window with many boxes:
Image
Click on them so in row Permissions to be 755.
Now on the question how to automate the castle script, so to have regular update.
Go into your cPannel and find the Cronjob button. Its usually near MIME Types or Index Manager. Click on it. Sellect on what interval of time you wish the script generator.php to update helios.js. This can be made on Add New Cron Job table. Its enought to choose from Common Settings: sub-menu "Once an hour(0****)"
This choice will run the script and update it on every hour.
After that go to Command: field and write this for a php file(which generator.php is):

Code: Select all

php /home/[user name]/public_html/gen/generator.php
This is it!
Further more, the webhost will send to your main email of your site mail for each cronjob which has been done. If you dont want it to spam your mail simply add this after the command you previously put: >/dev/null 2>&1
It should look like this:

Code: Select all

php /home/[user name]/public_html/gen/generator.php >/dev/null 2>&1
And there will be no more mails. Dont worry, cronjob will continue to run, this disable only the email notification.
If you wish to stop this cronjob you must delete it from the Cronjob manager.
I hope this little guide will help to someone!

KaTSiKa
Posts: 16
Joined: Sun Feb 17, 2013 9:53 pm

Re: Castle Control Script

Post by KaTSiKa » Mon Feb 25, 2013 4:54 pm

seems like a quite usefull thing. i will sure take a look

User avatar
OrcBubba
Posts: 50
Joined: Mon Mar 18, 2013 7:04 pm

Re: Castle Control Script

Post by OrcBubba » Mon May 27, 2013 3:11 pm

Hi guys. I am getting this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in generator.php on line 57

Any suggestions? Thanks

User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Castle Control Script

Post by jurchiks » Mon May 27, 2013 3:31 pm

Means the query failed to execute and returned FALSE on mysql_query(), possibly a typo somewhere.
Also, mysql_* is deprecated, time to switch to mysqli/PDO.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.

Post Reply