Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Seeing as people cant properly read and have to report my last question Even though it was definately clear . So AGAIN. this is a game script im trying to fix the bug on It Works for the most part . The issue with the script its not updating the Users Battle points when its being used to buy the Gems from the Market nor is it updating the Users Gem stats. The only thing it is doing is taking away from the Stock.txt which tells the user how many are in Stock. How do i fix this issue. And if you report this saying its not a question Someone needs to properly read english and have common sense that the question box only allows so much to input which doesnt give me enough room to ask the full question

PHP
<?php
        if($_COOKIE['edited']) {
          session_start();
          }
        header("Cache-control: private"); //IE 6 Fix
        include "includes/lonconfig.php";
        $title = "Skill Trader Xur";
        include "includes/private_header.inc.php";
        if(!isset($_COOKIE['edited'])) {
          error("not_logged_in");
          return;
          }
/*       if($playerinfo[status]!=4) {
         echo "sorry we are closed for the moment<br> " ;
         return;
         }
*/
       $tendency=sin(date('j')*12)*.1;     //factor to affect prices to generate a ciclycal up/down tendency. I love this, jeje
       $stockdata=loaddata();
       $spread=.50;
       //echo "<br>$tendency";

switch ($action)
{
   case "buy";
      if ($amount!=1) { echo "What are you trying to do ? I didn't offer that deal!<br><br>"; echo "<center><a href=$PHP_SELF>Back</a><br></center>"; break; }
      if ($price!=ceil($stockdata[baseprice][$gem]*(1+$spread)))
      {
         echo "Gem Market prices have changed since last quote. New price is ".ceil($stockdata[baseprice][$gem]*(1+$spread))."<br>";
         echo "Do you want to continue the trade? (prices might change again till you decide)<br><Br>";
         echo "<a href=$PHP_SELF?action=buy&amount=$amount&gem=$gem&price=".ceil($stockdata[baseprice][$gem]*(1+$spread)).">Yes</a> / <a href=$PHP_SELF>No</a><br><br>";
         break;
      }

      if ($amount>$stockdata[amount][$gem]) { echo "Sorry, I don't have that much...<br>Come back later, maybe I can get some for you<br><br>"; echo "<center><a href=$PHP_SELF>Back</a><br></center>"; break; }

      if ($playerinfo[battle_points]>=$price*$amount)
      {
         echo "<br>You bought $amount ".$stockdata[gemname][$gem]."(s) for ".$price*$amount."<br><br>";
         echo "<center><a href=$PHP_SELF>Back</a><br></center>";
         mysql_query("update userdb set battle_points=battle_points-".$price*$amount.", ".$stockdata[gemname][$gem]."=".$stockdata[gemname][$gem]."+$amount where id=$playerinfo[id] limit 1");
         mysql_query("INSERT INTO `user_tradelogs` ( `fromid` , `type` , `itemdesc` , `amount` , `amount1` , `fecha` ) VALUES ( '$playerinfo[id]','13', '".$stockdata[gemname][$gem]."', '$amount', '".$price*$amount."', FROM_UNIXTIME(unix_timestamp())+0 )");

         $stockdata[baseprice][$gem]=1+ceil($stockdata[baseprice][$gem]*(1+$amount*.00005));
         $stockdata[amount][$gem]-=$amount;

         savedata($stockdata);
      } else echo "You don't have the required battle points to close that operation<br><br><center><a href=$PHP_SELF>Back</a><br></center>";
      break;

   default:

      echo "You enter the building and the amount of people screaming for buying and selling is amazing, You don't know where to go,";
      echo " Xur approaches you and tells you: \"Welcome to the Gem Market... Pretty busy, uh ?<br><br>What can I do for you?<br><br><br>";
      echo "<table width=100% border=1><tr><th>Item</th><th>Charging</th><th>Buy</th>";
      if ($playerinfo[status]==5) echo "<th>Stock</th>";
      echo "<th colspan=4>In Stock</th></tr>";

      for ($i=1;$i<=3;$i++)
      {
         $gemname=$stockdata[gemname][$i];
         $buyprice=ceil($stockdata[baseprice][$i]*(1-$spread));
         $amount=$stockdata[amount][$i];
         echo "<tr><td align=center>$gemname</td><td align=center>$buyprice</td>";
         if ($playerinfo[status]==5) echo "<td align=center>$amount</td>";
         echo "<td><a href=$PHP_SELF?action=buy&amount=1&gem=$i&price=$buyprice>Buy 1</a></td>";
         echo "<td>$amount</a></td>";
         echo "</tr>";
      }
      echo "</table>";

      echo "<center><font color=yellow>Battle Points: ($playerinfo[battle_points])</font></center>";
      echo "<br><br><center><a href=stxur.php>Exit Room</a><br></center>";

      break;
}


