Page 1 of 1

Text Based Mafia Game || Crimes Part 10 Final part of these tutorials Rate Topic: -----

#1 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 16 November 2010 - 01:16 PM

Please check out my other tutorials PART 1, PART 2, PART 3, PART 4, PART 5, PART 6, PART 7, PART 8,
PART 9.

Files We are going to use
  • Safe.php
  • function.php



Files We are going to create
  • _crimes.php
  • Crimes.php


I would like to say a huge congratz to all those who followed these tutorials from Part 1 and have done every step, because by now you have a small game that is in the creation of being big game depending on the amount of work you put in to it. What we have done is just the foundation of the house, now it is up to you to build the rest of the house.
By the end of this tutorial you have have started building your first wall. Crimes is an activity to do in the game that the outcome is completely random, but we can choose how random the really are. Doing crimes can be renamed to anything. like:
Jobs
working
Digging for gold
Searching for coins.
Lots more, just use your imagination. Remember anything can be done, just make sure that is will attract players, because the more the merrier. When it comes to crimes the only thing you can overdo is the amount you payout to players. try and control the rate that money flows in the game. because if every in the game is trillionaires then the game will be really boring and stupid, because you dont need to work hard for things. Also you want be able to have any fun of it or if you are looking to make money, you wont.
OK lets begin.
Crimes.php
Before we start making the crimes page we need to create the names of the crimes for our players to do. For the purpose of these tutorials i have created quick 5. (you can create as many crimes as you want.) my five are:
  • Steal from a child
  • Rob Denis' house.
  • Kidnap a member of the DIC STAFF for ransom
  • Rob a bank
  • Kidnap the Steve jobs for ransom

Warning: Please do not attempt any of these in real life. i am sure JackOfAllTrades wont like it if you kidnapped him for ransom.

Step One. - Setting up.
We need to set up a few things before we can start coding the crimes page. Add this to database
--
-- Table structure for table `crimetimes`
--

