PDA

View Full Version : Cash System


Seapyramid
10-07-2009, 07:33 PM
OK.. I suck at tutorials but I will give this a try

Find if ($newclicks >= $requiredclicks and $requiredclicks != 0 and $requiredclicks != "") {
// We need to level this adoptable up...

$query = "UPDATE " . $prefix . "owned_adoptables SET currentlevel='" . $nextlevel . "' WHERE aid='" . $id . "'";
mysql_query($query);

// Now we check if we are enabling alternate images...

// Get the ID of the parent type adoptable
$parentid = converttypetoparentid($type);
// Check if we are using alternate images or not...
$altstatus = getaltstatus($parentid, $id, $nextlevel);

if ($altstatus == "yes") {
// We are enabling alternate images for this adoptable...

$query = "UPDATE " . $prefix . "owned_adoptables SET usealternates='yes' WHERE aid='" . $id . "'";
mysql_query($query);
}

// Now we can see if the adoptable's owner gets a reward...
// The reward function will take care of sending out any reward that exists...

$rewardstatus = reward($id, $type, $nextlevel, $owner);
}
// End the if statement if we are leveling the adoptable up
$image = getcurrentimage($id);


$article_title = "You just gave " . $name . " one Maturity Training.<br />";
$article_content = $article_content . "<br /><br />";
}

on your levelup.php page. Directly below it add
// ************************************************

// Start Rewards

// ************************************************


//Get currency on level up

$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < 1) {
$money = @mysql_result($result, $i, "money");

// Change this number 10 to the number of currency you want users to earn on level up
$newbalance = $money + 2;

$i++;
}

mysql_query("UPDATE `adopts_users` SET `money`='" . $newbalance . "' WHERE `username`='$loggedinname'");


$article_content = $article_content . "<div align='center'><br />You have earned 2 Gold Pieces for leveling up this Companion. <br />You now have " . $newbalance . " Gold Pieces.</div>";


on this line in the above script
$newbalance = $money + 2; is where you change the amount to whatever you want it to be.

You will have to modify your adopts_users table and add a new field called money `money` int(11) NOT NULL default '0',

Lastly you will have to modify your register.php page
mysql_query("INSERT INTO ".$prefix."users VALUES ('', '$username', '$pass1','$email','3','1', '$date', '0','','','','','','0')");

If I didn't forget anything it should work.

Sea

Bloodrun
10-08-2009, 07:49 AM
Very nice seapyramid =D

This will even work with the next release of the forum, as it gives points for posts and what not which could be "converted" into "money".

arlecchina
10-08-2009, 02:31 PM
Thanks so much for posting this Sea.

Seapyramid
10-08-2009, 02:32 PM
Thank you & all are quite welcome.

Sea

Tequila
10-22-2009, 09:43 AM
I just installed this, it wasn't even that bad. :) You did a great job on this Sea. Nice and easy.

Seapyramid
10-22-2009, 12:57 PM
I just installed this, it wasn't even that bad. :) You did a great job on this Sea. Nice and easy.


Thank you :)

Tequila
10-23-2009, 08:46 AM
I just came across an idea to show how much money a user has on their profile & in their sidefeed menu. What variable would I need to use for that?

Haylzee
10-30-2009, 12:55 AM
Thanks, this works really well. :)

Now to figure out what to use the currency for lol.

Seapyramid
10-30-2009, 01:36 AM
rolf.. I do have a few games that are generic the can can be used on by those with a bit of knowledge... items systems are quite personalized to the site so I cant help you there. :)

Sea

Haylzee
10-30-2009, 01:49 AM
lol well I managed to show the currency on profiles so at the moment it can just be used to show who clicks the most pets. :D

Arianna
11-17-2009, 11:59 PM
Wow, this is awesome. :D
I just installed it (very easy to, thanks!) and it's working amazingly. I might add something so pets can be 'bought', is that okay? I'll share it on here, when I'm finished. :)

