MyBB Hacks

Full Version: Task -> Update Age
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I run an rpg forum which means automatic aging is a nice thing to have.

I’ve followed this freebie to a t (meaning I’ve installed everything as how it’s shown here): http://rpg-directory.com/showthread.php?tid=86759

Anytime I try to manually run the task for testing purposes (I have it set up to run every minute) I get an SQL error and essentially this thing doesn’t work at all.

Error attached in screenshot.

If anyone knows what the issue could be please let me know because this is frustrating and I’ve not been able to get ahold of the original creator of this for a while. .
The table named set twice on the task query. Also, it seems that there is something wrong with your code near to the UPDATE.
I figured out that it was incorrect table wise as it is not mybb_ it's actually mybbsc_ for my database.

Here is the full code:

PHP Code:
 <?php
/**
* Author: Shinka
* Description: Task that, when ran, automatically adjusts all characters' ages
* based on current age, registration date, and current date.
*/

function task_age($task)
{
global $mybb, $db;

/**
* INCREMENT AMOUNT
* Amount to increment age by.
* Can be integer (e.g. 1) or float (e.g. 0.5).
*/
$INCREMENT = 0.5;

/**
* UPDATE AGE
* Replace "fid18" with the ID of your custom profile field.
* If your age field only allows whole numbers, change "DECIMAL(11, 2)" to "UNSIGNED".
*/
$query = $db->query("
   UPDATE mybbsc_userfields userfields
   SET fid2 = CAST(fid2 as DECIMAL(100, 1)) + {$INCREMENT};
");

add_task_log($task, "The age characters task successfully ran.");
}


I'm also noticing that the regular expression for the profile field will not recognize 0 (as if filled in on the profile as 0 it will not show up, just acts as if it doesn't even exist? which is weird and then also won't update with the task).

Changed "DECIMAL(11, 2)" to "DECIMAL(100, 1)" so that there was more room for numbers before the decimal and only one number after the decimal.

I originally did not want decimals at all, just whole increments and tried to follow the tutorial for that, however when replacing "DECIMAL(100, 1)" with "UNSIGNED" it shows up as another SQL error like that is completely incorrect variable? I'm wondering if maybe this script is just certainly too buggy or incorrect to use?

Example with "DECIMAL(100, 1)" changed to "UNSIGNED" :

PHP Code:
 <?php
/**
* Author: Shinka
* Description: Task that, when ran, automatically adjusts all characters' ages
* based on current age, registration date, and current date.
*/

function task_age($task)
{
global $mybb, $db;

/**
* INCREMENT AMOUNT
* Amount to increment age by.
* Can be integer (e.g. 1) or float (e.g. 0.5).
*/
$INCREMENT = 1;

/**
* UPDATE AGE
* Replace "fid18" with the ID of your custom profile field.
* If your age field only allows whole numbers, change "DECIMAL(11, 2)" to "UNSIGNED".
*/
$query = $db->query("
   UPDATE mybbsc_userfields userfields
   SET fid2 = CAST(fid2 as UNSIGNED) + {$INCREMENT};
");

add_task_log($task, "The age characters task successfully ran.");
}

(12-26-2017 06:36 AM)Niki Wrote: [ -> ]I originally did not want decimals at all, just whole increments and tried to follow the tutorial for that, however when replacing "DECIMAL(100, 1)" with "UNSIGNED" it shows up as another SQL error like that is completely incorrect variable?

What error you get?
Reference URL's