Jump to content
MakeWebGames

Free V1/V2 MOD Horse Racing ported to NWE


a_bertrand

Recommended Posts

An old (2008) V1 / V2 mod which someone in the chat wanted to have running, I thought I would give a little spin to make basically the same for NWE. I kept the original copyright even if the code is pretty much... a rework.

Anyhow the original code can be found here:

http://makewebgames.io/showthread.php/23634

The code for NWE:

<?php
/******************************
> CREATED BY oxidation
> NOT FOR RE SALE FREE MOD ONLY
> COPYRIGHT 2008
******************************
> PORTED TO NWE BY A. Bertrand
******************************/

$horses = array("Dorke", "Wickwear", "Shandy", "Warsky", "Propeller", "Shalasy", "Rickmond", "Yowelle", "Crossbone", "Eastporse");

if (isset($_GET["horse"]))
{
   if ($userStats["!Currency"]->value < GetConfigValue("horseTicketPrice") + 0)
   {
       ErrorMessage("You don't have enough !Currency currently.");
   }
   else
   {
       $userStats["!Currency"]->value -= GetConfigValue("horseTicketPrice");
       $winner = rand(0, count($horses) - 1);

       if ($winner == $_GET["horse"] + 0)
       {
           ResultMessage(Translate("You won %s! Incredible!", FormatNumber(GetConfigValue("horsePrize"))), false);
           $userStats["!Currency"]->value += GetConfigValue("horsePrize");
       }
       else
       {
           ErrorMessage(Translate("No luck, you bet on %s instead %s won the race.", $horses[$_GET["horse"] + 0], $horses[$winner]), false);
       }
   }
}

TableHeader("Horse Racing Department");
echo Translate("Want to make a bet of winning a high amount of bars?<br>
Each ticket costs %s. You may choose which horse you would like to bet on.
If you win, You will recieve the winning prize of %s.", FormatNumber(GetConfigValue("horseTicketPrice")), FormatNumber(GetConfigValue("horsePrize")));
if ($userStats["!Currency"]->value < GetConfigValue("horseTicketPrice") + 0)
{
   echo "<br><b>" . Translate("You don't have enough !Currency currently.") . "</b>";
   TableFooter();
}
else
{
   TableFooter();

   ButtonArea();
   foreach ($horses as $key => $val)
       LinkButton($val, "index.php?p=horse_racing&horse=$key");
   EndButtonArea();
}

 

I actually made the code a bit cleaner and more compact, yet while using NWE functions.

If you want just to make it yourself:

Admin panel => Create new module

Module name: horse_racing

Display name: Horse Racing

In game menu: Horse Racing

Configuration key: horseTicketPrice, 300000

Configuration key: horsePrize, 2700000

The copy / paste the code in the content.php file of the newly created module.

As easiest / fastest, download the attacked NWP package which is basically the full module ready to be used.

To note:

- I don't use any DB access directly as NWE offers user stats access via the $userStats variable.

- I use TableHeader / TableFooter, ButtonArea, LinkButton and Translate to correctly format / output the different pieces as well as support for direct translation of the text.

horse_racing.nwp

Link to comment
Share on other sites

Here is a minimalistic port (not the one I would use), if you don't know or want to use NWE functions and just want to make it work:

 

<?php
/******************************
> CREATED BY oxidation
> NOT FOR RE SALE FREE MOD ONLY
> COPYRIGHT 2008
******************************
> PORTED TO NWE BY A. Bertrand
******************************/

define("horseTicketPrice",300000);
define("horsePrize",2700000);

$horses = array("Dorke", "Wickwear", "Shandy", "Warsky", "Propeller", "Shalasy", "Rickmond", "Yowelle", "Crossbone", "Eastporse");

if (isset($_GET["horse"]))
{
   if ($userStats["!Currency"]->value < horseTicketPrice)
   {
       echo "You don't have enough \$ currently.";
   }
   else
   {
       $userStats["!Currency"]->value -= GetConfigValue("horseTicketPrice");
       $winner = rand(0, count($horses) - 1);

       if ($winner == $_GET["horse"] + 0)
       {
           echo "You won ".horsePrize."\$! Incredible!";
           $userStats["!Currency"]->value += horsePrize;
       }
       else
       {
           echo "No luck, you bet on ".$horses[$_GET["horse"] + 0]." instead ".$horses[$winner]." won the race.<br><br>";
       }
   }
}

echo "Want to make a bet of winning a high amount of bars?
Each ticket costs ".horseTicketPrice."\$. You may choose which horse you would like to bet on.
If you win, You will recieve the winning prize of ".horsePrize."\$.<br><br>";
if ($userStats["!Currency"]->value < horseTicketPrice)
   echo "<b>You don't have enough \$.</b>";
else
{
   foreach ($horses as $key => $val)
       echo " [<a href='index.php?p=horse_racing&horse=$key'>$val</a>]";
}

 

As you can see, the only thing specific to NWE in this version is the $userStats array. That could have been replaced as well with DB instructions, but honestly it would only make the code more complex.

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...