Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Jade Dynasty improved 'add jaden' script

Junior Spellweaver
Joined
Sep 3, 2011
Messages
150
Reaction score
94
Hi there,

As many players and devs should notice, theres a issue with missing jadens when you use both, vote for jadens and hourly jadens.

Its caused by `usecashnow` table structure (MySQL).

It allows only one record per userid cause of unique key: PRIMARY(userid,zoneid,sn).

Example:
When your script just added hourly jadens for all online players, it stores records in this table until game server process it.
Procesing usualy takes 1-10 min.

So if player will vote when his hourly jaden record are still in this table it will cause mysql error:#1062 - Duplicate entry '1-1-1' for key 'PRIMARY'.

I prepared script that will allow you to vote, add jadens from GM panel, hourly jadens etc at same time so players wont loose any jadens.

First you need new table in MySQL:
Code:
CREATE TABLE IF NOT EXISTS `cashtable` (
  `userid` int(11) NOT NULL,
  `zoneid` int(11) NOT NULL,
  `cash` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Now scripts:
jaden/safecash.php
Code:
<?php
$DBHost='localhost';
$DBUser='root';
$DBName='dynasty';
$DBPassword='password';

$conn = mysql_connect($DBHost, $DBUser, $DBPassword );

if (!$conn) {
	echo "Database connection error. Details  : " . mysql_error();
    exit;
}
if (!mysql_select_db($DBName)) {
	echo "The database doesn't exists. Details  : " . mysql_error();
	exit;
}
$time=date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']);
$result = mysql_query("SELECT `userid`,`zoneid`,`cash` FROM `cashtable`");
while($cash=mysql_fetch_row($result)){
	$sn=mysql_num_rows(mysql_query("SELECT * FROM `usecashnow` WHERE `userid` = $cash[0] AND `zoneid`=$cash[1] LIMIT 1"));
	if($sn==0){
		MySQL_Query("INSERT INTO `usecashnow` (userid, zoneid, sn, aid, point, cash, status, creatime) VALUES ($cash[0], $cash[1], 0, 1, 0, $cash[2], 1, '$time')");
		MySQL_Query("DELETE FROM `cashtable` WHERE `userid`=$cash[0] AND `zoneid`=$cash[1] AND `cash`=$cash[2] LIMIT 1");
		echo $cash[0].'->'.$cash[2].'<br />';
	}
	else continue;
}
?>

/auto5/safecash.sh
Code:
#!/bin/sh
/opt/lampp/bin/php -f /jaden/safecash.php >> logfile2.txt 2>&1

Add to crontab (/etc/crontab)
Code:
*/5        *       *       *       *       root   /auto5/safecash.sh

Now need to change all add jadens INSERTS in ur web scripts:

from for example:
Code:
MySQL_Query("INSERT INTO usecashnow (userid, zoneid, sn, aid, point, cash, status, creatime) VALUES ('$UID', 1, 0, 1, 0, 500, 1, '$TIME')");
to
Code:
MySQL_Query("INSERT INTO cashtable (userid, zoneid, cash) VALUES ($UID, 1, 500)");
You will edit jaden value by ur own of course.

Ill add hourly jaden script as a bonus here:
Code:
<?
$DBHost = "localhost";  
$DBUser = "root";
$DBPassword = "password";
$DBName = "dynasty";
$Hcash=1000;
$Link = MySQL_Connect($DBHost, $DBUser, $DBPassword) or die ("Can't connect to MySQL");
MySQL_Select_Db($DBName, $Link) or die ("Database ".$DBName." does not exist.");

$OnlineAccountQuery = Mysql_Query("SELECT * FROM point WHERE zoneid > -1");
$OnlineAccountNum = Mysql_Num_Rows($OnlineAccountQuery);

$i=0;
WHILE($i < $OnlineAccountNum){
    $OnlineAccountArray = Mysql_Fetch_Array($OnlineAccountQuery);
	$UID = $OnlineAccountArray['uid'];
	MySQL_Query("INSERT INTO cashtable (userid, zoneid, cash) VALUES ($UID, 1, $Hcash)");
	echo"$UID DONE!<br>";
    $i++;
}
?>
/auto60/jaden.sh:
Code:
#!/bin/sh
/opt/lampp/bin/php -f /jaden/XFVS.php >> logfile.txt 2>&1

Crontab for hourly jaden:
Code:
0          *       *       *       *       root   /auto60/jaden.sh
 
Last edited:
Junior Spellweaver
Joined
Dec 21, 2008
Messages
195
Reaction score
10
Great, this is problem in my server, thank you

2
 
Newbie Spellweaver
Joined
May 12, 2016
Messages
7
Reaction score
0
Code:
<?php

$DBHost = "";  // localhost or your IP
$DBUser = "";  // Mysql Login
$DBPassword = "";  // Mysql Password
$DBName = "";  // Base Name
$gold = "2000"; //Jadens (2000 = 20 Jadens in shop)


$Link = MySQL_Connect($DBHost, $DBUser, $DBPassword) or die ("Can't connect to MySQL");
MySQL_Select_Db($DBName, $Link) or die ("Database ".$DBName." do not exists.");


$mysqlresult=MySQL_Query("select * from `point` where `zoneid`=1");
$myrow=mysql_fetch_array($mysqlresult);
do
{
$account=$myrow['uid'];
MySQL_Query("call usecash($account,1,0,11,0,$gold,1 [USER=116066]ERROR[/USER])") or die ("usecash failed!");
}
while($myrow=mysql_fetch_array($mysqlresult));


?>
jadens for online player
 
Back
Top