Seapyramid
11-18-2009, 02:04 AM
Sure its ok :) Actaully I have a separte shop for that which also uses paypal ipn.. you might want to look at it http://mysticgrove.net/grove/shop_queen.php For just using the ingame coin to buy stuff I have http://mysticgrove.net/grove/shop_gnome.php for trinkets (kinda like mini pets I gues) & http://mysticgrove.net/grove/shop_merlin.php for useable items. I also currently have 3 gambling games in game coin can be used for with more planned :)

Much can be done with the coin system once it is in place :)

Sea

Arianna
11-18-2009, 10:56 AM
Ooh, awesome. :) I love how you have the trinket shop and stuff. :) I think that I'll work on the code when I have time, then. x3

Arianna
11-19-2009, 07:34 AM
I just made the thing to buy adoptables. It works well, except for I can't get it to set the price in the admin CP - it always defaults to then 10 that I've set. Here's what I did.
<?

// FILE: admin.php
// okay, I'm a failure here. It only works if I insert it in phpmyadmin. help?
// After line 158 add:
<p>Price:
<input name='price' type='text' id='price'>
</p>

// reminder to me: there's a good code for a style switcher on line 119-213

// FILE: nadopt.php
// After line 136 add:
$price = $_POST["price"];
$price = secure($price);

// Change line 243 (about) to:
mysql_query("INSERT INTO ".$prefix."adoptables VALUES ('', '$name', '$description','$eggimage','$cba','$promocode', '$freqcond', '$number','$datecond','$date','$adoptscond','$maxn umcond','$morethannum','$usergroupcond','$usergrou ps','$alternates','$altoutlevel','$altchance','$pr ice')");

// in the table adopts_adoptables, use the sql query. Change the '10' to your default adoptable price.
ALTER TABLE `adopts_adoptables` ADD `price` INT( 10 ) NOT NULL DEFAULT '10';

// we still have to alter two more things - the adopt.php page, and the doadopt.php page.
// FILE: adopt.php
// After line 96 add:
$price=@mysql_result($result,$i,"price");
// After line 152 add:
$price=@mysql_result($result,$i,"price");
// After line 174 add:
<p>I cost ".$price." coins!</p>
// And after line 179 add:
<input name='price' type='hidden' id='price' value='".$price."'>

// FILE: doadopt.php
// After line 102 add:
$price=@mysql_result($result,$i,"price");
// Insert this giant junk of code after:
$code = rand(1, 20000);
// Here's the code:
$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < 1) {
$money = @mysql_result($result, $i, "money");
$newbalance = $money - $price;
$i++;
}

mysql_query("UPDATE `adopts_users` SET `money`='" . $newbalance . "' WHERE `username`='$loggedinname'");

$article_content = $article_content . "<div align='center'>Thanks for buying your adoptable! Now you have ".$newbalance." coins!</div>";

// I can't guarentee that this is right, but if you have any problems, please tell me. :D
?>

Arianna
11-21-2009, 12:12 PM
Sea, I hate to be annoying (xD) but have you any idea on the price of the adoptables not working? I thought I was following the same layout as other stuff, but somehow, I guess it isn't working. :P

Seapyramid
11-22-2009, 01:15 PM
Sorry,

I have been very busy, we just put the script rewrite/opt code on line this morning & preparing all the changes & setting it live was a big task. :) I will try to look at the code this week. Right now, I am tweaking bugs with the new lease & starting on the new full featured trading system coming next.

Sea

Arianna
11-22-2009, 01:34 PM
Ooh, that sounds awesome! And scary, too.
The trading system sounds awesome, too.

Fireballchad
11-29-2009, 11:15 PM
Hey Arianna I sort of got your cash thing working...
I will try to make a tut of what I did.
Yours worked sorta of but you missed a few things it needed...
I am currently trying to make it so if you dont have enough money then you cant buy it... As of right now it allows you to go negative...
<?
//File admin.php
//After line 165 add:
<input name='cba' type='radio' value='pricenum'>
Only when users pay this much money:
<input name='price' type='text' id='price'>
<br>

// FILE: nadopt.php
// After line 94 add: it will be this but with promo instead
$price = $_POST["price"];
$price = secure($price);

