Jump to content

How To Check Position for Slot Free in Item Shop


Recommended Posts

Hello, i give you a function that helps you check the empty space in ItemSHOP.

Here is a video shows that it works

 

	public function checkPosition($newsize){
    
    $slot=array(
            "0" => 0,
            "1" => 0,
            "2" => 0,
            "3" => 0,
            "4" => 0,
            "5" => 0,
            "6" => 0,
            "7" => 0,
            "8" => 0,
            "9" => 0,
            "10" => 0,
            "11" => 0,
            "12" => 0,
            "13" => 0,
            "14" => 0,
            "15" => 0,
            "16" => 0,
            "17" => 0,
            "18" => 0,
            "19" => 0,
            "20" => 0,
            "21" => 0,
            "22" => 0,
            "23" => 0,
            "24" => 0,
            "25" => 0,
            "26" => 0,
            "27" => 0,
            "28" => 0,
            "29" => 0,
            "30" => 0,
            "31" => 0,
            "31" => 0,
            "32" => 0,
            "33" => 0,
            "34" => 0,
            "35" => 0,
            "36" => 0,
            "37" => 0,
            "38" => 0,
            "39" => 0,
            "40" => 0,
            "41" => 0,
            "42" => 0,
            "43" => 0,
            "44" => 0,
        );
    
    
    $own_id=$_SESSION['user_id'];
        
    $sql = "SELECT item.pos,item_proto.size AS item_size 
    FROM player.item
    INNER JOIN player.item_proto 
    ON item_proto.vnum=item.vnum
    WHERE item.owner_id=? AND item.window=?";
    $stmt = $this->o_db->prepare($sql);
    $stmt->execute(array($own_id,"MALL"));
        
    $result =$stmt->FetchAll();
    
    $nextposition = 0;
    foreach($result as $exist){
        $replace = array($exist['pos'] => 1);
        $slot = array_replace( $slot, $replace); 
	        if($exist['item_size'] == '2'){
            $replace2 = array($exist['pos']+5=>1);
            $slot = array_replace( $slot, $replace2); 
        }
        if($exist['item_size'] == '3'){
            $replace3 = array($exist['pos']+5=>1,$exist['pos']+10=>1);
            $slot = array_replace( $slot, $replace3); 
        }
    }
    for($zorke=0;$zorke<=44;$zorke++){
        if($newsize == '1'){
            if($slot[$zorke] == '0'){
                $nextposition = $zorke;
                $zorke = 45;
            }
            if($zorke == 44)
            {
            $nextposition = 45;
            $zorke = 45;  
            }
        }
        if($newsize == '2'){
            if($slot[$zorke] == '0' && $slot[$zorke+5] == '0' ){
                $nextposition = $zorke;
                $zorke = 45;
            }
            if($zorke == 40){
            $nextposition = 45;
            $zorke = 45;
            }
        }
        if($newsize == '3'){
            if($slot[$zorke] == '0' && $slot[$zorke+5] == '0' && $slot[$zorke+10] == '0'){
                $nextposition = $zorke;
                $zorke = 45;
            }
            if($zorke == 35){
            $nextposition = 45;
            $zorke = 45;
            }
        }
        
    }
	    return $nextposition; 
      
    }

01.The function returns the next free position .. it is perfectly functional on all 3 sizes. You will need to do (or integrate) a function that will receive the size of the item in itemshop, each as done by itemshop.

02.To call her use $this->checkPosition($variabilă), where does it say variabilă you have to put the size of the item, if you do not use classes the function is called directly checkPosition($variabilă).

03.The db connection must be pdo.

04. This line $nextposition = 45; in my buyitem function I made the condition that if it is greater than or equal to 45 to display the message that there are too many items and has the inventory full. 

All the best,
Zorke.

  • Love 1
Link to comment
Share on other sites

  • Bronze

http://sandbox.onlinephpfunctions.com/code/72df51282264211c57a6957c8681ac1b7f14b64a

PS: you need this to use that simple function otherwise you need to pass your $proto[$vnum] = $size; or change it to whatever you want

	while($item = $query->fetch_object())
    {
    	for($i = 0; $i < $proto[$item->vnum]->size; ++$i)
			$items[$item->pos + ($i * 5)] = $item->vnum;
    }

 

  • Love 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.