MyBB Community Forums

Full Version: Query not writing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2017-07-30, 11:49 AM)fizz Wrote: [ -> ]
(2017-07-30, 10:27 AM)chack1172 Wrote: [ -> ]The function random_reset() is never executed in your code.
Oh lol can't believe I didn't notice that.

(2017-07-30, 10:31 AM)Wires Wrote: [ -> ]This is probably the 2nd plugin I've attempted. Mind explaining a little more?
Nowhere in your plugin do you call random_reset(). It's just a function that's defined and never used right now.
Also side note: you shouldn't include the closing tag "?>" at the end of the file as PHP will auto-append it to all files automatically by default.

For what I'm doing, how would you suggest I do that for an IF statement?
Ok your code is wrong for your purposes, settings is a general var for all users, so i read some part of your code and it's bad, due you have to update the usergroup to the new one on user, not settings.

And the random value can setting it up via count in users table and the random php function to get the value instead inserting the value into that plugin part, is more easy to asign manually the user to the new created group, you have to reload cache for usergroups either and more things, your called hooks do nothing. So plugin would not work.

I think is more easy to make it from scratch with entire change of the code because this way your plugin will do an unnecessary query'es and is hard to know what is the purpose, i think you want to add the user or set as a new usergroup, created by the setting in your query, but i dunno.

Anyways the plugin at this moment do nothing, i have changed many parts but i do not really know what you whant to do at all.

The only thing you are doing is changing plugin settings like you are in settings page....

And this is the working on code, only you have to workn on the new parts, but i recommend you to not create an usergroup, but a new field onto users to set the image, and a var adds to setting it up in the parts you wish to show that, i mean for me this plugin have no sense at all, due it can be done in other ways more easily bro.

<?php
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly. Please Make Sure IN_MYBB Is Defined.");
}

// Hooks
$plugins->add_hook('global_start', 'random_global_start');

