Zorke 1 Posted April 22, 2018 Share Posted April 22, 2018 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. 1 Link to comment Share on other sites More sharing options...
IonutRO 936 Posted April 23, 2018 Share Posted April 23, 2018 Here is my function This is the hidden content, please Sign In or Sign Up Maybe will be helpful for somebody 10 1 1 2 5 Link to comment Share on other sites More sharing options...
metin2team 766 Posted April 23, 2018 Share Posted April 23, 2018 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; } 1 Link to comment Share on other sites More sharing options...
Endymion 320 Posted April 23, 2018 Share Posted April 23, 2018 Can somebody explain me why are you using these functions if we can use item_award? 1 Link to comment Share on other sites More sharing options...
Tasho 243 Posted April 23, 2018 Share Posted April 23, 2018 (edited) You can also use the new features from that repository: This is the hidden content, please Sign In or Sign Up Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal 4 1 1 Link to comment Share on other sites More sharing options...
Zorke 1 Posted April 24, 2018 Author Share Posted April 24, 2018 it's just a function everyone uses what they want Link to comment Share on other sites More sharing options...
Recommended Posts