SMF Shop

SMFShop => General SMFShop Discussion => Topic started by: matkins70 on September 04, 2006, 08:52:06 am

Title: SMFShop and SMF Arcade
Post by: matkins70 on September 04, 2006, 08:52:06 am
I was wondering whether anyone had looked into the possibility, or even created a script for giving a user credits if they acheive a highscore in the arcade.

I don't want to make anything complicated, such as retaining the score for certain amount of time or anything.  I just wanted to have a script, where if a user gets a highscore in one of the games, they get, say 50 credits, and a little message saying so.

If anyone has any leads to acheiving this, i thank you now, as i would like to implement it with my forum (http://www.matkins70.com/forums).

Am very new to SMF Boards, and SMFShop, so please forgive my nievity

Thanks

P.s.  SMFShop rules!
Title: Re: SMFShop and SMF Arcade
Post by: Basil Beard on September 04, 2006, 09:46:46 am
This has been talked about before and is probably possible; the problem is that none of us have experience with the SMF Arcade code to know how exactly to accomplish this.
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 04, 2006, 10:13:54 am
Ok.
Do you think that anyone else over at SMF forum might have experience.

I haven't actually looked at the coding for the various items yet, but was also wondering whether a scratch card item might be easily feasible.  Would work on a basis of 40% chance you win nothing, 20% chance you get money back, so on, until 1% chance you win 100 credits.
If this is easily feasible, is there an item you would recommend for changing the code to make this as easily as possible.

Thanks basil.

P.s..  Was looking at the shop details, and you lot of got tens of thousands in the bank!  is that through posting alone, or interest, items?
Title: Re: SMFShop and SMF Arcade
Post by: Basil Beard on September 05, 2006, 09:59:14 am
Using a steal money on daniel15? Interest has done the rest I guess

A scratch card like that would be very doable. Actually scratching would be tricky, but you can just use $value = mt_rand(lowerbound,upperbound) and then if statments to do a random item like that.
Title: Re: SMFShop and SMF Arcade
Post by: TechnoDragon on September 05, 2006, 11:15:44 am
Just use the random money item and rename it to something else for your shop
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 05, 2006, 11:30:41 am
Really hoping someone is online here, as im gonna go to bed soon.  Before i started on other things, i decided to try and make something basic.  Its a multiplier, that multiplies someones pocket by between -50% and +50%.
I edited one of the existing item scripts...(random money, i think).

When finished, i shoved the file in the items folder, and went to try it out, but when i click on 'add items' i get this error:

Quote
Parse error: parse error, unexpected '(' in //forums/Sources/shop/items/Multiplier.php on line 49

Err, i dont know if its my code, or whether i have to do something to the file to 'install' it. (just to note, i changed it to 777, as all the other items were that).

Just in case, here is the code:

Code: [Select]
<?php

/**********************************************\

|         For the SMFShop Mod                  |

|         (c) 2006 Matkins70                   |

|       http://www.matkins70.com/              |

\**********************************************/



//File: Multiplier.php

//      Item



//VERSION: 2.1 (Build 9)

//DATE: 05th September 2006

// $Id: Multiplier.php 17 2006-09-05 03:05:12Z Matkins70 $



class item_Multiplier extends itemTemplate {

    function 
getItemDetails() {

        
$this->name "Multiplier";

        
$this->desc "Multiply your money in your pocket between -50% and +50%";

        
$this->price 500;

        

        
$this->require_input false;

        
$this->can_use_item true;

    }



    
//See AddToPostCount.php for more information

    
function getAddInput() {

        return 
"Minimum percentage: <input type='text' name='info1' value='50'><br>

                Maximum percentage: <input type='text' name='info2' value='150'>"
;

    }



    function 
onUse() {

        global 
$db_prefix$ID_MEMBER$item_info;

        

        
//simple fix for the 'number expected' errors

        
if (!isset($item_info[1]) || $item_info[1] == "")

            
$item_info[1] = 50;



        if (!isset(
$item_info[2]) || $item_info[2] == "")

            
$item_info[2] = 150;



        
$amount mt_rand($item_info[1], $item_info[2]);



if ($amount 0) {



$result db_query("UPDATE {$db_prefix}members

SET money = money * (
{$amount} / 100)

WHERE ID_MEMBER = 
{$ID_MEMBER}",

__FILE____LINE__);

return "You got a percentage of "($amount)".  Multiplied with your money in your pocket, you now have ".formatMoney($row['money'])."!";

}

    }



}



?>



Thanks for any help
Title: Re: SMFShop and SMF Arcade
Post by: Daniel15 on September 08, 2006, 09:14:06 pm
matkins70, there's a problem with your code, on the last 'return' line.
Replace:
Code: [Select]
return "You got a percentage of "($amount)".  Multiplied with your money in your pocket, you now have ".formatMoney($row['money'])."!";With:
Code: [Select]
return("You got a percentage of {$amount}.  Multiplied with your money in your pocket, you now have ".formatMoney($row['money'])."!");Or:
Code: [Select]
return("You got a percentage of ".$amount.".  Multiplied with your money in your pocket, you now have ".formatMoney($row['money'])."!");
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 09, 2006, 03:22:41 am
Thanks daniel.  Basil had just beaten you to it with a personal message :P

Been updating a few things with the shop, quite a fun little project.  I now have it set up so if someone gets a new highscore in the arcade, then they get given 50 credits.  My multiplier is up, though im not completely happy with it, but all in due course.

My next task is to make a scratchcard.  I think i mentioned it before.   Im trying to think of the best way to get the weighted results, so that basically, there is a 40% chance of 0, 20% of 100 credits, 5% of X credits, and so on.  My only idea at the moment is to use the rand feature to generate a number between 1 - 100, and then that correspondes to the percentage.  So 1-40 is 0 returns, 41-60 is 100 credits, etc, all the way to 100.

Anyone think of a better solution, as im not very trusting of the random thing, as my results see a little strnage...
Title: Re: SMFShop and SMF Arcade
Post by: Basil Beard on September 09, 2006, 04:15:59 am
Yes. That is how you do random things. Although if you are doing that you could just use the rand feature to get a number between 1 and 10 and do

1-4: 0; 4-6; 100 etc...
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 09, 2006, 07:38:12 am
Yeah, but then doing 5% and 1% wont be possible, as it selects an integer, and between 1-10, 1% would be 0.1
Title: Re: SMFShop and SMF Arcade
Post by: Daniel15 on September 10, 2006, 04:45:51 pm
Quote
  My only idea at the moment is to use the rand feature to generate a number between 1 - 100, and then that correspondes to the percentage.  So 1-40 is 0 returns, 41-60 is 100 credits, etc, all the way to 100.
Yeah, that's probably the best way to get weighed results... Something like


$rand = mt_rand(0, 100);
if ($rand < 40) {
$number = 0;
} elseif (41 < $rand && $rand < 60) {
$number = 100;
// and so on
}
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 10, 2006, 11:08:20 pm
I thought i was doing so well... :'(

I made the code, uploaded it, put it in the shop,  bought item, but when i used it, i just left a blank item.  Just had the "go back to inventory" link.  Not sure whats wrong.  The code is:

Code: [Select]
<?php

/**********************************************\

|         For the SMFShop Mod                  |

|         (c) 2006 Matkins70                   |

|       http://www.matkins70.com/              |

\**********************************************/



//File: Scratchcard.php

//      Item



//VERSION: 2.1 (Build 9)

//DATE: 10th September 2006

// $Id: Scratchcard.php 17 2006-09-10 14:54:12Z Matkins70 $

class item_Scratchcard extends itemTemplate {

    function 
getItemDetails() {

        
$this->name "MatkinsScratchcard";

        
$this->desc "MatkinsLotto presents the MatkinsScratchcard";

        
$this->price 150;

        

        
$this->require_input false;

        
$this->can_use_item true;

    }



   



    function 
onUse() {

        global 
$db_prefix$ID_MEMBER$item_info;

        

        



        
$rand mt_rand(0,100);
if ($rand 46) {
$winnings 0;
} elseif (45 $rand && $rand 66) {
$winnings 100;

} elseif (65 $rand && $rand 81) {
$winnings 200;
} elseif (80 $rand && $rand 91) {
$winnings 400;
} elseif (90 $rand && $rand 96) {
$winnings 1000;
} elseif (95 $rand && $rand 100) {
$winnings 2000;
} elseif ($rand 100) {
$winnings 4000;
}



if ($winnings 0) {



$result db_query("UPDATE {$db_prefix}members

SET money = money + {&winnings} WHERE ID_MEMBER = 
{$ID_MEMBER}",

__FILE____LINE__);

return "You find a grubby looking coin in your pocket.  You eagerly scratch off the silver foil to reveal your winnings.  You won ".formatmoney($winnings).".  You go back to the shop and collect your winnings and shove them in your back pocket.   Remember kids, gambling can be bad for your health.  If you feel it's taking over your life, walk away.";

} elseif ($winnings 0) {
return "You find a grubby looking coin in your pocket.  You eagerly scratch off the silver foil to reveal your winnings. Sadly you won 0 credits.  You curse under your breath and shake your fist in anger towards the sky.  Remember kids, gambling can be bad for your health.  If you feel it's taking over your life, walk away.";
}


    }



}



?>



Title: Re: SMFShop and SMF Arcade
Post by: Basil Beard on September 11, 2006, 05:20:15 am
For one, your logic is wrong. Instead of $winnings = 100 and $winnings = 0; you should use a double equals. I don't think that should cause the problem though, but you can start there and see if it gets fixed.
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 11, 2006, 06:15:57 am
So like this?
Code: [Select]
$rand = mt_rand(0,100);
if ($rand < 46) {
$winnings == 0;
} elseif (45 < $rand && $rand < 66) {
$winnings == 100;

} elseif (65 < $rand && $rand < 81) {
$winnings == 200;

Cos it still doesnt work...:(
I thought it was gonna be fine:'(
Title: Re: SMFShop and SMF Arcade
Post by: Basil Beard on September 11, 2006, 07:17:00 am
Erm no, like this

Code: [Select]
  } elseif ($rand == 100) {
$winnings = 4000;
}
...
 } elseif ($winnings == 0) {
return "You find a grubby looking coin in your pocket.  You eagerly scratch off the silver foil to reveal your winnings. Sadly you won 0 credits.  You curse under your breath and shake your fist in anger towards the sky.  Remember kids, gambling can be bad for your health.  If you feel it's taking over your life, walk away.";
}
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 11, 2006, 07:53:10 am
Yay, after changing that, and editing a couple more things, and now its working, thanks a lot.  Sorry about my lack of knowledge, had never touched php until last week.
Title: Re: SMFShop and SMF Arcade
Post by: Daniel15 on September 16, 2006, 12:58:14 pm
OK, I'm glad that you got it working :)
I'm assuming that you realised that {&winnings} was meant to be {$winnings}?

If you want to learn PHP, there's heaps of good tutorials, just search Google to find some. I think that W3Schools has some
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on September 17, 2006, 03:10:26 am
yeah, realised that, thanks.
Title: Re: SMFShop and SMF Arcade
Post by: TechnoDragon on September 20, 2006, 01:30:12 am
Alright, over at SMF Arcade they came up with the code to award points when you get champion in a particular game, but they could not figure out how to show the award...it just is given.  Any chance of you guys here being able to help me out to make it that when they get the champion it also says they've been awarded the points?

Also, Theye have released an Awards mod for SMF.  any possibility of tying it in wit hthe shop as well so that if members are given an award they are awarded points as well?
Title: Re: SMFShop and SMF Arcade
Post by: Rezet on January 21, 2007, 05:55:10 am
Can you help me how to integrate SMF Shop and SMF Arcade?
I want my users to buy tickets for games, and win or lose credits...
Title: Re: SMFShop and SMF Arcade
Post by: Luxsphinx on January 21, 2007, 06:35:53 am
Yes, I to would like to link my SMF Shop with my SMF Arcade so that getting high scores or championships will give the user credits.  If anyone could supply that code or a place to get it, that would be great!
Title: Re: SMFShop and SMF Arcade
Post by: perplexed on February 07, 2007, 11:42:38 pm
Thanks daniel.  Basil had just beaten you to it with a personal message :P

Been updating a few things with the shop, quite a fun little project.  I now have it set up so if someone gets a new highscore in the arcade, then they get given 50 credits.  My multiplier is up, though im not completely happy with it, but all in due course.

My next task is to make a scratchcard.  I think i mentioned it before.   Im trying to think of the best way to get the weighted results, so that basically, there is a 40% chance of 0, 20% of 100 credits, 5% of X credits, and so on.  My only idea at the moment is to use the rand feature to generate a number between 1 - 100, and then that correspondes to the percentage.  So 1-40 is 0 returns, 41-60 is 100 credits, etc, all the way to 100.

Anyone think of a better solution, as im not very trusting of the random thing, as my results see a little strnage...

I wondered if this was made available for others Matkins, as it sounds pretty cool but I dont see the download on this site?

~Thanks
Title: Re: SMFShop and SMF Arcade
Post by: matkins70 on February 08, 2007, 06:43:16 am
What, the Scratchcard?  Err, I could post up the code i suppose.
Title: Re: SMFShop and SMF Arcade
Post by: TechnoDragon on February 08, 2007, 01:28:02 pm
the random money item works perfectly as a scratchcard
Title: Re: SMFShop and SMF Arcade
Post by: perplexed on February 14, 2007, 09:26:16 pm
What, the Scratchcard?  Err, I could post up the code i suppose.

I just thought it sounded cool, better than just random money
Title: Re: SMFShop and SMF Arcade
Post by: Kimojuno on February 22, 2007, 08:06:21 am
Been updating a few things with the shop, quite a fun little project.  I now have it set up so if someone gets a new highscore in the arcade, then they get given 50 credits.

Just wondering what the code is. I've looked around for awhile and haven't found any yet, in fact pretty much every SMF Webmaster seems to be asking around for such codes. I could be blind and it's on the forum, but I haven't noticed it around.
Title: Re: SMFShop and SMF Arcade
Post by: TechnoDragon on February 25, 2007, 01:43:20 pm
Ok, here's the code I use in my arcade to give credits anytime someone gets a new high score...I have this set that the first score they submit they get nothing, but every new score that is a high score after that they do...I am also using the Powered by modified version E1.5 of the arcade...but here's  the code that you need to look for (in that version at least)
Code: [Select]
//player has new high score and gets to comment - winner :)
{
if($context['arcade']['submit']['looser'] == '1')
{

And then add after it this bit of code:
Code: [Select]
db_query("
UPDATE {$db_prefix}members
SET money = (money + 250)
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);

If you want to let them know they have won the money change the text string underneath that to this:
Code: [Select]
echo '',$txt['arcade_1258'],' ',$txt['arcade_1262'],' ',$context['arcade']['submit']['score'],'<br />',$txt['arcade_1264'],'<br /><strong>You have received 500',$modSettings['shopCurrencySuffix'],'!</strong><br />', implode($txt['arcade_or'],$choice), '<br />';

Not that I have it set to 500 credits...the reason that the query does 250 is because they get the first 250 when they get to the screen, and then they get another 250 when they submit their comment...

Hope this helps everyone...
Title: Re: SMFShop and SMF Arcade
Post by: perplexed on February 28, 2007, 11:19:35 am
What, the Scratchcard?  Err, I could post up the code i suppose.

any chance?  I can't code so I'm at your mercy :)
Title: Re: SMFShop and SMF Arcade
Post by: TechnoDragon on February 28, 2007, 02:23:27 pm
Thanks go to Feildmaster at my forum for this one...9 hours of no sleep can really produce some tremendous results!
Please Note this in only tested to work on Arcade version 1.5.2 and 1.5.3!
Ok, first in your Sources directory, open Arcade.php and find:
Code: [Select]
if(!isset ($row_check['plays']) )
{
Add this after:
Code: [Select]
db_query("
UPDATE {$db_prefix}members
SET money = (money + 50)
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
NOTE: Change the 50 to whatever amount you want to give the member playing for submitting a score for the first time...

Then find:
Code: [Select]
elseif((($gameSubmitArray['highscore']==0)&&($row_check['score']< $gameSubmitArray['score'])&&($row_check['plays'] >= 1 ))||(($gameSubmitArray['highscore']==1)&&($row_check['score']> $gameSubmitArray['score'])&&($row_check['plays'] >= 1 )))
{
add this after it:
Code: [Select]
db_query("
UPDATE {$db_prefix}members
SET money = (money + 250)
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
NOTE: Change the 250 to whatever you want them to get when they get a new high score (not champ)

Then find this:
Code: [Select]
$results = db_query($sql, __FILE__, __LINE__);
$looser = '0';
}

Then add this right after:
Code: [Select]
//player is champion
elseif((($gameSubmitArray['highscore']==1) && ($gameSubmitArray['champion_score'] < $gameSubmitArray['score'])) || (($gameSubmitArray['highscore']==0) && ($gameSubmitArray['champion_score'] < $gameSubmitArray['score'])))
{
db_query("
UPDATE {$db_prefix}members
SET money = (money + 1000)
WHERE ID_MEMBER = $ID_MEMBER", __FILE__, __LINE__);
//update score, players number of plays, time played and total plays for the game
$sql = "UPDATE {$db_prefix}games_high "
. "SET score = {$gameSubmitArray['score']} , plays = plays+1, stime = {$gameSubmitArray['timenow']}, warning = {$gameSubmitArray['warning']},ptime = {$gameSubmitArray['timenow']}, playscore = {$gameSubmitArray['score']},duration = duration+{$gameSubmitArray['duration']},ip='{$ip}' "
. "WHERE id='{$row_check['id']}' ";
$results = db_query($sql, __FILE__, __LINE__);
//set for congrats in template */
$looser = '3';
}
NOTE: Again change the 1000 to the amount you want your members to receive for becoming the champion!

Now for the text strings!
In your default theme open up Arcade.template.php and find this:
Code: [Select]
if($context['arcade']['submit']['looser'] == '0')

change the echo statement right below it to this:
Code: [Select]
echo '</',$txt['arcade_1260'],' ',$txt['arcade_1262'],' ',$context['arcade']['submit']['score'],'<br />',$txt['arcade_1264'],'<br /><strong>You have received 50 ',$modSettings['shopCurrencySuffix'],'!</strong> Just for playing this game!<br />', implode($txt['arcade_or'],$choice), '<br />';

then find this:
Code: [Select]
if($context['arcade']['submit']['looser'] == '1')

and change the echo statement below to this:
Code: [Select]
echo '',$txt['arcade_1258'],' ',$txt['arcade_1262'],' ',$context['arcade']['submit']['score'],'<br />',$txt['arcade_1264'],'<br /><strong>You have received 250',$modSettings['shopCurrencySuffix'],'!</strong><br />', implode($txt['arcade_or'],$choice), '<br />';

then find this:
Code: [Select]
//player has new high score and gets to comment - winner :)
{

and add this right after it:
Code: [Select]
if($context['arcade']['submit']['looser'] == '3')
{
echo '<strong>Congratulations! You are the new champion with the score of ',$context['arcade']['submit']['score'],'!<br />You have received 1000',$modSettings['shopCurrencySuffix'],' as a prize!</strong><br />', implode($txt['arcade_or'],$choice), '<br />'; }

Now, not only will your members get rewarded for playing, beating their old high score or becvoming the champ...they will see it too!
Title: Re: SMFShop and SMF Arcade
Post by: Hambil on March 10, 2007, 05:10:16 am
I've just released an integration for the shop and the arcade. I hope you enjoy it.

http://www.daniel15.com/forum/index.php/topic,668.0.html