Jump to content
MakeWebGames

Cron Events


peterisgb

Recommended Posts

I'm trying to make a cron file where the prizes are auto credited and an announcement is made.

I've done abit of this so far and all the functions.

but its not quite right and i need a little help to finish it of so it will work,

This is what i have so far.

<?php
include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
$userInfo = $db->query('SELECT `userid`, `sides` FROM `users` ORDER BY sides DESC LIMIT 3');
if($db->num_rows($userInfo) > 0) {
$ir = $db->fetch_row($userInfo);
$AddAnnouce = sprintf("INSERT INTO mod_announcements (`annouce_NAME`, `annouce_TEXT`, `annouce_TIME`, `annouce_URGENCY`, `annouce_TOPIC`, `annouce_POSTED`)VALUES ('Hackers VS Police', 'Hackers Vs Police Event has Finished.<br />
The Winners are:<br />
1st Place - {username} Winning 10 Magic Boxes<br />
2nd Place - {username} Winning 5 Magic Boxes<br />
3rd Place - {username} Winning 1 Magic Boxes<br />
<br />Congrats and well done.<br />', unix_timestamp(), 'No Urgency', 'Fun', 'System Message')");
$db->query($AddAnnouce);
$db->query("UPDATE users SET new_announcements=new_announcements+1");
$db->query("INSERT INTO inventory VALUES('',72,{winner},10)", $c);
$db->query("INSERT INTO inventory VALUES('',72,{second},5)", $c);
$db->query("INSERT INTO inventory VALUES('',72,{third},1)", $c);
$db->query("UPDATE users SET sides=0 WHERE sides > 0");
?>

 

As you can see there are a few bits missing and things are wrong, but i've done what i can to the best of my knowledge.

Any help would be great, thanks

Link to comment
Share on other sites

<?php


require_once('globals_nonauth.php');


if ($argc == 2)
{
   if ($argv[1] != $_CONFIG['code'])
   {
       exit;
   }
}
else if (!isset($_GET['code']) || $_GET['code'] !== $_CONFIG['code'])
{
   exit;

}

///Picks at random (The winner)

$draw=mysql_query("SELECT * FROM userstatistics WHERE draw > 0 LIMIT 1");
$sql=mysql_fetch_array($draw);
$draw2 = mysql_query("SELECT * FROM users WHERE userid = {$sql['userid']}");
$sql2=mysql_fetch_array($draw2);




///This is where the item is added

item_add($sql2['userid'], ITEMID, 1);

///This is where the event is added

event_add($sql2['userid'],"Congratulations, you are a winner of this weeks donators draw and have been credited a donator pack - offer 1");




///This is where the annoucement is added


      $name="Donator Draw";
       $announcement="<font size=3 face=Impact color=orange><u>General Draw</u></font>

       The winners of this weeks general draw is:

       Winner - {$sql2['username']} [{$sql2['userid']}]

       Winner will be credited immediately along with an event notification.

       Want to take part?
   Login on your account in any one week to be automatically entered.

       Prize:
   Prize is a free Donator Pack - Offer 1.";

       $db->query("UPDATE users SET userstatistics  = 0");
       $db->query("UPDATE users SET `new_announcements` = `new_announcements` + 1");
       $db->query("INSERT INTO announcements (`announce_NAME`, `announce_TEXT`, `announce_TIME`, `announce_URGENCY`, `announce_TOPIC`, `announce_POSTED`) VALUES ('$name', '$announcement', unix_timestamp(), 'No Urgency', 'General News', 'SYSTEM')");

 

 

Here's an little help. Edit this in your needs.

Link to comment
Share on other sites

<?php


require_once('globals_nonauth.php');


if ($argc == 2)
{
   if ($argv[1] != $_CONFIG['code'])
   {
       exit;
   }
}
else if (!isset($_GET['code']) || $_GET['code'] !== $_CONFIG['code'])
{
   exit;

}

///Picks at random (The winner)

$draw=mysql_query("SELECT * FROM userstatistics WHERE draw > 0 LIMIT 1");
$sql=mysql_fetch_array($draw);
$draw2 = mysql_query("SELECT * FROM users WHERE userid = {$sql['userid']}");
$sql2=mysql_fetch_array($draw2);




///This is where the item is added

item_add($sql2['userid'], ITEMID, 1);

///This is where the event is added

event_add($sql2['userid'],"Congratulations, you are a winner of this weeks donators draw and have been credited a donator pack - offer 1");




///This is where the annoucement is added


      $name="Donator Draw";
       $announcement="<font size=3 face=Impact color=orange><u>General Draw</u></font>

       The winners of this weeks general draw is:

       Winner - {$sql2['username']} [{$sql2['userid']}]

       Winner will be credited immediately along with an event notification.

       Want to take part?
   Login on your account in any one week to be automatically entered.

       Prize:
   Prize is a free Donator Pack - Offer 1.";

       $db->query("UPDATE users SET userstatistics  = 0");
       $db->query("UPDATE users SET `new_announcements` = `new_announcements` + 1");
       $db->query("INSERT INTO announcements (`announce_NAME`, `announce_TEXT`, `announce_TIME`, `announce_URGENCY`, `announce_TOPIC`, `announce_POSTED`) VALUES ('$name', '$announcement', unix_timestamp(), 'No Urgency', 'General News', 'SYSTEM')");

 

 

Here's an little help. Edit this in your needs.

Its say's login into your account to be automatically entered were will this happen

Link to comment
Share on other sites

<?php


require_once('globals_nonauth.php');


if ($argc == 2)
{
   if ($argv[1] != $_CONFIG['code'])
   {
       exit;
   }
}
else if (!isset($_GET['code']) || $_GET['code'] !== $_CONFIG['code'])
{
   exit;

}

///Picks at random (The winner)

$draw=mysql_query("SELECT * FROM userstatistics WHERE draw > 0 LIMIT 1");
$sql=mysql_fetch_array($draw);
$draw2 = mysql_query("SELECT * FROM users WHERE userid = {$sql['userid']}");
$sql2=mysql_fetch_array($draw2);




///This is where the item is added

item_add($sql2['userid'], ITEMID, 1);

///This is where the event is added

event_add($sql2['userid'],"Congratulations, you are a winner of this weeks donators draw and have been credited a donator pack - offer 1");




///This is where the annoucement is added


      $name="Donator Draw";
       $announcement="<font size=3 face=Impact color=orange><u>General Draw</u></font>

       The winners of this weeks general draw is:

       Winner - {$sql2['username']} [{$sql2['userid']}]

       Winner will be credited immediately along with an event notification.

       Want to take part?
   Login on your account in any one week to be automatically entered.

       Prize:
   Prize is a free Donator Pack - Offer 1.";

       $db->query("UPDATE users SET userstatistics  = 0");
       $db->query("UPDATE users SET `new_announcements` = `new_announcements` + 1");
       $db->query("INSERT INTO announcements (`announce_NAME`, `announce_TEXT`, `announce_TIME`, `announce_URGENCY`, `announce_TOPIC`, `announce_POSTED`) VALUES ('$name', '$announcement', unix_timestamp(), 'No Urgency', 'General News', 'SYSTEM')");

 

 

Here's an little help. Edit this in your needs.

Yes because posting a whole different script is really going to help.................................. >.<

Link to comment
Share on other sites

  • 2 weeks later...

Question: Why use sprintf() on straight text?

Untested, but this should work - not the cleanest code in the world

<?php
include(__DIR__ . '/config.php');
global $_CONFIG;
define("MONO_ON", 1);
require(__DIR__ . '/class/class_db_'.$_CONFIG['driver'].'.php');
$db = new database;
$db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']);
$db->connect();
$c = $db->connection_id;
$userInfo = $db->query('SELECT `userid`, `username`, `sides` FROM `users` ORDER BY `sides` DESC LIMIT 3');
if($db->num_rows($userInfo) > 0) {
$announce = '';
$i = 0;
$stNdRd = array(
	1 => '1st',
	2 => '2nd',
	3 => '3rd'
);
$prize = array(
	1 => 10,
	2 => 5,
	3 => 1
);
while($row = $db->fetch_row($userInfo)) {
	++$i;
	$announce .= $stNdRd[$i].' Place - '.$row['username'].' Winning '.$prize[$i].' Magic Box'.(($prize[$i] == 1) ? '' : 'es')."\r\n";
	$db->query("INSERT INTO `inventory` VALUES (NULL, 72, ".$row['userid'].", ".$prize[$i].")");
}
$db->query("INSERT INTO mod_announcements (`annouce_NAME`, `annouce_TEXT`, `annouce_TIME`, `annouce_URGENCY`, `annouce_TOPIC`, `annouce_POSTED`) VALUES ('Hackers VS Police', 'Hackers Vs Police Event has Finished.
The Winners are:
".$announce."
Congrats and well done.', unix_timestamp(), 'No Urgency', 'Fun', 'System Message')");
$db->query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1");
$db->query("UPDATE `users` SET `sides` = 0 WHERE `sides` > 0");
}
?>
Edited by Magictallguy
Bug fixes and a rework
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...