Quote:
Originally Posted by moat
Had that same issue. Our forum is mostly local so its doesn't get any hits overnight. The way VB's scheduling works if noone's hit the site for a few hours the next person only triggers one update and doesn't catchup on the missed ones. I made a few changes to the update script to calculate the number of missed updates and perform a catchup of the missed ones (just wrapped the existing code in a loop)
My conquestCycle.php below. I've changed the update time to 30 mins (the figure of 1800 in 2 lines below) and changed the VB scheduler to 15 minutes. A bit rough but it worked.
PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$settings = $vbulletin->db->query_first("SELECT * FROM ".TABLE_PREFIX."conquest_gameset");
$time = time();
// $next = $settings[gLastCycle] + (60 * $settings[gCycleMinutes]);
$loopz = (time()-$settings[gLastCycle]) / 1800;
$roundednext = time() - (time() % 1800);
// if ($time >= $next)
for($i=1;$i<=$loopz;$i++)
{
$vbulletin->db->query_write("UPDATE IGNORE ".TABLE_PREFIX."conquest_gameset SET gLastCycle = '".$roundednext."'");
$players = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."conquest_players AS conquest_players
LEFT JOIN ".TABLE_PREFIX."conquest_nations AS conquest_nations ON conquest_players.nationID = conquest_nations.nationID
");
while ($player = $vbulletin->db->fetch_array($players))
{
$spyCost = $player[pSpies] * $settings[gSpyUpkeep];
$goldGain = ceil($settings[gCycleGold] * (1 + $player[nIncome]/100)) - $spyCost;
$newTurns = $player[pTurns] + $settings[gCycleTurns];
$newGold = $player[pGold] + $goldGain;
$newTroops = $player[pTroops] + $settings[gCycleTroops];
if ($newTroops < $settings[gMinTroops]) { $newTroops = $settings[gMinTroops]; }
if ($newTurns > $settings[gMaxTurns]) { $newTurns = $settings[gMaxTurns]; }
$vbulletin->db->query_write("
UPDATE IGNORE ".TABLE_PREFIX."conquest_players
SET pTurns = ".$newTurns.",
pGold = ".$newGold.",
pTroops = ".$newTroops."
WHERE playerID = ".$player[playerID]."
");
}
}
?>
|
Where do i need to put this code?