function loaddata()
{
   global $tendency;
   $filename='stocks.txt';
   $fp = @fopen($filename, "r");
   if($fp)
   {
      for ($i=1;$i<=3;$i++)
      {
         $stockdata[gemname][$i] =trim(fgets($fp));
          $stockdata[amount][$i] =(int)trim(fgets($fp));
          $stockdata[baseprice][$i] =(int)(trim(fgets($fp))*(1+$tendency));
          $stockdata[limit][$i] =(int)trim(fgets($fp));
       }
       fclose($fp);
       return $stockdata;
   }
}

function savedata($stockdata)
{
   global $tendency;
   $filename='stocks.txt';
   $fp = fopen($filename, "w+");
   if($fp)
   {
      for ($i=1;$i<=3;$i++)
      {
          fputs($fp,$stockdata[gemname][$i]."\n");
          fputs($fp,$stockdata[amount][$i]."\n");
          fputs($fp,round($stockdata[baseprice][$i]/(1+$tendency))."\n");
          fputs($fp,$stockdata[limit][$i]."\n");
       }
       fclose($fp);
   }
}
?>
Posted
Updated 3-Sep-15 8:46am
v2
Comments
Richard Deeming 3-Sep-15 14:27pm    
Starting your question by insulting the UNPAID VOLUNTEERS who answer questions in this site is not going to win you any friends.
Member 11957253 3-Sep-15 14:31pm    
well they shouldnt be reporting things saying it doesnt have a question and its not clear when it is clear what the issue is and does ask a question. Not like if i care for points
Richard Deeming 3-Sep-15 14:33pm    
It might be clear to you, but it's obviously not clear to everyone else.

Remember, we can't see your screen, access your hard-drive, or read your mind.

Assume that the person reading your question knows nothing about what you're doing, why you're doing it, what problems you're having, etc.
PIEBALDconsult 3-Sep-15 14:57pm    
"which doesnt give me enough room to ask the full question"
B.S. So you admit you're not asking the full question? That's a step in the right direction.
Please use Improve question to provide more information about this "Stock.txt" -- is this simply a matter of the file not being updated? And why are you not using a database?
Most problems people encounter can be eliminated by doing things the right way.
Sergey Alexandrovich Kryukov 3-Sep-15 15:23pm    
Agree.

I added some partial answer based on the inquirer's previous question, now auto-removed due to our abuse reports.

—SA

1 solution

See below the answer to your previous question which has been automatically removed due to abuse report:

Sorry, the question makes little sense. You can change any variable regardless the purpose of this variable. First of all, you should have indicated that the question about the PHP used in a Web site, because PHP can be used in a stand-along way. On a page, you cannot run the script interactively. This is not how Web works. You need to have a page with controls, such as buttons and input controls. You need to take value of controls and send an HTTP request to the same or another page. This another page should handle the request and create HTTP response. In this response, you can re-calculate data.

Now, to send HTTP request, you can use the form element, and you need at a submit button <input type="submit">. You also need the attribute action (URL) and specify the method, such as "post". On server side, you can use PHP $_POST:
http://php.net/manual/en/reserved.variables.post.php[^].

Alternatively, to send an HTTP request, you can use JavaScript and AJAX:
https://en.wikipedia.org/wiki/Ajax_%28programming%29[^],
http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp[^].

In this case, form is not needed. Using the form is much simpler. Please see: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Sending_and_retrieving_form_data[^].

This is all you need.
I must admit that your previous question was much clearer than the present one, so it deserved some answer. Even though the particular problem wasn't clearly pointed out, your post suggested that you had some misunderstanding which can be fixed.

Perhaps understanding of all that may help you to solve the problem you formulated in the present question. But I agree with all the comments to the question you got. You need to explain your problem in much more detail. Your complains about treating your badly are simply inappropriate; I don't event want to discuss it any further.

Perhaps you need to shorted your code as much as possible, but focus on one particular problem and add decent description. If you thing you have a bug, you need to describe precisely how it is manifested. Also, you have to describe your ultimate goals, explain what exactly you are trying to achieve and how.

Sorry for incomplete answer, but I think next step should be yours. I agree with the comment to the question by PIEBALDconsult who mentioned that "That's a step in the right direction".

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900