function random_info()
{
	return array(
        "name"  => "Random Userbar Game",
        "description"=> "Steal a userbar from someone when repping them",
        "website"        => "http://softwaysandre.com",
        "author"        => "Wires",
        "authorsite"    => "http://softwaysandre.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
    );
}
// Activate
function random_activate() {

global $db, $cache;

$random_group = array(
        'name'  => 'random',
        'title'      => 'Random Userbar Game',
        'description'    => 'Settings For My First Plugin',
        'disporder'    => 1,
        'isdefault'  => 0,
    );

$db->insert_query('settinggroups', $random_group);
$gid = $db->insert_id();

$random_setting_1 = array(
        'name'        => 'random_enable',
        'title'            => 'Power on?',
        'description'    => 'If you set this option to yes, this plugin be active on your board.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 1,
        'gid'            => intval($gid),
    );

$random_setting_2 = array(
        'name'        => 'random_userbar',
        'title'            => 'Userbar URL',
        'description'    => 'Set IMG url to userbar',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 2,
        'gid'            => intval($gid),
    );
    
$random_setting_3 = array(
        'name'        => 'random_reset',
        'title'            => 'Reset',
        'description'    => 'Reset and rebuild settings page.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 4,
        'gid'            => intval($gid),
    );
    
$random_setting_4 = array(
        'name'        => 'random_uid',
        'title'            => 'Set UID',
        'description'    => 'Give a user the userbar to begin with.',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 3,
        'gid'            => intval($gid),
    );

	$db->insert_query('settings', $random_setting_1);
	$db->insert_query('settings', $random_setting_2);
	$db->insert_query('settings', $random_setting_3);
	$db->insert_query('settings', $random_setting_4);
	rebuild_settings();
	
    
// Create usergroup
$random_create_group = array(
        'type'            => 1,
        'title'            => 'Lucky Usergroup',
        'description'    => 'You stole the userbar.',
        'namestyle'    => '{username}',
        'usertitle'        => '',
        'stars'         => 0,
        'starimage'         => 'images/stars.png',
        'image'        => 'test',
        'disporder'        => 0,
        'isbannedgroup'        => 0,
        'canview'        => 1,
        'canviewthreads'        => 1,
        'canviewprofiles'        => 1,
        'candlattachments'        => 1,
        'canviewboardclosed'        => 0,
        'canpostthreads'        => 1,
        'canpostreplys'        => 1,
        'canpostattachments'        => 1,
        'canratethreads'        => 1,
        'modposts'        => 0,
        'modthreads'        => 0,
        'mod_edit_posts'        => 0,
        'modattachments'        => 0,
        'caneditposts'        => 1,
        'candeleteposts'        => 1,
        'candeletethreads'        => 1,
        'caneditattachments'        => 1,
        'canviewdeletionnotice'        => 1,
        'canpostpolls'        => 1,
        'canvotepolls'        => 1,
        'canundovotes'        => 0,
        'canusepms'        => 1,
        'cansendpms'        => 1,
        'cantrackpms'        => 1,
        'candenypmreceipts'        => 1,
        'pmquota'        => '200',
        'maxpmreceipients'        => '5',
        'cansendemail'        => 1,
        'cansendemailoverride'        => 0,
        'maxemails'        => '5',
        'emailfloodtime'        => '5',
        'canviewmemberlist'        => 1,
        'canviewcalender'        => 1,
        'canaddevents'        => 1,
        'canbypasseventmod'        => 0,
        'canmoderateevents'        => 0,
        'canviewonline'        => 1,
        'canviewwolinvis'        => 0,
        'canviewonlineips'        => 0,
        'cancp'        => 0,
        'issupermod'        => 0,
        'cansearch'        => 1,
        'canusercp'        => 1,
        'canuploadavatars'        => 1,
        'canratemembers'        => 1,
        'canchangename'        => 0,
        'canbereported'        => 1,
        'canchangewebsite'        => 1,
        'showforumteam'        => 0,
        'usereputationsystem'        => 1,
        'cangivereputations'        => 1,
        'candeletereputations'        => 1,
        'reputationpower'        => '1',
        'maxreputationsday'        => '5',
        'maxreputationsperuser'        => '0',
        'maxreputationsperthread'        => '0',
        'candisplaygroup'        => 1,
        'attachquota'        => '0',
        'cancustomtitle'        => 1,
        'canwarnusers'        => 0,
        'canreceivewarnings'        => 1,
        'maxwarningsday'        => '0',
        'canmodcp'        => 0,
        'showinbirthdaylist'        => 1,
        'canoverridepm'        => 0,
        'canusesig'        => 1,
        'canusesigxposts'        => 0,
        'signofollow'        => 0,
        'canedittimelimit'        => 0,
        'maxposts'        => 0,
        'showmemberlist'        => 1,
        'canmanageannounce'        => 0,
        'canmanagemodqueue'        => 0,
        'canmanagereporedcontent'        => 0,
        'canviewmodlogs'        => 0,
        'caneditprofiles'        => 0,
        'canbanusers'        => 0,
        'canviewwarnlogs'        => 0,
        'canuseipsearch'        => 0,
        'gid'            => intval($gid),
    );
    
	$db->insert_query('usergroups', $random_create_groups);
	$cache->update('usergroups');
}
// Disable
function random_deactivate()
  {
  global $db, $cache;
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('random_enable', 'random_userbar', 'random_reset', 'random_uid')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='random'");
	rebuild_settings();
    $db->query("DELETE FROM ".TABLE_PREFIX."usergroups WHERE title='Lucky Usergroup'");
	$cache->update('usergroups');
	
}
// Start Hook
function random_global_start(){
global $mybb;

	if ($mybb->settings['random_enable'] == 1){
		random_reset();
	}
}
// Reset
function random_reset() {
  global $mybb, $db;
if ($mybb->settings['random_reset'] == 1){
	$uid = (int)$mybb->settings['random_uid'];
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
	if($uid > 0)
	giveuserbar($uid);
	rebuild_settings();	
	}
}

function giveuserbar($uid)
{
// Here you write the code for the uid and done !!!
}

