Help - Search - Members - Calendar
Full Version: Need Help Scripting Random Numbers
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Mack34
First off let me say I am about as new as you can get to PHP and I am learning as I go, so please bare with my terminology and what not. With that said, I am running a text based mafia game at GodsOfMafia.vndv.com. The site is up and running and everything is going great, but I am ready to start working on upgrading my site for the players experience so here is my problem.

The prices of drugs in the game are set prices in each city...here is the code that I have now:

CODE
if ($location == "USA"){
$sputnit = 1225;
$skunk = 4200;
$ecstacy = 5250;
$cocaine = 7525;
}elseif ($location == "New Zealand"){
$sputnit = 875;
$skunk = 3150;
$ecstacy = 4550;
$cocaine = 7000;
}elseif ($location == "Australia"){
$sputnit = 525;
$skunk = 2275;
$ecstacy = 3325;
$cocaine = 4550;
}elseif ($location == "England"){
$sputnit = 1400;
$skunk = 4550;
$ecstacy = 5950;
$cocaine = 8750;
}elseif ($location == "South Africa"){
$sputnit = 525;
$skunk = 700;
$ecstacy = 3750;
$cocaine = 6500;
}elseif ($location == "Cuba"){
$sputnit = 350;
$skunk = 875;
$ecstacy = 2275;
$cocaine = 4200;
}


Here is what I would like to have. I would like each of the cities prices, for each drug, randomized between a certain set of numbers but I would like those prices to change again at certain intervals (say every 30mins or so). I kind of know about the RAND function but not enough to really fix my issue. Any help or guidance would be greatly appreciated.

Thanks for your time,

Mack
zpcs
Hi Mack34,
I don't have a clue but I just wanted to drop in after seeing this listing and say "reminds of a board game developed back in the early 80's called SCAM which later in the 90's somebody (HapHustler, I believe) modified the storyline and created a software package that allowed a virtual 30 days to amass as much virtual profit thru the deals without getting getting popped, shot, mugged or becoming the victim of loan sharks or smokin' paraquat treated substances. Just wanted to say good luck with the venture here and if you do get this running correctly post the complete address somehow, I think I'd like to play a round or two. Thanks for keeping the game alive!

zpcs


Edit Note: 9:40 PM (CST); Thanks Mack34 for providing the link, I don't have the time to play a round at the moment - I did notice that you have to register to enter (hmm, no terms of service or privacy agreement for my registering prior to providing possible sensitive information). Looks like a nice site though! Thanks again for your response.
Mack34
On Gods Of Mafia we don't start new rounds every 30 days, you are on the game until you are killed or quit smile.gif. You also have to options of making a Family in either of the 6 cities and buy businesses to help your Family make money daily. On a more personal character level, there are also businesses you can obtain like race tracks, slot machine and bullet factories. Of course you can set your max bets and prices on bullets also.

The game is fully functional right now, I am just trying to slowly upgrade it to keep everyone interested and to bring more players in. We are currently up to 30 members at this time, which isn't bad since we have only been completely online for 4 days. If you would like to come by and take a look the site is http://godsofmafia.vndv.com.
swordz
You haven't actually given us enough information yet.

For help on using the rand() function just use the manual. However, for more precise info you're going to have to tell us more about how you want the number calculated.

swordz
Mack34
For instance I will use South africa as an example. If I write the code like this I know the price of sputnit will be random between 350 and 1400, but it is randomized every time some goes to the page.

}elseif ($location == "South Africa"){
$sputnit = (rand(350,1400));

My problem is that I would like that random number to only be generated every 30 minutes.
SP_
I'm guessing all this info is stored in a database. What you could do is store a time-stamp. Run a quick query on the page to determine if the stored time-stamp is older than 30mins. For example,

CODE
if ( $row = @mysql_fetch_array ( @mysql_query ( 'SELECT update.time FROM `table`' ) ) )
{
   if (  ( $row['update.time'] - time() ) > 1600 ) )
      {
         // The randomize code
        
         @mysql_query ( 'UPDATE `table` SET update.time = time()' ) or die(); // Reset the time.
      }
}
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.