Jump to content
MakeWebGames

Drug Mod iam creating


Newbie

Recommended Posts

Hey i have been working on a drug mod where users can pick a drug and then gain a profit every day

You will see from the coding what i mean its not nearly completed but just wanted to ask if this would work really.

I dont have mccodes set up

 


<?php

# Drug Mod
# Mccodes V2
# Created for MWG
# Free Mod


include ("globals.php");

if($ir['level'] > 10)
{
echo "Restricted Access: Please come back when you are level 10 or higher.";
$h->endpage();
exit;
}


echo "<h2><b>Drug Corrner</b></h2><br />

<i>Here in the drug corrner you can pick a drug to choice from and it will earn you profit each day!</i>";





$drug_array[0] = "Rohypnol";
$drug_array[1] = "Valium";
$drug_array[2] = "Mcat";
$drug_array[3] = "Cannabis";
$drug_array[4] = "Speed";
$drug_array[5] = "Xanax";
$drug_array[6] = "MDMA";
$drug_array[7] = "Cocaine";
$drug_array[8] = "Heroin";

$drug_price[0] = "100";
$drug_price[1] = "250";
$drug_price[2] = "500";
$drug_price[3] = "750";
$drug_price[4] = "1500";
$drug_price[5] = "2500";
$drug_price[6] = "5000";
$drug_price[7] = "10000";
$drug_price[8] = "20000";

$gain_price = $drug_array[0] + $drug_price[0] * ($ir['IQ']) / 50 # Total price your drugs earn!



$h->endpage();

?>

 

So basicly am i on the right track or way off?

so say they had drug number 0

price number 0

Rohypnol

$100

*

users iq

then divided that by 5

 

(Drug price:100) * (IQ: 1000) / 50 = 2000 profit

Thanks

Steve

Edited by Newbie
Link to comment
Share on other sites

Hi Steve,

You're on the correct track -although others would have done it differently- it will still yield the same result.

I look forward to seeing this complete, to see how you complete it, and what methods you'll use.

If you don't have mccodes set up due to the price, how about using McCodes FREE, and then convert it, if you wish it to be for version two as well.

If you need help in any areas, PM me (:

Good Luck,

Sniko

Link to comment
Share on other sites

i just purchased a license for v2 but me being stupid i put the money on my account where you spend it on mods so had to speak to cold about that and he has gave me a license however there is no engine to download so just waiting on that getting sorted out and ill be able to get it up and tested and hopefully get the mod finished asap as i said in another post you don't see very much mods getting posted on here anymore.

i will hit you up if i get stuck appreciate any help i could get :)

Link to comment
Share on other sites

i just purchased a license for v2 but me being stupid i put the money on my account where you spend it on mods so had to speak to cold about that and he has gave me a license however there is no engine to download so just waiting on that getting sorted out and ill be able to get it up and tested and hopefully get the mod finished asap as i said in another post you don't see very much mods getting posted on here anymore.

i will hit you up if i get stuck appreciate any help i could get :)

Goodie - yeah, it's a shame really. I arrived here when it was known as 'Criminal Existence' - and the community was -somewhat- booming. Seeing it die slowly..... /violin music and camera pans across a desert landscape/

Anyway, back on topic, like I said, excited to see this finished!

Link to comment
Share on other sites

I'm new here, but may i ask why you have your arrays like this?

 
$drug_array[0] = "Rohypnol";
$drug_array[1] = "Valium";
$drug_array[2] = "Mcat";
$drug_array[3] = "Cannabis";
$drug_array[4] = "Speed";
$drug_array[5] = "Xanax";
$drug_array[6] = "MDMA";
$drug_array[7] = "Cocaine";
$drug_array[8] = "Heroin";

$drug_price[0] = "100";
$drug_price[1] = "250";
$drug_price[2] = "500";
$drug_price[3] = "750";
$drug_price[4] = "1500";
$drug_price[5] = "2500";
$drug_price[6] = "5000";
$drug_price[7] = "10000";
$drug_price[8] = "20000";

 

The numbers aren't needed.

$drug_array = array();
$drug_array[] = "Rohypnol";
$drug_array[] = "Valium";
$drug_array[] = "Mcat";
$drug_array[] = "Cannabis";
$drug_array[] = "Speed";
$drug_array[] = "Xanax";
$drug_array[] = "MDMA";
$drug_array[] = "Cocaine";
$drug_array[] = "Heroin";

