 //Variabler
 var qurub1 = 0; var qufle1 = 0;  var quman1 = 0; var peter1 = 0; var qubomb1 = 0; var qucle1 = 0; var qucleb1 = 0; var quher1 = 0; var blupfe1 = 0;
 // Pijlen
for(i = 0; i < 40; i++) {
	var itemSlot = pinv.getItemInSlot(i);
	if (itemSlot != null && itemSlot.getItemID() == 262) {
		qufle1 = qufle1 + itemSlot.quantity;
}	}
if (typeof qufle2 == "undefined") {
	var qufle2 = qufle1;
}
if (qufle1 > qufle2) {
    sound.playSoundUI("sound.get item");
}
qufle2 = qufle1;


 // kleine sleutel
for(i = 0; i < 40; i++) {
	var itemSlot = pinv.getItemInSlot(i);
	if (itemSlot != null && itemSlot.getItemID() == 457) {
		quher1 = quher1 + itemSlot.quantity;
}	}
if (typeof qubomb2 == "undefined") {
	var quher2 = quher1;
}
if (quher1 > quher2) {
    sound.playSoundUI("sound.small item");
}
quher2 = quher1;

// Boss sleutel
for(i = 0; i < 40; i++) {
	var itemSlot = pinv.getItemInSlot(i);
	if (itemSlot != null && itemSlot.getItemID() == 465) {
		qucleb1 = qucleb1 + itemSlot.quantity;
}	}
if (typeof qubomb2 == "undefined") {
	var qucleb2 = qucleb1;
}
if (qucleb1 > qucleb2) {
    sound.playSoundUI("sound.small item");
}
qucleb2 = qucleb1;

//Rupee Houder
if(pinv.getItemInSlot(35) != null)
{
        if(pinv.getItemInSlot(35).getItemID() != 353)
        {
                for(i=0;i<35;i++)
                {
                        if(pinv.getItemInSlot(i) == null)
                        {
                            try
							{
								var pitem = pinv.getItemInSlot(35).copy();
                                pinv.emptySlot(35);
                                pinv.setSlot(i, pitem);
							}
							catch(e) {}
                        }
                }
        }
}
if (pinv.getSlotContainingItem(353) != -1)
{
	var item = pinv.getItemInSlot(pinv.getSlotContainingItem(353)).copy();
    if (pinv.getSlotContainingItem(353) != 35)
    {
        try
        {
            var count = pinv.getItemInSlot(35).getQuantity();
        }
        catch(e) { var count = 0; }
        pinv.emptySlot(pinv.getSlotContainingItem(353));
        if (count < 500)
        {
            if (item.getQuantity() + count <= 500)
            {
                item.setQuantity(item.getQuantity() + count);
            }
            else
            {
                item.setQuantity(500);
            }
			
			if(pinv.getSlotContainingItem(339) == -1)
			{
				if(pinv.getSlotContainingItem(353) == -1)
				{
					if(item.getQuantity() >= 100)
					{
						item.setQuantity(999);
					}	
				}
				else
				{
					if(item.getQuantity() >= 201)
					{
						item.setQuantity(200);
					}
				}
			}
		}
	    else
        {
            item.setQuantity(500);
        }
        pinv.setSlot(35, item);
    }
	else
	{
		if(pinv.getSlotContainingItem(339) == -1)
		{
			if(pinv.getSlotContainingItem(353) == -1)
			{
				if(item.getQuantity() >= 100)
				{
					item.setQuantity(999);
				}	
			}
			else
			{
				if(item.getQuantity() >= 201)
				{
					item.setQuantity(200);
				}
			}
		}
		else if(pinv.getItemInSlot(35).getQuantity() > 500)
		{
			pinv.getItemInSlot(35).setQuantity(500);
		}
	}
			
}

// bommen
for(i = 0; i < 40; i++) {
	var itemSlot = pinv.getItemInSlot(i);
	if (itemSlot != null && itemSlot.getItemID() == 466) {
		qubomb1 = qubomb1 + itemSlot.quantity;
}	}
if (typeof qubomb2 == "undefined") {
	var qubomb2 = qubomb1;
}
if (qubomb1 > qubomb2) {
    sound.playSoundUI("sound.get item");
}
qubomb2 = qubomb1;

//Rupee Geluid
for(i = 0; i < 40; i++) {
	var itemSlot = pinv.getItemInSlot(i);
	if (itemSlot != null && itemSlot.getItemID() == 353) {
		qurub1 = qurub1 + itemSlot.quantity;
}	}
if (typeof qurub2 == "undefined") {
	var qurub2 = qurub1;
}
if (qurub1 > qurub2) {
    sound.playSoundUI("sound.tp_get_rupee");
}
qurub2 = qurub1;

