= 90) // Hit the high 90% $price = $StockR["price"] + mt_rand(5, 10); elseif($chance <= 10) // Hit low 10% $price = $StockR["price"] + mt_rand(-10, -5); else // Hit 11% - 89% $price = $StockR["price"] + mt_rand(-5, 5); if($price <= 0){ $price = 1; } mysql_query("UPDATE stock_market SET price = '$price' WHERE id = '{$StockR['id']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); $sqlStockRecord = mysql_query("SELECT price from stock_market_records where stock_id = '{$StockR['id']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); if(mysql_num_rows($sqlStockRecord) == 1){ if($price > mysql_result($sqlStockRecord, 0, 'price')){ //update records! mysql_query("UPDATE stock_market_records SET price = '$price', thetime = NOW() where stock_id = '{$StockR['id']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); } } else { mysql_query("INSERT INTO stock_market_records (stock_id, price, thetime) values ('{$StockR['id']}', '$price', NOW())") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); } } } } if($hour % 1 == 0 && $min == 00){ // every hour } if($hour == 12 && $min == 00){ //midday } if($hour == 00 && $min == 00){ //midnight //Do Stock Opens $StockQ = mysql_query("SELECT id, price from stock_market") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); while($StockR = mysql_fetch_array($StockQ)){ mysql_query("UPDATE stock_market SET open_price = '{$StockR['price']}' WHERE id = '{$StockR['id']}'") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); } //Do pays $PayQ = mysql_query("SELECT id, (SELECT pay FROM jobs WHERE id = job) as job_pay, name FROM characters where job > 0") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); while($PayR = mysql_fetch_array($PayQ)){ updateBank("money", "(money + {$PayR['job_pay']})", $PayR['id']); alert($PayR['id'], "Pay", "{$PayR['name']}, it's payday! You have an extra " . format($PayR['job_pay']) . " KD in the bank!"); } } if($hour == 19 && $min == 00){ //do lottery! $numbers = array(); for($i=1;$i<=6;$i++){ do $rand = mt_rand(1,50); while(in_array($rand, $numbers)); $numbers[$i] = $rand; } $query = mysql_query("SELECT user_id, ticket FROM game_lottery") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); if(mysql_num_rows($query) > 0){ $prizepool = mysql_num_rows($query) * 1000; $prizepool += 10000; $first = floor(PercentOfNumberIs(55, $prizepool)); $second = floor(PercentOfNumberIs(25, $prizepool)); $third = floor(PercentOfNumberIs(15, $prizepool)); $forth = floor(PercentOfNumberIs(5, $prizepool)); while($row = mysql_fetch_array($query)){ $matches = 0; $othernumb = explode(",", $row["ticket"]); for($i = 1; $i <= 6; $i++){ if(in_array($othernumb[$i], $numbers)) $matches++; } if($matches < 3){ $CharacterInfo = GetCharacterInfo($row['user_id']); $message = "We're sorry {$CharacterInfo['name']}!!!\nYou have not won anything in the National Kingsleyville Lottery!!\n"; if($matches > 0){ $message .= "You did however get $matches numbers right!\n"; } $message .= "We do hope you play again!\n-Lottery Adminstrators"; alert($row['user_id'], "Lottery", $message); } if($matches == 3){ $fourthWinners[] = $row['user_id']; } if($matches == 4){ $thirdWinners[] = $row['user_id']; } if($matches == 5){ $secondWinners[] = $row['user_id']; } if($matches == 6){ $firstWinners[] = $row['user_id']; } } //do forth winners if(count($forthWinners) > 0) { $forthPrize = floor($forth / count($forthWinners)); $tax = floor(PercentOfNumberIs($config['tax'], $forthPrize)); $forthPrize -= $tax; foreach($fourthWinners as $winnerID) { GiveMoney(5,$tax); $CharacterInfo = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE id = '{$winnerID}'") or print(mysql_error())); GiveMoney($winnerID, $forthPrize); alert($winnerID, "Lottery", "Congratulations {$CharacterInfo['name']}!!!\nYou have won " . format($forthPrize) . " KD (after tax)!!\nIn the Forth Division of the National Kingsleyville Lottery!!\nWe do hope you play again!\n-Lottery Adminstrators"); alert(5, "Lottery tax", "{$CharacterInfo['name']} won " . format($forthPrize) . " KD!!\nIn the Forth Division of the National Kingsleyville Lottery!!\nA tax of " . format($tax) . " has been paid.\n-Lottery Adminstrators"); } } //do third winners if(count($thirdWinners) > 0) { $thirdPrize = floor($third / count($thirdWinners)); $tax = floor(PercentOfNumberIs($config['tax'], $thirdPrize)); $thirdPrize -= $tax; foreach($thirdWinners as $winnerID) { GiveMoney(5,$tax); $CharacterInfo = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE id = '{$winnerID}'") or print(mysql_error())); GiveMoney($winnerID, $thirdPrize); alert($winnerID, "Lottery", "Congratulations {$CharacterInfo['name']}!!!\nYou have won " . format($thirdPrize) . " KD!!\nIn the Third Division of the National Kingsleyville Lottery!!\nWe do hope you play again!\n-Lottery Adminstrators"); alert(5, "Lottery tax", "{$CharacterInfo['name']} won " . format($thirdPrize) . " KD!!\nIn the Third Division of the National Kingsleyville Lottery!!\nA tax of " . format($tax) . " has been paid.\n-Lottery Adminstrators"); } } //do second winners if(count($secondWinners) > 0) { $secondPrize = floor($second / count($secondWinners)); $tax = floor(PercentOfNumberIs($config['tax'], $secondPrize)); $secondPrize -= $tax; foreach($secondWinners as $winnerID) { $CharacterInfo = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE id = '{$winnerID}'") or print(mysql_error())); GiveMoney(5,$tax); GiveMoney($winnerID, $secondPrize); alert($winnerID, "Lottery", "Congratulations {$CharacterInfo['name']}!!!\nYou have won " . format($secondPrize) . " KD!!\nIn the Second Division of the National Kingsleyville Lottery!!\nWe do hope you play again!\n-Lottery Adminstrators"); alert(5, "Lottery tax", "{$CharacterInfo['name']} won " . format($secondPrize) . " KD!!\nIn the Second Division of the National Kingsleyville Lottery!!\nA tax of " . format($tax) . " has been paid.\n-Lottery Adminstrators"); } } //do first winners if(count($firstWinners) > 0) { $firstPrize = floor($first / count($firstWinners)); $tax = floor(PercentOfNumberIs($config['tax'], $firstPrize)); $firstPrize -= $tax; foreach($firstWinners as $winnerID) { $CharacterInfo = mysql_fetch_array(mysql_query("SELECT * FROM characters WHERE id = '{$winnerID}'") or print(mysql_error())); GiveMoney(5,$tax); GiveMoney($winnerID, $firstPrize); alert($winnerID, "Lottery", "Congratulations {$CharacterInfo['name']}!!!\nYou have won " . format($firstPrize) . " KD!!\nIn the First Division of the National Kingsleyville Lottery!!\nWe do hope you play again!\n-Lottery Adminstrators"); alert(5, "Lottery tax", "{$CharacterInfo['name']} won " . format($firstPrize) . " KD!!\nIn the Forth Division of the National Kingsleyville Lottery!!\nA tax of " . format($tax) . " has been paid.\n-Lottery Adminstrators"); } } //update lottery record mysql_query("INSERT INTO game_lottery_records (ball_1, ball_2, ball_3, ball_4, ball_5, ball_6, drawdate) VALUES ('{$numbers[1]}', '{$numbers[2]}', '{$numbers[3]}', '{$numbers[4]}', '{$numbers[5]}', '{$numbers[6]}', NOW())") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); mysql_query("TRUNCATE game_lottery") or print(mysql_error() . " " . __FILE__ . " #" . __LINE__); } } if($hour == 19 && $min == 00 && ($day == "Saturday")){ // Big weekly draw. } mysql_close($connect); ?>