$drug_price = array();
$drug_price[] = 100;
$drug_price[] = 250;
$drug_price[] = 500;
$drug_price[] = 750;
$drug_price[] = 1500;
$drug_price[] = 2500;
$drug_price[] = 5000;
$drug_price[] = 10000;
$drug_price[] = 20000;

 

Also don't see the point in two arrays you can combine both of them like this.

$drugs = array();
$drugs[] = array('name' => "Rohypnol", 'price' => 100);
$drugs[] = array('name' => "Valium", 'price' => 250);
$drugs[] = array('name' => "Mcat", 'price' => 500);
$drugs[] = array('name' => "Cannabis", 'price' => 750);
$drugs[] = array('name' => "Speed", 'price' => 1500);
$drugs[] = array('name' => "Xanax", 'price' => 2500);
$drugs[] = array('name' => "MDMA", 'price' => 5000);
$drugs[] = array('name' => "Cocaine", 'price' => 10000);
$drugs[] = array('name' => "Heroin", 'price' => 20000);

Either that or do something like this.

$drugs = array();
$drugs['Rohypnol'] = array('price' => 100);

 

You can do the rest. :)

Link to comment
Share on other sites

alright thanks for that this is my first time i have tried to put it in arrays i was just referring to what i read on tiztag.com i thought i would try put it into action see if it would work.

 

as i said any help is appreciated as i will be releasing the mod for free for V2 and when i do convert it to V1 when its done unless someone beats me :P

thanks again for the ideas

Link to comment
Share on other sites

I usually like to have those data in a table instead in the code. The reason behind it is to be able to edit the data, add content, without editing the code. So either from phpMyAdmin or yet better via an admin panel. But that's me.

yep would seem better to use a new table but for example lets say this is the table

drugs

ID
dID
dNAME
dPRICE

 

so if i wanted to make out how much they would make a day would it be something like this

 

($ir['dNAME'] & $ir['dPRICE'] * $ir['IQ'] / 50) 
Link to comment
Share on other sites

ok so i went with a_bertrand and decided to try do it from the table heres what i got

