Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2019, 03:28 PM
kristhasirah's Avatar
kristhasirah kristhasirah is offline
Member
 
Join Date: Jan 2010
Location: In middle of the nothingness
Posts: 196
Gender: Female
Credits: 32,779
kristhasirah
Default Items Stock limit

*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:
PHP Code:
rare,    varchar(30),    latin1_swedish_ci,        ,    NULL             
stock
int(11),            ,    default 
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:
PHP Code:
$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:
PHP Code:
        $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 :
PHP Code:
 public function edit(){ 
you need to replace
PHP Code:
$itemForm->add(new TextField("rare""Common")); 
with
PHP Code:
$itemForm->add(new TextField("rare"$item->rare)); 
and
PHP Code:
$itemForm->add(new TextField("stock""10000")); 
with:
PHP Code:
$itemForm->add(new TextField("stock"$item->stock)); 
in admincp/ search and open item.php
look for:
PHP Code:
  "consumable" => $mysidia->input->post("consumable"
and paste this after :
PHP Code:
 "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:
PHP Code:
        $fields->put(new String("rare"), NULL);
        
$fields->put(new String("stock"), NULL); 
after
PHP Code:
        $fields->put(new String("function"), NULL); 
and for last search for
PHP Code:
        $itemTable->buildHeaders("Image""Item""Description""Function""edit""Delete"); 
and add:
PHP Code:
 "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:
PHP Code:
        foreach($this->items as $stockitem){
              
$item $this->getitem($stockitem); 
and paste this after:
PHP Code:
                $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 == && $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 == && $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:
PHP Code:
 elseif($item->rare == "common"){$refill 10000;} 
below ultrarare or after uncommon
now find:
PHP Code:
            $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:
PHP Code:
/* 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 == && $item->rare == "Uncommon" || $item->stock == && $item->rare == "Rare" || $item->stock == && $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
PHP Code:
            $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:
PHP Code:
      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 >= 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:

PHP Code:
    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 >= and $item->quantity 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 >= 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:

PHP Code:
       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 >= and $item->quantity 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;
    }
  } 
Attached Files
File Type: php item.php (5.4 KB, 3 views)
File Type: php itemview.php (9.4 KB, 4 views)
File Type: php class_itemshopcommonunlimited.php (7.7 KB, 3 views)
File Type: php class_itemshoplimited.php (6.5 KB, 4 views)
File Type: txt instrucctions.txt (10.8 KB, 7 views)
__________________

Last edited by kristhasirah; 07-23-2019 at 10:03 PM. Reason: fixed some errors....
Reply With Quote
  #2  
Old 07-23-2019, 10:08 PM
kristhasirah's Avatar
kristhasirah kristhasirah is offline
Member
 
Join Date: Jan 2010
Location: In middle of the nothingness
Posts: 196
Gender: Female
Credits: 32,779
kristhasirah
Default

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.
__________________
Reply With Quote
  #3  
Old 08-07-2019, 06:25 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,201
Abronsyth is on a distinguished road
Default

Lovely mod! I am curious, why not use cronjobs for the restocking?
Reply With Quote
  #4  
Old 08-08-2019, 10:18 AM
kristhasirah's Avatar
kristhasirah kristhasirah is offline
Member
 
Join Date: Jan 2010
Location: In middle of the nothingness
Posts: 196
Gender: Female
Credits: 32,779
kristhasirah
Default

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...
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:55 AM.

Currently Active Users: 737 (0 members and 737 guests)
Threads: 4,081, Posts: 32,031, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636