Hi, everyone!
I came back with some new tested code...
What the code does so far:
- it allows users to put up for sale in the bazaar the items from the mysticalshop module...
- it removes the item from the user inventory and add it to the bazaar respective shelf...
- it allows users to remove from sale in the bazaar the items from the mysticalshop module...
- it removes the item from the bazaar respective shelf and add it again to the user inventory...
I have not extended the functionality to the buy function of the shelf, as I have still some unfinished touch with adding and removing the item to and from the mysticalshop bazaar shelf...
The code of the bazaar shelf is this following:
<?php
function bazaarmysticalshop_getmoduleinfo(){
$prefs = array(
"Bazaar Magic Items User Preferences,title",
);
//the following code is taken directly from the mysticalshop module.
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$prefs[$magicitemname] = "How much ".$magicitemname." does this player have up for sale?|0";
$prefs[$magicitemname."cost"] = "How much gold does it cost to purchase a(n) ".$magicitemname."?|0";
}
}
}
$info = array(
"name"=>"Bazaar Mystical Equipment",
"version"=>"0.9.3",
"author"=>"Alchemion and Nightborn (pls), based on Derek's work",
"category"=>"Bazaar",
"download"=>"",
"requires"=>array(
"bazaar"=>"0.9.3|By Derek",
"mysticalshop"=>"|By Eth",
),
"settings"=>array(
"Bazaar Magic Items Settings,title",
"Please do not uninstall any other Bazaar module unless EVERYONE has sold all of their items for that module or they will be lost,note",
"enabled"=>"Can players put magic items up for sale at the Bazaar? (players can still buy the ones remaining or they can be removed),bool|1",
),
//the prefs are used to store not only the cost of each item but the number currently in the shop.
"prefs" => $prefs
);
return $info;
}
function bazaarmysticalshop_install(){
//hook this module into the Bazaar module
module_addhook("bazaar-shop");
module_addhook("bazaar-create");
return true;
}
function bazaarmysticalshop_uninstall(){
return true;
}
function bazaarmysticalshop_dohook($hookname,$args){
global $session;
switch ($hookname) {
case "bazaar-shop":
//this is when a user is browsing an other player's shop
//**the args are:**
//$args['nav'], which is the nav that needs to be used. You do have to add this module's file name at the end, so it knows that the link is for this module.
//$args['id'], which is the player whose shop this player is currently browsing. This isn't needed, but can be used to get info like the name of the
$exists = false;
$list = array();
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$list[$magicitemname] = get_module_pref($magicitemname,"bazaarmysticalshop",$args['id']);
if ($list[$magicitemname] > 0) { $exists = true; }
}
}
}
//check to make sure the player running the shop has some magic items in the shop for the player to purchase.
if ($exists) {
//add the nav to this specific shelf, making sure to add the "bazaarmysticalshop" onto the end because that is the name of this file.
addnav("Magic Item Shelf",$args['nav']."bazaarmysticalshop");
//and output text so the player knows what this shelf sells.
output("One of the shelves of this stand seems to be stocked with many different types of items. The sign says, 'Magic Items Exchange at great prices!'`n`n");
}
break;
case "bazaar-create":
//this is when the player is creating his/her shop
//**the args are:**
//$args['addtext'] and $args['removetext'], which are the names of the groups for the navs. Use this instead of "Add an Item" and "Remove an Item".
//$args['navadd'] and $args['navremove'], which are the navs that needs to be used for adding and removing items to this player's shop. You do have to add this module's file name at the end, so it knows that the link is for this module.
$exists = false;
$list = array();
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$list[$magicitemname] = get_module_pref($magicitemname);
if ($list[$magicitemname] > 0) { $exists = true; }
}
}
}
//check to make sure the user is allowed to add more
if (get_module_setting("enabled") == 1) {
//add the nav to this shelf's options, making sure to add the "bazaarmysticalshop" onto the end because that is the name of this file.
addnav($args['addtext']);
addnav("Magic Item Shelf",$args['navadd']."bazaarmysticalshop");
}
//first, check to make sure the player has items to remove
if ($exists) {
//and if so, add the link to remove them.
addnav($args['removetext']);
addnav("Magic Item Shelf",$args['navremove']."bazaarmysticalshop");
}
//also output how many magic items the player has in the shop.
foreach($list as $key => $value)
{
output("You currently have ");
if ($value >= 1){output($value." ".$key.", ");}
if ($value == 0){output("0 item up for sale on Magic Item Shelf.`n`n");}
}
break;
}
return $args;
}
//this function is called when a player buys something on this specific shelf. The $id variable is the ID of the player whose shop you're perusing, and the $args variable is normally used to tell what item has been bought, based on which link is clicked in the _shop function.
function bazaarmysticalshop_buy($id,$args) {
global $session;
$argss = explode(';', $args, 2);
if ($session['user']['gold'] < (get_module_pref($argss[1]."cost","bazaarmysticalshop",$id)*$argss[0])) {
output("You do not have enough gold to exchange for that magic item!");
} else {
output("You successfully purchase the item.");
//since the player has bought an item, take it out of the shop, and add it to his/her inventory.
set_module_pref($argss[1],get_module_pref($argss[1],"bazaarmysticalshop",$id)-$argss[0],"bazaarmysticalshop",$id);
set_module_pref($argss[1],get_module_pref($argss[1],"mysticalshop")+$argss[0],"mysticalshop");
//and remove the gold cost from the player, and give it to the seller.
$session['user']['gold'] -= (get_module_pref($argss[1]."cost","bazaarmysticalshop",$id)*$argss[0]);
set_module_pref("revenue",get_module_pref("revenue","bazaar",$id)+(get_module_pref($argss[1]."cost","bazaarmysticalshop",$id)*$argss[0]),"bazaar",$id);
}
}
//this function is called when a player is perusing this module specifically, which we call a "shelf". The $id variable is the ID of the player whose shop you're perusing, and the $nav variable holds the base nav for which to link, save the item that they're buying.
function bazaarmysticalshop_shop($id,$nav) {
global $session;
//add the nav for buying an magic item. For a more complicated module, you would add different navs for each item to buy, placing the name of the item on the end of the $nav variable. Since there is only one item, I use it for the quantity.
//Also note the 'get_module_pref("itemcost","bazaarmysticalshop",$id)' This is getting the cost of the item to place into the nav. Please note that you need the "bazaarmysticalshop" AND the $id, or it will not function correctly.
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$list[$magicitemname] = get_module_pref($magicitemname,"bazaarmysticalshop",$id);
$cost[$magicitemname] = get_module_pref($magicitemname."cost","bazaarmysticalshop",$id);
}
}
}
foreach($list as $key => $value) {
if ($value >= 1) {
addnav($key);
addnav("Buy ".$key." (".$cost[$key]." gold)",$nav."1;".$key);
} if ($value >= 10) {
addnav("Buy 10 ".$key." (".($cost[$key]*10)." gold)",$nav."10;".$key);
} if ($value >= 100) {
addnav("Buy 100 ".$key." (".($cost[$key]*100)." gold)",$nav."100;".$key);
}
}
//and output some text describing the shelf
output("You look at the shelf of the stall named 'Magic Items'. There are many different types of money that are probably used more often in another place.`n`n");
}
//this function runs when the player adds an item to his shop on this shelf. The $args holds the item's name, the $gold holds the gold, and the $num holds the number of items.
function bazaarmysticalshop_add($args,$gold,$num) {
global $session;
$list = array();
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$list[$magicitemname] = get_module_pref($magicitemname);
}
}
}
foreach($list as $key => $value)
{
if ($key == get_module_pref('glovename','mysticalshop')){
output("`nGloves out!`n");
$value=0;
set_module_pref( 'glove',$value,'mysticalshop');
require_once("modules/mysticalshop.php");
require_once("modules/mysticalshop/lib.php");
require_once("modules/mysticalshop_buffs.php");
require_once("modules/mysticalshop_buffs/stripbuff.php");
}
}
set_module_pref($args,get_module_pref($args,"bazaarmysticalshop")+$num,"bazaarmysticalshop");
set_module_pref($args."cost",$gold,"bazaarmysticalshop");
output("`n`nYou successfully added %s %s to your stall, with a sign saying %s gold.",$num,$args,$gold);
}
//this function is used to show whatever method of selecting the item to add. Since this module only has one item, there is nothing needed here. If you have multiple items you need the user to select from, add a radio or selection box here, and name it 'args'
function bazaarmysticalshop_addform() {
global $session;
output("Which magic item would you like to add?`n`n");
//add a form named "args", for the player to choose which magic item to add
//also, I am storing them in a temporary variable, then replacing the first occurrence of ">" with "checked>" to make sure that the first one there is always checked.
rawoutput("<input type='text' name='args' value='Enter item name here.'>");
}
//this function runs when the player removes an item from his shop on this shelf. The $args holds the item to remove.
function bazaarmysticalshop_remove($args,$num) {
global $session;
$list = array();
if (is_module_active("mysticalshop")) {
if (db_table_exists(db_prefix("magicitems"))){
$sql = "SELECT name FROM ".db_prefix("magicitems");
$result = db_query($sql);
for ($i=0;$i<db_num_rows($result);$i++){
$row = db_fetch_assoc($result);
$magicitemname = $row['name'];
$list[$magicitemname] = get_module_pref($magicitemname);
}
}
}
foreach($list as $key => $value)
{
if ($key == get_module_pref('glovename','mysticalshop')){
output("`nGloves on hands!`n");
$value=1;
set_module_pref( 'glove',$value,'mysticalshop');
require_once("modules/mysticalshop.php");
require_once("modules/mysticalshop/lib.php");
require_once("modules/mysticalshop_buffs.php");
require_once("modules/mysticalshop_buffs/addbuff.php");
}
}
set_module_pref($args,get_module_pref($args,"bazaarmysticalshop")-$num,"bazaarmysticalshop");
}
//this function is used to show whatever method of selecting the item to remove. Since this module only has one item, there is nothing needed here. If you have multiple items you need the user to select from, add a radio or selection box here, and name it 'args'. You may also only want to put options for items that the player already has in the shop.
function bazaarmysticalshop_removeform() {
global $session;
output("Which magic item would you like to remove?`n`n");
rawoutput("<input type='text' name='args' value='Enter item name here.'>");
}
//this function is used to make sure the player is not adding more items then he/she has on his/her person. $q is the number the player is trying to take out.
function bazaarmysticalshop_checkadd($q,$args) {
global $session;
if ($q > get_module_pref('bootname','mysticalshop') || $q > get_module_pref('glovename','mysticalshop') || $q > get_module_pref('ringname','mysticalshop') || $q < 0) {
return false;
}
return true;
}
//this function is used to make sure the player is not removing more items then he/she has in the shop. $q is the number the player is trying to take out.
function bazaarmysticalshop_checkremove($q,$args) {
global $session;
if ($q > get_module_pref($args,"bazaarmysticalshop") || $q < 0) {
return false;
}
return true;
}
?>
I used for requirements :
require_once("modules/mysticalshop/lib.php");
require_once("modules/mysticalshop_buffs.php");
require_once("modules/mysticalshop_buffs/stripbuff.php");
require_once("modules/mysticalshop_buffs/addbuff.php");
I have attached for analysis purpose the modules/mysticalshop/
lib.php , modules/mysticalshop_buffs/
stripbuff.php and modules/mysticalshop_buffs/
addbuff.phpCould you please look over and tell where to add/remove what in order that the script removes all enhancements and buffs given to user by the item, once the item is put up for sale and removed from user inventory, and restores/gives back all enhancements and buffs to user, once the item is removed from sale and put back in the user inventory...
That would be gracefull...
Thank you very much for your patience and help so far.
Emanuel