PDA

View Full Version : Mys 1.3.4 Items Stock limit


kristhasirah
07-13-2019, 02:28 PM
*Sorry i made some typing mistakes. all the files have been corrected, same in the manual intall. also added the fix for the: Inputting decimal value to shop item quantity gives full item at half price bug*

for some reason the site won't let me post all the instructions in the thread, so everyting you need are in the attatchment files.

Remenber to save your files before doing any edit!.

you just need to create 2 new columns in the adopts_items database with this info:

rare, varchar(30), latin1_swedish_ci, Sí, NULL
stock, int(11), Sí, default 0

this files are using a clean version of mysidia. do not use them if you are using Kyttias item shop mod or you have made changes to the class_itemshop.php file!!

the first attatchment is for those that want to keep the common items always available and only limit from uncommon and above.

In the second attatchment all the items have a stock limit.

chose only one of the files and Just remove commonunlimited/limited from the name and upload the file to the class folder, will replace your class_itemshop.php file. if not just open the file copy and paste everything in the class_itemshop.php

If you have Kyttias itemshop mod follow the instrucction file in there are the instrucction to install the commonunlimited or the all the items unlimited.


AdminCP Edit:
edit and add rarity and stock quantity by using the admin cp:
open itemview.php in admincp/view search for this:
$itemForm->add(new CheckBox("<b>The item can be consumed(thus its quantity decreases by 1 each time used)</b>", "consumable", "yes"));
copy and paste this after that line:

