function serverCmdPouch(%this) {
	%player = (%this.getClassName() $= "AIPlayer" ? %this : %this.getControlObject());
	if(!isObject(%player)) return;
	if(!%player.dataBlock.pouch) {
		messageClient(%this, '', "\c6You do not have a pouch.");
		return;
	}
	if(!isObject(%player.holding) && !isObject(%player.getMountNodeObject(%player.dataBlock.pouchNode))) return;
	if(isObject(%obj = %player.getMountNodeObject(%player.dataBlock.pouchNode))) {
		if(isObject(%player.holding)) {
			messageClient(%this, '', "\c6Either eat \c7(/mouth & /swallow)\c6 or drop the player you have now to get the one in your pouch.");
			return;
		}
		%obj.inPouch = 0;
		Player::holdOtherPlayer(%player, %obj);
	} else {
		if(!isObject(%obj = %player.holding)) {
			messageClient(%this, '', "\c6You don't have anything to put in your pouch.");
			return;
		}
		%obj.inPouch = 1;
		Player::holdOtherPlayer(%player);
		%player.mountObject(%obj, %player.dataBlock.pouchNode);
	}
}
function serverCmdMouth(%this) {
	%player = (%this.getClassName() $= "AIPlayer" ? %this : %this.player);
	if(!isObject(%player)) return;
	if(!isObject(%player.holding)) return;
	if(%player.getClassName() $= "AIPlayer" && isObject(%player.holding.client) && isObject(%player.spawnBrick))
		%player.spawnBrick.onMouthPlayer(%player.holding.client);
		
	%player.mouthHeldObject();
}
function serverCmdSwallow(%this) {
	%player = (%this.getClassName() $= "AIPlayer" ? %this : %this.player);
	if(!isObject(%player)) return;
	if(isObject(%this.oldPlayer) && %this.oldPlayer != %player) {
		%this.setControlObject(%this.oldPlayer);
	}
	if(!isObject(%player.holding)) return;
	if(!%player.holding.inMouth) {
		messageClient(%this,'',"\c6You must do \c3/mouth\c6 first!");
		return;
	}
	if(%player.getClassName() $= "AIPlayer" && isObject(%player.holding.client) && isObject(%player.spawnBrick))
		%player.spawnBrick.onSwallowPlayer(%player.holding.client);

	messageClient(%this,'',"\c6You swallow.");
	messageClient(%player.holding.client,'',"\c6You were swallowed.");
	%player.holding.setShapeName("", 8564862);
	Player::eatHeldObject(%player);
}
function Player::holdOtherPlayer(%this, %other) {
	if(%this.isEating) return;
	// fix outstretched arms
	%this.playThread(3,"root", 1);
	if(!isObject(%other)) {
		if(!isObject(%this.holding)) return;
		if(%this.holding.inMouth) return;
		if(%this.dataBlock.holdNodeName !$= "" && %this.dataBlock.notHoldingNodeName !$= "") {
			%this.hideNode(%this.dataBlock.holdNodeName);
			%this.unHideNode(%this.dataBlock.notHoldingNodeName);
		}
		%this.unMountObject(%this.holding);
		if(%this.getClassName() !$= "AIPlayer" || (%this.trustsObj(%this.holding) || %this.isNotVorist)) {
			if(%this.holding.getClassName() $= "AIPlayer") {
				if(%this.holding.trustsObj(%this)) {
					%this.holding.lastHeldBy = %this;
				}
			} else %this.holding.lastHeldBy = %this;
		}
		if(isObject(%this.holding.client)) {
			if(%this.holding.client.getControlObject() == %this) {
				%this.holding.client.setControlObject(%this.holding);
				%this.holding.client.player = %this.holding.client.oldPlayer;
				%this.holding.getDatablock().doDismount(%this.holding);
			}
		}
		%this.holding.heldBy = "";
		%this.holding = "";
		%this.playThread(2,"root", 1);
		return;
	}
	if(%this.dataBlock.holdNodeName !$= "" && %this.dataBlock.notHoldingNodeName !$= "") {
		%this.unHideNode(%this.dataBlock.holdNodeName);
		%this.hideNode(%this.dataBlock.notHoldingNodeName);
	}
	%this.playThread(2,"armReadyLeft",1);
	%this.holding = %other;
	%other.heldBy = %this;
	%other.inMouth = 0;
	%this.mountObject(%other,1);
}
function Player::mouthHeldObject(%this) {
	if(!isObject(%held = %this.holding)) return;
	if(!%held.inMouth) {
		if(isObject(%held.client) && isObject(%this.client)) {
			messageClient(%held.client,'',"\c6"@%this.client.getPlayerName()@" holds you in their mouth.");
			messageClient(%this.client,'',"\c6You hold "@%held.client.getPlayerName()@" in your mouth.");
		}
		%held.inMouth = 1;
		%held.stomach_stamina = (%held.stomach_stamina $= "" ? 100 : %held.stomach_stamina);
		%this.playThread(2,"root",1);
		if($Stomach::use) {
			%this.unMountObject(%held);
			AIPlayer::Mouth_add(%this, %held);
			return;
		} else {
			if(wordPos(%held.trustList, %this.client) != -1) %held.trustList = removeWord(%held.trustList, wordPos(%held.trustList, %this.client));
			if(!%this.dataBlock.mouth) %held.setDataBlock(voreInternalPlayerType);
		}
		
		if(%this.dataBlock.mouth) {
			%this.unhideNode("mouth");
			%this.mountObject(%held,5);
		} else {
			%this.mountObject(%held,2);
			%held.hideNode("ALL");
		}
	} else {
		if($Stomach::use) AIPlayer::Mouth_remove(%this, %held);
		if(isObject(%held.client)) {
			%held.client.applyBodyParts();
			%held.client.applyBodyColors();
		}
		if(!%this.dataBlock.mouth) {
			%held.setDataBlock((!isObject(%held.defaultPlayerType) ? PlayerStandardArmor : %held.defaultPlayerType));
			%held.unhideNode("headSkin");
			if(%held.getDataBlock().getName() !$= "PlayerStandardArmor") %held.unHideNode("ALL");
		} else {
			%this.hideNode("mouth");
		}
		%held.inMouth = 0;
		%this.holdOtherPlayer(%held);
	}
}
function Player::eatHeldObject(%this) {
	%held = %this.holding;
	if(!isObject(%held)) return;
	if(!%held.inMouth) return;
	%this.lastInStomach = %held;
	%this.isEating  = 1;
	%held.inMouth   = 0;
	%held.inStomach = 1;
	%this.isEating  = 0;
	%this.holding   = "";
	Player::onConsumed(%held);
	
	if($Stomach::use) {
		if(%this.getClassName() $= "AIPlayer") %this.setHeadAngle(0);
		
		%this.unMountObject(%held);
		AIPlayer::Stomach_add(%this, %held);
		return;
	}
	
	if(!%this.dataBlock.mouth) { %this.mountObject(%held, 7); %held.hideNode("ALL"); }
	else { %this.hideNode("mouth"); %this.unhideNode("stomach"); %this.mountObject(%held, 8); }
	%held.setShapeName("",8564862);
	%this.schedule(300,setField,"isEating",0);
	%this.schedule(300,setField,"holding","");
	if(%this.getClassName() $= "AIPlayer") %this.loopMarcAI();
}
function Player::onConsumed(%this) {
	%client = %this.client;
	if(isObject(%client)) messageClient(%client,'',"\c6You were consumed!");
	%this.digestAmt = 0;
	%this.stomach_struggle = 0;
	%this.digest();
	%this.setShapeName("", 8564862);
}

