Jump to content

Recommended Posts

I have 2 scripts that both work but only separately. The first is the fight script here:

<?php
session_start();
$uname = $_SESSION['uname'];
session_start(); // start our session
if(!isset($_SESSION['loot_chance_run']))
{
    // if $_SESSION['loot_chance_run] not set, proceed and run it

    $_SESSION['loot_chance_run'] = true; // set the session var now


  // initialize outcome of fight and loot chances
  $outcome = mt_rand(1,100);
  $level_advance = 1;
  $gold = mt_rand(1000,4000);
  $diamonds = mt_rand(3,;
  $rubies = mt_rand(3,7);
    
  // First the fight
  if($outcome < 70){

  // Connect to database
  include('includes/config.php');
  
  // Advance level

  // Update database
  $sql="UPDATE $tbl_name SET 
onhand = onhand + $gold,
diamond = diamond + $diamonds,
rubie = rubie + $rubies,
advance = advance + $level_advance
WHERE uname='$uname'";
  mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
  include('header.php');
  include('dungeon1/fight_success.php');
  include('footer.php');
} 


else{
include('header.php');
include('dungeon1/fight_failure.php');
include('footer.php');
}

}
else
{
      // give an error message and call them a cheater 
     echo 'Sorry, this operation cannot be completed again cheater';
}
?>

 

and the second is an advance level script here:

 

<?php
session_start();
$uname = $_SESSION['uname'];

// Level Array
$level = array(10,30,90,180,300,500,700,900,1000,1200,1400,1600,1600,1800,2000,2200,2400,2600,2800,3000,3200,3400,3600,4000);

// Connect to Database
include ('includes/config.php');

// Check for advancement requirements
$sql = "SELECT advance FROM $tbl_name WHERE uname='$uname'";
$result = mysql_query($sql);
$row = mysql_fetch_array( $result );

// Foreach loop to get level
if(in_array($row['advance'],$level))
{
// Update Database
$sql="UPDATE $tbl_name SET 
levl = levl + 1,
onhand = onhand + 5000,
diamond = diamond + 20,
rubie = rubie + 20,
hitp = hitp + 15,
advance = advance + 1
WHERE uname='$uname'";
mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
header("Location:mainview.php?show=congratulations");
}
else{

}
?>

 

Now I have tested them separately and I had been trying to include the advance inside the fight script. I am not able to see where to go to get them where to integrate and work together?? Any hints or mistakes shown me would be appreciated.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/120312-solved-how-do-i-combine-scripts/
Share on other sites

Well my idea was to have a random chance at winning a fight between a character and a monster.Depending on the outcome of the fight if you matched one of the numbers in the level array against the advance points it would increase your level giving you the extra bonuses and of course the next level, but if you didn't meet the criteria and still won the fight you received the loot and an advance point. If you loose you go back to town and the extra was for catching cheaters in a round about way. I got the cheater code from here at phpfreaks from chronister and dezkit. So they worked separately, if I ran the the fight script it worked real well if i ran the level script at the exact corresponding level it would advance my leve but I couldn't figure out how to combine them to get all 3 to work. However I am always in a rush and found the solution about and hour after posting. and here is the code I ended up with.

 

<?php
session_start();
$uname = $_SESSION['uname'];
session_start(); // start our session
if(!isset($_SESSION['loot_chance_run']))
{

// if $_SESSION['loot_chance_run] not set, proceed and run it
$_SESSION['loot_chance_run'] = true; // set the session var now
    
// initialize outcome of fight and loot chances
$outcome = mt_rand(1,100);
$level_advance = 1;
$gold = mt_rand(1000,4000);
$diamonds = mt_rand(3,;
$rubies = mt_rand(3,7);

// Level Array
$level = array(10,30,90,180,300,500,700,900,1000,1200,1400,1600,1600,1800,2000,2200,2400,2600,2800,3000,3200,3400,3600,4000);

// Connect to Database
include ('includes/config.php');

// Check for advancement requirements
$sql = "SELECT * FROM $tbl_name WHERE uname='$uname'";
$result = mysql_query($sql);
$row = mysql_fetch_array( $result );

// Foreach loop to get level
if(in_array($row['advance'],$level))
{

// Update Database
$sql="UPDATE $tbl_name SET 
levl = levl + 1,
onhand = onhand + 5000,
diamond = diamond + 20,
rubie = rubie + 20,
hitp = hitp + 15,
advance = advance + 1
WHERE uname='$uname'";
mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
header("Location:mainview.php?show=congratulations");
}

elseif($outcome < 70){
// Update database
  $sql="UPDATE $tbl_name SET 
onhand = onhand + $gold,
diamond = diamond + $diamonds,
rubie = rubie + $rubies,
advance = advance + $level_advance
WHERE uname='$uname'";
  mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
  
// Take to Fight Sucess
include('header.php');
include('dungeon1/fight_success.php');
include('footer.php');
} 

// Take To Fight Failure
else{
include('header.php');
include('dungeon1/fight_failure.php');
include('footer.php');
}

}

// Check For Cheating
else
{
// give an error message and call them a cheater 
echo 'Sorry, this operation cannot be completed again cheater';
}
?>

 

This has worked in 4 separate tests. I apologize for being to hasty in asking for help and I do appreciate the replies I leave this here for anyone else who might benefit from it. I'll try to be more patient and sorry to for being so long winded. Thanks again!

 

:-\

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.