Jump to content

SCRIP module/component (virtual cash, not script) for my Joomla site


Skippy93

Recommended Posts

Are there any guides or ebooks on how to make a scrip module for my joomla site? I want users to be able to earn scrip by doing different things, and then being able to buy things with the scrip.

 

If you don't know what Scrip is, Scrip is any substitute for currency which is not legal tender and is often a form of credit (http://en.wikipedia.org/wiki/Scrip)

 

It's fine if there isn't a guide for joomla, as long as I can learn how to code a scrip application in PHP, I can port it to joomla.

 

It's been an ass of a time searching on how to do this, mainly because searching scrip only returns scripts (here and on google.) please help!

Link to comment
Share on other sites

Since no one has replied I'm going to do what I can to help here for you.

 

I know exactly what you're talking about with the virtual cash, and it'd be something like L$ on myyearbook.com and is one thing I'll be implementing on my own site as well. I don't know of any e-books, but if you're wanting to just find out how to make a script as an add-on I can give you some pointers to watch out for as I've done research into the whole thing just using google and patience.

 

First, you'd want to create a class for your... jombux, we'll call them for this example.

In your class you'd want your functions for checking the registered users balance, adding to the users balance, and deducting from the user's balance when they go to use their jombux. You'll probably want to add an extra field on to the end of your users tables with their jombux amount. You could create a new table with all user ids and jombux amounts and join them, but this just in results in less work for you if you're looking to do it for your own site and not as a module for resale.

 

So I'll show you my pseudo-code class here (this assumes you are using MySQL):

<?php
class jombux {
  /**
   *Class for jombux. This is assuming you've added a field named 'jombux' to the end of your main 'users' table.
   * I will note here that if you're expecting to have LARGE numbers in this field using FLOAT numbers instead of
   * INT would be more ideal.
   */

  function deposit($amount, $user) {
    mysql_query("UPDATE users SET jombux $amount WHERE user_id = '$user'"); //Adds amount to user's jombux.
}

  function check($user) {
    $row = mysql_fetch_object("SELECT * FROM users WHERE user_id = '$user'"); //Fetches user's jombux balance.
   $balance = $row->jombux;
   return $balance; //return user's jombux balance.
}

  function withdraw($amount, $user) {
  mysql_query("UPDATE users SET jombux WHERE user_id = '$user'"); //you will want $amount to be a negative number here. 
}
}
/*While this isn't perfected it suits the needs of my example for you */
?>

That's all pretty simple. Then you need to decide where you want your jombux to be used. How they will be earned and how they will be spent. I will have you keep in mind that you should always calculate how much jombux are being added to a user server side only, so if you are using games and whatnot, be sure that if you are basing the amount of jombux awarded that the score if already submitted server side before the user sees it. This is to prevent tampering of HTTP headers to cheat their way into getting crazy amounts of jombux (Yes, I've done it on other sites and got in trouble, but advised on how to prevent it... whether they listened or not is up to them. I've also tried it on myyearbook and they have it all done server side.)

 

So for instance, say that you want to award 5 jombux to each user when two users become friends. You will have to find the function (I'm not sure if you are using JomSocial or just Joomla) but either way, you'll need to find the function that adds two users as friends. In that function you will simply add 5 jombux on a successful friendship.

 

(This is pseudo code, I have no idea what the actual class or function is named in Joomla, sorry.)

<?php
class friends {
/* ... Already written code (functions, etc, etc) ...*/

function friendshipAdd($user1, $user2) {
/* ... Code that enters friendship into database. ...*/
//Adding right into the function a mysql query that awards them both 5 jombux.
//get the amount for user 1
$jb = new jombux;
$balance = $jb->check($user1);
$newbalance = $balance + 5;
//then you'll want to update that user's balance.
$jb->deposit($newbalance, $user1);
/* You'll want to repeat that for user2, if you wish. */
}
}

 

That should be the VERY basics that you'd need. You'll need to determine where you want to add to the user's balance and subtract from it. I can't stress enough that you SHOULD, I won't say you must, but I strongly advise that you do all calculating of your jombux -SERVER SIDE ONLY-

 

I've seen way too many sites always sending the data from a cookie or as a post and it's way too easy to tamper with that kind of thing. Especially if you plan on eventually making it something that people can purchase for awards, or whatever have you ,you'll need to make sure it's as secure as you can get it.

 

I know that what I've shown you was really just a rough draft of some pseudo coding without even looking at any source, if you'd like more help feel free to message me and I'll help you out further as I do have a copy of Joomla somewhere in my scripts folder. :P

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.