$itemForm->add(new Comment("The rarity of the item", FALSE));
$itemForm->add(new TextField("rare", "Common"));
$itemForm->add(new Comment("chose from Common, Uncommon, Rare, Ultrarare, Legendary"));
$itemForm->add(new Comment("The quantity stock of the item", FALSE));
$itemForm->add(new TextField("stock", "10000"));
$itemForm->add(new Comment("change the quantity to any number. this is only efective on the item shops."));
there are 2 areas, one if for creating a new item and the second is for editing. in the : public function edit(){
you need to replace $itemForm->add(new TextField("rare", "Common")); with $itemForm->add(new TextField("rare", $item->rare)); and $itemForm->add(new TextField("stock", "10000")); with: $itemForm->add(new TextField("stock", $item->stock));

in admincp/ search and open item.php
look for: "consumable" => $mysidia->input->post("consumable")

and paste this after : , "rare" => $mysidia->input->post("rare"), "stock" => $mysidia->input->post("stock")

this code must be copy/paste 2 times: one is for the creating a new item and the second for editing the item.


If you want to see the rarity and stock quantity in the manage items page then in the itemview.php paste this: $fields->put(new String("rare"), NULL);
$fields->put(new String("stock"), NULL); after $fields->put(new String("function"), NULL);

and for last search for $itemTable->buildHeaders("Image", "Item", "Description", "Function", "edit", "Delete");
and add: , "Rare", "Stock" after "Function"

if you havent done any changes or edits to those files then just download item.php and itemview.php and upload them to the folder admincp and admincp/view

Manual Install: Unlimited Common items
(will see if the site lets me add the manual install for those that have made changes to your class_itemshop.php file)
in Class_itemshop.php
search for:
foreach($this->items as $stockitem){
$item = $this->getitem($stockitem);
and paste this after:
$h = date("H:i", strtotime('-5 hours')); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week (Monday=1, Tuesday=2, Wednesday=3, Thursday=4, Friday=5, Saturday=6, Sunday=0).

$reset = $d == 4 && $h == 15; /* change it to match your need*/
/* Change the number and rarity name to anything you want*/
if($item->rare == "Uncommon" ){$refill = 1000;}
elseif($item->rare == "Rare"){$refill = 500;}
elseif($item->rare == "Ultrarare"){$refill = 100;}
if($item->stock == 0 && $reset){
$mysidia->db->update("items", array("stock" => $refill), "itemname = '{$item->itemname}'");
}

*Note: to make all the items limited and restocked icluding the common items just add:
elseif($item->rare == "common"){$refill = 10000;} below ultrarare or after uncommon
now find:
$cells = new LinkedList;
$cells->add(new TCell(new Image($item->imageurl)));
$cells->add(new TCell($item->category));
$cells->add(new TCell($item->itemname));
$cells->add(new TCell($item->description));
$cells->add(new TCell($item->price));
$cells->add(new TCell($itemList->getHelper()->getItemPurchaseForm($this, $item)));
$itemList->buildRow($cells);

and replace with this:

/* this part will remove the stock limit for the common items and will only appear for uncommon,rare,ultrarare*/
if($item->rare == "Common"){$stock = '';}else{$stock = "<br/>In Stock: {$item->stock}";}

$cells = new LinkedList;
$cells->add(new TCell(new Image($item->imageurl)));
$cells->add(new Comment("{$item->category}<br><img src='/picuploads/item{$item->rare}.png'/>"));/* this will show thecategory and the image for the rarity of the item, if you dont have an image remove <img...png/> and put {$item->rare}*/
$cells->add(new TCell($item->itemname));
$cells->add(new TCell($item->description));
$cells->add(new Comment("{$item->price}{$stock}"));
if($item->stock == 0 && $item->rare == "Uncommon" || $item->stock == 0 && $item->rare == "Rare" || $item->stock == 0 && $item->rare == "Ultrarare"){
$cells->add(new Comment("sorry item out of stock",FALSE));}
else{
$cells->add(new TCell($itemList->getHelper()->getItemPurchaseForm($this, $item)));}
$itemList->buildRow($cells);

*Note: to include all items and make them limited including the common items use this code intead of the above

$cells = new LinkedList;
$cells->add(new TCell(new Image($item->imageurl)));
$cells->add(new Comment("{$item->category}<br><img src='/picuploads/item{$item->rare}.png'/>"));/* this will show thecategory and the image for the rarity of the item, if you dont have an image remove <img...png/> and put {$item->rare}*/
$cells->add(new TCell($item->itemname));
$cells->add(new TCell($item->description));
$cells->add(new Comment("{$item->price}{$item->stock}"));
if($item->stock == 0){
$cells->add(new Comment("sorry item out of stock",FALSE));}
else{
$cells->add(new TCell($itemList->getHelper()->getItemPurchaseForm($this, $item)));}
$itemList->buildRow($cells);

now search for:

public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
else{
$item->quantity = $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}

and replace with:

public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if ($item->shop != $this->shopname) Throw new NoPermissionException('Did you really think this item could be bought at this shop?');
else {
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');

/* this code will check that the number in stock is the same as the quantity the user want to buy if is more that the one in stock will tigger the error*/
elseif($item->stock <= $mysidia->input->post("quantity") && $item->rare == "Uncommon" ||$item->stock <= $mysidia->input->post("quantity") && $item->rare == "Rare" ||
$item->stock <= $mysidia->input->post("quantity") && $item->rare == "Ultrarare") Throw new NoPermissionException('You are trying to buy more that what we have in stock');

/*this code is for the uncommon,rare,ultrarare this code will remove the quantity from the available stock*/
elseif($item->rare == "Rare" || $item->rare == "Ultrarare" || $item->rare == "Uncommon"){
$item->quantity = (int) $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
$stockleft = $item->stock - $mysidia->input->post("quantity");
if($moneyleft >= 0 and $item->quantity > 0 and $item->stock > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$mysidia->db->update("items", array("stock" => $stockleft), "itemname = '{$item->itemname}'");
$status = TRUE; }
}
/* this is the code for the common items, noting will be removed from the stock*/
else{
$item->quantity = (int) $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
if($moneyleft >= 0 and $item->quantity > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}
}
*Note: if you want all the items to have limit use this code instead of the above:


public function purchase(Item $item){
$mysidia = Registry::get("mysidia");
if ($item->shop != $this->shopname) Throw new NoPermissionException('Did you really think this item could be bought at this shop?');
else {
if($item->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');

/* this code will check that the number in stock is the same as the quantity the user want to buy if is more that the one in stock will tigger the error*/
elseif($item->stock <= $mysidia->input->post("quantity")) Throw new NoPermissionException('You are trying to buy more that what we have in stock');

else{
$item->quantity = (int) $mysidia->input->post("quantity");
$cost = $item->getcost($this->salestax, $item->quantity);
$moneyleft = $mysidia->user->money - $cost;
$stockleft = $item->stock - $mysidia->input->post("quantity");
if($moneyleft >= 0 and $item->quantity > 0 and $item->stock > 0){
$purchase = $item->append($item->quantity, $item->owner);
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$item->owner}'");
$mysidia->db->update("items", array("stock" => $stockleft), "itemname = '{$item->itemname}'");
$status = TRUE;
}
else throw new InvalidActionException($mysidia->lang->money);
}
return $status;
}
}

kristhasirah
07-23-2019, 09:08 PM
For some reason the code for calling the hours stopped working for me, so i have updated the code to a new one. If you have a better way to call the hours and remove the hours to match your time zone feel free to use it. if not then you can use the new one instead.

Abronsyth
08-07-2019, 05:25 PM
Lovely mod! I am curious, why not use cronjobs for the restocking?

kristhasirah
08-08-2019, 09:18 AM
wish i know how to use them, sadly i have no idea, i can only do small changes/edits to the codes i know or mysidia uses, if i have to code something from scratch and my life depends on it... probably wont be here now...