Author Topic: Bazaar for Equipment Shop' magic items  (Read 7963 times)

Alchemion

  • Guest
Bazaar for Equipment Shop' magic items
« on: December 03, 2009, 02:43:41 pm »
Hello,

I am trying to integrate Equipment Shop with the Bazaar.

I came up with this module:

Code: [Select]
<?php

function bazaarmysticalshop_getmoduleinfo(){
$prefs = array(
"Bazaar Witch Garden User Preferences,title",
);
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"=>"XEvolution based on Derek's work",
"category"=>"Bazaar",
"download"=>"",
"requires"=>array(
"bazaar"=>"0.9.3|By Derek",
"mysticalshop"=>"|By Eth",
),
"settings"=>array(
"Bazaar Witch Garden 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 currencies 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;
require_once(
"./modules/mysticalshop/run/shop_what/purchase.php");

$argss explode(';'$args2);

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;
require_once(
"./modules/mysticalshop/run/shop_what/purchase.php");

//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 'Currencies'. 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;
require_once(
"./modules/mysticalshop/run/shop_what/sellfinal.php");

set_module_pref($args,get_module_pref($args,"bazaarmysticalshop")+$num,"bazaarmysticalshop");
set_module_pref($args,get_module_pref($args,"mysticalshop")-$num,"mysticalshop");
set_module_pref($args."cost",$gold,"bazaarmysticalshop");
}

//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;
require_once(
"./modules/mysticalshop/run/shop_what/sellfinal.php");

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.
$out "";
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'];
$out .= "<input type='radio' name='args' value='".$magicitemname."'> ".$magicitemname."<br>\n";
}
}
}

rawoutput(preg_replace ("/>/","checked>",$out,1));
}

//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;
require_once(
"./modules/mysticalshop/run/shop_what/sell.php");

set_module_pref($args,get_module_pref($args,"bazaarmysticalshop")-$num,"bazaarmysticalshop");
set_module_pref($args,get_module_pref($args,"mysticalshop")+$num,"mysticalshop");
}

//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;
require_once(
"./modules/mysticalshop/run/shop_what/sell.php");

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 remove
//also check to make sure the player has them in the shop before removing them.
//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.
$out "";
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'];
if (get_module_pref($magicitemname,"bazaarmysticalshop") >= 1) {
$out .= "<input type='radio' name='args' value='".$magicitemname."'> ".$magicitemname."<br>\n";
}
}
}
}

rawoutput(preg_replace ("/>/","checked>",$out,1));

}


//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;
require_once(
"./modules/mysticalshop/run/shop_what/sellfinal.php");

if ($q get_module_pref($args,"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;
require_once(
"./modules/mysticalshop/run/shop_what/sell.php");

if ($q get_module_pref($args,"bazaarmysticalshop") || $q 0) {
return false;
}
return true;
}
?>


The module does not returns output errors, it connects to the magicitems in the database, yet, probably the requirements are set wrongly, when I try to add an item (that I have bought and equipped from Equipment Shop, it says:
Quote
The item can't be sold. You don't have that many items on your person!

Please have a look onto the code and lend a helping hand for this useful module (at least for some of us  ::) ...

Thank you, greatly.

Emanuel C.

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #1 on: December 07, 2009, 12:55:27 pm »
Hi,
Any magic hint on the subject ?...  :P

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #2 on: December 17, 2009, 11:33:28 am »
No, sorry, but I won't really support 3rd party modules here =)
It is unrelated to the core code, hence I would need to test + debug it for you, which I have no time for.

Especially as you miss the part in the code where the action is taken, these are in separate files =)

Debugging works by i.e. output()ing the variables that get checked to output the result you see, you need to track what is set - and then see why something that *should* set it does either not or why it is altered afterwards.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #3 on: December 17, 2009, 12:52:16 pm »
Hi,
Thanks for the reply.
You may have made so far an idea on my stubborness on adapting my modules... you may know that I don't draw back from work ...
With no other intention but to show my limits on coding, I repeat that I am a specialist in law, not in php...
The Christmas comes, spirits cheer up, some useful hint may you bless us these days...
Where do I put the script for debug inside the module ?... I have debug output active for superuser, I guess it is not enough ...
So, Nightborn, ave Maria, may you leave long, prosper and happy !...
Some lead development expected from you...
Thank you very much.
Emanuel
 ;D  :P

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #4 on: January 13, 2010, 01:18:26 pm »
Hi again,

well, my christmas was nice, thanks =) hope yours was too.

However, I did no big work on the kernel itself, but I will release the current version soon.

I think it's pretty stable.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #5 on: January 19, 2010, 11:58:54 am »
do you happen to use any of the bazaar shelves on your servers ?
have adapted any?
Thanks.

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #6 on: January 24, 2010, 09:47:10 am »
Hi,

no, I don't use any.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #7 on: January 27, 2010, 12:31:24 pm »
Could you, please, attach here the market module you're using ?... ::)

With no great expectations on the first effect,

Best wishes,

Emanuel.


Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #8 on: January 29, 2010, 08:55:44 am »
 ;D I do not use any market module ;)
There are no auctions or player-to-player-sells going on at my servers. I have one instance to sell items. And only one randomly appearing (limited) to buy them.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #9 on: February 02, 2010, 10:59:34 am »
All right,
So, any hint on the error regarding the message ?...
 :P

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #10 on: February 06, 2010, 11:23:14 am »
No ;) as I have no clue about what code is in that module =)
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

A Cool Guy

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • Code Angels Game
Re: Bazaar for Equipment Shop' magic items
« Reply #11 on: February 07, 2010, 09:18:49 am »
Although i dont have that module a lot of the time its the way it selects the item for example in some stuff i coded i had to
use

$what = get_module_pref("name_of_field","name_of_module","persons_id_selecting_item");

however most people would use

$what = get_module_pref("name_of_field");

this way brings back a null selection for some reason.

can you post the contents of ("/modules/mysticalshop/run/shop_what/purchase.php") i might be able to see what the problem is but im not guaranteeing it LoL
If i can i will.
If i cant i wont :)

Nightborn

  • Administrator
  • Sr. Member
  • *****
  • Posts: 320
  • Karma: +20/-0
    • View Profile
    • Shinobilegends
Re: Bazaar for Equipment Shop' magic items
« Reply #12 on: February 10, 2010, 09:36:43 am »
you have to use the first function call if you need the pref
*from another module* and/or
*from another player than the one currently hitting that page*.

Depends on where you want to know what.
It should be fixed, but it won't be easy and it won't be fast. If you want
to help - wonderful. But keep in mind that it will take months of wading
through the ugliest code we have in the tree. If you've got a weak stomach -
stay out. I've been there and it's not a nice place.

   - Al Viro

Alchemion

  • Guest
Re: Bazaar for Equipment Shop' magic items
« Reply #13 on: March 30, 2010, 11:43:44 am »
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:


Code: [Select]
<?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(';'$args2);

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

Could 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
« Last Edit: March 30, 2010, 11:58:20 am by Alchemion »