MyBB Community Forums

Full Version: How to add newpoints per Award
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hello,

i'm want to add points per a user get a award but i can't find this feature.

i'm trying to create a new function but i think i have some error can any one help me what's wrong in this code


function newpoints_newaward()

    {

        global $db, $mybb, $aid;

     

        if (!$mybb->user['uid'])

            return;

     
        if ($mybb->settings['newpoints_main_enabled'] != 1)
            return;
         
        if ($mybb->settings['newpoints_income_award'] == 0)

            return;

        $where = "u.uid='".(int)$user['uid']."'";

        // Get awards

        $query = $db->query('

            SELECT u.*, a.*

            FROM '.TABLE_PREFIX.'ougc_awards_users u

            LEFT JOIN '.TABLE_PREFIX.'ougc_awards a ON (u.aid=a.aid)

            WHERE '.$where.'

            ');

        $awards = $db->fetch_array($query);

        $aid = $awards['aid'];

        // check forum rules

        $forumrules = newpoints_getrules('forum', $aid);

        if (!$forumrules)

            $forumrules['rate'] = 1; // no rule set so default income rate is 1

     

        // if the forum rate is 0, nothing is going to be added so let's just leave the function

        if ($forumrules['rate'] == 0)

            return;

        // check group rules - primary group check

        $grouprules = newpoints_getrules('group', $mybb->user['usergroup']);

        if (!$grouprules)

            $grouprules['rate'] = 1; // no rule set so default income rate is 1

     

        // if the group rate is 0, nothing is going to be added so let's just leave the function

        if ($grouprules['rate'] == 0)

            return;

        // give points to the user

        newpoints_addpoints($user['uid'], $mybb->settings['newpoints_income_award'], $forumrules['rate'], $grouprules['rate']);   
}
I can think of three ways to achieve this.
  1. Simply use the task system, which allows you to grant awards once users reach a specific newpoints amount.
  2. Use the core group promotion feature to promote user groups once they reach a newpoints amount. If promotion by newpoints is not possible you can try using my plugin OUGC Custom Promotion Field
    Then, use the OUGC Awards task system to grant awards to users from an specific group once.
  3. Use the plugin hook ougc_awards_give_award. Something around the lines of the following:
    $plugins->add_hook('ougc_awards_give_award', 'foo');
    function foo(&$args)
    {
    	global $mybb;
    
    	$uid = (int)$args['user']['uid'];
    
    	if(!$uid || !$mybb->settings['newpoints_main_enabled'] || !$mybb->settings['newpoints_income_award'])
    	{
    		return;
    	}
    
    	$user = get_user($uid);
    
    	$group_rate = 1;
    
    	if($grouprules = newpoints_getrules('group', (int)$user['usergroup']))
    	{
    		$group_rate = (float)$grouprules['rate'];
    	}
    
    	if(!$group_rate)
    	{
    		return;
    	}
    
    	newpoints_addpoints($uid, $mybb->settings['newpoints_income_award'], 1, $group_rate); // There are no forum assigned for awards.
    
    	newpoints_log('award_grant_points', "Award ID: {$args['award']['aid']}", $user['username'], $uid);
    }
    

I think the last option fulfills better what you want to achieve.
Hi

Thanks You for replying me i try this solution but nothing got happen

I'm trying to give amount of points received everytime a user get award (i add this setting in Income Settings of Newpoints Plugin)

for example when a user have 2 awards he got 100 points per award
The plugin hook should work for that. Using the example code I shared you should be able to get a plugin working.

How are you adding your hook? What error do you get from your code?
(2020-11-27, 10:59 AM)Omar G. Wrote: [ -> ]The plugin hook should work for that. Using the example code I shared you should be able to get a plugin working.

How are you adding your hook? What error do you get from your code?


add it in newpoints/core/hooks.php


i don't get any error but points is not working
Maybe if you share the exact code somebody might be able to assist you.
(2021-01-07, 05:55 PM)Omar G. Wrote: [ -> ]Maybe if you share the exact code somebody might be able to assist you.

Thanks this is my code

$plugins->add_hook('ougc_awards_give_award', 'newpoints_newaward');
function newpoints_newaward(&$args)
{
global $mybb;

$uid = (int)$args['user']['uid'];

if(!$uid || $mybb->settings['newpoints_main_enabled'] != 1  || $mybb->settings['newpoints_income_award'] == 0)
{
return;
}

$user = get_user($uid);

$group_rate = 1;

if($grouprules = newpoints_getrules('group', (int)$user['usergroup']))
{
$group_rate = (float)$grouprules['rate'];
}

if(!$group_rate)
{
return;
}

newpoints_addpoints($uid, $mybb->settings['newpoints_income_award'], 1, $group_rate);

newpoints_log('award_grant_points', "Award ID: {$args['award']['aid']}", $user['username'], $uid);

}
Any solution guys ??
Where exactly did you add that code (line number)?
https://github.com/DiogoParrinha/newpoin.../hooks.php

How do you grant users awards, from the ACP or from the ModCP?
(2021-01-12, 06:58 AM)Omar G. Wrote: [ -> ]Where exactly did you add that code (line number)?
https://github.com/DiogoParrinha/newpoin.../hooks.php

How do you grant users awards, from the ACP or from the ModCP?

Exactly in line 1168 after newpoints_restorethreads function.

i grant awards from ACP
Pages: 1 2 3