Welcome
Welcome to the Official<strong>World of Phaos</strong>Forums.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining the World of Phaos community for free, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join the World of Phaos community today</a>!

[Script] Selling Items - working

Updated or created a new script or part of WoP and you think the world should know, post it here and you may well see it in the next release of Phaos.
(Remember to keep all code clean and readable)

Moderators: Aradan, zeke

[Script] Selling Items - working

Postby Legolas on Sat Nov 24, 2007 1:51 pm

My players want a way to sell their items without using the market. I have tried to modify the characters.php code to create a new building where they can sell directly the items getting a 30% of their starting value. In a future version I'd like to tie this percentage to the mental ability of the characters.

(sorry for not having translated the script in english, but I think is quite understandable)

Code: Select all
<?
include "header.php";
include_once "class_character.php";
include_once "items.php";

session_start();

isset($_SESSION['check'])  ?  $check =  $_SESSION['check']  :  $check = '';


$refsidebar= false;

// clear out any bad database rows
mysql_query("DELETE FROM phaos_char_inventory WHERE item_id='' AND type='' ");

$character=new character($PHP_PHAOS_CHARID);

include_once "location_actions.php";
$dropped= drop_actions($character);



if($refsidebar){
   refsidebar();
   $refsidebar= false;
}

?>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align=center colspan=2>
<big><b><? echo $lang_char["invent"]; ?></b></big>
<br>
<br><a name="inventory"><font color="#FFFFFF">Ordina:</font></a>
<br>
<a href="rigattiere.php">Tutto</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=weapon#inventory">Armi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=armor#inventory">Armature</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=boots#inventory">Stivali</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=gloves#inventory">Guanti</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=helm#inventory">Elmi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=shield#inventory">Scudi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=potion#inventory">Pozioni</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=spell_items#inventory">Incantesimi</a>
<table border=0 cellspacing=0 cellpadding=0>

<?php
$wheretype= "";

$item_type= @$_GET['act'];
if(isItemType($item_type)){
   $wheretype= " AND type = '$item_type' ";
}

//!PS: be careful with this code, it took some time to write

$items= array();
$list_inventory = mysql_query("SELECT * FROM phaos_char_inventory WHERE username = '$_COOKIE[PHP_PHAOS_USER]' $wheretype ORDER BY type ASC, item_id ASC");

if($list_inventory) {
   while ($row = mysql_fetch_assoc($list_inventory)) {
      $items[]= $row;
   }
   $items[]= null;// add an extra empty row to trigger routput
}

if(count($items)>1) {
   ?>
   <tr style="background:#004400;">
      <td align=center valign=top><b><? echo $lang_char["amount"]; ?> &nbsp</b></td>
      <td>&nbsp;</td>
      <td valign=top><b><? echo $lang_char["desc"]; ?> &nbsp</b></td>
      <td align=center valign=top></td>
      <td align=center valign=top colspan=3><b>Action &nbsp</b></td>
   </tr>
   <?
}
//end if show header