// Change line 243 (about) to: '$price' was added at the end
mysql_query("INSERT INTO ".$prefix."adoptables VALUES ('', '$name', '$description','$eggimage','$cba','$promocode', '$freqcond', '$number','$datecond','$date','$adoptscond','$maxn umcond','$morethannum','$usergroupcond','$usergrou ps','$alternates','$altoutlevel','$altchance','$pr ice')");

// in the table adopts_adoptables, use the sql query.
ALTER TABLE `adopts_adoptables` ADD `price` INT( 10 ) NOT NULL DEFAULT 'NULL';
// I Hand entered this into my data base Default should be NULL I don't know if
// 'NULL' will work or not but fix it if it doesn't

// we still have to alter two more things - the adopt.php page, and the doadopt.php page.
// FILE: adopt.php
// After line 63 (about) add:
$price = $_GET["price"];
$price = secure($price);
// After line 96 add:
$price=@mysql_result($result,$i,"price");
// After line 152 add:
$price=@mysql_result($result,$i,"price");
// After line 174 add:
<p>I cost ".$price." coins!</p>
// And after line 179 add:
<input name='price' type='hidden' id='price' value='".$price."'>

// FILE: doadopt.php
//After Line 75 (about) add:
$price = $_GET["price"];
$price = secure($price);
// After line 102 add:
$price=@mysql_result($result,$i,"price");
// Insert this giant junk of code after:
$id=@mysql_result($result,$i,"aid");


$i++;
}

// Here's the code:
$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < 1) {
$money = @mysql_result($result, $i, "money");
$newbalance = $money - $price;
$i++;
}

mysql_query("UPDATE `adopts_users` SET `money`='" . $newbalance . "' WHERE `username`='$loggedinname'");

$article_content = $article_content . "<div align='center'>Thanks for buying your adoptable! Now you have ".$newbalance." coins!</div>";

// Credit goes to Arianna I only helped fix some stuff... Still needs to be fixed!!!
?>

Arianna
11-30-2009, 12:06 AM
Maybe just check if ($newcash>=0) and then determine it via elseif. :)

Fireballchad
11-30-2009, 12:23 AM
<?
//File admin.php
//After line 165 add:
<input name='cba' type='radio' value='pricenum'>
Only when users pay this much money:
<input name='price' type='text' id='price'>
<br>

// FILE: nadopt.php
// After line 94 add: it will be this but with promo instead
$price = $_POST["price"];
$price = secure($price);

// Change line 243 (about) to: '$price' was added at the end
mysql_query("INSERT INTO ".$prefix."adoptables VALUES ('', '$name', '$description','$eggimage','$cba','$promocode', '$freqcond', '$number','$datecond','$date','$adoptscond','$maxn umcond','$morethannum','$usergroupcond','$usergrou ps','$alternates','$altoutlevel','$altchance','$pr ice')");


// Replace the orignal one of this with this new one.
if($cba != "always" and $cba != "promo" and $cba != "pricenum" and $cba != "conditions"){
$error = "You did not choose a valid scenario when this adoptable can be adopted. Please go back and either select the Always option, the Promo option or the Conditions option.";
}
// add this after the other ones that look like it around line 169
//If we are using money to buy this, we should have a amount in the box...
if($cba == "pricenum" and $price == ""){
$error = "You selected that this adoptable is available for adoption only with money, but you did not enter in a money amount. Please go back and either change this setting or type in a valid amount.";
}
// in the table adopts_adoptables, use the sql query.
ALTER TABLE `adopts_adoptables` ADD `price` INT( 10 ) NOT NULL DEFAULT 'NULL';
// I Hand entered this into my data base Default should be NULL I don't know if
// 'NULL' will work or not but fix it if it doesn't