// Pijlen

if (pinv.getSlotContainingItem(262) != -1)
{
    if (pinv.getSlotContainingItem(262) != 26)
    {
        try
        {
            var count = pinv.getItemInSlot(26).getQuantity();
        }
        catch(e) { var count = 0; }
        var item = pinv.getItemInSlot(pinv.getSlotContainingItem(262)).copy();
        pinv.emptySlot(pinv.getSlotContainingItem(262));
        if (count < 500)
        {
            if (item.getQuantity() + count <= 500)
            {
                item.setQuantity(item.getQuantity() + count);
            }
            else
            {
                item.setQuantity(500);
            }
			
			if(pinv.getSlotContainingItem(318) == -1)
			{
				if(item.getQuantity() >= 201)
				{
					item.setQuantity(200);
				}
				
			}
		}
	    else
        {
            item.setQuantity(500);
        }
        pinv.setSlot(26, item);
    }
    pinv.getItemInSlot(26).setDamage(pinv.getItemInSlot(26).getQuantity());
}

if(pinv.getItemInSlot(26) != null)
{
        if(pinv.getItemInSlot(26).getItemID() != 262)
        {
                for(i=0;i<35;i++)
                {
                        if(pinv.getItemInSlot(i) == null)
                        {
                                try
								{
									var pitem = pinv.getItemInSlot(26).copy();
									pinv.emptySlot(26);
									pinv.setSlot(i, pitem);
								}
								catch(e) {}
                        }
                }
        }
}

for(i=0 ; i<35 ; i++)
{
	if(pinv.getItemInSlot(i) != null)
	{
		if(pinv.getItemInSlot(i).getItemID() == 262 && i !=26)
		{
			quant2 = 0;
			pinv = pinv;
			quant = pinv.getItemInSlot(i).getQuantity();
			try
			{
				quant2 = pinv.getItemInSlot(26).getQuantity();
			}
			catch(e) {}
			pinv.emptySlot(i);
			pinv.setSlot(26, Item(262, quant + quant2));
			
		}
	}
}





// --- Tijd --- \\

time.set(1500);


// --- Hookshot --- \\

grapSearch = player.getEntitiesWithinRange(40);
for(i=0 ; i < grapSearch.length ; i++) {
	egrap = grapSearch[i];
	
	if(egrap.getClassType() == "Hookshot") {
		gpos = egrap.getPosition();
		for(j=-1 ; j <=1 ; j++) {
			for(k=-1 ; k<=1 ; k++) {
				if(world.getBlockID(gpos.x+j, gpos.y, gpos.z+k) == 17 || world.getBlockID(gpos.x+j, gpos.y, gpos.z+k) == 5 || (world.getBlockID(gpos.x+j, gpos.y, gpos.z+k) == 214
				&& (world.getMetadata(gpos.x+j, gpos.y, gpos.z+k) == 5 || world.getMetadata(gpos.x+j, gpos.y, gpos.z+k) == 7 || world.getMetadata(gpos.x+j, gpos.y, gpos.z+k) == 6))) {
					gslot = pinv.getSlotContainingItem(458);
					pinv.emptySlot(gslot);
					pinv.setSlot(gslot, Item(458));
		
				}			
			}	
		}	
		npcSearch = egrap.getEntitiesWithinRange(3);
		for(j=0 ; j < npcSearch.length ; j++) {
			enpc = npcSearch[j];
			if(enpc.getClassType() == "NPC") {
				gslot = pinv.getSlotContainingItem(458);
				pinv.emptySlot(gslot);
				pinv.setSlot(gslot, Item(458));
			}
			else if(enpc.getClassType() == "Script") {
				gslot = pinv.getSlotContainingItem(458);
				pinv.emptySlot(gslot);
				pinv.setSlot(gslot, Item(458));
}	}	}	}



// pijlen teller
var arrowAmount = 0;

for(i=0;i<=36;i++)
{
	thisItem = null;
	if(i == 36 && pinv.getCursorItem() != null)
	{
		thisItem = pinv.getCursorItem();
	}
	else if(pinv.getItemInSlot(i) != null)
	{
		thisItem = pinv.getItemInSlot(i);
	}

	if(thisItem != null)
	{
		if(thisItem.getItemID() == 262)
		{
			if(thisItem.getQuantity() > 0)
			{
				arrowAmount += thisItem.getQuantity();
			}
		}
	}
}

