Page 1 of 1

Raising the value slowly

Posted: Wed Feb 16, 2005 7:20 pm
by azz0r_
Ok basically Ive rewrote my kama system.

Basically say a user has 3000 karma, I have a forumula that works out how many blocks the user should have.

The only problem I have is the "step". Technically it should start off @ like 100 per block, then by the end require 400 odd per a block.

Example; http://forumz.wuggawoo.co.uk/index/test?user_karma=1999

Code

Code: Select all

Post three

Posted: Wed Feb 16, 2005 8:18 pm
by feyd
do you want to use a math equation for stepping, or just a facetted system?

Posted: Thu Feb 17, 2005 4:24 am
by azz0r_
Math equation, I'm not familiar with foreach.

However I am aware that Ive seen something similar to a step equation of like $amount * 1.3.

Posted: Thu Feb 17, 2005 1:33 pm
by azz0r_
Updated code

Code: Select all

function define_bar($actual_bar, $blocks)  {

	if($actual_bar <= ceil($blocks / 6))
	&#123;$bar_scale = 'sta';&#125;
		
		elseif($actual_bar == ceil($blocks / 4))
		&#123;$bar_scale = 'avg';&#125;
	
	elseif($actual_bar == ceil($blocks / 2))
	&#123;$bar_scale = 'med';&#125;
		
		elseif($actual_bar == $blocks)
		&#123;$bar_scale = 'max';&#125;

return $bar_scale;&#125;


	$forum_properties&#1111;'karma_limit'] = 2000;
	$forum_properties&#1111;'karma_blocks'] = 10;
	$per_block = ceil($forum_properties&#1111;'karma_limit'] / $forum_properties&#1111;'karma_blocks']);
	$user_karma = $_GET&#1111;'user_karma'];
	$number_of_blocks = floor($user_karma / $per_block);
	$block_steps = array(100, 200, 350, 500);
	
	echo "The karma limit is ".$forum_properties&#1111;'karma_limit']."<br />";	echo "The number of blocks to fill is ".$forum_properties&#1111;'karma_blocks']."<br />";	echo "For each block $per_block is needed.<br />"; echo "For this test, the user has $user_karma karma.<br />";	echo "That means there is $number_of_blocks blocks filled in.<br /><br />";


	while($x < $forum_properties&#1111;'karma_blocks'])//we make our blocks
	&#123;$x++; $actual_bar++;
	
	$bar_scale = define_bar($actual_bar, $forum_properties&#1111;'karma_blocks']);

	if($number_of_blocks > 0)
	&#123;$number_of_blocks--; $blocked .= "<img src="$bar_scale.jpg">";&#125;
	else
	&#123;$unblocked .= "<img src="empty.jpg">";&#125;&#125;



	echo $blocked.$unblocked;
Ive tried some foreach testing but I can get it right

Posted: Sat Feb 19, 2005 12:10 am
by feyd
exponential stepping:

Code: Select all

$exponential = 1.4;
$negative = $karma < 0;
$karma = abs($karma);
$blocks = 1;
$multiplier = 100;
while($karma > (pow($blocks, $exponential) * $multiplier)) $blocks++;
fiddle with $multipler and $exponential to adjust where the steps happen. If need be, you can store off the result and shave it into hundreds or something..

precalculating the level requirements for many blocks would help speed the processing..

Posted: Sat Feb 19, 2005 9:57 am
by azz0r_
I dont understand your code, so I tried to come up with something else.

Code: Select all

$block_steps = array(100, 200, 350, 500);

	foreach ($block_steps as $value)
	&#123;$step&#1111;$value] = floor($forum_properties&#1111;'karma_limit'] / $value);
	$total = $total + (($value * $step&#1111;$value]) / 4);
	$stepo&#1111;$value] = floor(($forum_properties&#1111;'karma_limit'] / $value) / 4);&#125;

echo $total;
print '<br />';print_r($step);
print '<br />';print_r($stepo);
Which doesnt consider how many blocks there is, but its a start

Posted: Mon Feb 21, 2005 10:20 am
by azz0r_
Hey I got it working, I decide the method I was going for was slightly slopped, the new method basically uses the array that would allow the admin to decide how many of each blocks there should be and is very versitile as you'll see below.

Code: Select all

$forum_properties&#1111;'user_karma'] = $_GET&#1111;'user_karma'];
	$karma_total&#1111;'fifty'] = 1;
	$karma_total&#1111;'one'] = 3;
	$karma_total&#1111;'two'] = 2;
	$karma_total&#1111;'three'] = 2;
	$karma_total&#1111;'four'] = 0;
	$karma_total&#1111;'five'] = 1;
	$karma_total&#1111;'six'] = 1;
	$karma_total&#1111;'seven'] = 1;
	$karma_total&#1111;'eight'] = 0;

$karma_array = array(
	array(50, $karma_total&#1111;'fifty'], 1), 
	array(100, $karma_total&#1111;'one'], 1), 
	array(200, $karma_total&#1111;'two'], 2), 
	array(300, $karma_total&#1111;'three'], 2), 
	array (400, $karma_total&#1111;'four'], 2), 
	array(500, $karma_total&#1111;'five'], 3), 
	array(600, $karma_total&#1111;'six'], 3), 
	array(700, $karma_total&#1111;'seven'], 3), 
	array(800, $karma_total&#1111;'eight'], 4));

#else	
####information
foreach($karma_array as $sub_array)
&#123;list($value, $amount) = $sub_array;
$total = $total + ($value * $amount);
$blocks = $blocks + $amount;&#125;
echo "Total karma to achieve a full bar is $total.<br />Total number of blocks is $blocks.<br />";
###information


	foreach($karma_array as $sub_array)
	&#123;list($value, $no_bars, $image) = $sub_array;

	while($no_bars > 0)  &#123;
	

	if($forum_properties&#1111;'user_karma'] >= $value)
	&#123;$block .= '<img src="'.$image.'.jpg" alt="'.$value.'" />';
	$forum_properties&#1111;'user_karma'] = $forum_properties&#1111;'user_karma'] - $value;&#125;
	else
	&#123;$unblock .= '<img src="empty.jpg" alt="" />';&#125;

	$no_bars--;
	&#125;#end while
	&#125;#end foreach
	


	echo $block.$unblock;
Thanks for your help :)