// we still have to alter two more things - the adopt.php page, and the doadopt.php page.
// FILE: adopt.php
// After line 63 (about) add:
$price = $_GET["price"];
$price = secure($price);
// After line 96 add:
$price=@mysql_result($result,$i,"price");
// After line 152 add:
$price=@mysql_result($result,$i,"price");
// After the $i++; } put this
$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < 1) {
$money = @mysql_result($result, $i, "money");

$i++;
}
if ($money >= $price) $get = "<input type='submit' name='Submit' value='Get Me'>";
else $get = "Sorry Cant Get, Not Enough Coin!";
// After line 174 add:
<p>I cost ".$price." coins!</p>
<div align='center'><br />You have " . $money . " coins </div>
// And after line 179 add:
<input name='price' type='hidden' id='price' value='".$price."'>
// Delete
<input type='submit' name='Submit' value='Get Me'>
//Add inplace of that
".$get."
// FILE: doadopt.php
//After Line 75 (about) add:
$price = $_GET["price"];
$price = secure($price);
// After line 102 add:
$price=@mysql_result($result,$i,"price");
// Insert this giant junk of code after:
$id=@mysql_result($result,$i,"aid");


$i++;
}

// Here's the code:
$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < 1) {
$money = @mysql_result($result, $i, "money");
$newbalance = $money - $price;
$i++;
}

mysql_query("UPDATE `adopts_users` SET `money`='" . $newbalance . "' WHERE `username`='$loggedinname'");

$article_content = $article_content . "<div align='center'>Thanks for buying your adoptable! Now you have ".$newbalance." coins!</div>";

// Credit goes to Arianna I only helped fix some stuff... WORKS NOW!!! I = Fireballchad
?>

Wow this is a messy tut.... sorry but I got it to take the submit button away when you don't have enough money.
Also in the admin you can change how much it cost to get the adoptable.
If you manage to install this it is wonderfull... or if someone does install it and makes a better tut that would be better!
you can see it work at Forumbuds (http://forumbuds.com)
Also some of my code may be weird or not wonderful... because I am a very novice PHP coder lol.

Haylzee
11-30-2009, 03:26 AM
I made a shop system awhile ago when the currency system was posted here, but it's a little different from yours Arianna. I checked out the cash/shop system someone made for the older version of the script and used that to make one for my site. I made a copy of the adopt.php page and called it shop.php, which shows the prices of the adoptables, and and a copy of the doadopt.php page and called it buy.php, when you buy an adoptable it leads to that instead of doadopt, and that page determines whether you have enough of the currency to buy the adoptable before it inserts into the database, and it removes the cost of the adoptable from the user's currency total. It works perfectly as far as I can see so far. I'm totally a php novice so I just really had to play around.

I never even bothered editing the admin.php page to be able to set prices or anything like that, I've just been doing it through phpmyadmin. lol actually it didn't even occur to me to try it, now I should go play around with that.

Fireballchad
11-30-2009, 04:34 AM
Nice, Well it works well just lots of editing involved which may turn some off. I might try to do separate pages also but I got it installed on mine... although I need to code it so it put free ones in a different group then pay ones...

Arianna
11-30-2009, 09:03 AM
I think that I'll just go and check with 'if', and I can say that it won't insert, if they don't have enough money. I think I'll have that done in a few days. :)

gjac1
12-03-2009, 06:30 AM
This mod is excellent, thank you very much for posting it :)

It installed and works perfectly.

gjac1
12-04-2009, 09:13 AM
I noticed that people still get a cash increase even if they have already levelled that adoptable that day, is there anyway to change it so members cant just keep re clicking on the same adoptable over and over to get credits ?

Arianna
12-04-2009, 02:41 PM
That doesn't happen on my site - are you sure that you've pasted the code into the right place?

Haylzee
12-04-2009, 05:37 PM
That doesn't happen on mine either, but I do remember I had to add an if statement to make the whole cash code work only when the adoptable isn't frozen, because it was originally letting you get the currency for continuously clicking the same frozen adoptable over and over.

gjac1
12-05-2009, 11:15 AM
Yes, i defiantly added it correctly :s , i will just have to try and figure it out as Haylzee did :)

Seapyramid
12-09-2009, 09:16 PM
That was a glitch before posting but has been corrected long before this was posted. If you are having that issue you dont have it embedded correctly.