The mod still is not finished yet :( but hoping that soon gets fixed i am having one problem so far

 

PROBLEM:

cant get the user to buy the building?? doesn't load it anything

SQL

 

CREATE TABLE IF NOT EXISTS `drugbuildings` (
 `bID` int(11) NOT NULL AUTO_INCREMENT,
 `dPRICE` int(11) NOT NULL,
 `bDRUG` varchar(255) NOT NULL,
 `bPROFIT` int(11) NOT NULL,
 PRIMARY KEY (`bID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

 

 

INSERT INTO `drugbuildings` (`bID`, `dPRICE`, `bDRUG`, `bPROFIT`) VALUES
(1, 1000, 'Weed', 10),
(2, 5000, 'Cocaine', 200);

 

ALTER TABLE `users` ADD  `permit` INT( 11 ) NOT NULL DEFAULT '0'
ALTER TABLE `users` ADD  `weed` INT( 11 ) NOT NULL DEFAULT '0'
ALTER TABLE `users` ADD  `Cocaine` INT( 11 ) NOT NULL DEFAULT '0'

 

drugbuildings.php

<?php

#  Drugs Mod 




include ("globals.php");

if($ir['permit'] == 0)
   { 
   echo "<br />
  	<img src='http://oulhaj.com/img/private.png' width='100px' height='100px' />

   <center><h5><font color=red>ACCESS DENINED:</font> <br /> <br />You do not own a permit please come back when you have one.</h5>
  <b>If you wish to purchase a Permit please go <a href='permit.php'><font color=gold>Permit Center</font></a> <center>";
  exit;
 }  

$drugprice = $db->query("SELECT `dPRICE` FROM drugbuildings", $c);
$drugprice2 = $db->fetch_row($drugprice);

$price = $ir['dPRICE'];
$price1 = number_format($price);


 	switch($_GET['action'])
 	{
 	case "buy":
 	buy();
 	break; 


	case "buildingbuy": 
buildingbuy();
break;  

default:
index();
break;
}

	 function index()
{
global $db, $ir,$c,$userid,$h;


$result = $db->query("SELECT * FROM drugbuildings"); 

echo "<h2>Buildings</h3><br />
   <i>Here you can purchase a building and gain profit from it each hour!</i>"; 

echo "<table border='1' width='50%'>
  <tr title='You are looking at Row 1' bgcolor='silver'> 
 <th>Building</th> 
 <th>Price</th> 
 <th>Profit</th> 
 <th>Buy</th>  
 <tr>";
 while($row = $db->fetch_row( $result )) {  
 echo"
 <td>{$row['bDRUG']}</td>
 <td>\${$row['dPRICE']}</td>
 <td>\${$row['bPROFIT']}</td>
 <td><a href='drugbuildings.php?action=buildingbuy'>Buy</a></td>
<tr>";
}
}

function buy()
{
global $db, $ir,$c,$userid,$h;
echo "Buying a building!

     	<a href='drugbuildings.php?action=buy'>Buy a Building</a>
";
}

function buildingbuy()
{
global $db, $ir,$c,$userid,$h;

if($ir['money'] <= $price)
{
echo "<center><font color=red>Error!</font> <br />You dont have enough for a building!
 <br />     
<a href='index.php'>Back Home</a>
";
}

if($ir['money'] > $price)
{
echo "<font color=green>Success!</font> You bought a ($ir['dNAME']).";
$db->query("UPDATE users SET money=money-'$cost' WHERE userid={$userid}");
$db->query("UPDATE users SET weed=weed+1 WHERE userid={$userid}"); # what i was wondering was how would i get it to upgrade whatever drug they buy???
}
}	

$h->endpage();    

?>

 

i created a permit.php where user needs to buy a permit before they can access the page this page works fine

permit.php

<?php

include ("globals.php");



if($ir['permit'] == 1)
   { 
   echo "<h5>You already own a permit silly go and invest your money into some drugs.</h5>
  	<i><a href='drugbuildings.php'><font color=green>Drugs<?font></a>";exit;
  }




switch($_GET['action'])
{	
case "buy":
buy();
break;	

case "buyconf":	
buyconf();
break;	

default:
index();
break;
}


	 function index()
	{
	global $db, $ir,$c,$userid,$h;	
	$cost = '1000';			
	echo "
		<h2>Permit Center</h2>

	<table border='1' width='75%'>
<tr title='info' bgcolour='silver'>
<th>Name</th>
<th>Cost</th>
<th>Info</th>	
<th>Buy</th>
<tr>

<td>Drug Permit</td>
<td>$1,000</td>
<td>A permit lets you access the drug building page where you can buy a building and gain profit from it every hour.</td>
<td><a href='permit.php?action=buyconf'>Buy Premit</a></td></tr></table>";	
}

function buy()
{
global $db, $ir,$c,$userid,$h;
echo "Buying Building Permit for $1,000

     	<a href='permit.php?action=buy'>Buy a Permit </a>
";
}

function buyconf()
{
global $db, $ir,$c,$userid,$h;

if($ir['money'] < '1000')
{
echo "<center><font color=red>Error!</font> <br />You dont have enough for a Permit you need <font color=green>$1,000.</font>
 <br />     
<a href='index.php'>Back Home</a>
";
}

if($ir['money'] > '999')
{
echo "<font color=green>Success!</font> You bought a permit for $1,000. <br /> Goto <a href='drugbuildings.php'>Drug Buildings</a> and see what you can invest!";
$db->query("UPDATE users SET money=money-1000 WHERE userid={$userid}");
$db->query("UPDATE users SET permit=permit+1 WHERE userid={$userid}");
}
}

$h->endpage();	


?>

 

What i cant get it to do is

Doesnt come up that you dont have enough money to buy building

buy button doesnt do anything

i wouldnt be able to get it to updrade the drug building for example its been taking out the drugbuildings table

 

$db->query("UPDATE users SET weed=weed+1 WHERE userid={$userid}");

 

would i have to write i new function for each drug so the database knows what i am adding because so far i have 2 drugs but im planning on adding more

Edited by Newbie
Link to comment
Share on other sites

function buildingbuy()
{
global $db,$ir,$c,$userid,$h;

if($ir['money'] <  $price) {
echo '<center><font color=red>Error!</font> You dont have enough for a building!
<a href='index.php'>Go Back Home</a>';  

	} else {
	echo "<font color=green>Success!</font> You bought a ($ir['dNAME']).";
	$db->query("UPDATE users SET money=money-'$cost' WHERE userid={$userid}");
	$db->query("UPDATE users SET weed=weed+1 WHERE userid={$userid}"); // what i was wondering was how would i get it to upgrade whatever drug they buy??? }
}
$h->endpage();      
?>

 

Cleaned up your buy function and also made it so that it should hopefully make it so if they don't have enough money so they can't buy a building.

Edited by Razor42
Small mistakes!
Link to comment
Share on other sites

function buildingbuy()
{
global $db,$ir,$c,$userid,$h;

if($ir['money'] <  $price) {
echo '<center><font color=red>Error!</font> You dont have enough for a building!
<a href='index.php'>Go Back Home</a>';  

	} else {
	echo "<font color=green>Success!</font> You bought a ($ir['dNAME']).";
	$db->query("UPDATE users SET money=money-'$cost' WHERE userid={$userid}");
	$db->query("UPDATE users SET weed=weed+1 WHERE userid={$userid}"); // what i was wondering was how would i get it to upgrade whatever drug they buy??? }
}
$h->endpage();      
?>

 

Cleaned up your buy function and also made it so that it should hopefully make it so if they don't have enough money so they can't buy a building.

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/drugempi/public_html/drugbuildings.php on line 79

line 79

echo "<font color=green>Success</font> You bought a ($ir['dNAME']).";

 

had to add this to fix it

 

echo "<font color=green>Success</font> You bought a " .($ir['dNAME']). " ";

 

the buy function does not work aswell when a user clicks buy it says

Success You bought a

even if they dont have the money needed???

when i created the permit.php i was using numbers

 

if($ir['money'] < '100')
{
echo "You cant afford this!";
exit;
}

if($ir['money'] > '99')
{
echo" congrats you bought a .....
$db->query("UPDATE users SET permit-permit+1 WHERE userid={$userid}");
Edited by Newbie
Link to comment
Share on other sites

function buildingbuy()
{
global $db,$ir,$c,$userid,$h;

   if($ir['money'] <  $price) {
   echo '<center><font color=red>Error!</font> You dont have enough for a building!
   <a href='index.php'>Go Back Home</a>';  

       } else {
       echo "<font color=green>Success!</font> You bought a ($ir['dNAME']).";
       $db->query("UPDATE users SET money=money-'$cost' WHERE userid={$userid}");
       $db->query("UPDATE users SET weed=weed+1 WHERE userid={$userid}"); // what i was wondering was how would i get it to upgrade whatever drug they buy??? }
}
$h->endpage();      
?>

Cleaned up your buy function and also made it so that it should hopefully make it so if they don't have enough money so they can't buy a building.

Where does $price come from.

(This is at OP: but Razor's code is more specific to the point I'm making)

Link to comment
Share on other sites

$price = $ir['dPRICE'];

 

i dont think i have the price bit right tbh

 

Iam trying to get it so it matches the price out of the database

In the database there is

dID

dPRICE

dPROFIT

i have 2 buildings in the table atm

 

Weed

costs $1000

profit is $10

Cocaine

costs $5000

profit $200

Link to comment
Share on other sites

$price = $ir['dPRICE'];

i dont think i have the price bit right tbh

Iam trying to get it so it matches the price out of the database

In the database there is

dID

dPRICE

dPROFIT

i have 2 buildings in the table atm

Weed

costs $1000

profit is $10

Cocaine

costs $5000

profit $200

Yes, but $price does not exist within the scope of your buildingbuy function.

An shoddy example:

<?php

$variable = 'Testing';

//Closest to yours.
function printVariable() {

   if (isset($variable))
       return $variable;

   return 'Not Found';
}

function printVariable2() {
   global $variable;
   if (isset($variable))
       return $variable;

   return 'Not Found';
}

function printVariable3($variable) {

   if (isset($variable))
       return $variable;

   return 'Not Found';
}

echo printVariable().' | '.printVariable2().' | '.printVariable3($variable);

Result:

Not Found | Testing | Testing
Link to comment
Share on other sites

  • 3 months later...

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