CREATE TABLE IF NOT EXISTS `crimetimes` (
`id` int(100) NOT NULL auto_increment,
`name` varchar(200) NOT NULL,
`crime1` varchar(200) NOT NULL default '0',
`crime1a` varchar(200) NOT NULL default '0',
`crime2` varchar(200) NOT NULL default '0',
`crime2a` varchar(200) NOT NULL default '0',
`crime3` varchar(200) NOT NULL default '0',
`crime3a` varchar(200) NOT NULL default '0',
`crime4` varchar(200) NOT NULL default '0',
`crime4a` varchar(200) NOT NULL default '0',
`crime5` varchar(200) NOT NULL default '0',
`crime5a` varchar(200) NOT NULL default '0',

PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1634 ;


Once a player has committed a crime we need a timer to not let them commit it until the timer goes down. This is s timer to help calculate the timer from mysql to php. so open functions.php and add this on there.

function crimemaketime($until){

   $now = time();
   $difference = $until - $now;

   $days = floor($difference/86400);
   $difference = $difference - ($days*86400);

   $hours = floor($difference/3600);
   $difference = $difference - ($hours*3600);

   $minutes = floor($difference/60);
   $difference = $difference - ($minutes*60);

   $seconds = $difference;
   $output = "$minutes Minutes and $seconds Seconds";

   return $output;
   
}



it has just occurred to me that we dont have functions.php linked to safe. so open up Safe.php and add the following. on line 2.
<? include_once("functions.php"); ?> 

just below
<? include_once("connect.php"); ?>


while we are on safe we need to add players on the `crimetimes` we have added to database. so scroll down to the bottom of the page on safe.php and add the following.

$sql = "SELECT id FROM crimetimes WHERE name='".mysql_real_escape_string($_POST['name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
	  
if($m_count >= "1"){
	
}else{
	$sql = "INSERT INTO crimetimes SET id = '$id' , name = '$name', crime1 = '0' , crime1a = '0' , crime2 = '0' ,crime2a = '0' , crime3 = '0' , crime3a = '0' , crime4 = '0' , crime4a = '0' , crime5 = '0' , crime5a = '0'";
$res = mysql_query($sql);
	}


Try and make sense of it....... to see if you understand what that is. if you cant i will explain............................................................................................................................ We have created a a database table called `crimestimes` this is going to hold information on the times of the crimes that the players will be committing, but it cant hold it if the player are not added. We only want one field per player, just like login. so

$sql = "SELECT id FROM crimetimes WHERE name='".mysql_real_escape_string($_POST['name'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){

checks to see if the player already has a field in the database. if the do have a field then do nothing, but if the dont insert this. $sql = "INSERT INTO crimetimes SET id = '$id' , name = '$name', crime1 = '0' , crime1a = '0' , crime2 = '0' ,crime2a = '0' , crime3 = '0' , crime3a = '0' , crime4 = '0' , crime4a = '0' , crime5 = '0' , crime5a = '0'";
$res = mysql_query($sql);
. so now we have fields to hold data of the times of crimes. The reason why we have crime1 and crime1a is because crime1 holds the timer and crime1a holds a 1 or 0 to indicate if the crime timer is down to 0. when someone commit a crime it goes to 1 and then the timer is down it goes back to 0 (more on this later) HOW EXCITING!!!

Step Two - Designing.
Trust me we have done the hard part of this. Why? - well because we have dont our setting up. like i said before about building half a wall. what we did in step one is like mixing the cement and made marking on where we are going to lay out wall and load out bricks.Now all we do is lay the cement and put the brick. which is Designing the page and add the timers. Simple. i created this html page for this tutorial feel free to use it. make sure that you have left and right at the top and your css is linked in on left. Add this in the body section of the page.
<?
require("_Crimes.php");
?>
<form id="form1" name="form1" method="post" action=""> 
<table width="90%" border="0" cellpadding="0" cellspacing="2" class="table">
  <tr>
    <td class="header">Crimes</td>
    <td class="header">Availability</td>
  </tr>
  <tr>
    <td class="cell"><input type="radio" name="radiobutton" id="radio" value="1" />
    Steal from a child </td>
    <td class="cell"></td>
  </tr>
  <tr>
    <td class="cell"><input type="radio" name="radiobutton" id="radio2" value="2" />
      Rob Denis' house.</td>
    <td class="cell">&nbsp;</td>
  </tr>
  <tr>
    <td class="cell"><input type="radio" name="radiobutton" id="radio3" value="3" />
    Kidnap a member from the DIC STAFF for ransom</td>
    <td class="cell">&nbsp;</td>
  </tr>
  <tr>
    <td class="cell"><input type="radio" name="radiobutton" id="radio4" value="4" />
    Rob a bank</td>
    <td class="cell">&nbsp;</td>
  </tr>
  <tr>
    <td class="cell"><input type="radio" name="radiobutton" id="radio5" value="5" />
      Kidnap the Steve jobs for ransom</td>
    <td class="cell">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="right" class="cell"><input type="submit" name="Commit" id="Commit" value="Commit" /></td>
  </tr>
</table>
</form>


as you can see i got a simple layout of the page and you can see my 5 crimes in the table. That's real it for designing.

_Crimes.php

Ok now time to get down to the hard stuff. Now we have to build and set our times and give out our exp and money or gold. what every you choose to call it.

think in real if you rob a bank and came out with like 50K you will it will be good right. but then can you go back there the next second. NO NO NO. you will be caught and killed. OK well not killed but you will be caught. so we are going to add a to stop them from doing it again. kinda like hiding out in GTA.

Step One - Structure of the Crimes

Structure of committing the crimes
We have 5 crimes and a player can choose any one of those crimes in any particular order. so what we are going to do is have the sturcture like this.

If submit { // if player hit commit crime.
$Radiobutton = Select Radiobutton // this selects radio button of the crime and sets it to $Radiobutton. so we know what crime it is.

if $radiobutton == 1{ // This means the player selected the first crime.
$Crime_chance = ran(1,10); // chances of the crime committing or failing.

$crimetime1 = 10 // how long in seconds the should commit this crime again

$Crime_exp = rand(1,10) // a random exp is chosen to give out.

$Crime_money =rand(100,500)// a random money is chosen to give out

$timewait1=time()+ $crimetime1 // the time time added to the time. More on the $timewait1 at the bottom.

if $Crime_chance = 2 then
echo "you fail. SHAME HAHAHA :(/>"
add the time to database. add no exp and no money.
else

add the exp , money to user name and then add the timer.
echo "You Stole from a child and received $$Crime_money"

else if time isn't up.
echo you have to wait $timewait1 to do this crime again.


that's all for the basic structure of the crime. The rest is the only other this is how the pages are holding the crimes.

$sql2="SELECT * from crimetimes WHERE name='$name'";
$result2=mysql_query($sql2);

while($rows2=mysql_fetch_array($result2)){ // Start looping table row 

$timeleft1= $rows2['crime1'];
$timeleft2= $rows2['crime2'];
$timeleft3= $rows2['crime3'];
$timeleft4= $rows2['crime4'];
$timeleft5= $rows2['crime5'];


$last1 = $timeleft1 - time();
$last2 = $timeleft2 - time();
$last3 = $timeleft3 - time();
$last4 = $timeleft4 - time();
$last5 = $timeleft5 - time();


that's how. Every crime time is being called from database and attached to a variable that's help make it so that the player can see how long the have and you can compare this to the time now like

$last1 <= 0


that's all the complex things you need to worry about. Download the attachment of Attached File  _Crimes.php (2.25K)
Number of downloads: 393.

i only coded the first crime because i want you to do the rest to show that you have learned something at least.

in the availability section of the crimes you can add this so that players can see how long left of the crime the want to commit.
<?php if ($last1 <= 0){ echo "<font color=lightgreen>Available</font>"; }else{ echo crimemaketime($timeleft1) ; } ?>


the crimemaketime is our function we added to functions. and the rest you know.


Well that's the end of that. i may have missed something off this but i have checked like 5 times and everything seem in order. if you see anything our of place please inform me.

I want to thank you for following these tutorials. Remember if you are ready and serious nothing that you want you wont be able to get. I am putting together a site that is a mafia game built by me using all my knowledge and some awesome web 2.0 feature to make it socially interactive which is coming out 1st Jan 2011, and another site which is mainly helping you to get your game up and running. It will include services which helps you to get the basic information that you need fast. All this coming Next year. Keep tune to www.addplanet.co.uk. All in development for now. Will be ready for next year

Please Please if you have being doing these online , i want to see how you are doing, so please post some links to where you have being developing. i may also give you some tips and hints.

Enjoy :D/> :D/> :D/>



--------
Mod: the code can be found here:
https://github.com/m...ext_Based_Mafia


Is This A Good Question/Topic? 4
  • +

Replies To: Text Based Mafia Game || Crimes Part 10

#2 kris123  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 24-September 11

Posted 24 September 2011 - 02:05 PM

Hi can you make a full game tutorial in video or somethign thatl make it easier and try not to do too much errors more tutorials as im stuckl
Was This Post Helpful? -1
  • +
  • -

#3 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 11 April 2012 - 03:16 PM

View Postkris123, on 24 September 2011 - 10:05 PM, said:

Hi can you make a full game tutorial in video or somethign thatl make it easier and try not to do too much errors more tutorials as im stuckl


if you are stuck i am remaking my tutorials using a framework and explaining the awesomeness of framework and it will be a little advance as well with less chance of errors. Look out for it.
Was This Post Helpful? 0
  • +
  • -

#4 bamsetheking  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 16
  • Joined: 21-November 12

Posted 30 January 2014 - 10:54 AM

Posted Image

my game so far :D/>
Was This Post Helpful? 0
  • +
  • -

#5 Denis1  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 103
  • Joined: 29-July 09

Posted 06 February 2014 - 04:21 PM

View Postbamsetheking, on 30 January 2014 - 05:54 PM, said:

Posted Image

my game so far :D/>/>/>

looking sweet, keep it up.
Was This Post Helpful? 0
  • +
  • -

#6 dongangsters  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-May 14

Posted 10 May 2014 - 12:48 AM

can you please tell me how to make a ban, add news and also a kill page please also when i do crimes it dont rank my profile up how do i sort that ?
Was This Post Helpful? 0
  • +
  • -

#7 bamsetheking  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 16
  • Joined: 21-November 12

Posted 01 August 2014 - 08:50 AM

View PostDenis1, on 06 February 2014 - 04:21 PM, said:

View Postbamsetheking, on 30 January 2014 - 05:54 PM, said:

Posted Image

my game so far :D/>/>/>/>

looking sweet, keep it up.


can you maybe help with the kill page and make a ranking script ?:D
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9093
  • View blog
  • Posts: 34,145
  • Joined: 12-June 08

Posted 01 August 2014 - 08:56 AM

You haven't made one yet? It looks like you asked that at the begining of the year... What sort of progress have you made?
Was This Post Helpful? 0
  • +
  • -

#9 freelance php programmer  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 14-May 14

Posted 07 August 2014 - 01:11 AM

This is excellent help that I got via this topic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1