See yah !!!
(2017-07-30, 06:35 PM)Whiteneo Wrote: [ -> ]Ok your code is wrong for your purposes, settings is a general var for all users, so i read some part of your code and it's bad, due you have to update the usergroup to the new one on user, not settings.

And the random value can setting it up via count in users table and the random php function to get the value instead inserting the value into that plugin part, is more easy to asign manually the user to the new created group, you have to reload cache for usergroups either and more things, your called hooks do nothing. So plugin would not work.

I think is more easy to make it from scratch with entire change of the code because this way your plugin will do an unnecessary query'es and is hard to know what is the purpose, i think you want to add the user or set as a new usergroup, created by the setting in your query, but i dunno.

Anyways the plugin at this moment do nothing, i have changed many parts but i do not really know what you whant to do at all.

The only thing you are doing is changing plugin settings like you are in settings page....

And this is the working on code, only you have to workn on the new parts, but i recommend you to not create an usergroup, but a new field onto users to set the image, and a var adds to setting it up in the parts you wish to show that, i mean for me this plugin have no sense at all, due it can be done in other ways more easily bro.

<?php
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly. Please Make Sure IN_MYBB Is Defined.");
}

// Hooks
$plugins->add_hook('global_start', 'random_global_start');

function random_info()
{
	return array(
        "name"  => "Random Userbar Game",
        "description"=> "Steal a userbar from someone when repping them",
        "website"        => "http://softwaysandre.com",
        "author"        => "Wires",
        "authorsite"    => "http://softwaysandre.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
    );
}
// Activate
function random_activate() {

global $db, $cache;

$random_group = array(
        'name'  => 'random',
        'title'      => 'Random Userbar Game',
        'description'    => 'Settings For My First Plugin',
        'disporder'    => 1,
        'isdefault'  => 0,
    );

$db->insert_query('settinggroups', $random_group);
$gid = $db->insert_id();

$random_setting_1 = array(
        'name'        => 'random_enable',
        'title'            => 'Power on?',
        'description'    => 'If you set this option to yes, this plugin be active on your board.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 1,
        'gid'            => intval($gid),
    );

$random_setting_2 = array(
        'name'        => 'random_userbar',
        'title'            => 'Userbar URL',
        'description'    => 'Set IMG url to userbar',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 2,
        'gid'            => intval($gid),
    );
    
$random_setting_3 = array(
        'name'        => 'random_reset',
        'title'            => 'Reset',
        'description'    => 'Reset and rebuild settings page.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 4,
        'gid'            => intval($gid),
    );
    
$random_setting_4 = array(
        'name'        => 'random_uid',
        'title'            => 'Set UID',
        'description'    => 'Give a user the userbar to begin with.',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 3,
        'gid'            => intval($gid),
    );

	$db->insert_query('settings', $random_setting_1);
	$db->insert_query('settings', $random_setting_2);
	$db->insert_query('settings', $random_setting_3);
	$db->insert_query('settings', $random_setting_4);
	rebuild_settings();
	
    
// Create usergroup
$random_create_group = array(
        'type'            => 1,
        'title'            => 'Lucky Usergroup',
        'description'    => 'You stole the userbar.',
        'namestyle'    => '{username}',
        'usertitle'        => '',
        'stars'         => 0,
        'starimage'         => 'images/stars.png',
        'image'        => 'test',
        'disporder'        => 0,
        'isbannedgroup'        => 0,
        'canview'        => 1,
        'canviewthreads'        => 1,
        'canviewprofiles'        => 1,
        'candlattachments'        => 1,
        'canviewboardclosed'        => 0,
        'canpostthreads'        => 1,
        'canpostreplys'        => 1,
        'canpostattachments'        => 1,
        'canratethreads'        => 1,
        'modposts'        => 0,
        'modthreads'        => 0,
        'mod_edit_posts'        => 0,
        'modattachments'        => 0,
        'caneditposts'        => 1,
        'candeleteposts'        => 1,
        'candeletethreads'        => 1,
        'caneditattachments'        => 1,
        'canviewdeletionnotice'        => 1,
        'canpostpolls'        => 1,
        'canvotepolls'        => 1,
        'canundovotes'        => 0,
        'canusepms'        => 1,
        'cansendpms'        => 1,
        'cantrackpms'        => 1,
        'candenypmreceipts'        => 1,
        'pmquota'        => '200',
        'maxpmreceipients'        => '5',
        'cansendemail'        => 1,
        'cansendemailoverride'        => 0,
        'maxemails'        => '5',
        'emailfloodtime'        => '5',
        'canviewmemberlist'        => 1,
        'canviewcalender'        => 1,
        'canaddevents'        => 1,
        'canbypasseventmod'        => 0,
        'canmoderateevents'        => 0,
        'canviewonline'        => 1,
        'canviewwolinvis'        => 0,
        'canviewonlineips'        => 0,
        'cancp'        => 0,
        'issupermod'        => 0,
        'cansearch'        => 1,
        'canusercp'        => 1,
        'canuploadavatars'        => 1,
        'canratemembers'        => 1,
        'canchangename'        => 0,
        'canbereported'        => 1,
        'canchangewebsite'        => 1,
        'showforumteam'        => 0,
        'usereputationsystem'        => 1,
        'cangivereputations'        => 1,
        'candeletereputations'        => 1,
        'reputationpower'        => '1',
        'maxreputationsday'        => '5',
        'maxreputationsperuser'        => '0',
        'maxreputationsperthread'        => '0',
        'candisplaygroup'        => 1,
        'attachquota'        => '0',
        'cancustomtitle'        => 1,
        'canwarnusers'        => 0,
        'canreceivewarnings'        => 1,
        'maxwarningsday'        => '0',
        'canmodcp'        => 0,
        'showinbirthdaylist'        => 1,
        'canoverridepm'        => 0,
        'canusesig'        => 1,
        'canusesigxposts'        => 0,
        'signofollow'        => 0,
        'canedittimelimit'        => 0,
        'maxposts'        => 0,
        'showmemberlist'        => 1,
        'canmanageannounce'        => 0,
        'canmanagemodqueue'        => 0,
        'canmanagereporedcontent'        => 0,
        'canviewmodlogs'        => 0,
        'caneditprofiles'        => 0,
        'canbanusers'        => 0,
        'canviewwarnlogs'        => 0,
        'canuseipsearch'        => 0,
        'gid'            => intval($gid),
    );
    
	$db->insert_query('usergroups', $random_create_groups);
	$cache->update('usergroups');
}
// Disable
function random_deactivate()
  {
  global $db, $cache;
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('random_enable', 'random_userbar', 'random_reset', 'random_uid')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='random'");
	rebuild_settings();
    $db->query("DELETE FROM ".TABLE_PREFIX."usergroups WHERE title='Lucky Usergroup'");
	$cache->update('usergroups');
	
}
// Start Hook
function random_global_start(){
global $mybb;

	if ($mybb->settings['random_enable'] == 1){
		random_reset();
	}
}
// Reset
function random_reset() {
  global $mybb, $db;
if ($mybb->settings['random_reset'] == 1){
	$uid = (int)$mybb->settings['random_uid'];
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
	$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
	if($uid > 0)
	giveuserbar($uid);
	rebuild_settings();	
	}
}

function giveuserbar($uid)
{
// Here you write the code for the uid and done !!!
}

See yah !!!

Thanks a bunch. Unfortunately that didn't work. I'm probably going to start from scratch, but the whole idea is to create a plugin that's a forum game. Random user starts off with a userbar, first person to rep them whilst they have the userbar basically steals the userbar. Wanted to give this a go myself as my first proper plugin.

Any advice? Toungue
Yeah that code works as has written , so only rebuild settings inside plugin you have to set group by the right var, to make it, but only that group is a usergroup valid so you can set the img in that group and then set the user into thta group i have tested with some changes in the core file, but the code above only works as the writen parts, but not any more Smile

I can do the plugin when i have some free time if you need it but i have to know with images what are you looking for to make it maybe in this month if i have some free time because right now i am developing many plugins, mods, and helping many people with his sites so i am too bussy bro.

But i will give you a feedback if i got some time to do Smile
Pages: 1 2