// begin output loop
$lastrow= null;
$output= null;
foreach($items as $row) {
   if($row) {
      $id = $row["id"];
      $equiped = $row["equiped"];
      $item_type = $row["type"];
      $item_id = $row["item_id"];
      $sell_to_name = $row["sell_to"];
      $ask_price = $row["asking_price"];
      
      if(!@$_GET['act'] || $_GET['act'] == $item_type || $_GET['act'] == $item_type.'s' || $_GET['act'].'s' == $item_type) {
         if($lastrow && $row['item_id'] == $lastrow['item_id'] && $row['equiped'] == $lastrow['equiped'] && $row['type'] == $lastrow['type'] && $row['sell_to'] == $lastrow['sell_to'] && $row['asking_price'] == $lastrow['asking_price']) {
            ++$lastrow['itemcount'];
            $output= null;
         } else {
            $output= $lastrow;
            $lastrow= $row;
            $lastrow['itemcount']= 1;
         }
      } else {
         //ignore item
      }
   } else {
      $output= $lastrow;
   }
   if(!$output){
      //no output
      continue;
   } else {
      $id = $output["id"];
      $equiped = $output["equiped"];
      $item_type = $output["type"];
      $item_id = $output["item_id"];
      $sell_to_name = $output["sell_to"];
      $ask_price = $output["asking_price"];
      
      $info= fetch_item_additional_info(array('id'=>$item_id,'type'=>$item_type,'number'=>1),&$character);
      
      $description = $info['description'];
      $sell_price = $info['sell_price'];
      $image_path= $info['image_path'];
      $skill_req= $info['skill_req'];
      $damage_mess= @$info['damage_mess'];
      $skill_need= $info['skill_need'];
      $effect= $info['effect'];
      $skill_type= $info['skill_type'];
      $caso = microtime();
      
      //Calcola Prezzo
      $price = intval(($sell_price  / 100) * 30);
      
      // start outputting a row
      print ("<tr>");
      print ("<td align=center valign=top><b>$output[itemcount]</b>x</td>");
      ?><td align=center valign=top><?= makeImg($image_path) ?></td><?php
      print "<td>".ucwords($description)."&nbsp;<br>";
      print "Offerta: $price mo";
      
      print ("<p>
                <td align=center colspan=7 valign=top>
                <form method=\"post\" action=\"rigattiere.php\">
                <input type=\"submit\" value=\"Vendi\">
              <input type=\"hidden\" name=\"rigattiere\" value=\"yes\">
                <input type=\"hidden\" name=\"char_inv_id\" value=\"$id\">
              <input type=\"hidden\" name=\"price\" value=\"$price\">
              <input type=\"hidden\" name=\"type\" value=\"$item_type\">
              <input type =\"hidden\" name = \"check\" value = \"$caso\">
              </form>
                 </td>");
      ?></tr><?php
      ?><tr><td colspan="8"><hr width=50%></td></tr><?php
   }
   // end out put a row
}
// end loop
if($check === MD5(serialize($_POST)) )
{
   print "<tr><td align=center colspan=4><b>Ehi! Stai tentando di fregarmi?</b></td></tr>";
   exit;
} else {
   if(@$_POST['rigattiere'] == "yes")
   {
      $prezzo_vendita = $_POST['price'];
      $tipo_oggetto = $_POST['type'];
      $id_oggetto = $_POST['char_inv_id'];
      
      print "<tr><td align=center colspan=4><b> Hai venduto questo oggetto per $prezzo_vendita mo </b><br></td></tr>";
      $query = ("UPDATE phaos_characters SET gold = gold +".$prezzo_vendita." WHERE username = '".$PHP_PHAOS_USER."'");
      $req = mysql_query($query);
      if (!$req) {
         echo "<B>Error ".mysql_errno()." :</B> ".mysql_error().""; exit;
      }
      $req = mysql_query("DELETE FROM phaos_char_inventory WHERE id=$id_oggetto");
      if (!$req) {
         showError(__FILE__,__LINE__,__FUNCTION__); exit;
      }
      ?>
      <script language="JavaScript">
      <!--
      javascript:parent.side_bar.location.reload();
      javascript:window.location.reload();
      //-->
      </script>
      <?
      
      $_SESSION['check'] = MD5(serialize($_POST));
      
   }
   
}

if(!$output) {
   print "<tr><td align=center colspan=4><b>".$lang_char["noitem"].($wheretype?" ($_GET[act])":'')."</b></td></tr>";
}


?>
</table>

</td>
</tr>
</table>

</td>
</tr>
</table>

<?

include "footer.php";

?>


It seems to work except that it is possible to click on and sell each item 2 times before it is cancelled from the inventory. I am not able to find the error as I am a very newby to PHP coding... someone can help me?

THX
Legolas
Level 1
 
Posts: 3
Joined: Mon Nov 19, 2007 9:24 am

Postby Legolas on Sun Nov 25, 2007 9:30 am

Ok, it seems I have found the problem. This is the corrected code.
Now the price offered for an item is modified by the wisdom value of the character:

Code: Select all
<?
include "header.php";
include_once "class_character.php";
include_once "items.php";

//Refresh Exploit
session_start();
isset($_SESSION['check'])  ?  $check =  $_SESSION['check']  :  $check = '';

$refsidebar= false;

// clear out any bad database rows
mysql_query("DELETE FROM phaos_char_inventory WHERE item_id='' AND type='' ");

$character=new character($PHP_PHAOS_CHARID);

include_once "location_actions.php";

if($refsidebar){
   refsidebar();
   $refsidebar= false;
}

?>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td align=center colspan=2>
<big><b><? echo "RIGATTIERE<br><br>Cosa hai da vendere?<br>" ?></b></big>
<br>
<br><a name="inventory"><font color="#FFFFFF">Visualizza:</font></a>
<br>
<a href="rigattiere.php">Tutto</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=weapon#inventory">Armi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=armor#inventory">Armature</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=boots#inventory">Stivali</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=gloves#inventory">Guanti</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=helm#inventory">Elmi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=shield#inventory">Scudi</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=potion#inventory">Pozioni</a>
&nbsp;|&nbsp;<a href="rigattiere.php?act=spell_items#inventory">Incantesimi</a>
<table border=0 cellspacing=0 cellpadding=0>

<?php
$wheretype= "";

$item_type= @$_GET['act'];
if(isItemType($item_type)){
   $wheretype= " AND type = '$item_type' ";
}

//!PS: be careful with this code, it took some time to write

$items= array();
$list_inventory = mysql_query("SELECT * FROM phaos_char_inventory WHERE username = '$_COOKIE[PHP_PHAOS_USER]' $wheretype ORDER BY type ASC, item_id ASC");

if($list_inventory) {
   while ($row = mysql_fetch_assoc($list_inventory)) {
      $items[]= $row;
   }
   $items[]= null;// add an extra empty row to trigger routput
}

if(count($items)>1) {
   ?>
   <tr style="background:#004400;">
      <td align=center valign=top><b><? echo $lang_char["amount"]; ?> &nbsp</b></td>
      <td>&nbsp;</td>
      <td valign=top><b><? echo $lang_char["desc"]; ?> &nbsp</b></td>
      <td align=center valign=top></td>
      <td align=center valign=top colspan=3><b>Azione &nbsp</b></td>
   </tr>
   <?
}
//end if show header

// begin output loop
$lastrow= null;
$output= null;
foreach($items as $row) {
   if($row) {
      $id = $row["id"];
      $equiped = $row["equiped"];
      $item_type = $row["type"];
      $item_id = $row["item_id"];
      $sell_to_name = $row["sell_to"];
      $ask_price = $row["asking_price"];
      
      if(!@$_GET['act'] || $_GET['act'] == $item_type || $_GET['act'] == $item_type.'s' || $_GET['act'].'s' == $item_type) {
         if($lastrow && $row['item_id'] == $lastrow['item_id'] && $row['equiped'] == $lastrow['equiped'] && $row['type'] == $lastrow['type'] && $row['sell_to'] == $lastrow['sell_to'] && $row['asking_price'] == $lastrow['asking_price']) {
            ++$lastrow['itemcount'];
            $output= null;
         } else {
            $output= $lastrow;
            $lastrow= $row;
            $lastrow['itemcount']= 1;
         }
      } else {
         //ignore item
      }
   } else {
      $output= $lastrow;
   }
   if(!$output){
      //no output
      continue;
   } else {
      $id = $output["id"];
      $equiped = $output["equiped"];
      $item_type = $output["type"];
      $item_id = $output["item_id"];
      $sell_to_name = $output["sell_to"];
      $ask_price = $output["asking_price"];
      $info= fetch_item_additional_info(array('id'=>$item_id,'type'=>$item_type,'number'=>1),&$character);
      $description = $info['description'];
      $sell_price = $info['sell_price'];
      $image_path= $info['image_path'];
      $skill_req= $info['skill_req'];
      $damage_mess= @$info['damage_mess'];
      $skill_need= $info['skill_need'];
      $effect= $info['effect'];
      $skill_type= $info['skill_type'];
      $caso = microtime();
      
      //gold offered
      $modifier = $character->wisdom;
      if ($modifier > 70)
      {
         $modifier = 70;
      }
      $price = intval(($sell_price  / 100) * (30+$modifier));
      
      // start outputting a row
      print ("<tr>");
      print ("<td align=center valign=top><b>$output[itemcount]</b>x</td>");
      ?><td align=center valign=top><?= makeImg($image_path) ?></td><?php
      print "<td>".ucwords($description)."&nbsp;<br>";
      print "Offerta: $price mo";
      
      print ("<p>
                <td align=center colspan=7 valign=top>
                <form method=\"post\" action=\"rigattiere.php\">
                <input type=\"submit\" value=\"Vendi\">
              <input type=\"hidden\" name=\"rigattiere\" value=\"yes\">
                <input type=\"hidden\" name=\"char_inv_id\" value=\"$id\">
              <input type=\"hidden\" name=\"price\" value=\"$price\">
              <input type=\"hidden\" name=\"type\" value=\"$item_type\">
              <input type =\"hidden\" name = \"check\" value = \"$caso\">
              </form>
                 </td>");
      ?></tr><?php
      ?><tr><td colspan="8"><hr width=50%></td></tr><?php
   }
   // end out put a row
}
// end loop
if($check === MD5(serialize($_POST)) )
{
   print "<tr><td align=center colspan=4><b>Ehi! Stai tentando di fregarmi?</b></td></tr>";
   exit;
} else {
   if(@$_POST['rigattiere'] == "yes")
   {
      $prezzo_vendita = $_POST['price'];
      $tipo_oggetto = $_POST['type'];
      $id_oggetto = $_POST['char_inv_id'];
      
      print "<tr><td align=center colspan=4><b> Hai venduto questo oggetto per $prezzo_vendita mo </b><br></td></tr>
      <meta http-equiv='refresh' content='0;URL=rigattiere.php'>";
      $query = ("UPDATE phaos_characters SET gold = gold +".$prezzo_vendita." WHERE username = '".$PHP_PHAOS_USER."'");
      $req = mysql_query($query);
      if (!$req) {
         echo "<B>Error ".mysql_errno()." :</B> ".mysql_error().""; exit;
      }
      $req = mysql_query("DELETE FROM phaos_char_inventory WHERE id=$id_oggetto");
      if (!$req) {
         showError(__FILE__,__LINE__,__FUNCTION__); exit;
      }
            
      $_SESSION['check'] = MD5(serialize($_POST));
      
   }
   
}

if(!$output) {
   print "<tr><td align=center colspan=4><b>".$lang_char["noitem"].($wheretype?" ($_GET[act])":'')."</b></td></tr>";
}


?>
</table>

</td>
</tr>
</table>

</td>
</tr>
</table>

<?

include "footer.php";

?>
Legolas
Level 1
 
Posts: 3
Joined: Mon Nov 19, 2007 9:24 am

Postby Anarki99 on Sat Feb 09, 2008 9:03 pm

Nice! But i prefer the market..
User avatar
Anarki99
Level 1
 
Posts: 12
Joined: Sat Feb 09, 2008 4:57 pm

Postby DaWolf on Sat Feb 09, 2008 11:46 pm

Anarki, the market is nice, but for things like Clothes, no-one is gonna buy it cause it has no AC, also in my game wierd things can be found that have no real value to anyone, except that they can be sold to the shops for the player to make some money off of them.

This allows for the player to collect money off items that would generally never be bought by other players anyway (When have you ever said, oooh I am going to spend 2 gold on Worn Clothes!) So all those useless items would eventually clutter up your world!

Just my 2 cents.
<img>http://www.dawolf.us/phaos/siggy.php?user_id=1273&type=.jpg</img>
User avatar
DaWolf
Level 1
 
Posts: 11
Joined: Sat Feb 02, 2008 5:11 am


Return to Scripts

Who is online

Users browsing this forum: No registered users and 0 guests