function Player::regenerateStamina(%this) {
	if(!isObject(%this)) return;
	if(isEventPending(%this.regenerateStaminaSchedule)) return;
	if(isEventPending(%this.digestLoop)) return;
	if(%this.stomach_stamina >= 100) return;
	
	%this.stomach_stamina += getRandom(1, 4);
	
	cancel(%this.regenerateStaminaSchedule);
	%this.regenerateStaminaSchedule = %this.schedule(100, regenerateStamina);
}

function Player::digest(%this) {
	if(!isObject(%this)) return;
	if(!isObject(%this.getObjectMount())) return;
	if(isEventPending(%this.regenerateStaminaSchedule)) { cancel(%this.regenerateStaminaSchedule); }
	if(%this.getObjectMount().getClassName() $= "AIPlayer" && !%this.getObjectMount().digestionAmt) %this.getObjectMount().digestionAmt = 1;
	%digestAmt  = (%this.getObjectMount().getClassName() !$= "AIPlayer" ? %this.digestAmt : %this.getObjectMount().digestionAmt);
	%isCaptorAI = (%this.getObjectMount().getClassName() $= "AIPlayer" ? 1 : 0);
	if(%this.getState() $= "Dead") {
		if(%this.heldBy.dataBlock.mouth) {
			%captor = %this.heldBy;
			%this.heldBy = -2;
			%this.disMount();
			if(!isObject(%captor.getMountNodeObject(8))) %this.heldBy.hideNode("stomach");
		}
		if(isObject(%this.client)) %this.client.instantRespawn();
		else if(isObject(%this.spawnBrick)) %this.spawnBrick.respawnBot();
		else %this.schedule(1, delete);
		return;
	}
	if(isObject(%this.client)) {
		%c   = %this.client;
		if(%this.getDamageLevel() >= %this.dataBlock.maxDamage/2.2 && !%this.digest_deathMsg0) {
			messageClient(%c, '', "\c6Your vision grows dark, and your body limp. The environment renders all attempts to escape futile. You feel yourself growing more and more tired by the second.");
			%this.digest_deathMsg0 = 1;
		}
		%this.lastDigestMsgTime = getSimTime();
		if(%digestAmt >= 200) {
			if(%this.lastDigestMsg != 0) {
				%this.lastDigestMsg = 0;
				messageClient(%c, '', "\c6Bubbling gastric acid slowly begins to pool around you, eventually filling half of the stomach. It's really starting to burn.");
			}
		} else if(%digestAmt >= 148) {
			if(%this.lastDigestMsg != 1) {
				%this.lastDigestMsg = 1;
				messageClient(%c, '', "\c6You feel " @ %this.heldBy.firstName @ " pat her stomach as she feels her stomach juices start to flow.");
				messageClient(%c, '', "\c6The stomach contracts, pushing you to the middle.");
			}
		} else if(%digestAmt >= 100) {
			if(%this.lastDigestMsg != 2) {
				%this.lastDigestMsg = 2;
				%random = getWord("groaning gurgling glorping sloshing bubbling", getRandom(0, 4));
				messageClient(%c, '', "\c6You feel your skin begin to tingle as the stomach walls begin secreting what you assume is gastric acid. The stomach walls begin churning, and a loud " @ %random @ " can be heard every few seconds as your captor begins digesting you.");
			}
		} else {
			if(%this.lastDigestMsg != 3) {
				%this.lastDigestMsg = 3;
				messageClient(%c, '', "\c6As you reach the end of your trip down the esophogus, an extremely tight ring of muscle relaxes before the esophogus shoves you into the stomach."); messageClient(%c, '', "\c6The stomach walls contract extremely tightly, emitting a deafening rumble in the process. After a few seconds, the walls relax. You can hear a distinct rumbling sound, along with a heartbeat."); messageClient(%c, '', "\c6The air is extremely damp and staggeringly hot. You have to escape!");
			}
		}
	} else %this.setDamageLevel(%this.getDamageLevel() + getRandom(1,5));
	cancel(%this.digestLoop);
	%this.digestLoop = %this.schedule(getRandom(200,1000), digest);
}