if(arrowAmount <= 0)
{
	arrowAmount = 1;
}

if(pinv.getSlotContainingItem(261) != -1)
{
	var bowSlotId = pinv.getSlotContainingItem(261);
	for(i=0;i<=36;i++)
	{
		if(i == 36 && pinv.getCursorItem() != null)
		{
			if(pinv.getCursorItem().getItemID() == 261)
			{
				pinv.cursorItem = null;
			}
		}
		else if(pinv.getItemInSlot(i) != null)
		{
			if(pinv.getItemInSlot(i).getItemID() == 261)
			{
				pinv.emptySlot(i);
			}
		}
	}
	pinv.setSlot(bowSlotId, Item(261, arrowAmount));	
}

// bom placer
if (pinv.getSlotContainingItem(466) != -1)
{
    if (pinv.getSlotContainingItem(466) != 8)
    {
        try
        {
            var count = pinv.getItemInSlot(8).getQuantity();
        }
        catch(e) { var count = 0; }
        var item = pinv.getItemInSlot(pinv.getSlotContainingItem(466)).copy();
        pinv.emptySlot(pinv.getSlotContainingItem(466));
        if (count < 30)
        {
            if (item.getQuantity() + count <= 30)
            {
                item.setQuantity(item.getQuantity() + count);
            }
            else
            {
                item.setQuantity(30);
            }
			
			if(pinv.getSlotContainingItem(318) == -1)
			{
				if(item.getQuantity() >= 31)
				{
					item.setQuantity(30);
				}
				
			}
		}
	    else
        {
            item.setQuantity(30);
        }
        pinv.setSlot(8, item);
    }
    pinv.getItemInSlot(8).setDamage(pinv.getItemInSlot(8).getQuantity());
}

if(pinv.getItemInSlot(8) != null)
{
        if(pinv.getItemInSlot(8).getItemID() != 466)
        {
                for(i=0;i<35;i++)
                {
                        if(pinv.getItemInSlot(i) == null)
                        {
                                try
								{
									var pitem = pinv.getItemInSlot(8).copy();
									pinv.emptySlot(8);
									pinv.setSlot(i, pitem);
								}
								catch(e) {}
                        }
                }
        }
}

for(i=0 ; i<35 ; i++)
{
	if(pinv.getItemInSlot(i) != null)
	{
		if(pinv.getItemInSlot(i).getItemID() == 466 && i !=8)
		{
			quant2 = 0;
			pinv = pinv;
			quant = pinv.getItemInSlot(i).getQuantity();
			try
			{
				quant2 = pinv.getItemInSlot(8).getQuantity();
			}
			catch(e) {}
			pinv.emptySlot(i);
			pinv.setSlot(8, Item(466, quant + quant2));
			
		}
	}
}




// Zora tunic
if (player.isInsideOfWater() && pinv.getItemInSlot(38) != null && pinv.getItemInSlot(38).getItemID() == 303)
{
    player.setAir(280);
}
if(pinv.getSlotContainingItem(303) == 38)
{
	player.texture="/npc/zora link.png";
}
else
{
	player.texture="/mob/char.png";
}

// Iron boots
if (player.isInsideOfWater() && ((pinv.getItemInSlot(36) != null && pinv.getItemInSlot(36).getItemID() != 305) || pinv.getItemInSlot(36) == null))
{
player.addVelocity(0, .15, 0);
}

if (player.isInsideOfWater() && pinv.getItemInSlot(36) != null && pinv.getItemInSlot(36).getItemID() == 305)
{
    player.addVelocity(0, -0.046, 0);
}

// Levens
if (player.isAlive() && playeralive == false)
{
   player.setHealth(12);
   playeralive = true;
}else if(!player.isAlive())
{
   playeralive = false;
}



// rupee converter ding

if(pinv.getSlotContainingItem(273)>=0) // Rupee blau
{
	pinv.consumeItem(273);
	 sound.playSoundUI("sound.TP_get_rupee");
	pinv.addItem(Item(353,5));
}
if(pinv.getSlotContainingItem(256)>=0) // Rupee geel
{
	pinv.consumeItem(256);
	sound.playSoundUI("sound.TP_get_rupee");
	pinv.addItem(Item(353,10));
}
if(pinv.getSlotContainingItem(269)>=0) // Rupee rood
{
	pinv.consumeItem(269);
	sound.playSoundUI("sound.TP_get_rupee");
	pinv.addItem(Item(353,20));
}

// gui
