hi

i'm currently developing a php text based game which revolves around the crime world. Two good examples of sites that i want mine to be like are www.mafia.org and www.mobstar.cc.

However i have come to a problem. I need a script that will allow a person to choose a crime from a list, such as rob a bank, pickpocket etc, and then depending on the crime, give the user money.

Now this is where it gets tricky. The outcome of the robbery will depend on the users experience, be it like points, and also out of pure luck. so if someone is pretty experienced at crimes, he/she will be more likely to be able to do the crime.

Now when the user does that crime they get money for it. but depending on what crime it is, the user gets more or less money. so what will be displayed on screen is the following:

[] rob a bank
[] raid a deal
[] rob a shop
[] rob a house
[] pickpocket

[commit]

where [] is shown, this indicates a radio button. this is all wrapped in a form. [commit] is just the button to submit.

so when the user clicks on a crime, it will come up with text saying:

"well done, you just got xxx amount of cash"

for robbing a bank, you would get more money than pickpocketing. If the user failed the crime it would come up saying " bad luck".

This alogorithm has been doing my head in, so hopefully someone out their will know the answer to my problem!

Any help will be greatly appreciated plus your name will be put in the credits for the game!

thanks

    Well, it doesn't sound to complicated. Luck can be randomly generated (see [man]rand[/man] or [man]mt_rand[/man]). Combine that with the experience to reach the goal. Set the goals higher for the higher crimes.
    For instance, say these are your goals:
    rob a bank - 50
    raid a deal - 40
    rob a shop - 30
    rob a house - 20
    pickpocket - 10
    Now, assume the use has 15 experience. I'd base the random generation of luck off of max for the goal. So if he chooses to pickpocket, the luck won't matter. He's alread experienced enough to do that without relying on luck, but if he chooses to rob a bank, you'd need to calulate it

    $exp  = 15; // their experience
    switch($action) {
       case "rob a bank":
          $lvl = 50;
       break;
       case "raid a deal":
          $lvl = 40;
       break;
       case "rob a shop":
          $lvl = 30;
       break;
       case "rob a house":
          $lvl = 20;
       break;
       case "pickpocket":
          $lvl = 10;
       break;
    }
    
    // Now calculate the goal, and see if they are there yet.
    // If not, generate luck..
    if($exp < $lvl) {
       $luck = rand(0,$lvl);
       $exp += $luck;
    }
    
    // Now see if they were succesfull
    if($exp < $lvl) {
       // They failed
    }
    else {
       // They succeded
    }
    

    That's just a basic idea. Should push you in the right direction though

      7 months later

      TBH, you are better off just building from whats above. This way you can easilly design the system to be what you want it to be. Is it for a mafia type game? If so, then def yes to the above.

      Heres my code if you want to look at a finished one (thats messy, and first version that works, wouldn't want you having my finished code! lol)

      mysql_select_db($database_london, $london);
      $query_Recordset1 = sprintf("SELECT * FROM users WHERE username = '%s'", $colname_Recordset1);
      $Recordset1 = mysql_query($query_Recordset1, $london) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($Recordset1);
      
      $result = "";
      $mon = "";
      $crimeFormAction = $_SERVER['PHP_SELF']; 
      $p_exp = $row_Recordset1['exp'];
      $MM_Pid = $row_Recordset1['pid'];
      $next_c = $row_Recordset1['time_c'];
      
      if (isset($_POST['crime'])) {
      	$action=$_POST['crime'];
      
      // their experience 
      switch($action) { 
         case "1": 
            $lvl = 50;
      	  $mon = 500; 
         break; 
         case "2": 
            $lvl = 40;
      	  $mon = 400; 
         break; 
         case "3": 
            $lvl = 30; 
      	  $mon = 250;
         break; 
         case "4": 
            $lvl = 20;
      	  $mon = 100; 
         break; 
         case "5": 
            $lvl = 10; 
      	  $mon = 50;
         break; 
         case "6": 
            $lvl = 5; 
      	  $mon = 5;
         break; 
      } 
      
      // Now see if they were succesfull 
      if($p_exp < $lvl) {
         srand(time());
         $luck = rand(0,10); 
         srand(time());
         $cm = rand(1,$mon);
         $mon = $cm;
         if($luck <= 7) { 
         	 $mon = "";
        	 $result = 'You failed the crime ';// They failed 
      	 $fut = time() + 150;
      	 mysql_select_db($database_london, $london);
      	 $query_money = sprintf("UPDATE users SET time_c = '$fut' WHERE pid = '$MM_Pid'");
      	 $money = mysql_query($query_money, $london) or die(mysql_error());
      	 if($luck < 3){
      	 	mysql_select_db($database_london, $london);
      	 	$query_money = sprintf("UPDATE users SET jail = '1', time_jail = '$fut', jail_rea = 'Petty Crime' WHERE pid = '$MM_Pid'");
      		$money = mysql_query($query_money, $london) or die(mysql_error());
      		$result = 'You failed the crime and got banged up!';
      	 }
      	 $insertGoTo = "scrime_done.php?result=$result&mon=$mon";
           $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
           $insertGoTo .= $_SERVER['QUERY_STRING'];
      
       header(sprintf("Location: %s", $insertGoTo));
         } else { 
           $result = 'Success, you made £'; // They succeded 
      	 $fut = time() + 150;
      	 $exp = 1;
      	 if($next_c > time()) {
      	 	$mon = 0;
      		$exp = 0;
      	 } 
      	 mysql_select_db($database_london, $london);
      	 $query_money = sprintf("UPDATE users SET cash = cash + '$mon', exp = exp + '$exp', time_c = '$fut' WHERE pid = '$MM_Pid'");
      	 $money = mysql_query($query_money, $london) or die(mysql_error());
      
       $insertGoTo = "scrime_done.php?result=$result&mon=$mon";
       $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
       $insertGoTo .= $_SERVER['QUERY_STRING'];
      
       header(sprintf("Location: %s", $insertGoTo));
         }
      } else {
          srand(time());
          $cm = rand(1,$mon);
      	$mon = $cm;
      	$luck = rand(1,10);
      	$fut = time() + 150;
      	$exp = 1;
      	if($luck > 6){
      		$result = "That was too fucking easy! You made £";
      
      	mysql_select_db($database_london, $london);
      	$query_money = sprintf("UPDATE users SET cash = cash + '$cm', exp = exp + '$exp', time_c = '$fut' WHERE pid = '$MM_Pid'");
      	$money = mysql_query($query_money, $london) or die(mysql_error());	
      
      	$insertGoTo = "scrime_done.php?result=$result&mon=$mon";
      	$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
      	$insertGoTo .= $_SERVER['QUERY_STRING'];
      
      	header(sprintf("Location: %s", $insertGoTo));
      } else { 
      	 $mon = "";
      	 $result = 'You failed the crime ';// They failed 
       	 $fut = time() + 150;
      	 mysql_select_db($database_london, $london);
      	 $query_money = sprintf("UPDATE users SET time_c = '$fut' WHERE pid = '$MM_Pid'");
       	 $money = mysql_query($query_money, $london) or die(mysql_error());
       	 if($luck < 3){
       		mysql_select_db($database_london, $london);
       		$query_money = sprintf("UPDATE users SET jail = '1', time_jail = '$fut', jail_rea = 'Petty Theft' WHERE pid = '$MM_Pid'");
      		$money = mysql_query($query_money, $london) or die(mysql_error());
      		$result = 'You failed the crime and got banged up!';
       	 }
       	 $insertGoTo = "scrime_done.php?result=$result&mon=$mon";
       	 $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
       	 $insertGoTo .= $_SERVER['QUERY_STRING'];
      
       	 header(sprintf("Location: %s", $insertGoTo));
      
      }
      }
      }

      Hope that might help a little

        Write a Reply...