                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

import bool AddAchievement(Critter&cr,uint8 achievement)from"achievements";
import bool HaveAchievement(Critter&cr,uint8 achievement)from"achievements";                               

import void InitDBLogs()from"backend";

import void LogExperience(Critter&cr,int amount)from"backend";
import void LogExperience(Critter&cr,int amount,string@info)from"backend";
import void LogExperience(Critter&cr,int amount,int skill)from"backend";
import void LogExperience(Critter&cr,int amount,int skill,string@info)from"backend";
import void LogExperience(Critter&cr,int amount,int skill,int param)from"backend";
import void LogExperience(Critter&cr,int amount,int skill,string@info,int param)from"backend";
import void LogQuestExperience(Critter&cr,int amount,string@info)from"backend";
import void LogQuestExperience(Critter&cr,int amount,int skill,string@info)from"backend";
import void LogAttack(Map@map,Critter&cr,Critter&target,ProtoItem&weapon,ProtoItem@ammo,uint8 aim,bool isBurst,uint ammoRound,uint weaponRound,bool isHit,bool isCritical,uint critfailFlags)from"backend";
import void LogDamage(Map@map,Critter@attacker,Critter&target,Item@weapon,ProtoItem@ammo,uint8 aim,bool isBurst,uint damage,bool isCritical,uint eff,uint rounds)from"backend";
import void LogGathering(Critter&,uint16,int)from"backend";                                                                       

shared interface IBroadcastBuffer
{
	string GetString();
	
	void SetType(int type);
	int GetType();
	void SetTime(int time);
	int GetTime();
	void SetSetup(int setup);
	int GetSetup();
	void SetMessage(string message);
	void AppendMessage(string message);
	string GetMessage();
	void SetData(array<int>data);
	
	void SetStart(int time);
	void ResetStart();
	
	void SetLifetime(int lifetime);
	
	void SetFilters(int filters);
	void SetFilter(int filter);
	void SetFilter(int filter,int data);
	void UnsetFilter(int filter);
	bool Filter(int filter);
	bool CheckFilters(Critter@player);
	
	bool Send(Critter@player);
	uint SendToAll();
	
	void SetGM(int id);
	void UnsetGM();
	
	void ToDelete();
};  

import void UpdateBroadcast()from"broadcast";

import IBroadcastBuffer@AddBroadcastBuffer(int type,int time,int setup,string&message,array<int>&data,int lifetime,int flags)from"broadcast";
import void DumpBroadcastBuffer(Critter@player)from"broadcast";
import uint FindBroadcastBufferByType(int type,array<IBroadcastBuffer@>&buf)from"broadcast";
import uint FindBroadcastBufferByGM(int id,array<IBroadcastBuffer@>&buf)from"broadcast"; 

import IBroadcastBuffer@Broadcast_Message(string&message,int time,int filters,bool send)from"broadcast";
import IBroadcastBuffer@Broadcast_Message(string&message,int time,int filters)from"broadcast";
import IBroadcastBuffer@Broadcast_Message(string&message,int&time)from"broadcast";
import IBroadcastBuffer@Broadcast_Message(string&message,bool send)from"broadcast";
import IBroadcastBuffer@Broadcast_Message(string&message)from"broadcast"; 

import void Broadcast_TownControl_Set(string&message,int location,int time,int faction)from"broadcast";
import void Broadcast_TownControl_Set(int location,int time,int faction)from"broadcast";
import void Broadcast_TownControl_Stop(int location)from"broadcast"; 

import IBroadcastBuffer@Broadcast_Influence(int location,int time,string&message)from"broadcast"; 

import uint Broadcast_RequestHelp(Critter@player,string&message)from"broadcast";
import void Broadcast_CheckRequestHelpBuffer(Critter@gm)from"broadcast";
import void Broadcast_DumpRequestHelpBuffer(Critter@gm)from"broadcast";                                                                                           

shared interface Buffer
{
	bool IsRaw(uint len);
	
	Buffer@opCom();
	
	Buffer@opNeg();       
	
	Buffer@opShr(int8&value);
	Buffer@opShl(int8 value);
	Buffer@Get(int8&value);
	Buffer@Set(int8&value);
	
	Buffer@opShr(int16&value);
	Buffer@opShl(int16 value);
	Buffer@Get(int16&value);
	Buffer@Set(int16&value);
	
	Buffer@opShr(int32&value);
	Buffer@opShl(int32 value);
	Buffer@Get(int32&value);
	Buffer@Set(int32&value);
	
	Buffer@opShr(int64&value);
	Buffer@opShl(int64 value);
	Buffer@Get(int64&value);
	Buffer@Set(int64&value);
	
	Buffer@opShr(uint8&value);
	Buffer@opShl(uint8 value);
	Buffer@Get(uint8&value);
	Buffer@Set(uint8&value);
	
	Buffer@opShr(uint16&value);
	Buffer@opShl(uint16 value);
	Buffer@Get(uint16&value);
	Buffer@Set(uint16&value);
	
	Buffer@opShr(uint32&value);
	Buffer@opShl(uint32 value);
	Buffer@Get(uint32&value);
	Buffer@Set(uint32&value);
	
	Buffer@opShr(uint64&value);
	Buffer@opShl(uint64 value);
	Buffer@Get(uint64&value);
	Buffer@Set(uint64&value);
	
	Buffer@opShr(bool&value);
	Buffer@opShl(bool value);
	Buffer@Get(bool&value);
	Buffer@Set(bool&value);
	
	Buffer@opShr(string&value);
	Buffer@opShl(string value);
	Buffer@Get(string&value);
	Buffer@Set(string&value);
	
	Buffer@opShr(float&value);
	Buffer@opShl(float value);
	Buffer@Get(float&value);
	Buffer@Set(float&value); 
	
	Buffer@opShr(array<int8>&value);
	Buffer@opShl(array<int8>&value);
	Buffer@Get(array<int8>&value);
	Buffer@Set(array<int8>&value);
	
	Buffer@opShr(array<int16>&value);
	Buffer@opShl(array<int16>&value);
	Buffer@Get(array<int16>&value);
	Buffer@Set(array<int16>&value);
	
	Buffer@opShr(array<int32>&value);
	Buffer@opShl(array<int32>&value);
	Buffer@Get(array<int32>&value);
	Buffer@Set(array<int32>&value);
	
	Buffer@opShr(array<int64>&value);
	Buffer@opShl(array<int64>&value);
	Buffer@Get(array<int64>&value);
	Buffer@Set(array<int64>&value);
	
	Buffer@opShr(array<uint8>&value);
	Buffer@opShl(array<uint8>&value);
	Buffer@Get(array<uint8>&value);
	Buffer@Set(array<uint8>&value);
	
	Buffer@opShr(array<uint16>&value);
	Buffer@opShl(array<uint16>&value);
	Buffer@Get(array<uint16>&value);
	Buffer@Set(array<uint16>&value);
	
	Buffer@opShr(array<uint32>&value);
	Buffer@opShl(array<uint32>&value);
	Buffer@Get(array<uint32>&value);
	Buffer@Set(array<uint32>&value);
	
	Buffer@opShr(array<uint64>&value);
	Buffer@opShl(array<uint64>&value);
	Buffer@Get(array<uint64>&value);
	Buffer@Set(array<uint64>&value);
	
	Buffer@opShr(array<bool>&value);
	Buffer@opShl(array<bool>&value);
	Buffer@Get(array<bool>&value);
	Buffer@Set(array<bool>&value);
	
	Buffer@opShr(array<string>&value);
	Buffer@opShl(array<string>&value);
	Buffer@Get(array<string>&value);
	Buffer@Set(array<string>&value);
	
	Buffer@opShr(array<float>&value);
	Buffer@opShl(array<float>&value);
	Buffer@Get(array<float>&value);
	Buffer@Set(array<float>&value); 
	
	Buffer@opShr(array<array<int8>>&value);
	Buffer@opShl(array<array<int8>>&value);
	Buffer@Get(array<array<int8>>&value);
	Buffer@Set(array<array<int8>>&value);
	
	Buffer@opShr(array<array<int16>>&value);
	Buffer@opShl(array<array<int16>>&value);
	Buffer@Get(array<array<int16>>&value);
	Buffer@Set(array<array<int16>>&value);
	
	Buffer@opShr(array<array<int32>>&value);
	Buffer@opShl(array<array<int32>>&value);
	Buffer@Get(array<array<int32>>&value);
	Buffer@Set(array<array<int32>>&value);
	
	Buffer@opShr(array<array<int64>>&value);
	Buffer@opShl(array<array<int64>>&value);
	Buffer@Get(array<array<int64>>&value);
	Buffer@Set(array<array<int64>>&value);
	
	Buffer@opShr(array<array<uint8>>&value);
	Buffer@opShl(array<array<uint8>>&value);
	Buffer@Get(array<array<uint8>>&value);
	Buffer@Set(array<array<uint8>>&value);
	
	Buffer@opShr(array<array<uint16>>&value);
	Buffer@opShl(array<array<uint16>>&value);
	Buffer@Get(array<array<uint16>>&value);
	Buffer@Set(array<array<uint16>>&value);
	
	Buffer@opShr(array<array<uint32>>&value);
	Buffer@opShl(array<array<uint32>>&value);
	Buffer@Get(array<array<uint32>>&value);
	Buffer@Set(array<array<uint32>>&value);
	
	Buffer@opShr(array<array<uint64>>&value);
	Buffer@opShl(array<array<uint64>>&value);
	Buffer@Get(array<array<uint64>>&value);
	Buffer@Set(array<array<uint64>>&value);
	
	Buffer@opShr(array<array<bool>>&value);
	Buffer@opShl(array<array<bool>>&value);
	Buffer@Get(array<array<bool>>&value);
	Buffer@Set(array<array<bool>>&value);
	
	Buffer@opShr(array<array<string>>&value);
	Buffer@opShl(array<array<string>>&value);
	Buffer@Get(array<array<string>>&value);
	Buffer@Set(array<array<string>>&value);
	
	Buffer@opShr(array<array<float>>&value);
	Buffer@opShl(array<array<float>>&value);
	Buffer@Get(array<array<float>>&value);
	Buffer@Set(array<array<float>>&value); 
	
	Buffer@opShr(array<array<array<int8>>>&value);
	Buffer@opShl(array<array<array<int8>>>&value);
	Buffer@Get(array<array<array<int8>>>&value);
	Buffer@Set(array<array<array<int8>>>&value);
	
	Buffer@opShr(array<array<array<int16>>>&value);
	Buffer@opShl(array<array<array<int16>>>&value);
	Buffer@Get(array<array<array<int16>>>&value);
	Buffer@Set(array<array<array<int16>>>&value);
	
	Buffer@opShr(array<array<array<int32>>>&value);
	Buffer@opShl(array<array<array<int32>>>&value);
	Buffer@Get(array<array<array<int32>>>&value);
	Buffer@Set(array<array<array<int32>>>&value);
	
	Buffer@opShr(array<array<array<int64>>>&value);
	Buffer@opShl(array<array<array<int64>>>&value);
	Buffer@Get(array<array<array<int64>>>&value);
	Buffer@Set(array<array<array<int64>>>&value);
	
	Buffer@opShr(array<array<array<uint8>>>&value);
	Buffer@opShl(array<array<array<uint8>>>&value);
	Buffer@Get(array<array<array<uint8>>>&value);
	Buffer@Set(array<array<array<uint8>>>&value);
	
	Buffer@opShr(array<array<array<uint16>>>&value);
	Buffer@opShl(array<array<array<uint16>>>&value);
	Buffer@Get(array<array<array<uint16>>>&value);
	Buffer@Set(array<array<array<uint16>>>&value);
	
	Buffer@opShr(array<array<array<uint32>>>&value);
	Buffer@opShl(array<array<array<uint32>>>&value);
	Buffer@Get(array<array<array<uint32>>>&value);
	Buffer@Set(array<array<array<uint32>>>&value);
	
	Buffer@opShr(array<array<array<uint64>>>&value);
	Buffer@opShl(array<array<array<uint64>>>&value);
	Buffer@Get(array<array<array<uint64>>>&value);
	Buffer@Set(array<array<array<uint64>>>&value);
	
	Buffer@opShr(array<array<array<bool>>>&value);
	Buffer@opShl(array<array<array<bool>>>&value);
	Buffer@Get(array<array<array<bool>>>&value);
	Buffer@Set(array<array<array<bool>>>&value);
	
	Buffer@opShr(array<array<array<string>>>&value);
	Buffer@opShl(array<array<array<string>>>&value);
	Buffer@Get(array<array<array<string>>>&value);
	Buffer@Set(array<array<array<string>>>&value);
	
	Buffer@opShr(array<array<array<float>>>&value);
	Buffer@opShl(array<array<array<float>>>&value);
	Buffer@Get(array<array<array<float>>>&value);
	Buffer@Set(array<array<array<float>>>&value); 
	
	Buffer@opUShr(array<int8>&arr);
	Buffer@opUShrAssign(array<int8>&arr);
	array<int8>AsInt8();
	
	Buffer@opUShr(array<int16>&arr);
	Buffer@opUShrAssign(array<int16>&arr);
	array<int16>AsInt16();
	
	Buffer@opUShr(array<int32>&arr);
	Buffer@opUShrAssign(array<int32>&arr);
	array<int32>AsInt32();
	
	Buffer@opUShr(array<int64>&arr);
	Buffer@opUShrAssign(array<int64>&arr);
	array<int64>AsInt64();
	
	Buffer@opUShr(array<uint8>&arr);
	Buffer@opUShrAssign(array<uint8>&arr);
	array<uint8>AsUint8();
	
	Buffer@opUShr(array<uint16>&arr);
	Buffer@opUShrAssign(array<uint16>&arr);
	array<uint16>AsUint16();
	
	Buffer@opUShr(array<uint32>&arr);
	Buffer@opUShrAssign(array<uint32>&arr);
	array<uint32>AsUint32();
	
	Buffer@opUShr(array<uint64>&arr);
	Buffer@opUShrAssign(array<uint64>&arr);
	array<uint64>AsUint64();
};  

import Buffer@NewBuffer()from"buffer";   

import Buffer@NewBuffer(array<int8>@data)from"buffer";

import Buffer@NewBuffer(array<int16>@data)from"buffer";

import Buffer@NewBuffer(array<int32>@data)from"buffer";

import Buffer@NewBuffer(array<int64>@data)from"buffer";

import Buffer@NewBuffer(array<uint8>@data)from"buffer";

import Buffer@NewBuffer(array<uint16>@data)from"buffer";

import Buffer@NewBuffer(array<uint32>@data)from"buffer";

import Buffer@NewBuffer(array<uint64>@data)from"buffer";                                                                                                             

shared class CombatRes
{
	array<uint>Res;
	Critter@Crit;
	int Left;
	int Right;
	
	CombatRes()
	{
		Res.resize(1);
		Res[0]=1;
		Left=(-1);
		Right=(-1);
	}
};

void AddEff(Critter@crit,array<uint>&eff,array<CombatRes>&combatResults)
{
	int ptr=0; 
	
	if(combatResults.length()==0)
	{
		combatResults.resize(1);
		@combatResults[0].Crit=crit;
	}
	
	while(combatResults[ptr].Crit.Id!=crit.Id)
	{
		if(crit.Id<combatResults[ptr].Crit.Id)
		{
			if(combatResults[ptr].Left!=(-1))
			ptr=combatResults[ptr].Left;
			else
			{
				uint last=combatResults.length();
				combatResults.resize(last+1);
				combatResults[ptr].Left=last;
				ptr=last;
				@combatResults[last].Crit=crit;
			}
		}
		else
		{
			if(combatResults[ptr].Right!=(-1))
			ptr=combatResults[ptr].Right;
			else
			{
				uint last=combatResults.length();
				combatResults.resize(last+1);
				combatResults[ptr].Right=last;
				ptr=last;
				@combatResults[last].Crit=crit;
			}
		}
	} 
	
	uint len=eff.length();
	combatResults[ptr].Res.resize(combatResults[ptr].Res[0]+len);
	for(uint i=0;i<len;i++)
	combatResults[ptr].Res[i+combatResults[ptr].Res[0]]=eff[i];
	
	combatResults[ptr].Res[0]+=len;
}

void runTree(array<CombatRes>&combatResults,int ptr)
{
	if(ptr==0)
	if(combatResults.length()==0)
	return;    
	
	combatResults[ptr].Crit.SendCombatResult(combatResults[ptr].Res);    
	
	if(combatResults[ptr].Left!=(-1))
	runTree(combatResults,combatResults[ptr].Left);
	if(combatResults[ptr].Right!=(-1))
	runTree(combatResults,combatResults[ptr].Right);
}              

shared interface IConfigVar
{
	string GetName();
	string GetValue();
	array<string>GetValueAsArray();
	array<string>GetValueAsArray(string&delimeter);
	void SetValue(int val);
	void SetValue(uint val);
	void SetValue(string&val);
	void SetValue(array<string>&val);
	void SetValue(array<string>&val,string&delimeter);
};

shared interface IConfigSection
{
	string GetName();
	bool AddVar(string&var,string&val);
	bool DeleteVar(string&var);
	bool DeleteVar(string&var,bool caseSensitive);
	IConfigVar@GetVar(string&var);
	IConfigVar@GetVar(string&varname,bool caseSensitive);
	void GetVars(array<string>&list);
	bool SetVar(string&varname,string val);
	bool VarExists(string&var);
	bool VarExists(string&var,bool caseSensitive);
};

shared interface IConfigFile
{
	bool IsVirtual();
	string GetName();
	bool AddSection(string&section);
	IConfigSection@GetSection(string&section);
	IConfigSection@GetSection(string&sectioname,bool caseSensitive);
	void GetSections(array<string>&list);
	bool SectionExists(string&section);
	bool SectionExists(string&section,bool caseSensitive);
};  

import IConfigFile@NewConfig(string&filename)from"config_file";
import bool LoadConfig(string&filename)from"config_file";
import bool SaveConfig(string&filename)from"config_file";
import bool UnloadConfig(string&filename)from"config_file";

import IConfigFile@GetConfigFile(string&filename)from"config_file";
import IConfigFile@GetConfigFile(string&filename,bool caseSensitive)from"config_file";
import IConfigSection@GetConfigSection(string&filename,string&sectioname)from"config_file";
import IConfigSection@GetConfigSection(string&filename,string&sectioname,bool caseSensitive)from"config_file";
import IConfigVar@GetConfigVar(string&filename,string&sectioname,string@varname)from"config_file";
import IConfigVar@GetConfigVar(string&filename,string&sectioname,string@varname,bool caseSensitive)from"config_file";

import string@GetConfigValue(string&filename,string&section,string@varname)from"config_file";
import string@GetConfigValue(string&filename,string&sectioname,string@varname,bool caseSensitive)from"config_file";

import bool SetConfigValue(string&filename,string&sectioname,string@varname,string&value)from"config_file";
import bool SetConfigValue(string&filename,string&sectioname,string@varname,bool value)from"config_file";
import bool SetConfigValue(string&filename,string&sectioname,string@varname,int value)from"config_file";
import bool SetConfigValue(string&filename,string&sectioname,string@varname,uint value)from"config_file";                

import void SetBirthDate(Critter&cr)from"critter_age";
import void CheckBirthDate(Critter&cr)from"critter_age";
import void CritterAgeInit(Critter&cr)from"critter_age";
import void SynchronizeAge(Critter&cr)from"critter_age";                                 

import void WLog(string&type,string&message)from"debug";
import void WLog(string&type,string&message,int level)from"debug";
import void InitDebug()from"debug";                                                                                                                                                                                                                                                                                                                                                 

import void InitLogs()from"logging";
import void FLog(uint logindex,string&text)from"logging";
import void ILog(string&section,string&text)from"logging";
import void GMLog(Critter&cr,string&text)from"logging";
import void CloseLogs()from"logging";
import uint AddLog(string&filename)from"logging";
import uint AddLog(string&filename,uint index)from"logging";                                                                   

import void InitEconomy()from"economy";
import void SendLevelThresholds(Critter&)from"economy"; 

import bool BankAccountExists(uint bankid,uint account)from"economy";
import bool BankAccountRemoveMoney(uint bankid,uint account,uint amount)from"economy";
import bool BankHasAccess(uint bankid,uint account,uint playerid)from"economy";
import int BankGetAccountBalance(uint bankid,uint account)from"economy";
import int BankGetAccountID(uint bankid,uint playerid)from"economy";
import uint BankAddAccess(uint bankid,uint account,uint playerid)from"economy";
import uint BankCreateAccount(uint bankid,uint playerid)from"economy";
import uint BankDepositMoney(uint bankid,uint playerid,uint account,int amount)from"economy";
import uint BankGetAccessCount(uint bankid,uint account)from"economy";
import uint BankGetAccountOwner(uint bankid,uint account)from"economy";
import uint BankGetAccountType(uint bankid,uint account)from"economy";
import uint BankGetCreditRating(uint bankid,uint account)from"economy";
import uint BankGetLoan(uint bankid,uint account)from"economy";
import uint BankRemoveAccess(uint bankid,uint account,uint playerid)from"economy";
import uint BankSetAccountType(uint bankid,uint account,uint accounttype)from"economy";
import uint BankSetCreditRating(uint bankid,uint account,uint rating)from"economy";
import uint BankSetLoan(uint bankid,uint account,uint loan)from"economy";
import uint BankTakeLoan(uint bankid,uint account,uint amount)from"economy";
import uint BankTransferMoney(uint bankid,uint fromaccount,uint toaccount,uint amount)from"economy";
import uint BankWithdrawMoney(uint bankid,uint playerid,uint account,int amount)from"economy"; 

import bool BanksTransferFromCritter(Critter&critter,uint amount,uint type,bool virtual)from"economy";
import bool BanksTransferToCritter(Critter&critter,uint amount,uint type,bool virtual)from"economy";
import uint BanksGetTotalMoney()from"economy";
import void BanksAddMoney(uint amount)from"economy";
import void BanksRemoveMoney(uint amount)from"economy"; 

import bool BankAddMoney(uint bankid,uint amount)from"economy";
import bool BankRemoveMoney(uint bankid,uint amount)from"economy";
import bool BankSetMoney(uint bankid,uint amount)from"economy";
import uint BankGetLoanInterest(uint bankid)from"economy";
import uint BankGetNumberOfAccounts(uint bankid)from"economy";
import float BankGetSaveInterest(uint bankid)from"economy";
import uint BankGetTotalMoney(uint bankid)from"economy";
import uint BankGetTotalBalance(uint bankid)from"economy";
import float BankGetReserveRatio(uint bankid)from"economy";
import uint BankSetLoanInterest(uint bankid,uint interest)from"economy";
import uint BankSetSaveInterest(uint bankid,float interest)from"economy";
import bool BankTransferFromCritter(uint bankId,Critter&critter,uint amount,uint type,bool virtual)from"economy";

import void SaveBankData()from"economy";   

import int GetItemSellModifier(Critter&player,Critter&trader)from"economy";
import int GetItemBuyModifier(Critter&player,Critter&trader)from"economy";
import uint GetItemCost(Item&item,Critter&cr,Critter&trader,bool sell)from"economy";
import uint GetItemCostPlain(Item&item,Critter&cr,Critter&trader)from"economy";

import array<int>GetTraderLevels(Critter@npc)from"economy";
import uint GetTraderLevel(Critter@npc,uint type)from"economy";

import uint ItemLevel(Item&item)from"economy";
import uint ItemLevel(uint pid)from"economy";
import uint TraderCapacity(Critter@npc)from"economy";
import uint TraderCapacity(Critter@npc,uint type,uint level)from"economy";
import uint TraderMoneyCapacity(Critter@npc)from"economy";
import uint TradingItemType(Item&item)from"economy";
import uint TradingItemType(uint pid)from"economy";                                                                                                         

const string@FD_Bank_Result2String(uint res)
{
	if(res==(1))
	return"FD_BANK_RESULT_SUCCESS";
	else if(res==(2))
	return"FD_BANK_RESULT_UNKNOWN";
	else if(res==(3))
	return"FD_BANK_RESULT_TOO_MANY_ACCOUNTS";
	else if(res==(4))
	return"FD_BANK_RESULT_ALREADY_HAS_ACCOUNT";
	else if(res==(5))
	return"FD_BANK_RESULT_NOT_ENOUGH_MONEY";
	else if(res==(6))
	return"FD_BANK_RESULT_BANK_FULL";
	else if(res==(7))
	return"FD_BANK_RESULT_BANK_EMPTY";
	else if(res==(8))
	return"FD_BANK_RESULT_DATA_ERROR";
	else if(res==(9))
	return"FD_BANK_RESULT_INVALID_PLAYER";
	else if(res==(10))
	return"FD_BANK_RESULT_NO_ACCOUNT";
	else
	return"FD_Result: Unknown error code";
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

shared class Entire
{
	int Number;
	uint16 HexX;
	uint16 HexY;
	uint8 Direction;
};

uint ParseEntires(Map&map,array<Entire>&entires,int number)
{
	uint oldCount=entires.length();
	uint count=map.CountEntire(number);
	entires.resize(oldCount+count);
	
	for(uint i=0;i<count;i++)
	{
		Entire@ent=entires[oldCount+i];
		if(map.GetEntireCoords(number,i,ent.HexX,ent.HexY,ent.Direction)==false)
		return 0;
		ent.Number=number;
	}
	
	return count;
}

bool IsEntireFree(uint mappid,int number)
{
	Map@map=GetMapByPid(mappid,0);
	return IsEntireFree(map,number);
}

bool IsEntireFree(Map&map,int number)
{
	uint16 x,y;
	x=0;
	y=0;
	return GetEntireFreeHex(map,number,x,y);
}

bool GetEntireFreeHex(Map&map,int number,uint16&hx,uint16&hy,uint skip=0)
{
	uint count=map.CountEntire(number); 
	
	for(uint i=skip;i<count;i++)
	{
		if(map.GetEntireCoords(number,i,hx,hy)&&map.IsHexPassed(hx,hy))
		return true;
	}
	
	if(hx==0||hy==0||hx>=map.GetWidth()-1||hy>=map.GetHeight()-1)
	return false; 
	
	for(uint i=0;i<count;i++)
	{
		if(map.GetEntireCoords(number,i,hx,hy))
		{
			for(int x=-1;x<=1;x++)
			{
				for(int y=-1;y<=1;y++)
				{
					if(x==0&&y==0)
					continue;
					if(__MapHexagonal)
					{
						if((hx%2)==1&&((x==-1&&y==1)||(x==1&&y==1)))
						continue;
						if((hx%2)==0&&((x==-1&&y==-1)||(x==1&&y==-1)))
						continue;
					}
					
					if(map.IsHexPassed(hx+x,hy+y))
					{
						hx+=x;
						hy+=y;
						return true;
					}
				}
			}
		}
	}
	return false;
}

bool GetNearEntire(Map&map,int number,uint16&hx,uint16&hy)
{
	uint16 hxBase=hx;
	uint16 hyBase=hy;
	
	array<Entire>entires;
	uint count=ParseEntires(map,entires,number);
	if(count==0)
	return false;
	
	hx=entires[0].HexX;
	hy=entires[0].HexY;
	for(uint i=1;i<count;i++)
	{
		Entire@ent=entires[i];
		if(GetDistantion(hxBase,hyBase,ent.HexX,ent.HexY)<GetDistantion(hxBase,hyBase,hx,hy))
		{
			hx=ent.HexX;
			hy=ent.HexY;
		}
	}
	
	return true;
}                                                                                                                                                                                                                                                                                                                                                                                                        

import string GetCritterLexems(Critter&critter)from"lexems";
import string GetItemLexems(Item&item)from"lexems";

import bool IsLexem(Critter&critter,string&lex)from"lexems";
import bool IsLexem(Item&it,string&lex)from"lexems";
import bool IsLexem(string&lexems,string&lex)from"lexems";

import string GetLexem(Critter&critter,string&lex)from"lexems";
import string GetLexem(Item&item,string&lex)from"lexems";
import string GetLexem(string&lexems,string&lex)from"lexems"; 

import void SetLexem(Critter&critter,string&lex,string&value)from"lexems";
import void SetLexem(Item&item,string&lex,string&value)from"lexems";
import string SetLexem(string&lexems,string&lex,string&value)from"lexems";

import void UnsetLexem(Critter&critter,string&lex)from"lexems";
import void UnsetLexem(Item&item,string&lex)from"lexems";
import string UnsetLexem(string&lexems,string&lex)from"lexems";                                                                                                                                                                                                                                                                                                                                                                           

import Location@GetLocationOf(Critter&critter)from"utils";
import string GetLocationName(uint locId)from"utils";
import string GetLocationName(Location@loc)from"utils";
import bool ReadPids(array<int>&out pids,bool removeinvalid)from"utils";
import void ReadDefines(string@fileName,dictionary&items,array<string>@defines)from"utils";
import bool ParseDefine(const string&in line,string&out spid,int&out id)from"utils";
import int SkipWhitespaces(const string&in str,int start)from"utils";
import int SkipNonWhitespaces(const string&in str,int start)from"utils";
import bool IsParameterTag(string&str)from"utils";
import string GetParameterString(array<string@>@arr,string&parameter)from"utils";
import int GetIndexOfString(array<string@>@arr,string&str)from"utils";
import string GetConcatenatedString(array<string@>@arr,uint startindex,int stopindex)from"utils";
import string GetConditionOfCritter(Critter@cr)from"utils";
import string GetExtConditionOfCritter(Critter@cr)from"utils";
import uint GetAllOnlinePlayers(array<Critter@>&out players)from"utils";
import uint GetAuthenticatedPlayers(array<Critter@>&out players)from"utils";
import uint GetAuthenticatedPlayers(array<Critter@>&out players,bool ignorePriviledges)from"utils";
import uint GetNumberOfPlayersOnline()from"utils";
import void SetTurnBasedAvailability(Location@loc)from"utils";
import bool IsEncounterMap(Map@map)from"utils";
import bool IsTown(Map@map)from"utils";
import uint GetMapType(Map@map)from"utils";
import void LockDoor(uint x,uint y,Map@map,uint complexity,uint lockid)from"utils";
import void UnlockDoor(uint x,uint y,Map@map)from"utils";
import void ClearContainer(Item@container)from"utils";
import void MoveItemsCritterToCont(Critter&crFrom,Item&contTo,uint specid)from"utils";
import string GetCritterInfo(Critter&cr)from"utils";
import bool AddExpTeam(Critter&critter,int xp)from"utils";
import void ClearEnemyStack(Critter&critter)from"utils";
import void ClearEnemyStacksOnMap(Map@map)from"utils";
import bool IsCurrentEnemy(Critter&cr,uint targetId)from"utils";
import string@GetSafePlayerName(uint id)from"utils";
import string GetSafePlayerName(uint id,string&onSuccess,string&onError)from"utils";
import IDateTime@GetCurrentDateTime()from"utils";
import string GetCurrentDateTimeString()from"utils";
import string GetCurrentDateTimeString(bool date,bool time)from"utils";
import Critter@GetMostSkilled(array<Critter@>@group,int skill)from"utils";
import string GetAuthString(Critter&player)from"utils";
import string GetAuthString(int accesslevel)from"utils";
import bool CanRequestHelp(Critter&player)from"utils";
import void SetRequestedHelp(Critter&player)from"utils";
import void SetRequestedHelp(Critter&player,int minutes)from"utils";
import Critter@GetOnlineGM()from"utils";
import void Preprocess(Critter&player,string&commandString)from"utils";
import bool IsHumanoid(Critter@cr)from"utils";
import uint GetGroupIndex(Critter&cr)from"utils";
import uint GetGroupIndex(int st)from"utils";
import void SetGroupIndex(Critter&cr,uint val)from"utils";
import uint GetGroupRank(Critter&cr)from"utils";
import void SetGroupRank(Critter&cr,uint val)from"utils";
import uint GetGroupMode(Critter&cr)from"utils";
import void SetGroupMode(Critter&cr,uint val)from"utils";
import void SetGroupInfo(Critter&cr,uint faction,uint rank,uint mode)from"utils";
import void SetGroupInfoPack(Critter&cr,uint packInfo)from"utils";
import void ClearEvents(Critter&cr)from"utils";

import int GetGvar(uint gvar)from"utils";
import void SetGvar(uint gvar,uint value)from"utils";
import int GetLLvar(Location&location,uint llvar)from"utils";
import int GetLLvar(uint locationId,uint llvar)from"utils";
import void SetLLvar(Location&location,uint llvar,uint value)from"utils";
import int GetLMvar(Map&map,uint llvar)from"utils";
import int GetLMvar(uint mapId,uint llvar)from"utils";
import void SetLMvar(Map&map,uint llvar,uint value)from"utils";
import int GetLIvar(Item&item,uint llvar)from"utils";
import int GetLIvar(uint itemId,uint llvar)from"utils";
import void SetLIvar(Item&item,uint llvar,uint value)from"utils";
import int GetLvar(Critter&critter,uint lvar)from"utils";
import int GetLvar(uint id,uint lvar)from"utils";
import void SetLvar(Critter&critter,uint lvar,uint value)from"utils";
import void SetLvar(uint id,uint lvar,uint value)from"utils";
import int GetUvar(uint uvar,uint key,uint index)from"utils";
import void SetUvar(uint uvar,uint key,uint index,uint value)from"utils";

import uint GetContainerValue(Item@container)from"utils";
import uint BaseItemValue(uint pid,bool ammo)from"utils";
import uint BaseItemValue(uint pid,uint broken,uint det,bool ammo)from"utils";
import uint BaseItemValue(Item@item)from"utils";
import uint BaseItemValue(Item@item,uint proc)from"utils";
import uint BaseSingleItemValue(Item@item)from"utils";
import uint BaseSingleItemValue(Item@item,uint proc)from"utils";

import void SetBloodType(Critter@cr)from"utils";
import string GetBloodType(Critter@cr)from"utils";
import string GetBloodRandom()from"utils";

import void LogCommandUsage(Critter&player,string&commandString)from"utils";
import void DropTimeouts(Critter&cr)from"utils";

import bool HasItem(Critter@cr,uint pid)from"utils";
import bool HasSomeWeapon(Critter@cr)from"utils";
import uint GetBestWeaponSkill(Critter@cr)from"utils";
import void GiveBag(uint bag,Critter@cr)from"utils";
import void SetQuestGarbager(uint time,uint playerid,uint locid,uint var,uint val)from"utils";
import Critter@AddNpc(Map@map,uint16 pid,uint16 x,uint16 y,uint8 dir,uint dialogId,string&script,uint aiPack,uint bagId,uint teamId,bool isMob,uint level)from"utils";
import Critter@AddNpc(Map@map,uint16 pid,uint16 x,uint16 y,uint8 dir,uint dialogId,string&script,uint aiPack,uint bagId,uint teamId,uint factionRank,uint factionMode,bool isMob,uint level)from"utils";
import Critter@AddNpc(Map@map,uint16 pid,uint16 x,uint16 y,uint8 dir,array<int>params,uint dialogId,string&script,uint aiPack,uint bagId,uint teamId,bool isMob,uint level)from"utils";
import Critter@AddNpc(Map@map,uint16 pid,uint16 x,uint16 y,uint8 dir,array<int>params,uint dialogId,string&script,uint aiPack,uint bagId,uint teamId,uint factionRank,uint factionMode,bool isMob,uint level)from"utils";
import void AddScore(Critter@cr,uint score,uint points)from"utils";

import bool ReloadWeapon(Critter&cr)from"utils";
import Item@GetRadio(Critter&cr)from"utils";
import Item@GetRepairTool(Critter&cr)from"utils";
import Item@GetEquippedItem(Critter&cr,uint Pid)from"utils";
import Item@GetEquippedItem(Critter&cr,array<uint>&Pids)from"utils";
import Item@GetEquippedItemByType(Critter&cr,uint ItemType)from"utils"; 

import bool SkillRoll(Critter@cr,int skill,int bonus)from"utils";
import int SkillCheck(Critter&cr,int skill,int skillused,Item@item,int bonus)from"utils";
import string SkillName(uint8 skill)from"utils";
import void ChangeCrTypeSafe(Critter&cr,uint8 crType)from"utils";

import bool Pickable(Item@item)from"utils";

import void TransferItemsToContOnMap(Critter&cr,Map@map,int entid,int contpid,int itemtypes)from"utils";
import void TransferItemsFromContOnMap(Critter&cr,Map@map,int entid,int contpid)from"utils";

import string IpToString(uint ip)from"utils";

import void VerboseAction(Critter&cr,string&text)from"utils";
import void VerboseAction(Critter&cr,Critter&target,string&text)from"utils";
import void VerboseExperience(Critter&cr,int xpDiff,int levelDiff)from"utils";

import void SetChosenActions(Critter&cr,array<int>&actions)from"utils";

import void HexLine(uint16 x0,uint16 y0,uint16 x1,uint16 y1,array<uint16>@xList,array<uint16>@yList)from"utils";
import void HexCircle(uint16 x0,uint16 y0,uint16 radius,array<uint16>@xList,array<uint16>@yList)from"utils";

import void StartPersonalDataCleanup()from"utils";

import bool IsPersonalData(Location&location,string&name)from"utils";
import bool GetPersonalData(Location&location,string&name,array<uint8>&value)from"utils";
import uint GetPersonalData(Location&location,array<string>&names,array<array<uint8>>&values)from"utils";
import bool SetPersonalData(Location&location,string&name,array<uint8>&value)from"utils";
import bool UnsetPersonalData(Location&location,string&name)from"utils";

import bool IsPersonalData(Map&map,string&name)from"utils";
import bool GetPersonalData(Map&map,string&name,array<uint8>&value)from"utils";
import uint GetPersonalData(Map&map,array<string>&names,array<array<uint8>>&values)from"utils";
import bool SetPersonalData(Map&map,string&name,array<uint8>&value)from"utils";
import bool UnsetPersonalData(Map&map,string&name)from"utils";

import bool IsPersonalData(Critter&critter,string&name)from"utils";
import bool GetPersonalData(Critter&critter,string&name,array<uint8>&value)from"utils";
import uint GetPersonalData(Critter&critter,array<string>&names,array<array<uint8>>&values)from"utils";
import bool SetPersonalData(Critter&critter,string&name,array<uint8>&value)from"utils";
import bool UnsetPersonalData(Critter&critter,string&name)from"utils";

import bool IsPersonalData(Item&item,string&name)from"utils";
import bool GetPersonalData(Item&item,string&name,array<uint8>&value)from"utils";
import uint GetPersonalData(Item&item,array<string>&names,array<array<uint8>>&values)from"utils";
import bool SetPersonalData(Item&item,string&name,array<uint8>&value)from"utils";
import bool UnsetPersonalData(Item&item,string&name)from"utils";

import bool FindPreferredGridApprox(Map&map,uint16&hx,uint16&hy)from"utils";           

import bool StrToInt(string@s,uint64&inout val)from"strtoint";
import bool StrToInt(string@s,uint&inout val)from"strtoint";
import bool StrToInt(string@s,uint16&inout val)from"strtoint";
import bool StrToInt(string@s,uint8&inout val)from"strtoint";
import bool StrToInt(string@s,int64&inout val)from"strtoint";
import bool StrToInt(string@s,int16&inout val)from"strtoint";
import bool StrToInt(string@s,int8&inout val)from"strtoint";    

import int FindInArray(array<int>&arr,int value)from"utils";
import int FindInArray(array<uint>&arr,uint value)from"utils";
import int FindInArray(array<uint16>&arr,uint16 value)from"utils";
import int FindInArray(array<uint8>&arr,uint8 value)from"utils";
import bool FindInArray(array<int>&arr,int id,int&index)from"utils";
import bool FindInArray(array<uint>&arr,uint id,int&index)from"utils";
import bool FindInArray(array<uint8>&arr,uint8 id,int&index)from"utils";
import int FindInArray(array<string>&arr,string&value)from"utils";
import int FindInArray(array<string@>@arr,string&value)from"utils";
import bool Present(int what,array<int>&where)from"utils";
import bool Present(uint what,array<uint>&where)from"utils";
import bool Present(uint16 what,array<uint16>&where)from"utils";
import bool Present(string&what,array<string>&where)from"utils";
import bool Present(string&what,array<string@>@where)from"utils";

import uint CreateLocationForGroup(Critter&player,uint16 pid,uint16 worldX,uint16 worldY,array<Critter@>&)from"utils";
import bool FindFirstFreeHex(Map@map,uint16&x,uint16&y,uint8 dir,uint16 maxSteps)from"utils";
import bool FindNearestFreeHex(Map&map,uint16&x,uint16&y,uint radius)from"utils";

import bool GetItemCoordinates(Item&item,uint&mapID,uint16&x,uint16&y)from"utils";
import bool ItemOnHex(uint16 pid,Map@map,uint16 x,uint16 y)from"utils";

import void PrintCallstack()from"utils";
import void PrintCallstack(int level)from"utils";

import bool LocationHasCritters(Location&loc,uint findType)from"utils";
import uint LocationGetCritters(Location&loc,uint findType,array<Critter@>@critters)from"utils";
import bool LocationHasItems(Location&loc,uint16 protoId)from"utils";
import uint LocationGetItems(Location&loc,uint16 protoId,array<Item@>@items)from"utils";
import void LocationDeleteItems(Location&loc,uint16 protoId)from"utils";

import bool IsDisposableEncounter(Location@loc)from"utils"; 

shared class CPosition
{
	uint x;
	uint y;
	uint dir;
};

shared interface IRect
{
	bool IsWithin(Critter&cr);
};

shared class Rect:IRect
{
	uint x1;
	uint y1;
	uint x2;
	uint y2;
	
	Rect(uint x1,uint y1,uint x2,uint y2)
	{
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
	}
	
	bool IsWithin(Critter&cr)
	{
		return((cr.HexX>=this.x1&&cr.HexX<=this.x2)&&(cr.HexY>=this.y1&&cr.HexY<=this.y2));
	}
};

shared interface IDateTime
{
	uint16 get_Year();
	uint16 get_Month();
	uint16 get_DayOfWeek();
	uint16 get_Day();
	uint16 get_Hour();
	uint16 get_Minute();
	uint16 get_Second();
	uint16 get_Milliseconds();
	string@ToString();
};                                                            

import void AddWaitPlan(Critter&critter,uint waittime)from"npc_common";
import bool AttackCritter(Critter&attacker,Critter&target,uint minhp)from"npc_common";
import bool AttackCritter(Critter&attacker,Critter&target)from"npc_common";
import bool CanUseWeapon(Critter&critter,Item@weapon)from"npc_common";
import bool CanUseWeapon(Critter&critter,uint proto)from"npc_common";
import void ClearIllegalFlags(Critter&critter)from"npc_common";
import bool HasIntelligentBrain(Critter&follower)from"npc_common";
import void SetCritterIllegalFlag(Critter&critter,int reason)from"npc_common";
import void SetCritterIllegalFlag(Critter&critter,int location,int reason)from"npc_common";
import bool HasSameScript(Critter&critter1,Critter&critter2)from"npc_common";
import bool IsFlaggedAsIllegal(Critter&critter)from"npc_common";
import bool IsFlaggedAsIllegal(Critter&critter,int location)from"npc_common";
import bool IsInLocation(Critter&critter,int locationPID)from"npc_common";
import bool MoveByDir(Critter&critter,uint8 dir,uint steps,bool run)from"npc_common";
import void MoveRandom(Critter&npc,uint maxDist)from"npc_common";
import void MoveRandom(Critter&npc,uint maxDist,bool Run)from"npc_common";
import void MoveRandom(Critter&npc,uint maxDist,uint stepDist,bool Run)from"npc_common";
import void TransferToNPCMap(Critter&critter)from"npc_common";
import void UnsetCritterIllegalFlag(Critter&critter)from"npc_common";
import void UnsetCritterIllegalFlag(Critter&critter,int location)from"npc_common";
import void UnsetCritterIllegalFlag(uint id,int location)from"npc_common";
import int GetCritterIllegalFlag(Critter&critter)from"npc_common";
import int GetCritterIllegalFlag(Critter&critter,int location)from"npc_common";
import bool HasUnusableWeapon(Critter&critter,uint bag)from"npc_common";
import bool HasUnusableWeapon(Critter&critter)from"npc_common";
import bool HasUnusableWeapon(uint crpid,uint bag)from"npc_common";
import Item@ArmBestWeapon(Critter&critter)from"npc_common";
import Item@ArmFavoriteWeapon(Critter&critter)from"npc_common";
import void PutAwayItems(Critter&critter)from"npc_common";
import void Heal(Critter&cr)from"npc_common";
import void TryReportOffense(Critter@cr,Critter@offender,int reputationdrop)from"npc_common";
import uint GetCrittersWithScript(Map&map,uint16 pid,uint findType,string&scriptName,string&funcDeclaration,array<Critter@>@critters)from"npc_common";
import uint GetCrittersLoc(Location&loc,uint16 pid,uint findType,array<Critter@>@critters)from"npc_common";
import uint GetNearGuards(Map@map,uint16 hexX,uint16 hexY,uint radius,array<Critter@>@crits)from"npc_common";
import uint GetNearFactionGuards(Map@map,uint16 hexX,uint16 hexY,uint radius,uint faction,array<Critter@>@crits)from"npc_common";
import string GenerateNewName(Critter&critter)from"npc_common";
import string GetStoredName(Critter&critter)from"npc_common";
import string GetStoredFirstName(Critter&critter)from"npc_common";
import bool Flee(Critter&cr)from"npc_common";
import bool Flee(Critter&cr,bool Run)from"npc_common";
import void FindFreeHexes(Map@map,uint16 hexX,uint16 hexY,int&num,array<uint16>&coordsX,array<uint16>&coordsY)from"npc_common";
import bool FindNearestFreeHex(Map@map,uint16 hexX,uint16 hexY,uint16&outX,uint16&outY)from"npc_common";
import void SetDeleteEvent(Critter&cr,uint time)from"npc_common";
import void DropDeleteEvent(Critter&cr)from"npc_common";                  

import string GetRandomFirstName(uint gender)from"npc_names";
import string GetRandomFirstName(uint gender,int&index)from"npc_names";

import string GetRandomNick(uint gender)from"npc_names";

import string GetRandomSurname()from"npc_names";

import string GetRandomFullName(uint gender)from"npc_names";
import string GetRandomFullName(uint gender,int&firstName,bool&genderNick,int&nick,int&surname)from"npc_names"; 

import string GetFirstName(uint gender,uint index)from"npc_names";
import string GetNick(uint gender,uint index,bool genderNick)from"npc_names";
import string GetSurname(uint index)from"npc_names";  

import void LogNames(bool printNames)from"npc_names";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

shared class Serializator
{
	Serializator()
	{
		CurPos=0;
		BufSize=0;
		DataSize=0;
	}
	
	Serializator(uint approxSize)
	{
		CurPos=0;
		BufSize=0;
		DataSize=0;
		GrowBuffer(approxSize);
	}
	
	void GrowBuffer()
	{
		BufSize+=(128);
		Array.resize(BufSize);
	}
	
	void GrowBuffer(uint length)
	{
		BufSize+=length;
		Array.resize(BufSize);
	}
	
	bool Save(string&name)
	{
		if(DataSize==0)
		return false;
		bool result=SetAnyData(name,Array,DataSize);
		Clear();
		return result;
	}
	
	bool Load(string&name)
	{
		Clear();
		if(!IsAnyData(name))
		return false;
		if(!GetAnyData(name,Array))
		return false;
		BufSize=Array.length();
		DataSize=BufSize;
		return true;
	}
	
	void Clear()
	{
		CurPos=0;
		BufSize=0;
		DataSize=0;
	}
	
	Serializator@SetCurPos(uint pos)
	{
		if(pos>BufSize)
		GrowBuffer(pos-BufSize+(128));
		CurPos=pos;
		return this;
	}
	
	Serializator@Fill(uint8 value,uint length)
	{
		if(CurPos+length>BufSize)
		GrowBuffer(CurPos+length-BufSize+(128));
		for(uint i=0;i<length;i++)
		Array[CurPos++]=value;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@Set(const int64&value)
	{
		if(CurPos+8>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>56)&0xFF;
		Array[CurPos++]=(value>>48)&0xFF;
		Array[CurPos++]=(value>>40)&0xFF;
		Array[CurPos++]=(value>>32)&0xFF;
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const int64&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const int32&value)
	{
		if(CurPos+4>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const int32&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const int16&value)
	{
		if(CurPos+2>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const int16&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const int8&value)
	{
		if(CurPos+1>BufSize)
		GrowBuffer();
		Array[CurPos++]=value;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const int8&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const uint64&value)
	{
		if(CurPos+8>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>56)&0xFF;
		Array[CurPos++]=(value>>48)&0xFF;
		Array[CurPos++]=(value>>40)&0xFF;
		Array[CurPos++]=(value>>32)&0xFF;
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const uint64&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const uint32&value)
	{
		if(CurPos+4>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const uint32&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const uint16&value)
	{
		if(CurPos+2>BufSize)
		GrowBuffer();
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const uint16&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const uint8&value)
	{
		if(CurPos+1>BufSize)
		GrowBuffer();
		Array[CurPos++]=value;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const uint8&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const bool&value)
	{
		if(CurPos+1>BufSize)
		GrowBuffer();
		Array[CurPos++]=value?1:0;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const bool&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const string&value)
	{
		uint len=value.length();
		if(CurPos+len+1>BufSize)
		GrowBuffer(CurPos+len+1-BufSize+(128));
		for(uint i=0;i<len;i++)
		Array[CurPos++]=value[i];
		Array[CurPos++]=0;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const string&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const float&value)
	{
		int dummy=FloatToInt(value);
		return Set(dummy);
	}
	
	Serializator@opShl(const float&value)
	{
		return Set(value);
	}
	
	Serializator@Set(const array<int64>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*8;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<int64>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<int32>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*4;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<int32>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<int16>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*2;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<int16>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<int8>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<int8>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<uint64>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*8;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<uint64>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<uint32>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*4;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<uint32>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<uint16>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*2;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<uint16>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<uint8>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<uint8>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<bool>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<bool>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<string>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen;
		for(uint i=0,j=valuesLen;i<j;i++)
		len+=values[i].length();
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(values[i]);
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<string>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const array<float>&values)
	{
		uint valuesLen=values.length();
		uint len=4+valuesLen*4;
		if(CurPos+len>BufSize)
		GrowBuffer(CurPos+len-BufSize);
		Set(valuesLen);
		for(uint i=0,j=valuesLen;i<j;i++)
		Set(FloatToInt(values[i]));
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const array<float>&values)
	{
		return Set(values);
	}
	
	Serializator@Set(const Critter&cr)
	{
		if(CurPos+4>BufSize)
		GrowBuffer();
		uint value=cr.Id;
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const Critter&cr)
	{
		return Set(cr);
	}
	
	Serializator@Set(const Item&item)
	{
		if(CurPos+4>BufSize)
		GrowBuffer();
		uint value=item.Id;
		Array[CurPos++]=(value>>24)&0xFF;
		Array[CurPos++]=(value>>16)&0xFF;
		Array[CurPos++]=(value>>8)&0xFF;
		Array[CurPos++]=value&0xFF;
		if(CurPos>DataSize)
		DataSize=CurPos;
		return this;
	}
	
	Serializator@opShl(const Item&item)
	{
		return Set(item);
	}
	
	Serializator@Get(int64&value)
	{
		value=0;
		if(CurPos+8>DataSize)
		return this;
		value|=Array[CurPos++]<<56;
		value|=Array[CurPos++]<<48;
		value|=Array[CurPos++]<<40;
		value|=Array[CurPos++]<<32;
		value|=Array[CurPos++]<<24;
		value|=Array[CurPos++]<<16;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(int64&value)
	{
		return Get(value);
	}
	
	Serializator@Get(int32&value)
	{
		value=0;
		if(CurPos+4>DataSize)
		return this;
		value|=Array[CurPos++]<<24;
		value|=Array[CurPos++]<<16;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(int32&value)
	{
		return Get(value);
	}
	
	Serializator@Get(int16&value)
	{
		value=0;
		if(CurPos+2>DataSize)
		return this;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(int16&value)
	{
		return Get(value);
	}
	
	Serializator@Get(int8&value)
	{
		value=0;
		if(CurPos+1>DataSize)
		return this;
		value=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(int8&value)
	{
		return Get(value);
	}
	
	Serializator@Get(uint64&value)
	{
		value=0;
		if(CurPos+8>DataSize)
		return this;
		value|=Array[CurPos++]<<56;
		value|=Array[CurPos++]<<48;
		value|=Array[CurPos++]<<40;
		value|=Array[CurPos++]<<32;
		value|=Array[CurPos++]<<24;
		value|=Array[CurPos++]<<16;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(uint64&value)
	{
		return Get(value);
	}
	
	Serializator@Get(uint32&value)
	{
		value=0;
		if(CurPos+4>DataSize)
		return this;
		value|=Array[CurPos++]<<24;
		value|=Array[CurPos++]<<16;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(uint32&value)
	{
		return Get(value);
	}
	
	Serializator@Get(uint16&value)
	{
		value=0;
		if(CurPos+2>DataSize)
		return this;
		value|=Array[CurPos++]<<8;
		value|=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(uint16&value)
	{
		return Get(value);
	}
	
	Serializator@Get(uint8&value)
	{
		value=0;
		if(CurPos+1>DataSize)
		return this;
		value=Array[CurPos++];
		return this;
	}
	
	Serializator@opShr(uint8&value)
	{
		return Get(value);
	}
	
	Serializator@Get(bool&value)
	{
		value=false;
		if(CurPos+1>DataSize)
		return this;
		value=Array[CurPos++]==1?true:false;
		return this;
	}
	
	Serializator@opShr(bool&value)
	{
		return Get(value);
	}
	
	Serializator@Get(string&str)
	{
		uint len=0;
		for(uint i=CurPos;;i++)
		{
			if(i==DataSize)
			{
				str="";
				return this;
			}
			if(Array[i]==0)
			{
				len=i-CurPos;
				break;
			}
		}
		str.resize(len);
		for(uint i=0;i<len;i++)
		str[i]=Array[CurPos++];
		CurPos++;
		return this;
	}
	
	Serializator@opShr(string&str)
	{
		return Get(str);
	}
	
	Serializator@Get(float&value)
	{
		int dummy=0;
		Get(dummy);
		value=IntToFloat(dummy);
		return this;
	}
	
	Serializator@opShr(float&value)
	{
		return Get(value);
	}
	
	Serializator@Get(array<int64>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<int64>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<int32>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<int32>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<float>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		{
			int dummy=0;
			Get(dummy);
			values[i]=IntToFloat(dummy);
		}
		return this;
	}
	
	Serializator@opShr(array<float>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<int16>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<int16>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<int8>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<int8>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<uint64>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<uint64>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<uint32>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<uint32>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<uint16>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<uint16>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<uint8>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<uint8>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<bool>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<bool>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(array<string>&values)
	{
		uint valuesLen=0;
		Get(valuesLen);
		values.resize(valuesLen);
		for(uint i=0;i<valuesLen;i++)
		Get(values[i]);
		return this;
	}
	
	Serializator@opShr(array<string>&values)
	{
		return Get(values);
	}
	
	Serializator@Get(Critter@&cr)
	{
		@cr=null;
		if(CurPos+4>DataSize)
		return this;
		uint id=0;
		id|=Array[CurPos++]<<24;
		id|=Array[CurPos++]<<16;
		id|=Array[CurPos++]<<8;
		id|=Array[CurPos++];
		@cr=::GetCritter(id);
		return this;
	}
	
	Serializator@opShr(Critter@&cr)
	{
		return Get(cr);
	}
	
	Serializator@Get(Item@&item)
	{
		@item=null;
		if(CurPos+4>DataSize)
		return this;
		uint id=0;
		id|=Array[CurPos++]<<24;
		id|=Array[CurPos++]<<16;
		id|=Array[CurPos++]<<8;
		id|=Array[CurPos++];
		@item=::GetItem(id);
		return this;
	}
	
	Serializator@opShr(Item@&item)
	{
		return Get(item);
	}
	
	array<uint8>Array;
	uint CurPos;
	uint BufSize;
	uint DataSize;
};   

import bool AddToFollowerlist(Critter&master,Critter&follower)from"follower_common";  

uint e_DisableBagRefresh(array<uint>@values)
{
	Critter@cr=GetCritter(values[0]);
	if((@cr!=null))
	{
		cr.SetBagRefreshTime((uint(-1)));
		{;};
	}
	return 0;
}

void NerfWeaponSkills(Critter&cr,uint primary,uint secondary)
{
	for(uint i=(200);i<=(205);i++)
	{
		if(i!=primary&&i!=secondary)
		{
			if(i==(201))
			cr.SkillBase[i]=-80;
			else
			cr.SkillBase[i]=-30;
		}
	}
}

shared interface IMerc
{
	IMerc@Dialog(int dialogid);
	IMerc@Script(string&script);
	IMerc@AI(int aipack);
	IMerc@Bag(int bagid);
	IMerc@Team(int teamid);
	IMerc@Level(int level);
	IMerc@PID(int pid);
	IMerc@PID(array<int>npcpids);
	IMerc@Type(int type);
	IMerc@ID(int id);
	IMerc@Cost(int cost);
	IMerc@StartCost(int cost);
	IMerc@SellPrice(int price);
	IMerc@DynamicPrice();
	
	bool IsDynamicPrice();
	int GetDialog();
	string@GetScript();
	int GetAIPack();
	int GetBagID();
	int GetBagValue();
	int GetTeamID();
	int GetLevel();
	int GetLastPID();
	array<int>GetPIDs();
	uint GetType();
	int8 GetBaseType();
	int GetCost();
	int GetSellPrice();
	uint GetID();
	string@GetName();
	
	bool Spawn(Critter&master);
}; 

class CMerc:IMerc
{
	bool dynamicprice;
	int dir;
	int dialogid;
	string script;
	int aipack;
	int8 basetype;
	int bagid;
	int teamid;
	int level;
	int respawnTime;
	array<int>npcpids;
	int npcpid;
	int cost;
	int bagvalue;
	int startcost;
	uint type;
	int sellprice;
	uint id;
	string name;
	
	Serializator serializer;
	
	CMerc()
	{
		dir=Random(0,6);
		dialogid=(9310);
		script="follower@critter_init";
		basetype=-1;
		aipack=0;
		bagid=0;
		teamid=0;
		level=1;
		respawnTime=(-2);
		cost=0;
		sellprice=0;
		id=0;
		type=0;
		dynamicprice=false;
	}
	
	bool Spawn(Critter&master)
	{
		npcpid=(npcpids[Random(0,npcpids.length()-1)]);
		
		Critter@SpawnedNpc=AddNpc(master.GetMap(),npcpid,master.HexX,master.HexY,dir,dialogid,script,aipack,bagid,teamid,false,level);
		if((@SpawnedNpc!=null))
		{
			SpawnedNpc.FollowerVarBase[(929)]=(master.Stat[(106)]);
			SpawnedNpc.FollowerVarBase[(932)]=type;
			SpawnedNpc.FollowerVarBase[(930)]=id;
			basetype=SpawnedNpc.CrType;
			SpawnedNpc.FollowerVarBase[(933)]=master.Id;
			SpawnedNpc.StatBase[(84)]=respawnTime;
			
			if(type==(3)||type==(4)||type==(2))
			SpawnedNpc.StatBase[(103)]=master.Id;
			
			switch(type)
			{
				case(6):
				case(12):
				NerfWeaponSkills(SpawnedNpc,(204),(203));
				break;
				case(7):
				case(13):
				NerfWeaponSkills(SpawnedNpc,(200),0);
				break;
				case(8):
				case(11):
				NerfWeaponSkills(SpawnedNpc,(201),0);
				break;
				case(5):
				case(10):
				NerfWeaponSkills(SpawnedNpc,(203),(204));
				break;
				case(9):
				NerfWeaponSkills(SpawnedNpc,(202),0);
				break;
				default:
				break;
			}
			
			SpawnedNpc.ChangeCrType(SpawnedNpc.StatBase[(112)]);
			
			CreateTimeEvent(((__FullSecond)+(((3)*60))),"e_DisableBagRefresh",SpawnedNpc.Id,true);
			ArmBestWeapon(SpawnedNpc);
			
			if(Random(0,29-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(306)]+=1;
			if(Random(0,29-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(315)]+=1;
			if(Random(0,49-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(325)]+=1;
			if(Random(0,49-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(420)]+=1;
			if(Random(0,19-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(405)]+=1;
			if(Random(0,19-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(309)]+=1;
			if(Random(0,19-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(313)]+=1;
			if(Random(0,19-master.Stat[(6)])==0)
			SpawnedNpc.PerkBase[(330)]+=1;
			
			for(uint i=0;i<=6;i++)
			SpawnedNpc.StatBase[i]+=Random(-1,1);
			
			if(master.Stat[(3)]>8)
			SpawnedNpc.StatBase[(7)]+=(Random(7,12)*master.Stat[(6)]);
			else if(master.Stat[(3)]<5)
			SpawnedNpc.StatBase[(7)]-=(Random(10,15)-master.Stat[(6)]);
			
			SpawnedNpc.StatBase[(72)]=SpawnedNpc.Stat[(7)];
			
			if(!AddToFollowerlist(master,SpawnedNpc))
			__CompilerLog("Failed to assign merc's id to master("+master.Id+") followerlist");
			
			this.name=GenerateNewName(SpawnedNpc);
			
			if(this.name.length()>0)
			SetLexem(SpawnedNpc,"$name",this.name);
			
			return true;
		}
		else
		{
			__CompilerLog("Failed to create mercenary of PID "+npcpid+" with mercid "+id+" on map id "+master.GetMapId());
			master.Say((11),"Failed to create mercenary, report this error immediately");
		} 
		
		return false;
	}
	
	IMerc@Dialog(int dialogid)
	{
		this.dialogid=dialogid;
		return this;
	}
	
	IMerc@Script(string&script)
	{
		this.script=script;
		return this;
	}
	
	IMerc@AI(int aipack)
	{
		this.aipack=aipack;
		return this;
	}
	
	IMerc@Bag(int bagid)
	{
		this.bagid=bagid;
		
		bagvalue=0;
		array<uint>mincounts,maxcounts;
		array<int>slots;
		array<uint16>pids;
		uint num=GetBagItems(bagid,pids,mincounts,maxcounts,slots);
		uint cost=0;
		for(uint i=0;i<num;i++)
		{
			bagvalue+=BaseItemValue(pids[i],7,80,true)*(mincounts[i]+maxcounts[i])/2;
		}
		
		return this;
	}
	
	IMerc@Team(int teamid)
	{
		this.teamid=teamid;
		return this;
	}
	
	IMerc@Level(int level)
	{
		this.level=level;
		return this;
	}
	
	IMerc@PID(int npcpid)
	{
		this.npcpids.insertLast(npcpid);
		return this;
	}
	
	IMerc@PID(array<int>npcpids)
	{
		for(uint i=0;i<npcpids.length();i++)
		{
			this.npcpids.insertLast(npcpids[i]);
		}
		return this;
	}
	
	IMerc@Type(int type)
	{
		this.type=type;
		return this;
	}
	
	IMerc@ID(int id)
	{
		this.id=id;
		return this;
	}
	
	IMerc@DynamicPrice()
	{
		dynamicprice=true;
		return this;
	}
	
	bool IsDynamicPrice()
	{
		return dynamicprice;
	}
	
	IMerc@StartCost(int cost)
	{
		serializer.Clear();
		if(!serializer.Load("merc_"+id)||GetGvar((12000))==0)
		{
			this.cost=cost;
			serializer.Clear();
			serializer.Set(this.cost).Save("merc_"+id);
		}
		else
		serializer.Get(this.cost);
		
		return this;
	}
	
	IMerc@Cost(int cost)
	{
		{;};
		this.cost=cost;
		
		serializer.Clear();
		serializer.Set(this.cost).Save("merc_"+id);
		
		return this;
	}
	
	IMerc@SellPrice(int sellprice)
	{
		this.sellprice=sellprice;
		return this;
	}
	
	int GetDialog(){return dialogid;}
	string@GetScript(){return script;}
	int8 GetBaseType(){return basetype;}
	int GetAIPack(){return aipack;}
	int GetBagID(){return bagid;}
	int GetTeamID(){return teamid;}
	int GetLevel(){return level;}
	int GetLastPID(){return npcpid;}
	array<int>GetPIDs(){return npcpids;}
	int GetCost(){return cost;}
	int GetBagValue(){return bagvalue;}
	int GetSellPrice(){return sellprice;}
	uint GetID(){return id;}
	uint GetType(){return type;}
	string@GetName(){return name;}
}; 

import bool IsFollowing(Critter&critter)from"follower_common";
import bool IsOwnersFollower(Critter&owner,Critter&critter)from"follower_common";
import bool CanHaveMoreFollowers(Critter&player,uint FollowerType)from"follower_common";
import Critter@GetFollowersOwner(Critter&critter)from"follower_common";
import bool RightDistance(Critter&follower,Critter&owner)from"follower_common";
import bool HasFollowerOfBaseType(Critter&owner,uint basetype)from"follower_common";
import Critter@GetFollowerByBaseType(Critter&owner,uint basetype)from"follower_common";
import bool RemoveFollowerByBaseType(Critter&owner,uint basetype)from"follower_common";
import int GetNumberOfFollowingFollowersOfPlayer(Critter&player)from"follower_common";
import int GetNumberOfFollowersOfPlayer(Critter&player)from"follower_common";
import uint GetSlaveTypes(Critter&player)from"follower_common";
import void ClearFollowersEnemy(Critter&player,Critter&target)from"follower_common";
import void AddFollowersEnemy(Critter&player,Critter&target)from"follower_common";
import uint NumberOfFollowersOnMap(Map@map)from"follower_common";
import uint GetFollowerType(Critter&critter)from"follower_common";
import bool DisbandFollower(Critter&player,Critter&cr,bool reset)from"follower_common";
import bool MakeFollower(Critter&critter,uint type,string&script,uint dialogid,Critter&owner,bool FreeBarter)from"follower_common";
import Critter@LocateFollowerByType(IMerc@merc,Critter&owner)from"follower_common";
import Critter@LocateFollowerByID(uint id,Critter&owner)from"follower_common";
import int GetFollowers(Critter&player,Map@map,array<Critter@>&followers,bool OnlyIsSeen)from"follower_common";
import int GetFollowers(Critter&player,Map@map,array<Critter@>&followers)from"follower_common";
import int GetFollowers(Critter&player,bool all,array<Critter@>&followers)from"follower_common";
import uint CountFollowers(Critter&player,bool all)from"follower_common";
import uint CountFollowers(Critter&player,Map@map)from"follower_common";
import uint GetPartyPointsMax(Critter&player)from"follower_common";
import uint GetPartyPointsUsed(Critter&player)from"follower_common";
import bool IsMerc(Critter&follower)from"follower_common";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

const string@FD_Result2String(int res)
{
	if(res==(0))
	return"FD_RESULT_SUCCESS";
	else if(res==(1))
	return"FD_RESULT_ALREADY_EXISTS";
	else if(res==(2))
	return"FD_RESULT_NOT_FOUND";
	else if(res==(3))
	return"FD_RESULT_ANY_DATA_ERROR";
	else if(res==(4))
	return"FD_RESULT_INVALID_ARGUMENT";
	else if(res==(5))
	return"FD_RESULT_LVAR_ERROR";
	else if(res==(6))
	return"FD_RESULT_DB_NOT_FOUND";
	else if(res==(7))
	return"FD_RESULT_DB_FULL";
	else if(res==(8))
	return"FD_RESULT_DB_EMPTY";
	else
	return"FD_Result: Unknown error code";
}      

import bool IsBigFaction(uint faction)from"factions";
import bool IsTheSameFaction(uint player1Id,uint player2Id)from"factions";
import void _Resign(uint playerId)from"factions"; 

import int RegisterFaction(uint id,const string@name,bool playerDriven)from"factions";
import int RegisterFaction(const string@name,bool playerDriven,uint&out id)from"factions";

import bool RemoveFaction(uint faction)from"factions"; 

import bool GetFactionNameStr(uint faction,string&out name)from"factions";
import bool GetFactionId(const string@name,uint&out id)from"factions"; 

import bool IsFactionNameFree(const string&)from"factions";
import bool IsFactionNameValid(const string&)from"factions";

import bool IsGang(uint faction)from"factions";

import uint16 GetFactionRadioChannel(uint faction)from"factions";
import void SetFactionRadioChannel(uint faction,uint16 channel)from"factions"; 

import int AddPlayer(uint faction,uint id)from"factions";
import int AddPlayer(uint faction,uint id,uint playerFaction)from"factions";
import int AddPlayer(uint faction,uint id,uint playerFaction,uint rank)from"factions";
import int AddPlayer(uint faction,uint id,uint playerFaction,uint rank,uint status)from"factions"; 

import int RemovePlayer(uint faction,uint id)from"factions"; 

import int GetFaction(uint faction,uint id)from"factions";
import int GetStatus(uint faction,uint id)from"factions";
import int GetRank(uint faction,uint id)from"factions";
import bool IsMember(uint faction,Critter&cr)from"factions";
import bool IsMemberOffline(uint faction,uint id)from"factions";
import bool StoredInDB(uint faction,uint id)from"factions";
import uint GetRecordsCount(uint faction)from"factions";
import uint GetMembersCount(uint faction)from"factions";
import uint GetMembers(uint faction,array<uint>&ids)from"factions";
import uint GetLeaderId(uint faction)from"factions";
import void SetLeaderId(uint faction,uint id)from"factions";
import uint GetClaimId(uint faction)from"factions";
import void SetClaimId(uint faction,uint id)from"factions";
import uint GetLeaderTime(uint faction)from"factions";
import void SetLeaderTime(uint faction,uint time)from"factions";
import uint GetClaimTime(uint faction)from"factions";
import void SetClaimTime(uint faction,uint time)from"factions";
import uint GetFactionLocationId(uint faction)from"factions";
import bool GetFactionLocation(uint faction,uint&out locId,uint&out pid,uint&out x,uint&out y)from"factions";

import void GetFactionLocationCoords(uint faction,uint&out x,uint&out y)from"factions";

import uint GetFactionScore(uint faction)from"factions";
import void ModifyFactionScore(uint faction,int amount)from"factions";
import void UpdateLastUsed(uint faction)from"factions";
import uint GetFactionsCount()from"factions"; 

import int GetPrevId(uint faction,uint currId,bool members,uint&out prevId)from"factions";
import int GetNextId(uint faction,uint currId,bool members,uint&out nextId)from"factions";
import int GetFirstId(uint faction,bool members,uint&out id)from"factions"; 

import int ModifyRank(uint faction,uint id,uint newRank)from"factions";
import int ModifyStatus(uint faction,uint id,uint newStatus)from"factions";
import int ModifyFaction(uint faction,uint id,uint newFaction)from"factions"; 

import int InvitePlayer(uint faction,uint playerId)from"factions";
import int ConfirmInvitation(uint faction,uint playerId)from"factions";
import int AddMember(uint faction,uint playerId)from"factions";
import int AddMember(uint faction,uint playerId,bool applyModifiers)from"factions";
import int ChangeRank(uint faction,uint playerId,uint newRank)from"factions";
import int ExpelMember(uint faction,uint playerId)from"factions";
import int ExpelMember(uint faction,uint playerId,bool applyModifiers)from"factions";

import uint GetPlayerFaction(uint playerId)from"factions";
import uint GetPlayerRank(uint playerId)from"factions"; 

import void AddFactionNews(uint faction,uint master,uint slave,uint type)from"factions";
import bool GetFactionNews(uint faction,uint index,uint&out master,uint&out slave,uint&out type,uint16&out year,uint8&out month,uint8&out day,uint8&out hour,uint8&out minute)from"factions";
import uint GetFactionNewsCount(uint faction)from"factions"; 

import uint CheckFactionBaseCoords(uint x,uint y)from"factions";

import bool SaveFactionData(uint faction)from"factions";
import bool FactionExists(uint faction)from"factions"; 

import uint GetFactionLog(uint faction,bool fullLog,array<string>&strings,uint begin,uint end)from"factions";   

import void InitFactions()from"factions";
import void UpdateFactionsInfo(Critter&cr)from"factions";
import IFaction@GetFaction(int)from"factions";
import IFaction@GetFaction(const string&)from"factions";
import IFaction@GetFactionByIdx(int idx)from"factions";
import void UpdateGroupVars(Critter&player)from"factions";     

shared interface IFaction
{
	int get_Id()const;
	string get_Name()const;
	int get_StringId()const;
	string get_Database()const;
	int get_UpdateSeq()const;
	void set_UpdateSeq(int);
	
	int GetStatus(int id)const;
	void SetStatus(int id,int status);
	int GetRank(int id)const;
	void SetRank(int id,int rank);   
	
	int GetMembers(array<uint>&)const;
	int GetRecords(array<uint>&)const;  
	
	void AddKnownFaction(int);   
	
	int GetKnownFactions(array<int>&)const;
	void Remove();
};                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

shared interface IFactionBase
{
	
	uint get_Id()const;
	
	uint get_FactionId()const;
	
	const string&get_Name()const;
	
	uint get_LocationId()const; 
	
	void Show(Critter&cr)const;
	
	void Hide(Critter&cr)const; 
	
	bool IsRankAllowed(int rank)const;
	
	void AllowRank(int rank,bool allow);
	
	bool IsStatusAllowed(int status)const;
	
	void AllowStatus(int status,bool allow); 
	
	void Remove();
};  

import IFactionBase@GetFactionBase(uint faction_id,const string&faction_name)from"factions_bases";
import IFactionBase@GetFactionBase(uint id)from"factions_bases";
import IFactionBase@GetFactionBaseByLocId(uint id)from"factions_bases";
import uint GetFactionBases(uint faction_id,array<IFactionBase@>@)from"factions_bases";
import bool AddFactionBase(IFactionBase&)from"factions_bases";
import void AddFactionBase(uint)from"factions_bases";
import IFactionBase@CreateFactionBase(uint faction_id,const string&name,uint location_id)from"factions_bases";
import void RemoveFactionBase(uint,const string&)from"factions_bases";
import void RemoveFactionBase(IFactionBase&)from"factions_bases";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

bool GM_IsGameMaster(uint playerId)
{
	GameVar@var=GetLocalVar((4120),playerId);
	if(!(@var!=null))
	return false;
	else
	return var.GetValue()==1;
}   

int GM_GetCredit(uint playerId)
{
	GameVar@var=GetLocalVar((4121),playerId);
	if(!(@var!=null))
	return 0;
	else
	return var.GetValue();
}   

void GM_GiveCredit(uint playerId,uint amount)
{
	if(!GM_IsGameMaster(playerId))
	return;
	
	GameVar@var=GetLocalVar((4121),playerId);
	
	var+=amount;
}   

void GM_DeduceCredit(uint playerId,uint amount)
{
	if(!GM_IsGameMaster(playerId))
	return;
	
	GameVar@var=GetLocalVar((4121),playerId);
	
	var-=amount;
}   

void GM_BindNpc(uint playerId,uint npcId)
{
	if(!GM_IsGameMaster(playerId))
	return;
	
	GameVar@var=GetLocalVar((4122),playerId);
	
	var=npcId;
}   

void ExecGMCommand(array<string@>@command,Critter&player,Critter@target)
{
	player.Say((11),"Assigning GM");
	
	if(target.Id==player.Id)
	{
		player.Say((11),"You can't make GM out of yourself");
		return;
	}
	if(!target.IsPlayer())
	{
		player.Say((11),"Target has to be player");
		return;
	}
	
	GameVar@var=GetLocalVar((4120),target.Id);
	var=(1); 
	
	string s_credit=GetParameterString(command,"-c");
	int credit=0;
	StrToInt(s_credit,credit);
	if(credit>0)
	{
		GM_GiveCredit(target.Id,credit);
		player.Say((11),"Credit points: "+credit);
	} 
	
	string npc=GetParameterString(command,"-t");
	int npcId=0;
	StrToInt(npc,npcId);
	if(npcId!=0)
	{
		GM_BindNpc(target.Id,npcId);
		player.Say((11),"Bound to npc: "+npcId);
	}
}           

void ExecModCharCommand(array<string@>@command,Critter&player,Critter@target)
{
	player.Say((11),"Modifying GM character...");
	
	string stat=GetParameterString(command,"-s");
	if(stat!="")
	{
		int val=0;
		StrToInt(GetParameterString(command,"-v"),val);
		ModifyStat(player,target,stat,val);
	}
	string armor=GetParameterString(command,"-a");
	if(armor!="")
	{
		ModifyArmor(player,target,armor);
	}
}    

void ModifyArmor(Critter&player,Critter@target,const string&armor)
{
	if(armor=="body")
	{
		player.Say((11),"Wearing off cheated armor");
		mod_armor(target,0,0,0,0,0,0,0,0,0,0,0,0,0);
	}
	else if(armor=="lj")
	{
		player.Say((11),"Setting armor to leather jacket");
		mod_armor(target,8,0,20,0,20,0,10,0,10,0,20,0,30);
	}
	else if(armor=="la")
	{
		player.Say((11),"Setting armor to leather armor");
		mod_armor(target,15,2,25,0,20,0,20,0,10,0,20,0,30);
	}
	else if(armor=="ma")
	{
		player.Say((11),"Setting armor to metal armor");
		mod_armor(target,10,4,30,6,75,4,10,4,20,4,25,0,0);
	}
	else if(armor=="ca")
	{
		player.Say((11),"Setting armor to combat armor");
		mod_armor(target,20,5,40,8,60,4,30,4,50,6,40,2,50);
	}
	else if(armor=="pa")
	{
		player.Say((11),"Setting armor to powered armor");
		mod_armor(target,25,12,40,18,80,12,60,10,40,20,50,12,40);
	}
	else if(armor=="apa")
	{
		player.Say((11),"Setting armor to a-sucky-pa");
		mod_armor(target,30,15,55,19,90,16,70,15,60,20,65,15,60);
	}
	else if(armor=="god")
	{
		player.Say((11),"Setting an uber armor");
		mod_armor(target,90,9999,100,9999,100,9999,100,9999,100,9999,100,9999,100);
	}
} 

void mod_armor(Critter@crit,int ac,
int dt_norm,int dr_norm,
int dt_laser,int dr_laser,
int dt_fire,int dr_fire,
int dt_plasma,int dr_plasma,
int dt_explode,int dr_explode,
int dt_electrical,int dr_electrical)
{
	crit.StatBase[(9)]=ac;
	crit.StatBase[(16)]=dt_norm;
	crit.StatBase[(23)]=dr_norm;
	crit.StatBase[(17)]=dt_laser;
	crit.StatBase[(24)]=dr_laser;
	crit.StatBase[(18)]=dt_fire;
	crit.StatBase[(25)]=dr_fire;
	crit.StatBase[(19)]=dt_plasma;
	crit.StatBase[(26)]=dr_plasma;
	crit.StatBase[(22)]=dt_explode;
	crit.StatBase[(29)]=dr_explode;
	crit.StatBase[(20)]=dt_electrical;
	crit.StatBase[(27)]=dr_electrical;
}   

bool ModifyStat(Critter&player,Critter@target,const string&stat,int val)
{
	player.Say((11),"Modifying stat...");
	
	if(stat.length()==3)
	{
		if(stat[2]==43)
		val=1;
		else if(stat[2]==45)
		val=-1;
		else
		return false;
		
		string sub=substring(stat,0,2);
		if(sub=="st")
		target.StatBase[(0)]+=val;
		else if(sub=="pe")
		target.StatBase[(1)]+=val;
		else if(sub=="en")
		target.StatBase[(2)]+=val;
		else if(sub=="ch")
		target.StatBase[(3)]+=val;
		else if(sub=="in")
		target.StatBase[(4)]+=val;
		else if(sub=="ag")
		target.StatBase[(5)]+=val;
		else if(sub=="lk")
		target.StatBase[(6)]+=val;
		else
		{
			player.Say((11),"Wrong stat");
			return false;
		}
		
		if(val==1)
		player.Say((11),"Incremented "+sub);
		if(val==-1)
		player.Say((11),"Decremented "+sub);
	}
	
	else
	{
		if(val<1||val>10)
		{
			player.Say((11),"Incorrect stat value");
			return false;
		}
		
		if(stat=="st")
		target.StatBase[(0)]=val;
		else if(stat=="pe")
		target.StatBase[(1)]=val;
		else if(stat=="en")
		target.StatBase[(2)]=val;
		else if(stat=="ch")
		target.StatBase[(3)]=val;
		else if(stat=="in")
		target.StatBase[(4)]=val;
		else if(stat=="ag")
		target.StatBase[(5)]=val;
		else if(stat=="lk")
		target.StatBase[(6)]=val;
		else
		{
			player.Say((11),"Wrong stat");
			return false;
		}
		player.Say((11),"Modified "+stat+" to "+val);
	}
	return true;
}                                                                                                                                                                                                                                     

int GetRootMapData(Map&map,uint index)
{
	return map.GetLocation().GetMapByIndex(0).GetData(index);
}  

void SetRootMapData(Map&map,uint index,int val)
{
	map.GetLocation().GetMapByIndex(0).SetData(index,val);
}   

int GetRootMapData(Location&loc,uint index)
{
	return loc.GetMapByIndex(0).GetData(index);
}  

void SetRootMapData(Location&loc,uint index,int val)
{
	loc.GetMapByIndex(0).SetData(index,val);
}                                                  

import void SetMinigame(Critter&cr,int team,int id,int flags,int data)from"minigames";
import void UnsetMinigame(Critter&cr)from"minigames";
import void UnsetMinigame(Critter&cr,bool refreshColors)from"minigames";
import void ChangeMinigameTeam(Critter&cr,int team)from"minigames";
import int GetMinigameTeamColor(int minigameTeam)from"minigames";

import Item@GetDSpawn(Map@map,int minigameData)from"minigames";
import Item@GetNextDSpawn(Item@dSpawn,int minigameTeamAndId,bool reverse)from"minigames";

import void _DSpawn(Item&item,bool firstTime)from"minigames";
import void _DSpawnWalk(Item&item,Critter&crit,bool entered,uint8 dir)from"minigames";
import bool _DSpawnSkill(Item&item,Critter&crit,int skill)from"minigames";

import bool TryCaptureDSpawn(Item@dSpawn,Critter@crit)from"minigames";
import void CaptureDSpawn(Item@dSpawn,Critter@crit,uint minigameTeamAndId)from"minigames";
import uint CaptureDSpawnTick(array<int>@eventValues)from"minigames";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

void AI_TrySayCombatText(Critter&npc,int textType)
{
	AI_TrySayCombatText(npc,textType,false);
}

void AI_TrySayCombatText(Critter&npc,int textType,bool force)
{
	if(!npc.IsLife())
	return;
	uint ai=npc.Stat[(105)];
	if(!force&&AIData_[(((ai)<(286)?(ai):0)*22+16)]<Random(1,230))
	return;
	
	uint start=0,end=0;
	if(textType>=(0)&&textType<=(3))
	{
		start=AIGeneralMsg_[AIData_[(((ai)<(286)?(ai):0)*22+17)]*8+textType*2];
		end=AIGeneralMsg_[AIData_[(((ai)<(286)?(ai):0)*22+17)]*8+textType*2+1];
	}
	else if(textType>=(10)&&textType<=(17))
	{
		textType-=10;
		start=AIBodyMsg_[AIData_[(((ai)<(286)?(ai):0)*22+18)]*16+textType*2];
		end=AIBodyMsg_[AIData_[(((ai)<(286)?(ai):0)*22+18)]*16+textType*2+1];
	}
	else
	return;
	if(start<=end)
	npc.SayMsg((2),(5),Random(start,end)*10);
}

const int[]AIData_=
{
	
	10,15,3,1,1,(1),(3),(0),(1),(0),(4),(1),(2),(0),10,5,0,45,27,0,0,0,
	90,20,5,30,1,(0),(1),(0),(0),(0),(2),(2),0,(0),30,3,25,6,7,0,0,0,
	10,12,15,40,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),3,20,20,6,7,0,0,0,
	40,15,15,35,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),100,15,80,6,7,0,0,0,
	20,15,14,50,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,4,75,6,7,0,0,0,
	100,1,0,0,0,(0),(0),(6),(0),(0),(0),0,0,(0),10,10,0,45,27,0,0,0,
	10,15,0,0,0,(0),(0),(1),(0),(0),(0),(1),(2),(0),25,1000000,0,45,27,0,0,0,
	45,15,0,0,0,(0),(0),(1),(0),(0),(0),(2),0,(0),1000000,40,0,45,27,0,0,0,
	60,15,0,0,0,(0),(0),(1),(0),(0),(0),(2),0,(0),10000,10,0,45,27,0,0,0,
	40,17,0,0,0,(0),(0),(1),(0),(0),(0),(1),(2),(0),1000000,30,0,45,27,0,0,0,
	70,20,0,10,1,(0),(4),(3),(0),(0),(0),(1),(2),(0),20,15,0,45,27,0,0,0,
	20,10,30,20,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,30,35,11,10,0,0,0,
	80,20,4,20,1,(4),(4),(4),(3),(0),(0),(1),(2),(5),5,5,30,3,2,0,0,0,
	80,10,10,40,1,(0),(2),(0),(0),(0),(0),(1),(2),(4),1000,15,15,2,2,0,0,0,
	30,10,12,34,1,(0),(4),(0),(0),(0),(0),(1),(2),(3),10000,30,10,0,0,0,0,0,
	0,8,20,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,35,45,27,0,0,0,
	65,10,10,25,1,(4),(2),(4),(1),(0),(2),(1),(2),(4),10,8,23,2,2,0,0,0,
	33,8,8,30,1,(2),(4),(0),(0),(0),(0),(1),(2),(5),5000,20,25,1,1,0,0,0,
	90,15,1,25,1,(0),(0),(0),(0),(0),(0),(2),0,(0),40,8,16,5,2,0,0,0,
	20,10,10,28,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),3,1500,30,1,1,0,0,0,
	
	70,12,8,24,1,(0),(4),(0),(0),(0),(0),(1),(2),(4),80,30,20,0,0,0,0,0,
	80,18,0,0,0,(0),(0),(1),(0),(0),(0),(2),0,(0),600,200,0,45,27,0,0,0,
	95,19,1,15,1,(4),(4),(4),(0),(0),(2),0,0,(5),10,3,25,5,2,0,0,0,
	100,25,0,0,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,3,18,4,4,0,0,0,
	60,12,10,30,1,(0),(4),(0),(3),(0),(0),(1),(2),(5),75,20,25,2,2,0,0,0,
	95,7,0,0,1,(0),(4),(0),(3),(1),(1),(1),(2),(6),5,100,20,45,27,0,0,0,
	50,10,0,0,0,(0),(0),(1),(5),(0),(0),(1),(2),(0),20,20,0,45,27,(284),(81),(103),
	95,10,0,0,0,(0),(0),(1),(0),(0),(0),(1),(2),(0),20,20,0,45,27,0,0,0,
	50,10,0,10,0,(0),(4),(1),(0),(0),(1),(1),(2),(6),20,20,10,44,4,0,0,0,
	60,10,5,30,1,(0),(4),(3),(0),(0),(1),(1),(2),(6),20,20,0,45,27,0,0,0,
	50,10,10,30,1,(0),(2),(0),(0),(0),(0),(2),0,(0),20,20,15,9,6,0,0,0,
	100,13,0,0,1,(0),(4),(0),(0),(0),(0),(2),0,(0),20,20,20,9,6,0,0,0,
	90,10,0,0,1,(2),(4),(0),(0),(0),(2),(2),0,(6),10,10,25,9,6,0,0,0,
	20,10,30,30,1,(0),(0),(0),(0),(0),(0),(2),0,(0),20,20,25,0,0,0,0,0,
	40,10,10,20,1,(0),(4),(0),(0),(0),(0),(1),(2),(6),20,20,0,45,27,0,0,0,
	50,10,10,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,20,20,10,8,0,0,0,
	80,10,10,20,1,(1),(4),(4),(0),(0),(3),(1),(2),(0),20,4,25,10,8,0,0,0,
	40,10,10,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,20,10,10,8,0,0,0,
	80,15,8,10,1,(1),(4),(2),(5),(0),(1),(1),(2),(6),33,2,15,4,4,0,0,0,
	20,10,0,25,0,(0),(0),(0),(5),(0),(0),(1),(2),(0),20,2,0,45,27,(284),(81),(103),
	
	80,10,3,10,1,(0),(0),(0),(0),(0),(0),0,0,(6),2,200000,10,43,26,0,0,0,
	20,8,20,10,1,(0),(4),(0),(0),(0),(0),(1),(2),(0),20,20,20,1,1,0,0,0,
	2,5,30,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,20,18,2,2,0,0,0,
	35,5,15,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,20000,15,1,1,0,0,0,
	35,10,15,40,1,(0),(2),(0),(0),(0),(0),(1),(2),(4),20,15,15,2,2,0,0,0,
	35,7,15,40,1,(0),(0),(0),(1),(0),(0),(1),(2),(4),20,15,15,0,0,0,0,0,
	0,3,15,40,1,(2),(2),(2),(1),(0),(2),(1),(2),(3),20,15,15,0,0,0,0,0,
	95,15,1,20,1,(0),(4),(0),(0),(1),(0),(1),(2),(0),20,15,15,31,16,0,0,0,
	87,10,0,0,0,(0),(0),(1),(0),(0),(0),(1),(2),(0),20,15,0,45,27,0,0,0,
	35,5,15,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),20,20000,15,0,0,0,0,0,
	75,12,0,10,0,(4),(3),(3),(4),(0),(4),(1),(2),(0),20,200,0,45,27,(81),0,0,
	95,15,7,10,1,(0),(4),(0),(0),(0),(0),(1),(2),(0),20,1,15,10,8,0,0,0,
	45,12,10,10,1,(4),(3),(3),(4),(0),(4),(1),(2),(0),20,200,0,11,10,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(6),10,5,25,2,2,(81),0,0,
	45,12,10,10,1,(4),(2),(4),(3),(4),(2),(1),(2),(4),10,5,25,2,2,(81),0,0,
	45,12,10,10,1,(3),(0),(4),(3),(3),(5),(1),(2),(4),10,5,25,2,2,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(2),10,5,25,2,2,(81),0,0,
	1,12,10,10,1,(4),(4),(4),(3),(0),(4),(1),(2),(4),10,5,25,2,2,(81),0,0,
	45,12,10,10,1,(4),(4),(0),(1),(5),(2),(1),(2),(2),10,5,25,38,23,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(2),10,10,25,38,23,(81),0,0,
	
	45,12,10,10,1,(4),(0),(0),(3),(3),(5),(1),(2),(2),10,10,25,38,23,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(3),(0),(5),(1),(2),(1),20,200,25,38,23,(81),0,0,
	45,12,10,10,1,(4),(4),(4),(1),(0),(5),(1),(2),(2),10,10,25,38,23,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(1),(5),(2),(1),(2),(6),10,5,15,42,25,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(3),(4),(2),(1),(2),(5),10,10,15,42,25,(81),0,0,
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(4),20,200,15,42,25,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(3),20,200,15,42,25,(81),0,0,
	30,12,10,10,1,(4),(0),(0),(3),(0),(2),(3),0,(5),5,10,20,42,25,(81),0,0,
	45,12,10,10,1,(2),(3),(4),(3),(5),(2),(1),(2),(6),10,5,15,39,24,(81),0,0,
	45,12,10,10,1,(4),(3),(4),(3),(4),(2),(1),(2),(5),10,10,15,39,24,(81),0,0,
	45,12,10,10,1,(4),(0),(4),(3),(3),(4),(1),(2),(4),10,10,15,39,24,(81),0,0,
	45,12,10,10,1,(2),(4),(4),(2),(0),(5),(1),(2),(4),10,10,15,39,24,(81),0,0,
	45,12,10,10,1,(4),(3),(4),(3),(0),(2),(1),(2),(5),10,10,15,39,24,(81),0,0,
	45,12,10,10,1,(1),(4),(5),(4),(5),(1),(1),(2),(6),10,5,35,33,17,(81),0,0,
	45,12,10,10,1,(2),(4),(5),(3),(4),(2),(1),(2),(5),10,5,35,33,17,(81),0,0,
	45,12,10,10,1,(4),(0),(5),(3),(3),(4),(1),(2),(5),10,5,35,33,17,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(5),10,10,35,33,17,(81),0,0,
	75,12,10,10,1,(4),(1),(5),(3),(0),(1),(1),(2),(5),10,5,35,33,17,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(6),20,200,25,37,21,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(4),20,200,25,37,21,(81),0,0,
	
	45,12,10,10,1,(2),(0),(4),(2),(3),(4),(1),(2),(3),10,2,25,37,21,(81),0,0,
	45,12,10,10,1,(2),(2),(4),(2),(0),(4),(1),(2),(2),10,2,25,37,21,(81),0,0,
	50,12,10,10,1,(2),(2),(4),(2),(0),(4),(1),(2),(4),10,2,25,37,21,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(0),(5),(1),(1),(2),(6),20,200,10,46,27,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(0),(4),(1),(1),(2),(5),20,200,10,46,27,(81),0,0,
	45,12,10,10,1,(0),(0),(3),(0),(3),(4),(1),(2),(5),20,200,10,46,27,(81),0,0,
	45,12,10,10,1,(0),(2),(3),(0),(0),(2),(1),(2),(3),20,200,10,46,27,(81),0,0,
	80,12,0,10,1,(0),(0),(3),(0),(0),(4),0,0,(5),20,200,10,46,27,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(5),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(4),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(3),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(2),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(0),(4),(1),(2),(3),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(3),(5),(1),(1),(2),(6),20,200,25,36,20,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(3),(4),(1),(1),(2),(5),20,200,25,36,20,(81),0,0,
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(4),20,200,25,36,20,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(2),(0),(1),(1),(2),(5),20,200,25,36,20,(81),0,0,
	45,12,10,10,1,(0),(4),(3),(3),(0),(1),(1),(2),(5),20,200,25,36,20,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(6),20,200,20,1,1,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(5),20,200,20,1,1,(81),0,0,
	
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(4),20,200,20,1,1,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(2),20,200,20,1,1,(81),0,0,
	45,12,25,10,1,(5),(2),(0),(2),(0),(2),(1),(2),(4),20,200,20,1,1,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(6),20,200,15,1,1,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(5),20,200,15,1,1,(81),0,0,
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(4),20,200,15,1,1,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(3),20,200,15,1,1,(81),0,0,
	45,12,10,10,1,(3),(0),(4),(2),(0),(4),(1),(2),(4),20,200,15,1,1,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(6),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(5),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(4),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(2),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(1),(3),(0),(0),(1),0,0,(4),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(1),(3),(0),(0),(5),(2),(1),(2),(6),10,10,15,35,19,0,0,0,
	45,12,10,10,1,(2),(3),(0),(0),(4),(2),(1),(2),(5),10,10,15,35,19,(81),0,0,
	45,12,10,10,1,(3),(0),(4),(0),(3),(4),(1),(2),(5),10,5,15,35,19,(81),0,0,
	45,12,10,10,1,(1),(2),(3),(0),(0),(3),(1),(2),(1),10,10,15,35,19,(81),0,0,
	50,12,10,10,1,(1),(4),(3),(0),(0),(3),0,0,(0),10,10,15,35,19,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(4),(5),(4),(1),(2),(5),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(3),(0),(3),(4),(2),(1),(2),(4),20,200,0,45,27,(81),0,0,
	
	45,12,10,10,1,(3),(0),(0),(3),(3),(4),(1),(2),(3),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(2),(4),(0),(2),(0),(5),(1),(2),(2),20,200,0,45,27,(81),0,0,
	45,12,10,10,1,(4),(3),(3),(0),(0),(4),(1),(2),(3),20,200,0,45,27,(81),0,0,
	1,3,15,80,0,(4),(2),(3),(4),(0),(4),(1),(2),(1),20,200,0,45,27,(81),0,0,
	100,12,3,10,1,(4),(3),(4),(1),(0),(2),(1),(2),(0),5,4,35,32,2,(81),0,0,
	100,12,1,0,1,(4),(3),(3),(4),(0),(4),0,0,(0),2,20,0,2,2,(81),0,0,
	90,20,1,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),3000,30000,25,2,2,0,0,0,
	90,20,1,10,1,(4),(4),(4),(3),(0),(2),0,0,(5),5,4,25,5,2,0,0,0,
	90,20,1,10,1,(4),(4),(0),(0),(0),(0),0,0,(0),3000,5,30,14,22,0,0,0,
	90,20,1,10,1,(4),(4),(4),(0),(0),(2),0,0,(0),3000,5,25,31,16,0,0,0,
	100,20,1,10,1,(0),(0),(1),(0),(0),(0),0,0,(0),300,300,0,45,27,0,0,0,
	90,20,1,10,1,(0),(2),(3),(0),(0),(0),0,0,(0),3000,30000,0,45,27,0,0,0,
	90,20,1,10,0,(0),(0),(1),(0),(0),(0),0,0,(0),3000,30000,0,45,27,0,0,0,
	90,20,1,10,0,(0),(4),(3),(0),(0),(1),0,0,(6),5,30000,0,45,27,0,0,0,
	90,10,1,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),25,25,25,5,2,0,0,0,
	90,20,1,10,1,(4),(4),(4),(0),(0),(5),0,0,(0),3,3,25,13,11,0,0,0,
	90,20,1,10,1,(4),(3),(4),(0),(0),(2),0,0,(0),3,3,25,12,11,0,0,0,
	90,20,1,10,1,(0),(2),(0),(0),(0),(0),0,0,(0),3,3,0,45,27,0,0,0,
	10,10,10,10,1,(0),(4),(0),(0),(1),(1),0,0,(6),10,5000,30,17,12,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(5),(0),0,0,(0),10,5000,30,18,12,0,0,0,
	
	10,10,10,10,1,(0),(4),(0),(0),(1),(0),0,0,(3),10,5000,15,1,1,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,50,26,15,0,0,0,
	10,10,0,0,1,(4),(4),(0),(0),(1),(2),0,0,(6),5,5,15,45,27,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,6,7,0,0,0,
	10,10,10,10,0,(0),(0),(4),(0),(1),(0),0,0,(0),10,5000,15,45,27,0,0,0,
	10,10,0,0,1,(0),(3),(0),(0),(1),(0),(2),0,(6),10,5000,30,41,6,0,0,0,
	10,10,0,0,0,(0),(4),(1),(0),(1),(0),0,0,(6),4,5000,30,40,27,0,0,0,
	10,10,10,10,1,(1),(4),(0),(0),(1),(0),0,0,(5),10,5000,15,2,2,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,11,10,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,45,27,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,25,13,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,24,13,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,20,14,0,0,0,
	10,10,35,10,1,(0),(4),(0),(0),(1),(0),0,0,(5),10,5000,15,22,12,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,19,14,0,0,0,
	10,10,10,10,1,(0),(2),(0),(0),(1),(0),(2),(3),(5),10,2,15,21,14,0,0,0,
	10,12,10,0,1,(4),(4),(4),(3),(1),(5),(2),0,(5),10,2,25,22,12,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,23,13,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,23,13,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,23,13,0,0,0,
	
	10,10,10,10,1,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,15,23,13,0,0,0,
	10,10,10,10,1,(3),(2),(0),(0),(1),(0),0,0,(5),5,10,15,2,14,0,0,0,
	10,10,10,10,1,(1),(4),(4),(4),(1),(1),(2),0,(6),20,6,15,8,9,(87),0,0,
	100,50,1,50,1,(1),(4),(0),(2),(1),(0),0,0,(6),10,5000,30,8,9,0,0,0,
	10,10,10,10,0,(0),(0),(3),(0),(4),(1),0,0,(6),10,5000,15,45,27,0,0,0,
	10,10,10,10,0,(0),(4),(3),(0),(5),(1),0,0,(6),10,5000,15,45,27,0,0,0,
	10,10,10,10,0,(0),(4),(3),(0),(0),(4),0,0,(4),10,5000,15,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(3),(0),(0),(1),0,0,(5),10,5000,15,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(3),(0),0,0,(0),10,5000,15,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	10,10,10,10,0,(0),(0),(0),(0),(1),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	100,15,0,0,1,(0),(4),(0),(0),(1),(3),(2),(3),(6),1,5000,25,9,6,0,0,0,
	10,10,10,10,1,(2),(4),(4),(3),(1),(2),0,0,(5),2,3,25,5,2,(40),0,0,
	10,10,10,10,1,(0),(4),(0),(0),(0),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	100,15,0,0,1,(0),(2),(0),(0),(1),(0),0,0,(6),10,5000,25,44,4,0,0,0,
	10,10,10,80,0,(0),(0),(1),(0),(1),(0),0,0,(1),10,5000,15,45,27,0,0,0,
	10,10,100,90,1,(0),(0),(0),(0),(0),(0),0,0,(1),10,5000,15,0,0,0,0,0,
	
	10,10,10,10,1,(0),(0),(0),(0),(1),(3),0,0,(6),10,5000,15,0,0,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),10,5000,15,2,2,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),10,5000,15,2,2,0,0,0,
	100,20,0,0,1,(1),(4),(0),(0),(1),(2),0,0,(6),10,2,25,4,4,0,0,0,
	10,10,10,10,1,(0),(0),(0),(0),(0),(0),0,0,(1),10,5000,15,6,7,0,0,0,
	100,20,0,0,1,(1),(3),(0),(4),(1),(2),(2),0,(6),10,2,25,6,7,0,0,0,
	10,10,10,10,0,(0),(0),(1),(0),(0),(0),0,0,(0),10,5000,0,45,27,0,0,0,
	10,15,3,1,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10,5,0,45,27,0,0,0,
	80,22,0,1,1,(0),(0),(0),(0),(0),(0),0,0,(0),30,3,25,50,31,0,0,0,
	10,12,12,35,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),3,6,20,51,32,0,0,0,
	5,15,12,30,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,5,0,45,27,0,0,0,
	20,15,5,1,1,(0),(0),(0),(0),(0),(0),(3),0,(0),20,4,25,0,0,0,0,0,
	1,10,15,80,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),100,100,20,55,36,0,0,0,
	10,15,10,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),25,8,20,47,28,0,0,0,
	40,20,1,20,1,(0),(0),(0),(0),(0),(0),(2),0,(0),10,4,25,48,29,0,0,0,
	60,12,4,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,10,0,45,27,0,0,0,
	40,12,10,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000000,30,20,81,62,0,0,0,
	60,12,3,15,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),25,15,20,82,63,0,0,0,
	70,15,8,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,25,109,90,0,0,0,
	80,6,1,2,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,3,108,89,0,0,0,
	
	80,10,4,5,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,0,45,27,0,0,0,
	90,10,1,8,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,30,0,45,27,0,0,0,
	70,10,6,20,1,(0),(0),(0),(0),(0),(0),(2),0,(0),10000,30,25,49,30,0,0,0,
	75,10,10,20,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),15,25,23,57,38,0,0,0,
	33,10,8,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),50,20,25,58,39,0,0,0,
	55,12,8,20,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),40,30,10,59,40,0,0,0,
	60,15,4,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),30,15,30,60,41,0,0,0,
	80,12,6,14,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),80,30,20,112,93,0,0,0,
	70,18,8,17,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),60,20,25,112,93,0,0,0,
	78,10,3,30,1,(0),(0),(0),(0),(0),(0),0,0,(0),20,10,20,62,43,0,0,0,
	20,9,12,40,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,18,63,44,0,0,0,
	60,12,16,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),75,20,25,64,45,0,0,0,
	40,14,12,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10,15,20,65,46,0,0,0,
	95,12,10,5,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),100,8,30,66,47,0,0,0,
	80,10,5,15,1,(0),(0),(0),(0),(0),(0),(2),0,(0),10000,30,15,67,48,0,0,0,
	75,10,15,18,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,20,68,49,0,0,0,
	90,12,2,25,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),12,8,30,69,50,0,0,0,
	40,8,20,45,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),80,18,15,70,51,0,0,0,
	50,10,5,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),40,12,25,71,52,0,0,0,
	65,14,5,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,10,72,53,0,0,0,
	
	80,12,10,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),18,8,20,73,54,0,0,0,
	60,12,20,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,20,74,55,0,0,0,
	94,10,2,15,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,30,30,75,56,0,0,0,
	80,14,1,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,15,76,57,0,0,0,
	80,12,2,20,1,(0),(0),(0),(0),(0),(0),(2),0,(0),8,4,30,77,58,0,0,0,
	80,12,25,25,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),9,1,25,78,59,0,0,0,
	50,10,20,40,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10,10,25,79,60,0,0,0,
	20,7,18,50,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,20,80,61,0,0,0,
	40,10,12,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000000,100,15,81,62,0,0,0,
	60,12,5,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000000,1000,10,53,34,0,0,0,
	60,12,10,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),4,4,100,124,105,0,0,0,
	60,12,5,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000000,1000,30,53,34,0,0,0,
	60,12,5,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000000,1000,30,53,34,0,0,0,
	40,14,5,10,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),10,4,25,82,63,0,0,0,
	50,14,5,25,1,(0),(0),(0),(0),(0),(0),(2),0,(0),10,4,30,54,35,0,0,0,
	90,14,1,30,1,(0),(0),(0),(0),(0),(0),0,0,(0),10,4,30,84,65,0,0,0,
	90,20,1,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),6,2,20,85,66,0,0,0,
	30,10,20,5,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,30,86,67,0,0,0,
	30,10,8,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,15,87,68,0,0,0,
	60,10,16,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),75,20,20,88,69,0,0,0,
	
	50,7,13,35,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),200,50,15,89,70,0,0,0,
	70,6,1,20,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,30,0,45,27,0,0,0,
	50,10,8,45,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),1000,30,18,90,71,0,0,0,
	70,15,3,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,20,91,72,0,0,0,
	70,10,1,20,1,(0),(0),(0),(0),(0),(0),(3),(2),(0),10000,30,20,92,73,0,0,0,
	85,10,8,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,35,93,74,0,0,0,
	80,10,5,25,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,30,35,94,75,0,0,0,
	70,10,1,15,1,(0),(0),(0),(0),(0),(0),0,0,(0),4,30,20,95,76,0,0,0,
	55,12,20,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),16,30,20,96,77,0,0,0,
	50,12,1,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),40,20,20,97,78,0,0,0,
	30,12,12,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),200,20,15,98,79,0,0,0,
	70,10,1,15,1,(0),(0),(0),(0),(0),(0),(2),0,(0),20,10,25,99,80,0,0,0,
	80,10,1,10,1,(0),(0),(0),(0),(0),(0),(2),0,(0),10,6,8,100,81,0,0,0,
	70,14,1,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),14,6,12,52,33,0,0,0,
	10,7,12,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,15,102,83,0,0,0,
	20,8,15,10,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,35,121,102,0,0,0,
	70,10,1,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,20,110,91,0,0,0,
	100,14,1,1,1,(0),(0),(0),(0),(0),(0),0,0,(0),4,3,20,105,86,0,0,0,
	70,10,10,20,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,8,15,104,85,0,0,0,
	73,10,15,20,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,30,0,45,27,0,0,0,
	
	77,10,1,30,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,30,0,45,27,0,0,0,
	70,12,10,20,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,30,5,104,85,0,0,0,
	60,10,15,25,1,(0),(0),(0),(0),(0),(0),(1),0,(0),10000,30,20,107,88,0,0,0,
	30,10,12,25,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,25,20,61,42,0,0,0,
	20,8,8,20,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,15,103,84,0,0,0,
	90,8,10,10,1,(0),(0),(0),(0),(0),(0),0,0,(0),10000,30,25,106,87,0,0,0,
	75,12,10,25,1,(0),(0),(0),(0),(0),(0),(2),(1),(0),10000,30,20,111,92,0,0,0,
	20,8,1,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),12,12,15,101,82,0,0,0,
	20,8,1,30,1,(0),(0),(0),(0),(0),(0),(3),0,(0),12,12,30,113,94,0,0,0,
	50,12,20,15,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),2,2,35,114,95,0,0,0,
	90,15,1,15,1,(0),(0),(0),(0),(0),(0),(2),0,(0),4,3,35,115,96,0,0,0,
	10,12,20,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),44,22,25,116,97,0,0,0,
	45,8,15,30,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),10000,30,22,117,98,0,0,0,
	80,30,10,20,1,(0),(0),(0),(0),(0),(0),(2),0,(0),8,5,30,118,99,0,0,0,
	45,6,18,35,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),100,18,25,119,100,0,0,0,
	70,8,8,20,1,(0),(0),(0),(0),(0),(0),(2),0,(0),50,12,25,120,101,0,0,0,
	100,30,15,40,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),6,4,15,56,37,0,0,0,
	100,8,0,20,1,(0),(0),(0),(0),(0),(0),0,0,(0),4,10,25,122,103,0,0,0,
	0,8,14,25,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),400000,100000,20,123,104,0,0,0,
	100,20,1,1,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),40,2,0,45,27,0,0,0,
	
	80,4,0,1,1,(0),(0),(0),(0),(0),(0),0,0,(0),25,10,0,45,27,0,0,0,
	1,18,200,100,1,(0),(0),(0),(0),(0),(0),(1),(2),(0),25,10,0,45,27,0,0,0,
	95,15,1,20,1,(0),(0),(3),(0),(1),(0),(1),(2),(0),20,15,15,31,16,0,0,0,
	95,15,1,20,1,(0),(0),(4),(0),(1),(0),(1),(2),(0),20,15,15,31,16,0,0,0,
	45,12,10,10,1,(2),(4),(5),(3),(4),(2),(1),(2),(0),10,5,35,5,2,(81),0,0,
	45,12,10,10,1,(2),(4),(4),(3),(4),(2),(1),(2),(0),10,5,35,5,2,(81),0,0
};

const uint[]AIGeneralMsg_=
{
	
	2000,2019,2020,2039,2040,2059,2060,2079,
	2100,2119,2120,2139,2140,2159,2160,2172,
	2200,2219,2220,2239,2240,2259,2260,2272,
	2400,2405,2420,2427,2440,2449,2460,2465,
	2300,2319,2320,2339,2340,2359,2360,2372,
	2500,2505,2520,2525,2540,2552,2560,2565,
	2600,2606,2620,2629,2640,2651,2660,2669,
	2700,2705,2720,2727,2740,2749,2760,2765,
	2900,2905,2920,2925,2940,2950,2960,2964,
	3000,3005,3020,3025,3040,3049,3060,3065,
	3100,3119,3120,3139,3140,3159,3160,3179,
	3200,3205,3220,3226,3240,3246,3260,3265,
	12000,12006,12020,12038,12040,12049,12060,12065,
	12100,12105,12120,12125,12140,12149,12160,12165,
	12200,12205,12220,12228,12240,12249,12260,12266,
	26000,26005,26020,26025,26040,26050,26060,26060,
	26100,26105,26120,26126,26140,26149,26160,26166,
	32100,32105,32120,32128,32140,32149,32160,32165,
	32200,32205,32220,32228,32240,32249,32260,32265,
	32300,32305,32320,32325,32340,32348,32360,32365,
	
	32400,32405,32420,32428,32440,32448,32460,32465,
	32500,32505,32520,32526,32540,32549,32560,32565,
	32600,32604,32620,32626,32640,32649,32660,32665,
	32800,32805,32820,32828,32840,32847,32860,32865,
	33000,33005,33020,33028,33040,33045,33060,33064,
	33100,33105,33120,33128,33140,33149,33160,33165,
	36100,36105,36120,36124,36140,36148,36160,36165,
	36200,36205,36220,36223,36240,36249,36260,36265,
	36300,36305,36320,36323,36340,36348,36360,36365,
	36400,36405,36420,36423,36440,36449,36460,36465,
	36500,36500,36520,36523,36540,36548,36560,36565,
	36700,36705,36720,36727,36740,36749,36760,36765,
	36800,36819,36820,36839,36840,36859,36860,36879,
	40100,40119,40120,40139,40140,40159,40160,40179,
	44100,44102,44120,44100,44140,44100,44160,44100,
	44500,44507,44520,44528,44540,44549,44560,44566,
	44900,44909,44920,44939,44940,44959,44960,44979,
	41300,41319,41320,41339,41340,41359,41360,41379,
	42100,42117,42120,42133,42140,42159,42160,42177,
	40900,40912,40920,40929,40940,40959,40960,40979,
	
	10000,10000,10020,10038,10040,10058,10060,10060,
	10100,10100,10120,10139,10140,10159,10160,10160,
	41700,41719,41720,41739,41740,41759,41760,41779,
	18100,18107,18120,18127,18140,18154,18160,18177,
	14000,14009,14020,14029,14040,14049,14060,14069,
	50100,50100,50120,50120,50140,50140,50160,50160,
	60000,60000,60020,60020,60040,60041,60060,60060,
	61900,61905,61920,61911,61940,61921,61960,61900,
	62100,62105,62120,62111,62140,62121,62160,62100,
	61000,61005,61020,61011,61040,61021,61060,61000,
	61800,61805,61820,61811,61840,61821,61860,61800,
	62000,62005,62020,62011,62040,62021,62060,62000,
	62200,62205,62220,62211,62240,62221,62260,62200,
	65000,65005,65020,65011,65040,65021,65060,65000,
	65200,65205,65220,65211,65240,65221,65260,65200,
	61700,61705,61720,61711,61740,61721,61760,61700,
	68300,68300,68320,68300,68340,68300,68360,68300,
	61100,61105,61120,61111,61140,61121,61160,61100,
	61200,61205,61220,61211,61240,61224,61260,61200,
	61300,61305,61320,61311,61340,61321,61360,61300,
	
	61400,61405,61420,61411,61440,61421,61460,61400,
	61500,61505,61520,61511,61540,61521,61560,61500,
	63000,63005,63020,63011,63040,63022,63060,63000,
	63100,63105,63120,63111,63140,63121,63160,63100,
	63200,63205,63220,63211,63240,63221,63260,63200,
	63300,63305,63320,63311,63340,63321,63360,63300,
	63400,63405,63420,63411,63440,63421,63460,63400,
	63500,63505,63520,63511,63540,63521,63560,63500,
	63600,63605,63620,63611,63640,63621,63660,63600,
	63700,63705,63720,63711,63740,63721,63760,63700,
	63800,63805,63820,63811,63840,63821,63860,63800,
	63900,63905,63920,63911,63940,63921,63960,63900,
	64000,64005,64020,64011,64040,64021,64060,64000,
	64100,64105,64120,64111,64140,64121,64160,64100,
	64200,64205,64220,64211,64240,64221,64260,64200,
	64300,64305,64320,64311,64340,64321,64360,64300,
	64400,64405,64420,64411,64440,64421,64460,64400,
	64500,64505,64520,64511,64540,64521,64560,64500,
	64600,64605,64620,64611,64640,64621,64660,64600,
	64700,64705,64720,64711,64740,64721,64760,64700,
	
	64800,64805,64820,64811,64840,64821,64860,64800,
	64900,64905,64920,64911,64940,64921,64960,64900,
	65100,65105,65120,65111,65140,65121,65160,65100,
	68700,68705,68720,68711,68740,68721,68760,68700,
	65300,65305,65320,65311,65340,65321,65360,65300,
	65400,65405,65420,65411,65440,65421,65460,65400,
	65500,65505,65520,65511,65540,65521,65560,65500,
	65600,65605,65620,65611,65640,65621,65660,65600,
	65700,65705,65720,65711,65740,65721,65760,65700,
	65800,65805,65820,65811,65840,65821,65860,65800,
	65900,65905,65920,65911,65940,65921,65960,65900,
	66000,66005,66020,66011,66040,66021,66060,66000,
	66100,66105,66120,66111,66140,66121,66160,66100,
	66200,66205,66220,66211,66240,66221,66260,66200,
	66300,66305,66320,66311,66340,66321,66360,66300,
	66400,66405,66420,66411,66440,66421,66460,66400,
	66500,66505,66520,66511,66540,66521,66560,66500,
	66600,66605,66620,66611,66640,66621,66660,66600,
	66700,66705,66720,66711,66740,66721,66760,66700,
	66800,66805,66820,66811,66840,66821,66860,66800,
	
	66900,66905,66920,66911,66940,66921,66960,66900,
	67000,67005,67020,67011,67040,67021,67060,67000,
	62300,62305,62320,62311,62340,62321,62360,62300,
	62400,62405,62420,62411,62440,62421,62460,62400,
	68000,68005,68020,68011,68040,68021,68060,68000,
	62600,62605,62620,62611,62640,62621,62660,62600,
	62700,62705,62720,62711,62740,62721,62760,62700,
	68100,68105,68120,68111,68140,68121,68160,68100,
	68200,68205,68220,68211,68240,68221,68260,68200,
	61600,61605,61620,61611,61640,61621,61660,61600,
	62500,62505,62520,62511,62540,62521,62560,62500,
	62800,62805,62820,62811,62840,62821,62860,62800,
	62900,62905,62920,62911,62940,62921,62960,62900,
	67100,67105,67120,67111,67140,67121,67160,67100,
	67200,67205,67220,67211,67240,67221,67260,67200,
	67300,67305,67320,67311,67340,67321,67360,67300,
	67400,67405,67420,67411,67440,67421,67460,67400,
	67500,67505,67520,67511,67540,67521,67560,67500,
	67600,67605,67620,67611,67640,67621,67660,67600,
	67700,67705,67720,67711,67740,67721,67760,67700,
	
	67800,67805,67820,67811,67840,67821,67860,67800,
	67900,67905,67920,67911,67940,67921,67960,67900,
	68400,68402,68420,68405,68440,68408,68460,68400,
	68500,68500,68520,68502,68540,68505,68560,68500,
	68600,68605,68620,68611,68640,68621,68660,68600
};

const uint[]AIBodyMsg_=
{
	
	1000,1009,1010,1019,1020,1029,1030,1059,1060,1069,1070,1079,1080,1089,1090,1099,
	1100,1109,1110,1119,1120,1129,1130,1159,1160,1169,1170,1179,1180,1189,1190,1199,
	1200,1209,1210,1219,1220,1229,1230,1259,1260,1269,1270,1279,1280,1289,1290,1299,
	0,0,10,0,20,0,30,0,60,0,70,0,80,0,90,0,
	1300,1309,1310,1319,1320,1329,1330,1359,1360,1369,1370,1379,1380,1389,1390,1399,
	0,0,10,0,20,0,30,0,60,0,70,0,80,0,90,0,
	1400,1402,1410,1412,1420,1422,1430,1439,1460,1462,1470,1472,1480,1482,1490,1492,
	1500,1509,1510,1519,1520,1529,1530,1559,1560,1569,1570,1579,1580,1589,1590,1599,
	1600,1609,1610,1619,1620,1629,1630,1639,1660,1669,1670,1679,1680,1689,1690,1699,
	1700,1709,1710,1712,1720,1722,1730,1735,1760,1763,1770,1773,1780,1783,1790,1796,
	1800,1804,1810,1813,1820,1823,1830,1837,1860,1862,1870,1872,1880,1882,1890,1898,
	12300,12303,12310,12312,12320,12322,12330,12335,12360,12363,12370,12373,12380,12382,12390,12396,
	32000,32002,32010,32012,32020,32022,32030,32036,32060,32062,32070,32072,32080,32082,32090,32095,
	32700,32702,32710,32712,32720,32722,32730,32736,32760,32762,32770,32772,32780,32782,32790,32795,
	33200,33202,33210,33212,33220,33222,33230,33236,33260,33262,33270,33272,33280,33282,33290,33295,
	36000,36002,36010,36012,36020,36022,36030,36035,36060,36062,36070,36072,36080,36082,36090,36095,
	36600,36602,36610,36612,36620,36622,36630,36645,36660,36662,36670,36672,36680,36682,36690,36695,
	40000,40009,40010,40019,40020,40029,40030,40059,40060,40069,40070,40079,40080,40089,40090,40099,
	44000,44000,44010,44010,44020,44020,44030,44030,44060,44060,44070,44070,44080,44080,44090,44090,
	44400,44408,44410,44413,44420,44423,44430,44439,44460,44463,44470,44473,44480,44483,44490,44492,
	
	44800,44804,44810,44814,44820,44824,44830,44849,44860,44864,44870,44874,44880,44884,44890,44894,
	41200,41209,41210,41219,41220,41229,41230,41259,41260,41269,41270,41279,41280,41289,41290,41299,
	12400,12409,12410,12419,12420,12429,12430,12459,12460,12469,12470,12479,12480,12489,12490,12499,
	42000,42009,42010,42017,42020,42027,42030,42058,42060,42068,42070,42078,42080,42089,42090,42099,
	40800,40807,40810,40818,40820,40828,40830,40859,40860,40867,40870,40877,40880,40886,40890,40899,
	41600,41609,41610,41619,41620,41629,41630,41659,41660,41669,41670,41679,41680,41689,41690,41699,
	18000,18002,18010,18011,18020,18021,18030,18035,18060,18061,18070,18071,18080,18082,18090,18092,
	50000,50000,50010,50010,50020,50020,50030,50030,50060,50060,50070,50070,50080,50080,50090,50090,
	61928,61930,61938,61933,61948,61936,61958,61943,61988,61946,61998,61949,62008,61952,62018,61957,
	62128,62130,62138,62133,62148,62136,62158,62136,62188,62139,62198,62142,62208,62145,62218,62150,
	61028,61030,61038,61033,61048,61036,61058,61040,61088,61043,61098,61046,61108,61049,61118,61054,
	61828,61830,61838,61833,61848,61836,61858,61843,61888,61846,61898,61849,61908,61852,61918,61857,
	62028,62030,62038,62033,62048,62036,62058,62043,62088,62046,62098,62049,62108,62052,62118,62057,
	62228,62230,62238,62233,62248,62236,62258,62243,62288,62246,62298,62249,62308,62252,62318,62257,
	65028,65030,65038,65033,65048,65036,65058,65046,65088,65049,65098,65052,65108,65055,65118,65060,
	65228,65230,65238,65233,65248,65236,65258,65246,65288,65249,65298,65252,65308,65255,65318,65260,
	61728,61730,61738,61733,61748,61736,61758,61736,61788,61739,61798,61742,61808,61745,61818,61750,
	68302,68301,68312,68301,68322,68301,68332,68302,68362,68302,68372,68302,68382,68302,68392,68302,
	61128,61130,61138,61133,61148,61136,61158,61140,61188,61143,61198,61146,61208,61149,61218,61154,
	61231,61233,61241,61236,61251,61239,61261,61242,61291,61245,61301,61248,61311,61251,61321,61256,
	
	61328,61330,61338,61333,61348,61337,61358,61343,61388,61346,61398,61349,61408,61352,61418,61357,
	61428,61430,61438,61433,61448,61436,61458,61442,61488,61445,61498,61448,61508,61451,61518,61456,
	61528,61530,61538,61533,61548,61536,61558,61543,61588,61546,61598,61549,61608,61552,61618,61557,
	63028,63030,63038,63033,63048,63036,63058,63046,63088,63049,63098,63052,63108,63055,63118,63060,
	63128,63130,63138,63133,63148,63136,63158,63146,63188,63149,63198,63152,63208,63155,63218,63160,
	63228,63230,63238,63233,63248,63236,63258,63246,63288,63249,63298,63252,63308,63255,63318,63260,
	63328,63330,63338,63333,63348,63336,63358,63346,63388,63349,63398,63352,63408,63355,63418,63360,
	63428,63430,63438,63433,63448,63436,63458,63446,63488,63449,63498,63452,63508,63455,63518,63460,
	63528,63530,63538,63533,63548,63536,63558,63546,63588,63549,63598,63552,63608,63555,63618,63560,
	63628,63630,63638,63633,63648,63636,63658,63646,63688,63649,63698,63652,63708,63655,63718,63660,
	63728,63730,63738,63733,63748,63736,63758,63746,63788,63749,63798,63752,63808,63755,63818,63760,
	63828,63830,63838,63833,63848,63836,63858,63836,63888,63839,63898,63842,63908,63845,63918,63850,
	63928,63930,63938,63933,63948,63936,63958,63946,63988,63949,63998,63952,64008,63955,64018,63960,
	64028,64030,64038,64033,64048,64036,64058,64046,64088,64049,64098,64052,64108,64055,64118,64060,
	64128,64130,64138,64133,64148,64136,64158,64146,64188,64149,64198,64152,64208,64155,64218,64160,
	64228,64230,64238,64233,64248,64236,64258,64246,64288,64249,64298,64252,64308,64255,64318,64260,
	64328,64330,64338,64333,64348,64336,64358,64346,64388,64349,64398,64352,64408,64355,64418,64360,
	64428,64430,64438,64433,64448,64436,64458,64446,64488,64449,64498,64452,64508,64455,64518,64460,
	64528,64530,64538,64533,64548,64536,64558,64546,64588,64549,64598,64552,64608,64555,64618,64560,
	64628,64630,64638,64633,64648,64636,64658,64646,64688,64649,64698,64652,64708,64655,64718,64660,
	
	64728,64730,64738,64733,64748,64736,64758,64746,64788,64749,64798,64752,64808,64755,64818,64760,
	64828,64830,64838,64833,64848,64836,64858,64846,64888,64849,64898,64852,64908,64855,64918,64860,
	64928,64930,64938,64933,64948,64936,64958,64946,64988,64949,64998,64952,65008,64955,65018,64960,
	65128,65130,65138,65133,65148,65136,65158,65146,65188,65149,65198,65152,65208,65155,65218,65160,
	68728,68730,68738,68733,68748,68736,68758,68746,68788,68749,68798,68752,68808,68755,68818,68760,
	65328,65330,65338,65333,65348,65336,65358,65346,65388,65349,65398,65352,65408,65355,65418,65360,
	65428,65430,65438,65433,65448,65436,65458,65446,65488,65449,65498,65452,65508,65455,65518,65460,
	65528,65530,65538,65533,65548,65536,65558,65546,65588,65549,65598,65552,65608,65555,65618,65560,
	65628,65630,65638,65633,65648,65636,65658,65646,65688,65649,65698,65652,65708,65655,65718,65660,
	65728,65730,65738,65733,65748,65736,65758,65746,65788,65749,65798,65752,65808,65755,65818,65760,
	65828,65830,65838,65833,65848,65836,65858,65846,65888,65849,65898,65852,65908,65855,65918,65860,
	65928,65930,65938,65933,65948,65936,65958,65946,65988,65949,65998,65952,66008,65955,66018,65960,
	66028,66030,66038,66033,66048,66036,66058,66046,66088,66049,66098,66052,66108,66055,66118,66060,
	66128,66130,66138,66133,66148,66136,66158,66146,66188,66149,66198,66152,66208,66155,66218,66160,
	66228,66230,66238,66233,66248,66236,66258,66246,66288,66249,66298,66252,66308,66255,66318,66260,
	66328,66330,66338,66333,66348,66336,66358,66346,66388,66349,66398,66352,66408,66355,66418,66360,
	66428,66430,66438,66433,66448,66436,66458,66446,66488,66449,66498,66452,66508,66455,66518,66460,
	66528,66530,66538,66533,66548,66536,66558,66546,66588,66549,66598,66552,66608,66555,66618,66560,
	66628,66630,66638,66633,66648,66636,66658,66646,66688,66649,66698,66652,66708,66655,66718,66660,
	66728,66730,66738,66733,66748,66736,66758,66746,66788,66749,66798,66752,66808,66755,66818,66760,
	
	66828,66830,66838,66833,66848,66836,66858,66846,66888,66849,66898,66852,66908,66855,66918,66860,
	66928,66930,66938,66933,66948,66936,66958,66946,66988,66949,66998,66952,67008,66955,67018,66960,
	67028,67030,67038,67033,67048,67036,67058,67046,67088,67049,67098,67052,67108,67055,67118,67060,
	62328,62330,62338,62333,62348,62336,62358,62342,62388,62345,62398,62348,62408,62351,62418,62356,
	62428,62430,62438,62433,62448,62436,62458,62441,62488,62444,62498,62447,62508,62450,62518,62455,
	68028,68030,68038,68033,68048,68036,68058,68046,68088,68049,68098,68052,68108,68055,68118,68060,
	62628,62630,62638,62633,62648,62636,62658,62636,62688,62639,62698,62642,62708,62645,62718,62650,
	62728,62730,62738,62730,62748,62730,62758,62735,62788,62735,62798,62735,62808,62735,62818,62737,
	68128,68130,68138,68133,68148,68136,68158,68146,68188,68149,68198,68152,68208,68155,68218,68157,
	68228,68230,68238,68233,68248,68236,68258,68246,68288,68249,68298,68252,68308,68255,68318,68260,
	61628,61630,61638,61633,61648,61636,61658,61644,61688,61647,61698,61650,61708,61653,61718,61658,
	62528,62530,62538,62533,62548,62536,62558,62542,62588,62545,62598,62548,62608,62551,62618,62556,
	62828,62830,62838,62833,62848,62836,62858,62844,62888,62847,62898,62850,62908,62853,62918,62858,
	62928,62930,62938,62933,62948,62936,62958,62946,62988,62949,62998,62952,63008,62955,63018,62960,
	67128,67130,67138,67133,67148,67136,67158,67146,67188,67149,67198,67152,67208,67155,67218,67160,
	67228,67230,67238,67233,67248,67236,67258,67246,67288,67249,67298,67252,67308,67255,67318,67260,
	67328,67330,67338,67333,67348,67336,67358,67346,67388,67349,67398,67352,67408,67355,67418,67360,
	67428,67430,67438,67433,67448,67436,67458,67446,67488,67449,67498,67452,67508,67455,67518,67460,
	67528,67530,67538,67533,67548,67536,67558,67546,67588,67549,67598,67552,67608,67555,67618,67560,
	67628,67630,67638,67633,67648,67636,67658,67646,67688,67649,67698,67652,67708,67655,67718,67660,
	
	67728,67730,67738,67733,67748,67736,67758,67746,67788,67749,67798,67752,67808,67755,67818,67760,
	67828,67830,67838,67833,67848,67836,67858,67846,67888,67849,67898,67852,67908,67855,67918,67860,
	67928,67930,67938,67933,67948,67936,67958,67946,67988,67949,67998,67952,68008,67955,68018,67960,
	68411,68412,68421,68414,68431,68416,68441,68420,68471,68422,68481,68424,68491,68426,68501,68426,
	68508,68511,68518,68513,68528,68515,68538,68518,68568,68520,68578,68522,68588,68524,68598,68526,
	68628,68630,68638,68633,68648,68636,68658,68646,68688,68649,68698,68652,68708,68655,68718,68660
};                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

import bool AddMiscPlane(Critter&npc,uint priority,uint waitMinute,string@funcName)from"npc_planes";
import bool AddMiscPlane(Critter&npc,uint priority,int identifier,uint identifierExt,uint waitSecond,string@funcName)from"npc_planes";
import bool AddWalkPlane(Critter&npc,uint priority,uint16 hexX,uint16 hexY,uint8 dir,bool run,uint cut)from"npc_planes";
import bool AddWalkPlane(Critter&npc,uint priority,int identifier,uint identifierExt,uint16 hexX,uint16 hexY,uint8 dir,bool run,uint cut)from"npc_planes";
import bool AddAttackPlane(Critter&npc,uint priority,Critter&target)from"npc_planes";
import bool AddAttackPlane(Critter&npc,uint priority,uint critId)from"npc_planes";
import bool AddAttackPlane(Critter&npc,uint priority,Critter&target,int minHp)from"npc_planes";
import bool AddAttackPlane(Critter&npc,uint priority,uint critId,int minHp)from"npc_planes";
import bool AddAttackPlane(Critter&npc,uint priority,Critter&target,bool run)from"npc_planes";
import bool AddPickPlane(Critter&npc,uint priority,uint16 hexX,uint16 hexY,uint16 protoId,uint useItemId,bool toOpen)from"npc_planes";
import bool AddPickPlane(Critter&npc,uint priority,Item@item,uint useItemId,bool toOpen)from"npc_planes";
import bool AddPickPlane(Critter&npc,uint priority,Item@item,uint useItemId,bool toOpen,bool run)from"npc_planes";
import bool AddHealCritterPlane(Critter&npc,uint priority,Critter@target,bool run)from"npc_planes";
import bool AddDoctorCritterPlane(Critter&npc,uint priority,Critter@target,bool run)from"npc_planes";

import uint EraseAttackPlane(Critter&npc,uint priority,Critter&target)from"npc_planes";
import uint EraseAttackPlane(Critter&npc,uint priority,uint critId)from"npc_planes";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

shared interface IPolygon
{
	IPolygon@AddVertex(uint16 x,uint16 y);
	IPolygon@AddVertices(array<uint16>&hexes);   
	
	bool IsWithin(Critter&cr);
	bool IsWithin(Item&item);
	
	bool IsWithin(uint16 x,uint16 y);
};  

import IPolygon@NewPolygon()from"polygon"; 

import IPolygon@LoadShapeFromEntires(Map&map,uint first,uint last)from"polygon";          

import ITown@GetTownByIndex(uint index)from"towns";
import ITown@GetTown(uint id)from"towns";
import uint GetTownCount()from"towns";
import uint GetTowns(array<ITown@>@towns)from"towns";  

import bool AddMilitia(Map@map)from"town";
import void InitMilitia()from"town";
import bool IsTCTown(Map@map)from"town";
import uint RetrieveTownId(Map@map)from"town";
import uint RetrieveTownId(Critter&critter)from"town";
import ITown@RetrieveTown(Critter&critter)from"town";
import bool ValidTown(ITown@town)from"town";
import void GainControl(Critter&player)from"town";
import uint GetNearMembers(Critter&player)from"town";
import bool IsPolicy(Critter&player,uint policy)from"town";
import bool IsControllingTown(Critter&player)from"town";
import bool AlertMilitia(Critter&cr)from"town";
import int SelectBag(uint crpid)from"town";
import void SpawnInitMilitia(Map@map)from"town";
import int CountMilitia(Map@map)from"town";
import void ClearInfluenceBuffer(Critter&cr)from"town";  

class PresenceStruct
{
	uint factionId;
	uint count;
	PresenceStruct(uint factionId)
	{
		this.factionId=factionId;
		this.count=1;
	}
};

shared interface ITown
{
	ITown@SetMapID(uint id);
	ITown@SetTownID(uint id);
	ITown@SetBaseRewardValue(uint value);
	ITown@SetInfluenceMemberRequirement(uint number);
	ITown@SetNearbyMemberRequirement(uint number);
	ITown@SetTotalMemberRequirement(uint number);
	ITown@SetLimboContainer(Item@container);
	ITown@SetRewardContainer(Item@container);
	ITown@SetTownLeader(Critter@leader);
	ITown@SetSpeechModifier(int modifier);
	ITown@SetHour(uint hour);
	ITown@SetCaptureArea(IPolygon@capturearea);
	ITown@SetMilitiaEnabled();
	ITown@SetRewardStartCaps(uint caps);
	ITown@SetVersion(uint version);
	
	uint GetVersion();
	
	uint GetTownID();
	string GetTownName();
	bool LoadData();
	bool SaveData();
	bool IsMilitiaEnabled();
	bool IsFriendlyFaction(uint factionid);
	bool IsFriend(Critter&cr);
	bool IsValidCaptor(Critter&cr);
	bool IsWithinCaptureArea(Critter&cr);
	void AreaCheck();
	bool AddFriendlyFaction(uint factionid);
	bool RemoveFriendlyFaction(uint factionid);
	array<uint>GetFriendlyFactions();
	float GetControllingInfluence();
	uint GetMilitiaMax();
	uint GetControllingFaction();
	uint GetNumberOfKilledNPCs();
	uint GetControlCycles();
	uint GetStatus();
	void SetStatus(uint status);
	void SetScore();
	void SetPreviousFaction(uint previous);
	uint GetlastSecond();
	void SetlastSecond(uint sec);
	uint GetAreaCount();
	uint GetCountdown();
	void SetCountdownStatus(bool enabled);
	bool GetCountdownStatus();
	void SendCountdownTime(Critter&player);
	uint GetMemberNearbyRequirement();
	uint GetMemberTotalRequirement();
	Item@GetLimboContainer();
	Item@GetRewardContainer();
	uint GetTownLeaderId();
	uint GetMapID();
	int GetSpeechModifier();
	bool GainControl(Critter&player);
	void IncreaseNPCDeath(uint num);
	void ModifyInfluence(uint factionId,float value);
	void SetInfluence(uint factionId,float value);
	void ResetStats();
	void ResetControl();
	void RevertControl();
	void ClearRewardContainer();
	void ClearLimboContainer();
	void ClearContainers();
	void Update(uint hour,uint minute);
	void UpdateCountdown();
	void UpdateTick();
	void TownCheck();
	
	bool IsLaw(uint law);
	void SetLaw(uint law,bool enabled);
	
	void AddMoney(int money);
	int GetMoney(); 
	
	float GetInfluence(uint faction);
	
	Location@GetLocation();
};                                                 

import void MakeMine(Item&mine,uint explodeOwner,uint complexity,uint hideSkill,uint bonusDamage,uint bonusRadius)from"explode";
import void MakeSpearTrap(Item&trap,uint complexity,uint hideSkill,uint spearcount)from"traps";
import void MakeGenericShotTrap(Item&trap,uint complexity,uint hideSkill,uint16 pid,uint dmgmin,uint dmgmax)from"traps";
import void MakeBearTrap(Item&trap,uint complexity,uint hideSkill,uint bonusDamage)from"traps";
import void MakeAlarmTrap(Item&trap,uint complexity,uint hideSkill,uint16 pid,uint8 min,uint8 max,uint16 bag,uint8 level,uint8 entire)from"traps";
import void ClearWalkTrap(Item&item)from"traps";                                    

funcdef bool TRIGGER_FUNC(Item&tr,Critter@cr,uint dir,uint count,array<uint>@values);           

import void TriggerInit(Item@tr,uint funcId,uint settings,uint delay,uint nextTick)from"triggers";                                                                                                                                                                                                                                                                                                                                                                                              

shared interface IWeatherZone
{
	uint GetID();
	bool Load();
	bool Save();
	
	string GetName();
	void SetName(string name);
	
	uint GetTimeEvent();
	void SetTimeEvent(uint id);
	
	int GetFlags();
	bool GetFlag(int flag);
	void SetFlag(int flag);
	void UnsetFlag(int flag);
	
	uint GetSpeedMove();
	bool SetSpeedMove(uint speed);
	uint GetSpeedLevel();
	bool SetSpeedLevel(uint speed);
	uint GetSpeedRadius();
	bool SetSpeedRadius(uint speed);
	uint GetSubZones();
	bool SetSubZones(uint subzones);
	
	bool SetType(uint type);
	bool Position(uint coords_x,uint coords_y);
	bool Move(uint coords_x,uint coords_y);
	bool Level(uint level);
	bool Radius(uint radius);
	
	bool LoadActions(string&filename);
	void Action(uint action,uint data1,uint data2);
	void Update();
	void UpdateFast(Location@loc);
	void Lock();
	void Unlock();
	uint GetUpdateTime();
	uint SetUpdateTime(uint time);
	void Delete();
};  

import void InitWeather()from"weather";
import void SaveWeather()from"weather";

import uint AddWeatherZone(string&name)from"weather";
import uint AddWeatherZone(uint coords_x,uint coords_y,uint type)from"weather";

import IWeatherZone@GetWeatherZone(uint id)from"weather";
import IWeatherZone@GetWeatherZone(string&name)from"weather";

import void WeatherUpdate(Critter@critter,uint&type,int&level)from"weather";
import void WeatherUpdate(Location@loc,uint&type,int&level)from"weather";
import void WeatherUpdate(int locid,uint type,int level)from"weather";

import void WeatherUpdateFast(Location@loc)from"weather";

import void DeleteWeatherZone(uint&id,uint&speed_level,uint&speed_radius)from"weather";
import void DeleteWeatherZone(string&name,uint&speed_level,uint&speed_radius)from"weather";
import void DeleteWeatherZone(IWeatherZone@zone,uint&speed_level,uint&speed_radius)from"weather";              

import bool IsNight()from"world_common";
import bool IsDay()from"world_common";
import bool IsMorning()from"world_common";
import bool IsAfternoon()from"world_common";
import bool IsEvening()from"world_common";
import bool IsHospital(Map@map)from"world_common";
import bool IsCave(Map@map)from"world_common";
import bool IsMine(Map@map)from"world_common";
import bool IsJail(Map@map)from"world_common";
import bool IsBase(Map@map)from"world_common";
import bool IsTent(Map@map)from"world_common";
import bool IsWarzone(Map@map)from"world_common";                                                                                                            

uint[][]PositionDirs=
{
	{0},
	
	{1,4,3,2,1,0,5,2,3,4,5,0,1},
	{1,5,0,1,2,3,4,1,0,5,4,3,2},
	{1,4,2},
	{1,5,1},
	{2,1,2,0,0,1,2,3,3,0,0,4,5,3,3,4,5},
	{2,1,2,4,5},
	{2,4,4,0,0,4,4,3,3,0,0,2,2,3,3,2,2},
	{2,5,5,0,0,5,5,3,3,0,0,1,1,3,3,1,1},
	{2,1,2,0,0,0,0,1,2,3,3,3,3,0,0,0,0,4,5,3,3,3,3,4,5}
};                                                                                                                                                                

shared interface IZone
{
	uint GetX();
	uint GetY();
	uint GetTerrain();
	uint8 GetFactor();
	void SetFactor(uint8 factor);
	int GetValue();
	void SetValue(int val);
	void AddValue(int val);
	void SubValue(uint val);
	bool ContainsFlag(uint flag);
	void SetQuantity(uint group,uint quantity);
	void ChangeQuantity(uint group,int mod);
	uint GetBaseQuantity(uint group);
	uint GetQuantity(uint group);
	uint GetLocationPids(array<uint16>&pids);
}; 

import IZone@GetZone(uint wx,uint wy)from"worldmap";                     

uint __GetColor(int r,int g,int b,int a=0xFF)
{
	r=(((r)>(255))?(255):(((r)<(0))?(0):(r)));
	g=(((g)>(255))?(255):(((g)<(0))?(0):(g)));
	b=(((b)>(255))?(255):(((b)<(0))?(0):(b)));
	a=(((a)>(255))?(255):(((a)<(0))?(0):(a)));
	return(uint(((a)<<24)|(((r)&0xFF)<<16)|(((g)&0xFF)<<8)|((b)&0xFF)));
}                                                           

import void AffectRadiation(Critter&cr,int value)from"radiation";
import void DropDrugEffects(Critter&cr,bool dropAddictions)from"drugs";
import void DropPoison(Critter&cr)from"poison";
import void DropRadiation(Critter&cr)from"radiation";
import void Explode(Map@map,uint16 hexX,uint16 hexY,Critter@cr,uint16 explodePid,uint ownerId,int bonusDamage,int bonusRadius)from"explode";
import void ExplodeEx(Map&map,uint16 hexX,uint16 hexY,uint16 effectPid,uint effectRadius,uint damage,uint damageType,uint damageRadius,uint ownerId)from"explode";
import bool GetBaseType(const string&in,int&out)from"main";
import bool GetItemPid(const string&in,int&out)from"main";
import bool GetMapData(const string&in,int&out)from"main";
import bool GetVarId(const string&in,int&out)from"main";
import void InitPrices()from"economy";
import void InjureCritter(Critter&cr,uint dmg,uint dmgType,uint8 dir,uint attackerId)from"combat";
import bool IsGrenade(Item&item)from"throwing";
import uint numDigits(int number)from"critter_description";
import void SetCritterEvents(Critter&cr)from"logging_critter";
import void SetWear(Item&item,int wearProcent)from"repair";
import int stringReplaceText(string&s,string@f,string@t)from"config_file";
import array<Critter@>WorldmapGetPlayers(uint zx,uint zy)from"worldmap_players";
import int WorldmapGetTotalValue()from"worldmap";      

bool CheatsInitialized=false; 

dictionary Maps; 

array<int>eventItems;
array<int>eventCritters; 

string[]commandlist=
{
	"accesslist","addbankmoney","addfollower","addmob","addnpc","airstrike","alts",
	"animate","antiblock","append","aura","auracleanup",
	"bc","blockers","broadcast",
	"ces","changefaction","changerank","checkbank","checkbankaccount",
	"checkbankaccounts","checktown","cleanup","clearallillegalflags",
	"clearenemystack","clearenemystacks","clearinventory","clearillegalflags",
	"cleartimeouts","clone","condition","controlmobs","controlnpc","corecheats",
	"countitems","createlocation","crinfo","criticalchance","critterinfo",
	"cto",
	"damage","deathincarnate","deathmatch","deletelocation","devenable",
	"dialog","disguise","disabledismantling","disablegrids","disablepvp",
	"disabletb","disguiseinfo","dismiss","dismissteam","dropalltimeouts",
	"dropdrugs","dropitems",
	"emote","emoteh","enabledismantling","enablegrids","enablepvp","enabletb",
	"explode",
	"factioninfo","factionnews","factiononline","findchars","finditems",
	"findnpc","flash","foart",
	"gaintowncontrol","gameinfo","getclaim","getclaimtime","getcolor",
	"getitems","getleader","getleadertime","getuvar","getvar","give",
	"givekey","goto","gototeam",
	"heal","healall","help","hideloc","hidemap",
	"id2name","iddqd","idkfa","inspect","irradiate","itemflags","itemlight",
	"itemproto",
	"karma","karmateam","kill","killeradmin","killmobs",
	"la","lastregistered","lastspawned","listauthenticated","listcommands",
	"listfollowers","listfactions","listmaps","listplayers","listtents",
	"listtracked","lock","lockcar","log","lp","lt",
	"makeencounter","mapinfo","masssetanim","massslap","modchar","move",
	"name2id","netmsg","normaldeadly","numplayers",
	"param","perkadjust","pickitems","phase","phaseteam","playerkarma",
	"playmusic","playsound","playspeech","profadjust",
	"registerfaction","removebankmoney","removefaction","removeitems",
	"reservednickname","resetalldisguises","resetprices","resetreputations",
	"resettown","resettowns","resetworldmap","respawn","revive","respawnall",
	"reviveall","respawnallplayers","reviveallplayers","rotate","rundialog",
	"saferegen","say","sayh","setfaction","setmapdata","setanim","sethp",
	"setlexem","setperk","setreputation","setrep","settimeout","sto",
	"setuvar","setvar","setlocvisibility","shift","shiftteam","shout",
	"shouth","showhands","showloc","showvars","slap","spawncar","spawnitem",
	"spawnpoint","stoptrackplayer","suicide","summon","summonteam",
	"team","tentinfo","tp","teleport","teleporter","teleportteam","toglobal","trackplayer",
	"usedammo","unlockcar",
	"whisper","whisperh",
	"virtualmoney",
	"xp","xpteam",
	"zeroext","zone","zoneplayers"
};

string[]gmcommandlist=
{
	"addfollower","addmob","addnpc","animate","antiblock","append","alts",
	"bc","broadcast","blockers",
	"changefaction","changerank","checkbank","checkbankaccount",
	"checkbankaccounts","cleanup","clearenemystack","clearenemystacks",
	"clearillegalflags","clearinventory","ces","cleartimeouts","clone",
	"corecheats","cto","countitems","createlocation","criticalchance",
	"critterinfo","crinfo",
	"devenable","dialog","disguise","disguiseinfo","disabletb","dismiss",
	"dismissteam","dropalltimeouts","dropdrugs","dropitems",
	"emote","emoteh","enabletb","explode",
	"factioninfo","factionnews","factiononline","findchars","finditems",
	"findnpcs","flash","foart",
	"gameinfo","getclaim","getclaimtime","getcolor","getitems","getleader",
	"getleadertime","getuvar","getvar","give","givekey","goto","gototeam",
	"heal","healall","help","hideloc","hidemap",
	"id2name","inspect","irradiate","itemflags","itemlight","itemproto",
	"karma","karmateam","killmobs",
	"la","lastregistered","lastspawned","listauthenticated","listcommands",
	"listfollowers","listfactions","listmaps","listplayers","listtents",
	"listtracked","lp","lt","lock","lockcar","log",
	"makeencounter","mapinfo","massslap","modchar",
	"name2id","netmsg","normaldeadly","numplayers",
	"param","pickitems","phase","phaseteam","playerkarma","playmusic",
	"playsound","playspeech",
	"reservednickname","resetreputations","resetworldmap","respawn","revive",
	"respawnall","respawnallplayers","rotate","rundialog",
	"saferegen","say","sayh","setmapdata","setperk","setreputation","setrep",
	"settimeout","sto","setanim","setuvar","setvar","slap","shift",
	"shiftteam","shout","shouth","showhands","showloc","showvars",
	"showhands","spawncar","spawnitem","spawnpoint","stoptrackplayer",
	"suicide","summon","summonteam",
	"team","tentinfo","tp","teleport","teleporter","teleportteam","toglobal","trackplayer",
	"usedammo","unlockcar",
	"virtualmoney",
	"whisper","whisperh",
	"xp","xpteam",
	"zone"
};

string[]testercommandlist=
{
	"alts","animate",
	"blockers",
	"ces","changefaction","changerank","clearillegalflags","clearenemystack",
	"clearenemystacks","cleartimeouts","countitems","crinfo","critterinfo",
	"cto",
	"devenable","dismiss","dismissteam","dropitems",
	"finditems",
	"gameinfo","getcolor","getvar","goto","gototeam",
	"heal","healall","help",
	"id2name",
	"lastregistered","listcommands","listfactions","listfollowers","listmaps",
	"listplayers","listtents","listtracked","lp","lt","log",
	"mapinfo",
	"name2id","netmsg","numplayers",
	"pickitems","playerkarma","playmusic","playsound","playspeech",
	"revive","resetworldmap","respawnall","respawnplayers","rotate",
	"say","sayh","setanim","showhands","shout","shouth","showvars","slap",
	"suicide","summon","summonteam",
	"team","tentinfo","tp","teleport","teleportteam","toglobal","trackplayer",
	"whisper","whisperh"
};

int[]testerparamlist=
{
	
	(8),
	(70),
	(9),
	(11),
	(71),
	(13),
	(77),
	(7),
	(12),
	(30),(31),
	
	(16),(17),(18),(19),(20),(21),(22),
	(23),(24),(25),(26),(27),(28),(29),
	
	(138),(139),                                   
	
	(0),(1),(2),(3),(4),(5),(6), 
	
	(200),(201),(202),(203),(204),(205),(206),(207),(208),(209),(210),(211),(212),(213),(214),(215),(216),(217), 
	
	(226),(227),(228),(229), 
	
	(538),
	(531),
	(536),
	(514),
	(540),
	(537),
	(539),
	(530),
	(522)
};

void SetMapId(string location,uint mapprotoid)
{
	Map@map=GetMapByPid(mapprotoid,0);
	if(!(@map!=null))
	{
		{;};
		return;
	}
	
	WLog("cheats","Setting mapid for "+location+" to "+map.Id);
	Maps.set(location,map.Id);
}

void RefreshAliases(Critter&player,int,int,int)
{
	SetAliases();
}

void SetAliases()
{
	
	SetMapId("junktown",(70));
	SetMapId("jt",(70));
	SetMapId("hub",(221));
	SetMapId("glow",(240));
	SetMapId("gunrunners",(279));
	SetMapId("fortress",(279));
	SetMapId("adytum",(280));
	SetMapId("scavenger",(282));
	SetMapId("library",(283));
	SetMapId("lh",(85));
	SetMapId("v13",(90));
	SetMapId("necropolis",(141)); 
	
	SetMapId("arroyo",(1));
	SetMapId("den",(6));
	SetMapId("klamath",(9));
	SetMapId("klamcave",(11));
	SetMapId("modoc",(18));
	SetMapId("vc",(16));
	SetMapId("gecko",(31));
	SetMapId("bh",(115));
	SetMapId("broken",(115));
	SetMapId("nr",(54));
	SetMapId("gasstation",(58));
	SetMapId("tray",(58));
	SetMapId("t-ray",(58));
	SetMapId("sad",(25));
	SetMapId("v15",(34));
	SetMapId("ncr",(45));
	SetMapId("shady",(45));
	SetMapId("shadysands",(45));
	SetMapId("cathedral",(75));
	SetMapId("mariposa",(49));
	SetMapId("redding",(62));
	SetMapId("sf",(137));
	SetMapId("navarro",(109));
	SetMapId("golgotha",(247));
	SetMapId("raiders1",(112));
	SetMapId("khans",(112));
	SetMapId("raiders2",(114)); 
	
	SetMapId("repl1",(275));
	SetMapId("repl2",(276));
	SetMapId("repl3",(277));
	SetMapId("repl4",(278));
	SetMapId("repl5",(325));
	SetMapId("repl6",(326));
	SetMapId("repl7",(327));
	SetMapId("repl8",(328)); 
	
	SetMapId("bh_mine",(117));
	SetMapId("broken_mine",(117));
	SetMapId("klamath_mine",(374));
	SetMapId("ncr_mine",(376));
	SetMapId("redding_mine",(63));
	SetMapId("sf_mine",(372));
	SetMapId("jt_mine",(379));
	SetMapId("vc_mine",(377)); 
	
	SetMapId("sf_train",(552));
	SetMapId("la_train",(553));
	SetMapId("ncr_train",(554));
	SetMapId("vc_train",(555));
	
	SetMapId("train1",(552));
	SetMapId("train2",(553));
	SetMapId("train3",(554));
	SetMapId("train4",(555)); 
	
	SetMapId("slaver1",(568));     
	
	SetMapId("ares",(100));
	SetMapId("gasstation2",(566));
	SetMapId("hinkley",(3));
	SetMapId("hub_arena",(227));
	SetMapId("junkyard",(556));
	SetMapId("tesla",(2));
	SetMapId("themepark",(564));
	SetMapId("waterworks",(565));
	SetMapId("ncr_army",(569));
	SetMapId("ncrcf",(65));
	SetMapId("prison",(65));
	SetMapId("ncr_rails",(66)); 
	
	SetMapId("npcmap",(228));
	SetMapId("jail",(380));
	SetMapId("cubik",(570));
}

class CNPC
{
	uint protoId;
	uint dialogId;
	array<string>names;
	
	CNPC(uint protoId,uint dialogId)
	{
		this.protoId=protoId;
		this.dialogId=dialogId;
		names.resize(0);
	}
	
	bool IsImportant(Critter&cr)
	{
		if(cr.GetProtoId()==this.protoId&&
		cr.Param[(104)]==int(this.dialogId))
		return(true);
		else
		return(false);
	}
	
	CNPC@Name(string&name)
	{
		this.names.insertLast(name);
		
		return(this);
	}
};
array<CNPC@>INPC;

CNPC@ImportantNpc(uint protoId,uint dialogId)
{
	INPC.insertLast(CNPC(protoId,dialogId));
	return(INPC.last());
}

void SetImportantNpcs()
{  
	
	ImportantNpc(161,625)
	.Name("marcus")
	.Name("town_leader")
	;
	ImportantNpc(119,650)
	.Name("mercs")
	;
	
	ImportantNpc(58,9300)
	.Name("banker")
	;
	ImportantNpc(297,1405)
	.Name("dr_fung")
	.Name("doctor")
	;
	ImportantNpc(308,1403)
	.Name("lao_chou")
	.Name("trader")
	;
	ImportantNpc(300,1402)
	.Name("mai_da_chiang")
	.Name("trader");
	ImportantNpc(300,772)
	.Name("mercs")
	;
	ImportantNpc(472,46)
	.Name("tatoo")
	;
	
	ImportantNpc(149,10701)
	.Name("tamira")
	.Name("pe_ranger")
	.Name("support_perk")
	;
	
	ImportantNpc(100,1713)
	.Name("boyce")
	.Name("pe_dismantrler")
	.Name("support_perk")
	;
	
	ImportantNpc(409,2722)
	.Name("gomes")
	.Name("raiders")
	;
	
	ImportantNpc(150,1002)
	.Name("buster")
	.Name("trader_ncr")
	.Name("trader")
	;
	ImportantNpc(139,1025)
	.Name("hoss")
	.Name("pe_cautious_nature")
	.Name("pe_pathfinder")
	.Name("pe_awareness")
	.Name("support_perk")
	;
	ImportantNpc(20,1048)
	.Name("sha_enin")
	.Name("trader_ncr")
	.Name("trader")
	;
	ImportantNpc(144,1035)
	.Name("tandi")
	;
}           

bool GuardNotLegit(Critter@cr,Item@item,bool deleteItem)
{
	if((((((item.Val9))&((0x80000000)))!=0)))
	{
		if((cr.IsPlayer()&&cr.GetAccess()==(0))||cr.IsNpc())
		{
			Map@map=cr.GetMap();
			if((@map!=null)&&(((((map.GetData((9))))&((0x80000000)))!=0)))
			{
				Item@item2=cr.GetItem(item.GetProtoId(),-1);
				if(!(@item2!=null))
				{
					return false;
				}
				if((((((item2.Val9))&((0x80000000)))!=0))||!item2.IsStackable())
				{
					return false;
				}
			}
			if(deleteItem)
			{
				DeleteItem(item);
				cr.Say((11),"Not legit item removed.");
			}
			return true;
		}
	}
	return false;
}   

void RemoveNotLegit(Critter@cr)
{
	bool foundNotLegit=false;
	array<Item@>items;
	uint num=cr.GetItems(-1,items);
	for(uint i=0;i<num;i++)
	{
		if((((((items[i].Val9))&((0x80000000)))!=0)))
		{
			DeleteItem(items[i]);
			foundNotLegit=true;
		}
	}
	if(foundNotLegit)
	{
		cr.Say((11),"Not legit items removed.");
	}
};         

string cheatGetOption(array<string@>@command,int&option,string optionSwitch)
{
	if(StrToInt(GetParameterString(command,optionSwitch),option))
	{
		return option+"";
	}
	else
	{
		return option+" [default]";
	}
}

string cheatGetOption(array<string@>@command,uint&option,string optionSwitch)
{
	if(StrToInt(GetParameterString(command,optionSwitch),option))
	{
		return option+"";
	}
	else
	{
		return option+" [default]";
	}
}

string cheatGetOption(array<string@>@command,int16&option,string optionSwitch)
{
	if(StrToInt(GetParameterString(command,optionSwitch),option))
	{
		return option+"";
	}
	else
	{
		return option+" [default]";
	}
}

string cheatGetOption(array<string@>@command,uint16&option,string optionSwitch)
{
	if(StrToInt(GetParameterString(command,optionSwitch),option))
	{
		return option+"";
	}
	else
	{
		return option+" [default]";
	}
}

string cheatGetOption(array<string@>@command,bool&option,string optionSwitch)
{
	if(GetIndexOfString(command,optionSwitch)!=-1)
	{
		option=true;
		return option+"";
	}
	else
	{
		return option+" [default]";
	}
}

void InitCheats(bool fromGame)
{
	if(!fromGame)
	{  
		
	}
	
	SetAliases();
	SetImportantNpcs();
	LoadEventSpawns(); 
	
	CheatsInitialized=true;
}

void SaveCheats()
{    
	
}   

bool IsAllowed(uint playerId,const string&command)
{
	Critter@cr=GetCritter(playerId);
	if(!(@cr!=null)||cr.IsNpc())
	return false;
	switch(cr.GetAccess())
	{
		case(0):
		return false;
		case(1):
		return IsInArray(testercommandlist,command);
		case(2):
		return IsInArray(gmcommandlist,command);
		case(3):
		default:
		return GodOfTheRealm(playerId)||IsInArray(commandlist,command);
	}
	return false;
}

bool IsInArray(array<string>&arr,string&str)
{
	for(uint i=0,j=arr.length();i<j;i++)
	if(arr[i]==str)
	return true;
	return false;
}

bool GodOfTheRealm(uint id)
{
	return false;        
	
}

bool WrathOfTheGod(Critter&di)
{
	if(!GodOfTheRealm(di.Id))
	return(false);
	
	return(((di.Mode[(534)]&((0x00020000)))!=0));
}  

void god(Critter&cr,int,int,int)
{
	if(!GodOfTheRealm(cr.Id))
	{
		Critter@crit=null;
		crit.Param[0];
	}
	
	(cr.ModeBase[(534)]=cr.Mode[(534)]|((0x00020000)));
}

void mortal(Critter&cr,int,int,int)
{
	(cr.ModeBase[(534)]=(cr.Mode[(534)]|((0x00020000)))^((0x00020000)));
}

void adminlook(Critter&cr,int p,int r,int)
{
	if(r!=122389&&p!=0)
	return;
	Critter@player=(p==0?@cr:GetCritter(p));
	(player.ModeBase[(534)]=player.Mode[(534)]|((0x00008000)));
	(player.ModeBase[(534)]=player.Mode[(534)]|((0x00010000)));
}

void normallook(Critter&cr,int p,int r,int)
{
	if(r!=122389&&p!=0)
	return;
	Critter@player=(p==0?@cr:GetCritter(p));
	(player.ModeBase[(534)]=(player.Mode[(534)]|((0x00008000)))^((0x00008000)));
	(player.ModeBase[(534)]=(player.Mode[(534)]|((0x00010000)))^((0x00010000)));
}

void imsospeed(Critter&cr,int p0,int p1,int p2)
{
	Critter@target=cr;
	if(p1>0)
	@target=GetCritter(p1);
	if(!(@target!=null))
	return;
	
	if(p0==0)
	p0=500;
	
	SetLvar(target,(1337),p0);
}

void vals(Critter&cr,int,int,int id)
{
	if(id>0)
	{
		Item@it=GetItem(id);
		if((@it!=null))
		{
			cr.Say((11),"Val0: "+it.Val0);
			cr.Say((11),"Val1: "+it.Val1);
			cr.Say((11),"Val2: "+it.Val2);
			cr.Say((11),"Val3: "+it.Val3);
			cr.Say((11),"Val4: "+it.Val4);
			cr.Say((11),"Val5: "+it.Val5);
			cr.Say((11),"Val6: "+it.Val6);
			cr.Say((11),"Val7: "+it.Val7);
			cr.Say((11),"Val8: "+it.Val8);
			cr.Say((11),"Val9: "+it.Val9);
			return;
		}
	}
	cr.Say((11),"Item id not valid (format: ~run cheats vals 0 0 id)");
}

void Fly(Critter&cr,int pid,int p1,int p2)
{
	if(p2==0)
	{
		Critter@to=GetCritter(p1);
		cr.GetMap().RunFlyEffect(pid,cr,to,cr.HexX,cr.HexY,to.HexX,to.HexY);
	}
	else
	{
		cr.GetMap().RunFlyEffect(pid,cr,null,cr.HexX,cr.HexY,p1,p2);
	}
}

void grab(Critter&player,int,int,int id)
{
	Item@grabThis=GetItem(id);
	if((@grabThis!=null))
	{
		MoveItem(grabThis,grabThis.GetCount(),player);
	}
}

void checkparam2(Critter&cr,int p,int r,int)
{
	Critter@target=GetCritter(r);
	if(!(@target!=null))
	return;
	if(GodOfTheRealm(target.Id))
	@target=null;
	cr.Say((11),"param "+p+": "+target.Param[p]);
}

void mapdata(Critter&cr,int p,int,int)
{
	cr.Say((11),"map data "+p+": "+cr.GetMap().GetData(p));
}

void setmapdata(Critter&cr,int p,int r,int)
{
	cr.GetMap().SetData(p,r);
}

void massteleport(Critter&cr,int p0,int p1,int p2)
{
	array<Critter@>crits;
	uint n=cr.GetMap().GetCritters(0,(0x0F)|(0x10),crits);
	for(uint i=0;i<n;i++)
	crits[i].TransitToMap(p0,0);
}   

array<string>authName;
array<uint>authId;

string GetAuthed(uint id)
{
	for(uint a=0,aLen=authId.length();a<aLen;a++)
	{
		if(authId[a]==id)
		return(authName[a]);
	}
	
	return("[error:"+id+"]");
} 

string AuthedInfo(uint id)
{
	string gm=GetAuthed(id);
	string player=GetSafePlayerName(id);
	if(gm!=player)
	gm+=" ("+player+",";
	else
	gm+=" (";
	
	Critter@cr=GetCritter(id);
	if((@cr!=null)&&cr.GetMapId()>0)
	gm+="map:"+cr.GetMapId()+",id:";
	
	gm+=id+")";
	
	return(gm);
}

void SetAuthed(uint id,string name)
{
	for(uint a=0,aLen=authId.length();a<aLen;a++)
	{
		if(authId[a]==id)
		{
			authName[a]=name;
			return;
		}
	}
	
	authId.insertLast(id);
	authName.insertLast(name);
}

void RemoveAuthed(uint id)
{
	for(uint a=0,aLen=authId.length();a<aLen;a++)
	{
		if(authId[a]==id)
		{
			authId.removeAt(a);
			authName.removeAt(a);
			return;
		}
	}
}             

uint GetRandomDeathAnimation()
{
	
	array<uint>anims=
	{
		(102),(103),(110),(111),(112),
		(113),(114),(115),(116),(117),(118),(119)
	}; 
	
	return(anims[Random(0,anims.length()-1)]);
} 

string GenderString(Critter&player,string male,string female,string it)
{
	switch(player.Param[(71)])
	{
		case(0):
		return(male);
		case(1):
		return(female);
		case(2):
		default:
		return(it);
	}
	;
	return(it);
}     

void ExecGiveCommand(array<string@>@command,Critter@player,Critter@target)
{
	bool legit=false;
	cheatGetOption(command,legit,"-legit");
	if(legit&&player.GetAccess()<(3))
	{
		player.Say((11),"You need admin access level to give a legit item.");
		return;
	}
	
	if((target.IsPlayer()&&target.GetAccess()==(0))&&!legit)
	{
		Map@map=target.GetMap();
		if(!(@map!=null)||((@map!=null)&&(!((((map.GetData((9))))&((0x80000000)))!=0))))
		{
			player.Say((11),"You can't give not legit items to a player in a legit map.");
			return;
		}
	} 
	
	player.Say((11),"Executing give command");
	
	int pid=0,number=1;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],pid);
	
	if(!parsed)
	{
		if(!GetItemPid(command[2],pid))
		{
			player.Say((11),"Item does not exist");
			return;
		}
	}
	if(command.length()>3)
	{
		
		StrToInt(command[3],number);
	}
	
	if(number==0)
	{
		player.Say((11),"Nothing to spawn.");
		return;
	}
	else if(number<0)
	{
		player.Say((11),"Negative value, nothing to spawn.");
		return;
	}
	
	Item@item=number>0?target.AddItem(pid,1):null;
	if((@item!=null))
	{
		if(legit)
		{
			ILog("legitspawn",AuthedInfo(player.Id)+" gave legit item "+"(Id:"+item.Id+") to critter "+target.Id);
			{if((@item!=null))
				item.Val9=player.Id;};
		}
		else
		{
			{if((@item!=null))
				item.Val9=(int((player.Id)|(0x80000000)));};
		}
		
		player.Say((11),"Whoa, I've just found "+number+" item(s) with pid "+pid);
		
		string script=GetParameterString(command,"-script");
		if(script!="")
		{
			player.Say((11),"Script: "+script);
			if(!item.SetScript(script))
			player.Say((11)," !! ERROR setting script.");
			item.Update();
		}
		
		if(GetGvar((1234))==1)
		{
			eventItems.insertLast(item.Id);
		}
		player.LastSpawnedItem=item.Id;
		
		if(item.IsStackable())
		item.SetCount(number);
		else
		{
			for(int i=1;i<number;i++)
			{
				@item=target.AddItem(pid,1);
				if(legit)
				{
					ILog("legitspawn",AuthedInfo(player.Id)+" gave legit item "+"(Id:"+item.Id+") to critter "+target.Id);
					{if((@item!=null))
						item.Val9=player.Id;};
				}
				else
				{
					{if((@item!=null))
						item.Val9=(int((player.Id)|(0x80000000)));};
				}
				item.SetScript(script);
				item.Update();
			}
		}
	}
	else
	player.Say((11),"Failed to create "+number+" item(s) with pid "+pid);
}     

void ExecGiveKeyCommand(array<string@>@command,Critter@player,Critter@target)
{
	bool legit=false;
	cheatGetOption(command,legit,"-legit");
	if(legit&&player.GetAccess()<(3))
	{
		player.Say((11),"You need admin access level to create a legit key.");
		return;
	}
	
	if((target.IsPlayer()&&target.GetAccess()==(0))&&!legit)
	{
		Map@map=target.GetMap();
		if(!(@map!=null)||((@map!=null)&&(!((((map.GetData((9))))&((0x80000000)))!=0))))
		{
			player.Say((11),"You can't give not legit items to a player in a legit map.");
			return;
		}
	} 
	
	player.Say((11),"Executing give key command");
	
	int id=0,number=1;
	if(command.length()<2)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	if(!parsed)
	{
		player.Say((11),"Wrong key id");
		return;
	}
	if(command.length()>3)
	{
		
		StrToInt(command[3],number);
	}
	
	player.Say((11),""+number+" key(s) with id "+id+" created.");
	Item@it=target.AddItem((82),number);
	
	if((@it!=null))
	{
		it.LockerId=id;
		if(legit)
		{
			ILog("legitspawn",AuthedInfo(player.Id)+" spawned legit key "+id+" (Id:"+it.Id+")");
			{if((@it!=null))
				it.Val9=player.Id;};
		}
		else
		{
			{if((@it!=null))
				it.Val9=(int((player.Id)|(0x80000000)));};
		}
		it.Update();
		
		if(GetGvar((1234))==1)
		eventItems.insertLast(it.Id);
		
		player.LastSpawnedItem=it.Id;
		
	}
}        

void ExecAddNpcCommand(array<string@>@command,Critter@player,Critter@target,bool isMob,bool isFollower)
{
	if(isMob)
	player.Say((11),"Executing AddMob command");
	else if(!isFollower)
	player.Say((11),"Executing AddNpc command");
	else
	player.Say((11),"Executing AddFollower command");
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	uint16 pid=0;
	if(!StrToInt(command[2],pid)) 
	
	{
		player.Say((11),"Invalid arguments");
		return;
	}  
	
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"I wasn't able to obtain map object");
		return;
	}
	
	int dist=1;
	StrToInt(GetParameterString(command,"-dist"),dist);
	
	int x=target.HexX;
	int y=target.HexY;
	StrToInt(GetParameterString(command,"-x"),x);
	StrToInt(GetParameterString(command,"-y"),y);
	
	int dir=Random(0,6);
	StrToInt(GetParameterString(command,"-dir"),dir);
	
	int dialogId=0;
	StrToInt(GetParameterString(command,"-d"),dialogId);
	
	string script=GetParameterString(command,"-s");
	
	int aiPack=0;
	StrToInt(GetParameterString(command,"-a"),aiPack);
	
	int bagId=0;
	StrToInt(GetParameterString(command,"-b"),bagId);
	
	int teamIdPack=0;
	StrToInt(GetParameterString(command,"-t"),teamIdPack);
	
	int level=1;
	StrToInt(GetParameterString(command,"-l"),level);
	
	int respawnTime=-1;
	StrToInt(GetParameterString(command,"-r"),respawnTime);
	
	int npcRole=0;
	StrToInt(GetParameterString(command,"-role"),npcRole);
	
	int crType=0;
	StrToInt(GetParameterString(command,"-skin"),crType);
	
	int num=1;
	if(!StrToInt(GetParameterString(command,"-z"),num))
	{
		num=1;
	}
	;
	
	if(isFollower)
	{
		script="follower@critter_init";
		if(dialogId==0)
		dialogId=9310;
	}
	
	if(isMob)
	{
		script=("mob@critter_init");
	}  
	
	for(int i=0;i<num;i++)
	{
		
		Critter@SpawnedNpc=AddNpc(map,pid,x+Random(-dist,dist),y+Random(-dist,dist),dir,
		dialogId,script,aiPack,bagId,teamIdPack/100,(teamIdPack/10)%10,teamIdPack%10,isMob,level);
		
		if(!(@SpawnedNpc!=null))
		{
			player.Say((11),"Failed to spawn NPC.");
			return;
		}
		
		SpawnedNpc.StatBase[(84)]=respawnTime;
		SpawnedNpc.StatBase[(89)]=npcRole;
		if(crType!=0)
		{
			SpawnedNpc.ChangeCrType(crType);
			SpawnedNpc.StatBase[(112)]=crType;
		}
		if(GetGvar((1234))==1)
		{
			eventCritters.insertLast(SpawnedNpc.Id);
			(SpawnedNpc.ModeBase[(534)]=SpawnedNpc.Mode[(534)]|((0x00000400)));
		}
		
		if(GetIndexOfString(command,"-e")!=-1)
		(SpawnedNpc.ModeBase[(534)]=SpawnedNpc.Mode[(534)]|((0x00000800))); 
		
		player.Say((11),"Spawned npc: "+pid);
		player.Say((11),"Dialog: "+dialogId);
		player.Say((11),"Script: "+script);
		player.Say((11),"AiPack: "+aiPack);
		player.Say((11),"Bag: "+bagId);
		player.Say((11),"TeamPack: "+teamIdPack);
		player.Say((11),"Level: "+level);
		
		if(isFollower)
		{
			MakeFollower(SpawnedNpc,(5),"follower@FollowerBaseInit",dialogId,target,true);
			
			string name=GetParameterString(command,"-name");
			
			if(name=="")
			name=GetRandomFullName(SpawnedNpc.Stat[(71)]);
			SetLexem(SpawnedNpc,"$name",name);
			
			int attackpolicy=0;
			StrToInt(GetParameterString(command,"-c"),attackpolicy);
			SpawnedNpc.FollowerVarBase[(926)]=attackpolicy;
			
			int mode=0;
			StrToInt(GetParameterString(command,"-f"),mode);
			SpawnedNpc.FollowerVarBase[(925)]=mode;
		}
		player.LastSpawnedCritter=SpawnedNpc.Id;
		SpawnedNpc.SpawnedBy=player.Id;
	}
}   

void ExecSpawnItemCommand(array<string@>@command,Critter@player,Critter@target)
{
	bool legit=false;
	cheatGetOption(command,legit,"-legit");
	if(legit&&player.GetAccess()<(3))
	{
		player.Say((11),"You need admin access level to spawn a legit item.");
		return;
	}
	
	player.Say((11),"Spawning fat loot...");
	Map@map=target.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"Target on worldmap...");
		return;
	}
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	uint16 pid=0;
	
	bool parsed=StrToInt(command[2],pid);
	
	if(!parsed)
	{
		if(!GetItemPid(command[2],pid))
		{
			player.Say((11),"Item pid does not exist in the list.");
			return;
		}
	}
	int count=1;
	if(command.length()>3)
	StrToInt(command[3],count);
	if(count==0)
	{
		player.Say((11),"Nothing to spawn.");
		return;
	}
	else if(count<0)
	{
		player.Say((11),"Negative value, nothing to spawn.");
		return;
	}
	ProtoItem@proto=GetProtoItem(pid);
	if(!(@proto!=null))
	{
		player.Say((11),"Wrong proto number.");
		return;
	}
	uint16 x=target.HexX;
	uint16 y=target.HexY;
	StrToInt(GetParameterString(command,"-x"),x);
	StrToInt(GetParameterString(command,"-y"),y); 
	
	array<Item@>items;
	Item@cont;
	map.GetItems(x,y,items);
	if(items.length()==1&&items[0].GetType()==(8))
	{
		player.Say((11),"Container detected...");
		@cont=items[0];
	}
	
	uint max=count;
	StrToInt(GetParameterString(command,"-max"),max);
	uint min=max;
	StrToInt(GetParameterString(command,"-min"),min);
	min=(((min)<(max))?(min):(max));
	int chance=100;
	StrToInt(GetParameterString(command,"-c"),chance);
	chance=(((chance)>(100))?(100):(((chance)<(1))?(1):(chance)));
	int amount=1;
	StrToInt(GetParameterString(command,"-a"),amount);
	
	bool optLine=false;
	bool optCirc=false;
	cheatGetOption(command,optLine,"-line");
	cheatGetOption(command,optCirc,"-circ"); 
	
	if(chance>=Random(1,100))
	{
		Item@it;
		count=Random(min,max);
		uint spawned=0;
		int radius=0;
		StrToInt(GetParameterString(command,"-r"),radius);
		
		array<uint16>xList;
		array<uint16>yList;
		if(optLine)
		{
			HexLine(player.HexX,player.HexY,x,y,xList,yList);
			count=xList.length;
		}
		else if(optCirc)
		{
			if(radius<1)
			radius=1;
			HexCircle(x,y,radius,xList,yList);
			count=xList.length;
		}
		
		for(int i=0;i<count;i++)
		{
			if(optLine||optCirc)
			{
				@it=map.AddItem(xList[i],yList[i],pid,1);
			}
			else
			{
				if((@cont!=null))
				@it=cont.AddItem(pid,1,0);
				else
				@it=map.AddItem(x+Random(-radius,radius),y+Random(-radius,radius),pid,1);
			} 
			
			if((@it!=null))
			{
				if(legit)
				{
					ILog("legitspawn",AuthedInfo(player.Id)+" spawned legit item (Id:"+it.Id+")");
					{if((@it!=null))
						it.Val9=player.Id;};
				}
				else
				{
					{if((@it!=null))
						it.Val9=(int((player.Id)|(0x80000000)));};
				}
				
				spawned++;
				
				if(it.IsStackable())
				it.SetCount(amount);
				
				if((it.GetType()==(9)||it.GetType()==(8))&&
				it.Proto.Container_Changeble)
				{
					it.LockerOpen();
					it.LockerClose();
				}
				
				if(pid==(545))
				{
					
					((it.Flags)=(it.Flags)|((0x00020000)));
					it.Update();
					
					uint skill=150;
					StrToInt(GetParameterString(command,"-s"),skill);
					it.TrapValue=skill/5+10;
					it.Val4=(skill);
					if(GetIndexOfString(command,"-b")!=-1)
					it.Val5=(1);
					else
					it.Val5=(0);
					it.SetScript("explode@_ExplodeInit");
				}
				if(pid==(822))
				{
					
					uint skill=150;
					StrToInt(GetParameterString(command,"-s"),skill);
					(it.Val3)=skill;
					uint dmg=0;
					StrToInt(GetParameterString(command,"-dmg"),dmg);
					(it.Val4)=dmg;
				}
				
				string script=GetParameterString(command,"-script");
				if(script!="")
				{
					player.Say((11),"Script: "+script);
					it.SetScript(script);
				}
				
				if(GetIndexOfString(command,"-v0")>=0)
				StrToInt(GetParameterString(command,"-v0"),it.Val0);
				if(GetIndexOfString(command,"-v1")>=0)
				StrToInt(GetParameterString(command,"-v1"),it.Val1);
				if(GetIndexOfString(command,"-v2")>=0)
				StrToInt(GetParameterString(command,"-v2"),it.Val2);
				if(GetIndexOfString(command,"-v3")>=0)
				StrToInt(GetParameterString(command,"-v3"),it.Val3);
				if(GetIndexOfString(command,"-v4")>=0)
				StrToInt(GetParameterString(command,"-v4"),it.Val4);
				if(GetIndexOfString(command,"-v5")>=0)
				StrToInt(GetParameterString(command,"-v5"),it.Val5);
				if(GetIndexOfString(command,"-v6")>=0)
				StrToInt(GetParameterString(command,"-v6"),it.Val6);
				if(GetIndexOfString(command,"-v7")>=0)
				StrToInt(GetParameterString(command,"-v7"),it.Val7);
				if(GetIndexOfString(command,"-v8")>=0)
				StrToInt(GetParameterString(command,"-v8"),it.Val8);
				
				it.Update();
				
				if(it.Val0!=0)
				{
					player.Say((11),"Val0: "+it.Val0);
				}
				if(it.Val1!=0)
				{
					player.Say((11),"Val1: "+it.Val1);
				}
				if(it.Val2!=0)
				{
					player.Say((11),"Val2: "+it.Val2);
				}
				if(it.Val3!=0)
				{
					player.Say((11),"Val3: "+it.Val3);
				}
				if(it.Val4!=0)
				{
					player.Say((11),"Val4: "+it.Val4);
				}
				if(it.Val5!=0)
				{
					player.Say((11),"Val5: "+it.Val5);
				}
				if(it.Val6!=0)
				{
					player.Say((11),"Val6: "+it.Val6);
				}
				if(it.Val7!=0)
				{
					player.Say((11),"Val7: "+it.Val7);
				}
				if(it.Val8!=0)
				{
					player.Say((11),"Val8: "+it.Val8);
				}
				
				player.LastSpawnedItem=it.Id; 
				
			}
		}
		player.Say((11),""+spawned+" item(s) spawned.");
	}
	else
	player.Say((11),"Item(s) not spawned, chance test not passed.");
}   

void ExecLockCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Close, Simsim!");
	
	Map@map=target.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"Target on the worldmap.");
	}
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	int x=target.HexX;
	int y=target.HexY;
	StrToInt(GetParameterString(command,"-x"),x);
	StrToInt(GetParameterString(command,"-y"),y);
	
	Item@locker=map.GetDoor(x,y);
	if(!(@locker!=null))
	{
		array<Item@>items;
		map.GetItems(x,y,items);
		if(items.length()==1&&items[0].GetType()==(8))
		@locker=items[0];
	}
	if((@locker!=null))
	{
		int complexity=100;
		StrToInt(command[2],complexity);
		locker.LockerComplexity=complexity;
		int lockerid=Random(0,65535);
		StrToInt(GetParameterString(command,"-i"),lockerid);
		locker.LockerId=lockerid;
		Item@key=player.AddItem((82),1);
		key.LockerId=lockerid;
		string desc=GetParameterString(command,"-d");
		if(desc!="")
		{
			key.Info=2;
			SetLexem(key,"$desc",desc);
		}
		key.Update();
	}
	else
	player.Say((11),"Couldn't obtain the locker.");
}    

void ExecCloneCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"You turn into yourself. Whew, that was easy.");
		return;
	}
	
	if(target.IsPlayer())
	{
		if((player.GetAccess()<target.GetAccess())||GodOfTheRealm(target.Id))
		{
			player.Say((11),"You can't turn into this being.");
			return;
		}
	}
	
	bool optFull=false;
	cheatGetOption(command,optFull,"-full");
	
	if(optFull)
	{
		if(player.GetAccess()<(3))
		{
			player.Say((11),"This option requires admin access level.");
			return;
		}  
		
		for(uint i=0;i<=999;i++)
		player.ParamBase[i]=target.ParamBase[i];  
		
		if(player.ChangeCrType(target.CrType))
		player.ParamBase[(112)]=target.ParamBase[(112)];  
		
		if(IsLexem(target,"$~"))
		SetLexem(player,"$~",GetLexem(target,"$~"));
		else
		UnsetLexem(player,"$~");
		if(IsLexem(target,"$tatoo"))
		SetLexem(player,"$tatoo",GetLexem(target,"$tatoo"));
		else
		UnsetLexem(player,"$tatoo");
		if(target.IsNpc())
		{
			SetLexem(player,"$name","@msg dlg "+target.GetProtoId()+"0@");
			UnsetLexem(player,"$@");
			SetLexem(player,"$@","");
		}
		else
		{
			SetLexem(player,"$name",GetSafePlayerName(target.Id)+"'s clone");
			SetLexem(player,"$@",GetSafePlayerName(target.Id)+"'s clone");
		}      
		
		array<Item@>playerItems={};
		if(player.GetItems(-1,playerItems)>0)
		{
			DeleteItems(playerItems);
		}   
		
		array<uint>values={player.Id,target.Id};
		CreateTimeEvent(((__FullSecond)+(((1)*__TimeMultiplier))),"e_ExecCloneItems",values,false);
		
		player.Say((11),"You look exactly like the critter "+target.Id+".");
	}
	else
	{ 
		
		for(uint i=0;i<=__DamageEnd;i++)
		{
			player.ParamBase[i]=target.ParamBase[i];
		} 
		
		for(uint i=__TraitBegin;i<=__TraitEnd;i++)
		{
			player.ParamBase[i]=target.ParamBase[i];
		} 
		
		for(uint i=__ReputationBegin;i<=__ReputationEnd;i++)
		{
			player.ParamBase[i]=target.ParamBase[i];
		}
		
		player.Say((11),"You look similar to the critter "+target.Id+".");
	}
}

uint e_ExecCloneItems(array<uint>@values)
{
	Critter@player=GetCritter(values[0]);
	Critter@target=GetCritter(values[1]);
	
	if(!(@player!=null)||!(@target!=null))
	return 0;
	
	for(int slot=0;slot<(255);slot++)
	{
		array<Item@>targetItems={};
		uint num=target.GetItems(slot,targetItems);
		
		for(uint i=0;i<num;i++)
		{
			Item@source=targetItems[i];
			Item@copy=player.AddItem(source.Proto.ProtoId,source.GetCount());
			player.MoveItem(copy.Id,copy.GetCount(),slot);
			copy.SortValue=source.SortValue;
			copy.Info=source.Info;
			copy.PicMap=source.PicMap;
			copy.PicInv=source.PicInv;
			copy.AnimWaitBase=source.AnimWaitBase;
			copy.AnimStayBegin=source.AnimStayBegin;
			copy.AnimStayEnd=source.AnimStayEnd;
			copy.AnimShowBegin=source.AnimShowBegin;
			copy.AnimShowEnd=source.AnimShowEnd;
			copy.AnimHideBegin=source.AnimHideBegin;
			copy.AnimHideEnd=source.AnimHideEnd;
			copy.Cost=source.Cost;
			copy.Val0=source.Val0;
			copy.Val1=source.Val1;
			copy.Val2=source.Val2;
			copy.Val3=source.Val3;
			copy.Val4=source.Val4;
			copy.Val5=source.Val5;
			copy.Val6=source.Val6;
			copy.Val7=source.Val7;
			copy.Val8=source.Val8;
			copy.Val9=player.Id;
			copy.LightIntensity=source.LightIntensity;
			copy.LightDistance=source.LightDistance;
			copy.LightFlags=source.LightFlags;
			copy.LightColor=source.LightColor;
			copy.Indicator=source.Indicator;
			copy.BrokenFlags=source.BrokenFlags;
			copy.BrokenCount=source.BrokenCount;
			copy.Deterioration=source.Deterioration;
			copy.AmmoPid=source.AmmoPid;
			copy.AmmoCount=source.AmmoCount;
			copy.LockerId=source.LockerId;
			copy.LockerCondition=source.LockerCondition;
			copy.LockerComplexity=source.LockerComplexity;
			copy.Charge=source.Charge;
			copy.RadioChannel=source.RadioChannel;
			copy.RadioFlags=source.RadioFlags;
			copy.RadioBroadcastSend=source.RadioBroadcastSend;
			copy.RadioBroadcastRecv=source.RadioBroadcastRecv;
			copy.HolodiskNumber=source.HolodiskNumber;
			copy.OffsetX=source.OffsetX;
			copy.OffsetY=source.OffsetY;
			copy.Dir=source.Dir;
			copy.set_Flags(source.get_Flags());
			copy.Update();
		}
	}
	return 0;
}     

void ExecSpawnCarCommand(array<string@>@command,Critter@player,Critter@target)
{
	bool legit=false;
	cheatGetOption(command,legit,"-legit");
	if(legit&&player.GetAccess()<(3))
	{
		player.Say((11),"You need admin access level to spawn a legit car.");
		return;
	}
	
	player.Say((11),"Spawning car...");
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	int pid=0;
	
	bool parsed=StrToInt(command[2],pid);
	
	if(!parsed)
	{
		if(!GetItemPid(command[2],pid))
		{
			player.Say((11),"Item pid does not exist in the list.");
			return;
		}
	}
	int keyId=Random(10000,50000);
	StrToInt(GetParameterString(command,"-k"),keyId);
	
	Map@map=target.GetMap();
	
	Item@car;
	for(uint16 x=target.HexX-2;x<=target.HexX+2;x++)
	{
		for(uint16 y=target.HexY-2;x<=target.HexY+2;y++)
		{
			@car=map.AddItem(x,y,pid,1);
			if((@car!=null))
			break;
		}
		if((@car!=null))
		break;
	}
	if(!(@car!=null))
	{
		player.Say((11),"Couldn't spawn car.");
		return;
	}
	car.LockerId=keyId;
	car.Charge=0;
	car.Update();
	
	Item@bag=car.GetChild(0);
	if((@bag!=null))
	{
		bag.LockerId=keyId;
		bag.LockerComplexity=Random(50,100);
		bag.Update();
	}
	else
	player.Say((11),"Couldn't obtain car trunk.");
	
	Item@key=target.AddItem((82),1);
	if((@key!=null))
	{
		key.LockerId=keyId;
		key.Update();
	}
	
	if(legit)
	{
		ILog("legitspawn",AuthedInfo(player.Id)+" spawned legit car (Id:"+car.Id+")");
		{if((@car!=null))
			car.Val9=player.Id;};
		{if((@bag!=null))
			bag.Val9=player.Id;};
		{if((@key!=null))
			key.Val9=player.Id;};
	}
	else
	{
		{if((@car!=null))
			car.Val9=(int((player.Id)|(0x80000000)));};
		{if((@bag!=null))
			bag.Val9=(int((player.Id)|(0x80000000)));};
		{if((@key!=null))
			key.Val9=(int((player.Id)|(0x80000000)));};
	}
	
	player.LastSpawnedItem=car.Id;     
	
	if(GetGvar((1234))==1)
	{
		eventItems.insertLast(car.Id);
		eventItems.insertLast(bag.Id);
		eventItems.insertLast(key.Id);
	}
	
	player.Say((11),"Now go and drive.");
}     

void ExecCreateLocationCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Executing CreateLocation command");
	int pid=0;
	
	bool legit=false;
	cheatGetOption(command,legit,"-legit");
	if(legit&&player.GetAccess()<(3))
	{
		player.Say((11),"You need admin access level to create a legit location.");
		return;
	}
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	if(!StrToInt(command[2],pid)) 
	
	{
		player.Say((11),"Invalid arguments");
		return;
	}     
	
	Critter@[]crits={player};
	int id=CreateLocation(pid,player.WorldX,player.WorldY,crits);
	
	if(id==0)
	{
		player.Say((11),"I wasn't able to create location.");
	}
	else
	{
		player.Say((11),"Created location, id: "+id);
		
		array<Map@>maps;
		Location@loc=GetLocation(id);
		Map@map=loc.GetMapByIndex(0);
		WeatherUpdateFast(loc);
		uint n=loc.GetMaps(maps);
		if(GetIndexOfString(command,"-t")!=-1)
		player.TransitToMap(map.Id,0);
		
		if(legit)
		{
			ILog("legitspawn",AuthedInfo(player.Id)+" created legit location "+"(Id:"+id+")");
		}
		for(uint i=0;i<n;i++)
		{
			maps[i].SetData((1),(__FullSecond));
			if(legit)
			maps[i].SetData((9),player.Id);
			else
			maps[i].SetData((9),(int((player.Id)|(0x80000000))));
		}
		player.LastSpawnedLocation=id;
	}
}  

void ExecDeleteLocationCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Executing DeleteLocation command");
	
	uint id=0;
	if((@player.GetMap()!=null))
	{
		id=player.GetMap().GetLocation().Id;
		DeleteLocation(id);
		player.Say((11),"Deleted location with id: "+id);
	}
	else
	player.Say((11),"Not in valid location.");
	
}    

void ExecChangeRankCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing ChangeRank command");
	uint newRank=0;
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	if(!StrToInt(command[2],newRank))
	{
		player.Say((11),"Invalid arguments");
		return;
	}
	
	uint faction=GetGroupIndex(target); 
	
	if(faction>(1))
	{
		int res=ChangeRank(faction,target.Id,newRank);
		player.Say((11),"ChangeRank returned: "+FD_Result2String(res));
	}
	else
	player.Say((11),"Not a member of any faction");
}    

void ExecChangeFactionCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing ModifyFaction command");
	uint newFaction=0;
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	if(!StrToInt(command[2],newFaction))
	{
		player.Say((11),"Invalid arguments");
		return;
	}
	bool applyModifiers=false;
	if(GetIndexOfString(command,"-r")!=-1)
	applyModifiers=true;
	uint oldFaction=GetGroupIndex(target);
	int res=0;
	if(oldFaction!=(1))
	{
		
		res=ExpelMember(oldFaction,target.Id,applyModifiers);
		player.Say((11),"Expelling from previous faction: "+FD_Result2String(res));
	}
	res=AddMember(newFaction,target.Id,applyModifiers);
	player.Say((11),"AddMember returned: "+FD_Result2String(res));
}    

void ExecShowVarsCommand(array<string@>@command,Critter@player,Critter@target)
{
	
	player.Say((11),"DEPRECATED, use `critterinfo / `crinfo");
	player.Say((11),"  `critterinfo -p [player_name/id]");
	player.Say((11),"  `critterinfo -n [npc_id]");                   
	
}  

void ExecRemoveFactionCommand(array<string@>@command,Critter@player)
{
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	uint factionId=0;
	StrToInt(command[2],factionId);
	if(factionId>=(2)&&factionId<(4096))
	{
		if(RemoveFaction(factionId))
		player.Say((11),"Removed faction: "+factionId);
		else
		player.Say((11),"Unable to remove faction.");
	}
	else
	player.Say((11),"Wrong faction id");
}

bool ParseFactionBaseLocationId(const string&fparam,uint&out locId)
{
	int baseIdx=-1;
	int faction=0;
	array<string@>@fparams=split(fparam,".");
	if(fparams.length()>=1)
	{
		if(!StrToInt(fparams[0],faction))
		return(false);
		
		if(fparams.length()>=2)
		{
			stringReplaceText(fparams[1],"_"," ");
			StrToInt(fparams[1],baseIdx);
		}
		else
		baseIdx=0;
	}
	else
	return(false);
	
	if(baseIdx>=0)
	{
		array<IFactionBase@>bases;
		int count=GetFactionBases(faction,bases);
		if(baseIdx>count-1)
		return(false);
		else
		{
			locId=bases[baseIdx].get_LocationId();
			return(true);
		}
	}
	else
	{
		{;};
		IFactionBase@base=GetFactionBase(faction,fparams[1]);
		if((@base!=null))
		{
			locId=base.get_LocationId();
			return(true);
		}
		else
		return(false);
	}
}   

void ExecLocVisCommand(array<string@>@command,Critter@player,Critter@target,bool show)
{
	int locId=0;
	StrToInt(GetParameterString(command,"-l"),locId);
	if(locId==0)
	{
		if(!ParseFactionBaseLocationId(GetParameterString(command,"-f"),locId))
		{
			player.Say((11),"Unable to parse faction location param. Must be in form <faction_id>_<basename>.");
			return;
		}
	}
	if(locId==0)
	{
		player.Say((11),"Couldn't obtain location id.");
		return;
	}
	if(show)
	{
		player.Say((11),"Showing location "+locId+" to "+target.Name);
		target.SetKnownLoc(true,locId);
	}
	else
	{
		player.Say((11),"Hiding location "+locId+" from "+target.Name);
		target.UnsetKnownLoc(true,locId);
	}
}    

void ExecSetTimeoutCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing settimeout command");
	
	int to=0;
	if(command.length()==2)
	{
		player.TimeoutBase[(239)]=((__FullSecond)+(((1)*__TimeMultiplier*86400)));
		return;
	}
	
	if(!StrToInt(command[2],to))
	{
		player.Say((11),"Invalid arguments");
		return;
	}
	target.TimeoutBase[(239)]=((__FullSecond)+(to));
}   

void ExecGetVarCommand(array<string@>@command,Critter@player,uint targetId)
{
	player.Say((11),"Executing GetVar command");
	
	int id=0;
	if(command.length()<2)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	
	if(!parsed)
	{
		if(!GetVarId(command[2],id))
		{
			player.Say((11),"LVAR does not exist");
			return;
		}
	} 
	
	GameVar@var=GetLocalVar(id,targetId);
	if((@var!=null))
	player.Say((11),GetSafePlayerName(targetId)+"'s "+"Var value is: "+var.GetValue());
	else
	player.Say((11),"LVAR not found");
}   

void ExecSetVarCommand(array<string@>@command,Critter@player,uint targetId)
{
	player.Say((11),"Executing SetVar command");
	
	int id=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	
	if(!parsed)
	{
		if(!GetVarId(command[2],id))
		{
			player.Say((11),"LVAR does not exist");
			return;
		}
	}
	int val=0;
	if(!StrToInt(command[3],val))
	{
		player.Say((11),"Wrong value");
		return;
	} 
	
	GameVar@var=GetLocalVar(id,targetId);
	if((@var!=null))
	{
		player.Say((11),GetSafePlayerName(targetId)+"'s "+"Var value is: "+var.GetValue()+", changing to: "+val);
		var=val;
	}
	else
	player.Say((11),"LVAR not found");
}     

void ExecGetUVarCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing GetUVar command");
	
	int id=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	
	if(!parsed)
	{
		if(!GetVarId(command[2],id))
		{
			player.Say((11),"UVAR does not exist");
			return;
		}
	}  
	
	array<Critter@>critters;
	uint num=target.GetCritters(false,(0x0F),critters);
	GameVar@var;
	for(uint i=0;i<num;i++)
	{
		if(GetIndexOfString(command,"-r")!=-1)
		@var=GetUnicumVar(id,target.Id,critters[i].Id);
		else
		@var=GetUnicumVar(id,critters[i].Id,target.Id);
		
		if((@var!=null))
		critters[i].Say((1),"Var value is: "+var.GetValue());
		else
		critters[i].Say((1),"UVAR null");
	}
}   

void ExecSetUVarCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing SetUVar command");
	
	int id=0;
	if(command.length()<4)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	
	if(!parsed)
	{
		if(!GetVarId(command[2],id))
		{
			player.Say((11),"LVAR does not exist");
			return;
		}
	}
	int val=0;
	if(!StrToInt(command[3],val))
	{
		player.Say((11),"Wrong value");
		return;
	} 
	
	array<Critter@>critters;
	uint num=target.GetCritters(false,(0x0F),critters);
	GameVar@var;
	bool set=false;
	for(uint i=0;i<num;i++)
	{
		if(GetDistantion(target.HexX,target.HexY,critters[i].HexX,critters[i].HexY)>1)
		continue;
		
		if(GetDirection(target.HexX,target.HexY,critters[i].HexX,critters[i].HexY)!=target.Dir)
		continue;
		
		if(GetIndexOfString(command,"-r")!=-1)
		@var=GetUnicumVar(id,target.Id,critters[i].Id);
		else
		@var=GetUnicumVar(id,critters[i].Id,target.Id);
		if((@var!=null))
		{
			var=val;
			critters[i].Say((1),"Setting var value to: "+var.GetValue());
			set=true;
		}
		else
		critters[i].Say((1),"UVAR null");
	}
	if(!set)
	player.Say((11),"Critter should be in front of target");
}   

void ExecKillCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Executing... critter?"); 
	
	if(command.length()<3)
	{
		uint16 frontHexX=player.HexX;
		uint16 frontHexY=player.HexY;
		Map@map=player.GetMap();
		if((@map!=null))
		{
			map.MoveHexByDir(frontHexX,frontHexY,player.Dir,1);
			Critter@cr=map.GetCritter(frontHexX,frontHexY);
			if((@cr!=null))
			{
				if(cr.IsPlayer())
				cr.ModeBase[(532)]=1;
				cr.ToDead(GetRandomDeathAnimation(),null);
			}
			else
			player.Say((11),"Nobody to kill.");
		}
		else
		player.Say((11),"Nobody to kill.");
	}
	else
	{
		if(command[2]=="players")
		{
			player.Say((11),"Killing all Players in sight...");
			array<Critter@>critters;
			uint num=player.GetCritters(false,(0x10)|(0x01),critters);
			for(uint i=0;i<num;i++)
			{
				target.ModeBase[(532)]=1;
				critters[i].ToDead(GetRandomDeathAnimation(),null);
			}
		}
		else if(command[2]=="npcs")
		{
			player.Say((11),"Killing all NPCs in sight...");
			array<Critter@>critters;
			uint num=player.GetCritters(false,(0x20)|(0x01),critters);
			for(uint i=0;i<num;i++)
			{
				if((critters[i].IsNpc()&&!(((critters[i].Mode[(534)]&((0x00000020)))!=0))))
				critters[i].ToDead(GetRandomDeathAnimation(),null);
			}
		}
		else if(command[2]=="all")
		{
			player.Say((11),"Killing all critters in sight...");
			array<Critter@>critters;
			uint num=player.GetCritters(false,(0x01),critters);
			for(uint i=0;i<num;i++)
			{
				if(critters[i].IsPlayer())
				target.ModeBase[(532)]=1;
				critters[i].ToDead(GetRandomDeathAnimation(),null);
			}
		}
		else
		{
			
			if(player.Id==target.Id)
			{
				player.Say((11),"Are you crazy?");
				return;
			}
			
			if((@target!=null))
			{
				target.Say((11),"Out of a sudden, you decided to be a little bit dead. Sleep tight.");
				if(target.IsPlayer())
				target.ModeBase[(532)]=1;
				target.ToDead(GetRandomDeathAnimation(),null);
				player.Say((11),GetSafePlayerName(target.Id)+" died a painful death. You feel quite good about it.");
			}
			else
			player.Say((11),"Player not found");
		}
	}
}    

void ExecRegisterFactionCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Executing RegisterFaction command");
	
	int id=0;
	if(command.length()<4)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	if(!StrToInt(command[2],id))
	{
		player.Say((11),"Invalid parameters");
		return;
	}
	int res=RegisterFaction(id,command[3],true);
	if(res==(0))
	player.Say((11),"Faction registered");
	else
	player.Say((11),"Faction couln't be registered");
}   

void ExecTeleportCommand(array<string@>@command,Critter@player,Critter@target,bool team)
{
	player.Say((11),"Teleporting");
	
	uint mapId=0;
	uint entId=0;
	int hexX=-1,hexY=-1;
	bool toHex=false;
	if(command.length()>2)
	{
		if(GetIndexOfString(command,"-f")==-1)
		{
			if(!StrToInt(command[2],mapId))
			{
				if(Maps.exists(command[2]))
				Maps.get(command[2],mapId);
				else
				mapId=0;
			}
		}
		else
		{
			uint locid=0;
			if(ParseFactionBaseLocationId(command[2],locid))
			{
				Location@loc=GetLocation(locid);
				if((@loc!=null))
				{
					Map@map=loc.GetMapByIndex(0);
					if((@map!=null))
					{
						mapId=map.Id;
					}
				}
			}
			else
			{
				player.Say((11),"To teleport to faction base, command parameter must be in form:");
				player.Say((11)," teleport <factionId> -f (translated to <faction_id>.0)");
				player.Say((11)," teleport <factionId>.<baseNumber> -f (starting from 0)");
				player.Say((11)," teleport <factionId>.<baseName> -f (use _ instead of whitespace)");
				return;
			}
		}
	}
	if(mapId==0)
	{
		if(target.GetMapId()!=0)
		mapId=target.GetMapId();
		else
		{
			player.Say((11),"Invalid parameters. Your current map is worldmap.");
			return;
		}
	}
	
	StrToInt(GetParameterString(command,"-x"),hexX);
	StrToInt(GetParameterString(command,"-y"),hexY);
	if(hexX!=-1&&hexY!=-1)
	toHex=true;
	
	if(!toHex&&command.length()>3)
	{
		if(!StrToInt(command[3],entId))
		entId=0;
	}
	
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		@target=@target.GetFollowLeader();
		
		array<Critter@>followers;
		uint num=target.GetFollowGroup((0x0F),followers);
		for(uint i=0;i<num;i++)
		{
			if(toHex)
			followers[i].TransitToMap(mapId,hexX,hexY,followers[i].Dir);
			else
			followers[i].TransitToMap(mapId,entId);
		}
	}
	
	if(toHex)
	{
		if(target.TransitToMap(mapId,hexX,hexY,target.Dir))
		player.Say((11),"Teleported to location "+mapId+" at position: "+hexX+", "+hexY);
		else
		player.Say((11),"Couldn't teleport to location "+mapId+" at position: "+hexX+", "+hexY);
	}
	else
	{
		if(target.TransitToMap(mapId,entId))
		player.Say((11),"Teleported to location "+mapId+" at entrance: "+entId);
		else
		player.Say((11),"Couldn't teleport to location "+mapId+" at entrance: "+entId);
	}
	
}                                                                                   

void ExecTeleporterCommand(array<string@>@command,Critter@player)
{
	uint16 hx=player.HexX;
	uint16 hy=player.HexY;
	
	uint16 tx=0;
	uint16 ty=0;
	
	uint mapId=0;
	
	int dir=Random(0,6);
	
	bool allowItems=false;
	
	cheatGetOption(command,hx,"-x");
	cheatGetOption(command,hy,"-y");
	cheatGetOption(command,tx,"-tx");
	cheatGetOption(command,ty,"-ty");
	cheatGetOption(command,mapId,"-map");
	cheatGetOption(command,allowItems,"-it");
	cheatGetOption(command,dir,"-dir");
	dir=dir%6;
	
	if(mapId==0)
	{
		player.Say((11),"No Map ID given. Use -map <mapId>");
		return;
	}
	
	if(tx==0||ty==0)
	{
		player.Say((11),"No destination coordinates given. Use -tx <X> and -ty <Y>");
		return;
	}
	
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"You are not on valid map.");
		return;
	}
	
	uint pid=319;
	uint dialogId=10810;
	Critter@npc=AddNpc(map,pid,hx,hy,dir,
	dialogId,"",0,0,0,0,0,false,9999);
	
	if(!(@npc!=null))
	{
		player.Say((11),"Failed to create teleporter npc.");
		return;
	}
	int teleportPolicy=0;
	((teleportPolicy)=(teleportPolicy)|((0x04)));
	if(!allowItems)
	((teleportPolicy)=(teleportPolicy)|((0x01)));
	SetLvar(npc,(12013),teleportPolicy);
	SetLvar(npc,(12012),mapId);
	npc.ParamBase[(91)]=(((ty<<16)&0xFFFF0000)|(tx&0x0000FFFF));
	npc.SpawnedBy=player.Id;
}    

void ExecShiftCommand(array<string@>@command,Critter@player,Critter@target,bool team,bool random)
{
	player.Say((11),"Shifting");
	
	uint16 hexX,hexY;
	uint amount=2;
	
	if(command.length()>2)
	{
		StrToInt(command[2],amount);
	}
	
	hexX=target.HexX;
	hexY=target.HexY;
	
	if(random)
	{
		hexX+=Random(-20,20);
		hexY+=Random(-20,20);
	}
	else
	player.GetMap().MoveHexByDir(hexX,hexY,target.Dir,amount);
	
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		@target=@target.GetFollowLeader();
		hexX=target.HexX;
		hexY=target.HexY;
		
		if(random)
		{
			hexX+=Random(-20,20);
			hexY+=Random(-20,20);
		}
		else
		player.GetMap().MoveHexByDir(hexX,hexY,target.Dir,amount);
		
		array<Critter@>followers;
		uint num=target.GetFollowGroup((0x0F),followers);
		for(uint i=0;i<num;i++)
		followers[i].TransitToHex(hexX,hexY,0xff);
	}
	bool res=target.TransitToHex(hexX,hexY,0xff);
	if(res)
	player.Say((11),"Shifted!");
	else
	player.Say((11),"Tsk, tsk");
}    

bool Teleport(Critter@player,Critter@target,bool Safe)
{
	int ModX=0;
	int ModY=0;
	if(Safe)
	{
		(Random(0,1)==0?ModX=1:ModX=-1);
		ModY=ModX;
		ModX*=Random(2,10);
		ModY*=Random(2,10);
	}
	
	if(player.GetMapId()==target.GetMapId()&&player.GetMapId()!=0)
	return player.TransitToHex(target.HexX+ModX,target.HexY+ModY,0xff);
	else if(target.GetMapId()!=0)
	return player.TransitToMap(target.GetMapId(),target.HexX+ModX,target.HexY+ModY,0xff);
	else
	{
		
		if(player.GetMapId()==0)
		player.TransitToMap(1,0);
		return player.TransitToGlobalGroup(target.Id);
	}
}

void ExecSummonCommand(array<string@>@command,Critter@player,Critter@target,bool team)
{
	if(WrathOfTheGod(target))
	@target=player;
	
	if(team)
	player.Say((11),"Summoning team");
	else
	player.Say((11),"Summoning");
	
	if(player.Id==target.Id)
	{
		player.Say((11),"Wrong target.");
		return;
	}
	
	uint id=player.GetMapId();
	
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		@target=@target.GetFollowLeader();
	}
	
	target.StatBase[(97)]=target.GetMapId();
	target.StatBase[(98)]=target.HexX;
	target.StatBase[(99)]=target.HexY;
	
	uint num=0;
	
	if(team)
	{
		array<Critter@>followers;
		num=target.GetFollowGroup((0x0F),followers);
		for(uint i=0;i<num;i++)
		{
			
			followers[i].StatBase[(97)]=followers[i].GetMapId();
			followers[i].StatBase[(98)]=followers[i].HexX;
			followers[i].StatBase[(99)]=followers[i].HexY;
			if(Teleport(followers[i],player,false))
			num++;
		}
	}
	
	if(Teleport(target,player,false))
	num++;
	player.Say((11),num+" players summoned");
}   

void ExecDismissCommand(array<string@>@command,Critter@player,Critter@target,bool team)
{
	if(WrathOfTheGod(target))
	@target=player;
	
	if(team)
	player.Say((11),"Dismissing team");
	else
	player.Say((11),"Dismissing");
	
	if(player.Id==target.Id)
	{
		player.Say((11),"Wrong target.");
		return;
	}
	
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		{
			@target=@target.GetFollowLeader();
			{};
		}
	}
	
	if(team)
	{
		array<Critter@>followers;
		uint num=target.GetFollowGroup((0x0F),followers);
		{};
		for(uint i=0;i<num;i++)
		{
			if(followers[i].Stat[(97)]!=target.Stat[(97)])
			{
				{};
				followers[i].TransitToMap(target.Stat[(97)],target.Stat[(98)],target.Stat[(99)],0xff);
			}
			else
			
			followers[i].TransitToMap(followers[i].Stat[(97)],followers[i].Stat[(98)],followers[i].Stat[(99)],0xff);
		}
	}
	
	target.TransitToMap(target.Stat[(97)],target.Stat[(98)],target.Stat[(99)],0xff);
	player.Say((11),"Dismissed");
}   

void ExecGoToCommand(array<string@>@command,Critter@player,Critter@target,bool team)
{
	if(WrathOfTheGod(target))
	@target=player;
	
	if(team)
	player.Say((11),"Going to with team...");
	else
	player.Say((11),"Going to...");
	
	bool Safe=(GetIndexOfString(command,"-s")!=-1);
	
	int ItemId=0;
	StrToInt(GetParameterString(command,"-i"),ItemId);
	Item@It=ItemId>0?GetItem(ItemId):null;
	if(ItemId>0)
	{
		if((@It!=null))
		{
			if(It.Accessory==(1))
			{
				Critter@ItCritter=GetCritter(It.CritId);
				@target=ItCritter;
				string@carrier=GetSafePlayerName(It.CritId);
				player.Say((11),"Item is carried by critter "+It.CritId+
				((@carrier!=null)?" ("+carrier+")":""));
			}
			else
			{
				@target=null;
				if(player.GetMapId()==It.MapId&&player.GetMapId()!=0)
				player.TransitToHex(It.HexX,It.HexY,0xff);
				else if(It.MapId!=0)
				player.TransitToMap(It.MapId,It.HexX,It.HexY,0xff);
			}
		}
		else
		{
			player.Say((11),"Item not valid");
			return;
		}
	}
	
	if((!(@target!=null)&&!(@It!=null))||((@target!=null)&&target.Id==player.Id))
	{
		player.Say((11),"Target not valid");
		return;
	}
	
	if(target.GetMapId()==0&&(GetIndexOfString(command,"-f")==-1))
	{
		player.Say((11),"Target is on the worldmap. Use -f to go there anyway.");
		return;
	}
	
	uint num=0;
	
	if((@target!=null))
	{
		if(Teleport(player,target,Safe))
		num++;
	}
	if(team)
	{
		array<Critter@>followers;
		num=player.GetFollowGroup((0x0F),followers);
		for(uint i=0;i<num;i++)
		{
			if(Teleport(followers[i],player,false))
			num++;
		}
	}
	if((@target!=null))
	player.Say((11),num+" players teleported to "+target.Name+" ("+target.GetMapId()+")");
	else if((@It!=null))
	player.Say((11),num+" players teleported to item "+It.Id+" ("+It.MapId+")");
}

void ExecDamageCommand(array<string@>@command,Critter@player,Critter@target)
{
	uint val=0;
	
	int damagetype=(1);
	if(GetParameterString(command,"-t")!="")
	StrToInt(GetParameterString(command,"-t"),damagetype);
	
	int direction=Random(0,6);
	if(GetParameterString(command,"-dir")!="")
	StrToInt(GetParameterString(command,"-dir"),direction);
	
	int owner=0;
	StrToInt(GetParameterString(command,"-o"),owner);
	
	int damage=0;
	StrToInt(GetParameterString(command,"-d"),damage);
	
	InjureCritter(target,damage,damagetype,direction,owner);
}

void ExecSlapCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Slap that bitch up!");
	
	if(GodOfTheRealm(target.Id)&&!GodOfTheRealm(player.Id))
	@target=player;
	
	uint damagetype=(1);
	
	if(GetParameterString(command,"-t")!="")
	StrToInt(GetParameterString(command,"-t"),damagetype);
	uint lostAp=0;
	StrToInt(GetParameterString(command,"-a"),lostAp);    
	
	target.ToKnockout(((Random(0,1)==0)?(82):(83)),((Random(0,1)==0)?(86):(87)),((Random(0,1)==0)?(88):(89)),lostAp,target.HexX,target.HexY);
	
	if(GodOfTheRealm(target.Id))
	target.Say((11),"You've been slapped by "+player.Name);
}
void ExecMassSlapCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Down on your knees faggots!");
	
	uint lostAp=0;
	StrToInt(GetParameterString(command,"-a"),lostAp);
	int r=0;
	StrToInt(GetParameterString(command,"-r"),r);
	
	array<Critter@>crits;
	uint num=player.GetCritters(false,(0x0F),crits);
	for(uint i=0;i<num;i++)
	{
		if(!crits[i].IsDead()&&!GodOfTheRealm(crits[i].Id))
		crits[i].ToKnockout(((Random(0,1)==0)?(82):(83)),((Random(0,1)==0)?(86):(87)),((Random(0,1)==0)?(88):(89)),lostAp,crits[i].HexX+Random(-r,r),crits[i].HexY+Random(-r,r));
	}
}

void ExecSetHPCommand(array<string@>@command,Critter@player,Critter@target)
{
	int hp=0;
	GetParameterString(command,"-h");
	
	if((@target!=null))
	do{target.StatBase[(72)]+=(hp);if(target.Stat[(72)]<1)
		target.StatBase[(72)]=1;if(target.Stat[(72)]>target.Stat[(7)])
		target.StatBase[(72)]=target.Stat[(7)];}while(false);
	else
	do{player.StatBase[(72)]+=(hp);if(player.Stat[(72)]<1)
		player.StatBase[(72)]=1;if(player.Stat[(72)]>player.Stat[(7)])
		player.StatBase[(72)]=player.Stat[(7)];}while(false);
}

void ExecExplodeCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"You dont't want this.");
		return;
	}
	if(!(@target!=null))
	{
		player.Say((11),"Invalid player");
		return;
	}
	uint16 effectPid=(4011);
	uint effectRadius=2;
	uint damage=Random(300,400);
	uint damageType=(7);
	uint damageRadius=3;
	
	ExplodeEx(target.GetMap(),target.HexX,target.HexY,effectPid,effectRadius,damage,damageType,damageRadius,0);
	
}

void ExecAirstrikeCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"You dont't want this.");
		return;
	}
	if(!(@target!=null))
	{
		player.Say((11),"Invalid player");
		return;
	}
	
	player.Say((11),"Airstrike target confirmed. Dropping the payload now.");
	
	int amount=0;
	
	uint16 effectPid=(4011);
	uint effectRadius=2;
	uint damage=Random(1000,5000);
	uint damageType=(7);
	uint damageRadius=3;
	
	for(int i=0;i<20;i++)
	ExplodeEx(target.GetMap(),target.HexX+Random(-10,10),target.HexY+Random(-10,10),effectPid,effectRadius,damage,damageType,damageRadius,0);
}

void ExecAltsCommand(array<string@>@command,Critter@player)
{
	uint optLocation=0;
	cheatGetOption(command,optLocation,"-l");
	
	bool optOffline=false;
	cheatGetOption(command,optOffline,"-o");
	
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	uint totalNum=0;
	
	array<uint>checkedIp;
	bool nothingFound=true;
	
	if(optLocation==0)
	player.Say((11),"Possible multilogs:");
	else
	player.Say((11),"Possible multilogs in location "+optLocation+":");
	
	for(uint p=0,q=num;p<q;p++)
	{
		if(optLocation>0)
		{
			Map@map=players[p].GetMap();
			if((@map!=null))
			{
				Location@loc=map.GetLocation();
				if(loc.Id!=optLocation)
				continue;
			}
			else
			continue;
		}
		
		totalNum+=1;
		
		uint ip=players[p].GetIp();
		bool checkAlts=true;
		for(uint i=0,j=checkedIp.length;i<j;i++)
		{
			if(ip==checkedIp[i])
			{
				checkAlts=false;
				break;
			}
		}
		if(checkAlts)
		{
			checkedIp.insertLast(ip);
			bool foundAlts=false;
			for(uint i=p+1;i<num;i++)
			{
				if(optLocation>0)
				{
					Map@map=players[i].GetMap();
					if((@map!=null))
					{
						Location@loc=map.GetLocation();
						if(loc.Id!=optLocation)
						continue;
					}
					else
					continue;
				}
				
				if(!optOffline&&(players[i].GetSocket()==-1))
				continue;
				
				if(players[i].GetIp()==ip)
				{
					if(!foundAlts)
					{
						foundAlts=true;
						player.Say((11),"|0x009900 IP: "+IpToString(ip));
						if((players[p].GetSocket()==-1))
						player.Say((11),"|0x999999     "+players[p].Name+" ("+players[p].Id+") in map "+players[p].GetMapId()+" [off]");
						else
						player.Say((11),"    "+players[p].Name+" ("+players[p].Id+") in map "+players[p].GetMapId());
					}
					if((players[i].GetSocket()==-1))
					player.Say((11),"|0x999999     "+players[i].Name+" ("+players[i].Id+") in map "+players[i].GetMapId()+" [off]");
					else
					player.Say((11),"    "+players[i].Name+" ("+players[i].Id+") in map "+players[i].GetMapId());
					nothingFound=false;
				}
			}
		}
	}
	if(nothingFound)
	player.Say((11),"    None.");
	
	player.Say((11),"Number of characters: "+totalNum);
	if(totalNum>0)
	{
		player.Say((11),"Number of unique IPs: "+checkedIp.length()+" ("+((checkedIp.length()*100)/totalNum)+"%)");
	}
	
}

void ExecListPlayersCommand(array<string@>@command,Critter@player)
{
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	
	for(uint i=0;i<num;i++)
	{
		if(!(@players[i]!=null))
		continue;
		
		if(WrathOfTheGod(players[i]))
		continue;
		
		if((GetIndexOfString(command,"-f")!=-1)&&(players[i].GetMapId()==0))
		continue;
		
		player.Say((11),GetSafePlayerName(players[i].Id)+" ("+players[i].Id+")"+"("+players[i].GetMapId()+")"+"("+GetPlayerFaction(players[i].Id)+")");
	}
}

void ExecCritterInfoCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(!(@target!=null))
	return;
	
	if(WrathOfTheGod(target))
	@target=player;
	
	string what="\n";
	if(target.IsPlayer())
	what+="PLAYER "+GetSafePlayerName(target.Id);
	else
	what+="NPC |dlgName"+target.Id+"|"; 
	
	GameVar@var=null;
	
	player.Say((11),what+" ("+target.Id+")"+":");
	
	player.Say((11),"Map ID: "+target.GetMapId());
	
	player.Say((11),"Map Position: "+"x:"+target.HexX+" y:"+target.HexY);
	
	if(target.IsNpc())
	{
		uint mapId=0;
		uint16 hexX=0,hexY=0;
		uint8 dir=0;
		
		target.GetHomePos(mapId,hexX,hexY,dir);
		
		player.Say((11),"Home Position: ("+mapId+") "+hexX+","+hexY+","+dir);
	}
	
	player.Say((11),"Worldmap position: "+"x:"+target.WorldX+" y:"+target.WorldY);
	
	if(target.IsNpc()&&target.Param[(104)]>0)
	player.Say((11),"Dialog: "+target.Param[(104)]);
	
	player.Say((11),"Level: "+target.Stat[(77)]);
	
	player.Say((11),"SPECIAL:"+
	" ST:"+target.Stat[(0)]+
	" PE:"+target.Stat[(1)]+
	" EN:"+target.Stat[(2)]+
	" CH:"+target.Stat[(3)]+
	" IN:"+target.Stat[(4)]+
	" AG:"+target.Stat[(5)]+
	" LK:"+target.Stat[(6)]
	);
	array<string>tag;
	for(uint t=(226);t<=(229);t++)
	{
		string skill=SkillName(target.Param[t]);
		if(skill.length()>0)
		tag.insertLast(skill);
		else if(target.Param[t]!=0)
		tag.insertLast("UNKNOWN("+target.Param[t]+")");
	}
	
	if(tag.length()>0)
	{
		string tagList="Tag: ";
		tag.sortAsc();
		for(uint t=0;t<tag.length;t++)
		{
			if(t!=0)
			tagList+=", ";
			tagList+=tag[t];
		}
		player.Say((11),tagList);
	}
	
	@var=GetLocalVar((4101),target.Id);
	if((@var!=null))
	{
		int fid=var.GetValue();
		int rank=0;
		@var=GetLocalVar((4102),target.Id);
		if((@var!=null))
		rank=var.GetValue();
		if(fid>1&&FactionExists(fid))
		{
			string[]ranks_player={"UNKNOWN","Rookie","Accepted","Trusted","Important","Leader"};
			string[]ranks_bos={"UNKNOWN","Initiate","Apprentice","Senior","Elder","LEADER"};
			string[]ranks_enclave={"UNKNOWN","Boot","Trooper","Sergeant","Officer","LEADER"};
			string[]ranks_unity={"UNKNOWN","Initiate","Child","Priest","Elder","LEADER"};
			string[]ranks_ncr={"UNKNOWN","Democrat","Citizen","Magistrate","Marshal","LEADER"};
			string[]ranks_vc={"UNKNOWN","Admitted","Citizen","Regulator","Proconsul","LEADER"};
			array<string>ranks=ranks_player;
			switch(fid)
			{
				case(2):
				ranks=ranks_bos;
				break;
				case(3):
				ranks=ranks_enclave;
				break;
				case(4):
				ranks=ranks_unity;
				break;
				case(5):
				ranks=ranks_ncr;
				break;
				case(6):
				ranks=ranks_vc;
				break;
			}
			
			if((fid<((4096))))
			player.Say((11),"Faction: "+GetFaction(fid).get_Name()+" ("+fid+")");
			else
			player.Say((11),"INVALID FACTION <"+fid+">");
			if((rank<=5)&&rank>=0)
			player.Say((11),"Rank: "+ranks[rank]+" ("+rank+")");
			else
			player.Say((11),"INVALID RANK <"+rank+">");
		}
		
	} 
	
	@var=GetLocalVar((3005),target.Id);
	if((@var!=null))
	{
		int locId=var.GetValue();
		if(locId>0)
		{
			Location@loc=GetLocation(locId);
			if((@loc!=null))
			{
				Map@map=loc.GetMapByIndex(0);
				if((@map!=null))
				{
					player.Say((11),
					"Tent map: "+map.Id+" ("+((loc.WorldX)/(50))+":"+((loc.WorldY)/(50))+
					", "+loc.WorldX+","+loc.WorldY+")"
					);
				}
			}
		}
	}
	
	if((((target.Mode[(534)]&((0x00000020)))!=0)))
	player.Say((11),"Master: "+GetSafePlayerName(target.FollowerVar[(933)])+" ("+target.FollowerVar[(933)]+")");
	
	Critter@leader=target.GetFollowLeader();
	if((@leader!=null))
	player.Say((11),"Following: "+GetSafePlayerName(leader.Id)+" ("+leader.Id+")");
	
	if(target.IsNpc()&&target.SpawnedBy>0)
	player.Say((11),"Spawned by: "+GetSafePlayerName(target.SpawnedBy));
	
	if(target.DisguisedBy>0&&target.DisguisedBy!=target.Id)
	player.Say((11),"Disguised by: "+GetSafePlayerName(target.DisguisedBy));
	
	bool achievementText=true;
	for(uint8 a=(0);a<=(254);a++)
	{
		if(HaveAchievement(target,a))
		{
			if(achievementText)
			{
				player.Say((11),"Achievements:");
				achievementText=false;
			}
			player.SayMsg((11),(0),((20000)+(a*10)));
		}
	}
}

void ExecZeroExtCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(!(@target!=null))
	return;
	if(!target.IsPlayer())
	return;
	
	for(uint i=(32);i<=(63);i++)
	target.StatBase[i]=0;
}  

void ExecGodCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Praise");
	
	for(uint i=(0);i<=(6);i++)
	player.StatBase[i]=10;
	player.SkillBase[(200)]=player.SkillBase[(201)]=player.SkillBase[(202)]=
	player.SkillBase[(203)]=player.SkillBase[(204)]=player.SkillBase[(205)]=
	player.SkillBase[(206)]=player.SkillBase[(207)]=player.SkillBase[(208)]=player.SkillBase[(209)]=player.SkillBase[(210)]=
	player.SkillBase[(211)]=player.SkillBase[(212)]=player.SkillBase[(213)]=player.SkillBase[(214)]=player.SkillBase[(215)]=
	player.SkillBase[(216)]=player.SkillBase[(217)]=300;
	
	player.StatBase[(8)]=80;
	
	player.StatBase[(14)]=100; 
	
	player.ModeBase[(527)]=1;
}
void ExecIDKFACommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"IDDQD, IDKFA and send me to hell!");
	
	Item@item=target.AddItem((531),1);
	player.MoveItem(item.Id,1,(1));
	player.AddItem((39),500);
}

void ExecCleanupCommand(array<string@>@command,Critter@player)
{
	array<Critter@>crits;
	uint num=player.GetCritters(false,(0x0F),crits);
	uint count=0;
	
	for(uint i=0;i<num;i++)
	{
		if(crits[i].Cond==(3))
		{
			if(crits[i].IsPlayer())
			continue;
			else
			{
				DeleteNpc(crits[i]);
				count++;
			}
		}
	}
	
	player.Say((11),count+" critters sucessfully removed.");
}   

bool ControlNpc(Critter&npc,string&cmd,Critter&target,Critter&player,bool setHome)
{
	if(cmd=="move"||cmd=="run")
	{
		if(setHome)
		npc.SetHomePos(target.HexX,target.HexY,target.Dir);
		return AddWalkPlane(npc,0,target.HexX,target.HexY,Random(0,5),(cmd=="move")?false:true,0);
	}
	else if(cmd=="attack")
	return AttackCritter(npc,target);
	else if(cmd=="kill")
	return AttackCritter(npc,target);
	else if(cmd=="stop")
	return npc.ErasePlane(-1,true)>0?true:false;
	else if(cmd=="halt")
	return npc.ErasePlane((2),true)>0?true:false;
	return false;
}   

void ExecControlNpcCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Controling npc...");
	
	string npcTarget=GetParameterString(command,"-t");
	string cmd=GetParameterString(command,"-c");
	bool setHome=false;
	if(GetIndexOfString(command,"-h")!=-1)
	setHome=true;
	
	if(cmd==""||!(@npcTarget!=null))
	{
		player.Say((11),"Incorrect parameters");
		return;
	}
	uint npcId=0;
	StrToInt(npcTarget,npcId);
	
	Critter@npc=GetCritter(((5000000)+(npcId)));
	if(!(@npc!=null))
	{
		player.Say((11),"Couldn't obtain npc target");
		return;
	}
	if(ControlNpc(npc,cmd,target,player,setHome))
	player.Say((11),"OK");
	else
	player.Say((11),"Fail");
}   

void ExecControlMobsCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Controlling mobs");
	
	array<Critter@>crits;
	uint num=player.GetCritters(false,(0x0F),crits);
	
	string cmd=GetParameterString(command,"-c");
	bool setHome=false;
	if(GetIndexOfString(command,"-h")!=-1)
	setHome=true;
	
	if((cmd=="")||(!(@target!=null)))
	return;
	
	for(uint i=0;i<num;i++)
	{
		if(crits[i].IsPlayer())
		continue;
		
		ControlNpc(crits[i],cmd,target,player,setHome);
	}
}

void ExecDeathmatchCommand(array<string@>@command,Critter@player)
{
	array<Critter@>crits;
	
	uint num=player.GetCritters(false,(0x03),crits);      
	
	for(uint i=0;i<num;i++)
	{
		if(crits[i].IsDead())
		continue;
		
		if(crits[i].IsPlayer())
		continue;
		
		for(uint y=Random(0,num);y<num;y++)
		{
			if(!crits[y].IsDead())
			AddAttackPlane(crits[i],0,crits[y],-6);
		}
	}
}   

void ExecInspectCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Inspecting...");
	
	array<Critter@>critters;
	uint num=player.GetCritters(false,(0x0F),critters);
	
	for(uint i=0;i<num;i++)
	{
		critters[i].Say((2),"Hp: "+critters[i].Stat[(72)]);
	}
	int val=0;
	if(command.length()>2)
	StrToInt(command[2],val);
	
	player.SendMessage(((2^32-1)/2),val,(1));
}   

void ExecXpCommand(array<string@>@command,Critter&player,Critter@target,bool team)
{
	if(team)
	player.Say((11),"Rewarding team "+GetSafePlayerName(target.Id)+" belongs to.");
	else
	{
		if(target.Id==player.Id)
		player.Say((11),"Rewarding myself...");
		else
		player.Say((11),"Rewarding "+GetSafePlayerName(target.Id));
	}
	
	uint amount=1000;
	StrToInt(GetParameterString(command,"-a"),amount);
	
	string msg=GetParameterString(command,"-m");
	
	array<Critter@>followers;
	uint num=0;
	
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		@target=@target.GetFollowLeader();
		
		num=target.GetFollowGroup((0x0F),followers);
	}
	followers.insertLast(target);
	num++;
	
	if(GM_IsGameMaster(player.Id))
	{
		uint cr=GM_GetCredit(player.Id);
		if(amount*num>cr)
		{
			player.Say((11),"Not enough credit points");
			player.Say((11),"Required: "+amount*num+", you have: "+cr);
			return;
		}
		else
		GM_DeduceCredit(player.Id,amount*num);
	}
	for(uint i=0;i<num;i++)
	{
		if(msg!="")
		followers[i].Say((11),msg);
		followers[i].StatBase[(76)]+=amount;
		LogExperience(followers[i],amount,"Cheat");
	}
}   

void ExecKarmaCommand(array<string@>@command,Critter&player,Critter@target,bool team)
{
	if(team)
	player.Say((11),"Karming team "+GetSafePlayerName(target.Id)+" belongs to.");
	else
	{
		if(target.Id==player.Id)
		player.Say((11),"Karming myself...");
		else
		player.Say((11),"Karming "+GetSafePlayerName(target.Id));
	}
	
	uint amount=10;
	StrToInt(GetParameterString(command,"-a"),amount);
	
	string msg=GetParameterString(command,"-m");
	
	array<Critter@>followers;
	uint num=0;
	if(team)
	{
		
		if((@target.GetFollowLeader()!=null))
		@target=@target.GetFollowLeader();
		num=target.GetFollowGroup((0x0F),followers);
	}
	followers.insertLast(target);
	num++;
	
	if(GM_IsGameMaster(player.Id))
	{
		uint cr=GM_GetCredit(player.Id);
		if(amount*num>cr)
		{
			player.Say((11),"Not enough credit points");
			player.Say((11),"Required: "+amount*num+", you have: "+cr);
			return;
		}
		else
		GM_DeduceCredit(player.Id,amount*num);
	}
	
	for(uint i=0;i<num;i++)
	{
		if(msg!="")
		followers[i].Say((11),msg);
		followers[i].StatBase[(80)]+=amount;
	}
}

void ExecPlayerKarmaCommand(array<string@>@command,Critter&player,Critter@target,bool team)
{
	uint amount=10;
	StrToInt(GetParameterString(command,"-a"),amount);
	
	string msg=GetParameterString(command,"-m");
	
	if(target.Id==player.Id)
	{
		player.Say((11),"Karming myself...");
		player.StatBase[(100)]=amount;
	}
	else
	{
		player.Say((11),"Karming "+GetSafePlayerName(target.Id));
		
		target.StatBase[(100)]=amount;
		if(msg!="")
		target.Say((11),msg);
	}
}   

void ExecIrradiateCommand(array<string@>@command,Critter&player,Critter@target)
{
	if(target.Id==player.Id)
	player.Say((11),"Irradiating myself...");
	else
	player.Say((11),"Irradiating "+GetSafePlayerName(target.Id));
	
	uint amount=0;
	StrToInt(GetParameterString(command,"-a"),amount);
	
	if(amount!=0)
	AffectRadiation(target,amount);
	else
	player.Say((11),"RadiationLevel: "+target.Stat[(74)]);
}   

void ExecFactionInfoCommand(array<string@>@command,Critter&player,Critter@target,bool all)
{
	int id=-1;
	if(command[1]=="factioninfo")
	{
		if((@target!=null)&&target.Id!=player.Id)
		{
			if(target.Param[(106)]>=2)
			id=target.Param[(106)];
			else
			{
				player.Say((11),target.Name+"("+target.Id+") doesn't belong to any faction.");
				return;
			}
		}
		else if(!StrToInt(GetParameterString(command,"-f"),id))
		{
			player.Say((11),"You must specify faction id.");
			return;
		}
	}
	
	bool fullLog=false;
	if(GetIndexOfString(command,"-full")!=-1)
	fullLog=true;
	
	uint begin=2;
	uint end=(4096);
	if(command[1]=="listfactions")
	{
		StrToInt(GetParameterString(command,"-b"),begin);
		StrToInt(GetParameterString(command,"-e"),end);
		player.Say((11),"Listing factions from to "+begin+(end!=(4096)?" to "+end:"end"));
	}
	
	string[]_rank={"UNKNOWN","Rookie","Accepted","Trusted","Important","Leader"};
	string[]_status={"UNKNOWN","Friend","Neutral","Enemy","Invited"};
	
	for(uint f=0,fcount=GetFactionsCount();f<fcount;f++)
	{
		IFaction@faction=GetFactionByIdx(f);
		if(!(@faction!=null))
		continue;
		if((id>0&&faction.get_Id()!=id)||
		(id<0&&(faction.get_Id()<int(begin)||faction.get_Id()>int(end))))
		continue;
		
		int fid=(id>0?id:faction.get_Id());
		
		player.Say((11),"\nFaction "+fid);
		player.Say((11),"Name: "+faction.get_Name());
		player.Say((11),"Score: "+GetFactionScore(fid));
		
		player.Say((11),"Radio channel: "+GetFactionRadioChannel(fid));
		
		array<IFactionBase@>base;
		GetFactionBases(fid,base);
		if(base.length()>0)
		{
			player.Say((11),"Base"+(base.length()>1?"s":"")+" ("+base.length()+"):");
			for(uint b=0,bcount=base.length();b<bcount;b++)
			{
				player.Say((11)," \""+base[b].get_Name()+"\" ("+base[b].get_Id()+")");
				string _loc="  Location: "+base[b].get_LocationId();
				Location@loc=GetLocation(base[b].get_LocationId());
				if((@loc!=null))
				{
					player.Say((11),_loc+" "+((loc.WorldX)/(50))+":"+((loc.WorldY)/(50))+" "+
					loc.WorldX+","+loc.WorldY);
					Map@map=loc.GetMapByIndex(0);
					if((@map!=null))
					player.Say((11),"  Map: "+map.Id);
				}
				else
				player.Say((11),_loc+" (don't exists!)");
			}
		}
		
		if(!fullLog)
		{
			player.Say((11),"------------------------------");
			continue;
		}
		
		array<uint>member;
		faction.GetMembers(member);
		if(member.length()==0)
		{
			player.Say((11),"No members.");
			continue;
		}
		
		player.Say((11),"Member"+(member.length()>1?"s":"")+" ("+member.length()+"):");
		for(uint m=0,mcount=member.length();m<mcount;m++)
		{
			if(m>0)
			player.Say((11),"-------------------");
			
			int rank=faction.GetRank(member[m]);
			int status=faction.GetStatus(member[m]);
			player.Say((11)," "+GetSafePlayerName(member[m])+"("+m+")"+
			(rank>0?" "+_rank[rank]:"")+
			((rank>0&&status>0)?",":"")+
			(status>0?" "+_status[status]:"")
			);
			
		}
		
		player.Say((11),"------------------------------");
		
	}
	
}

void ExecFactionOnlineCommand(array<string@>@command,Critter&player)
{
	uint faction=0;
	bool found=false;
	if(command.length()<3)
	{
		player.Say((11),"You must specify a faction id.");
		return;
	}
	
	if(!StrToInt(command[2],faction))
	{
		player.Say((11),"You must specify a faction id.");
		return;
	}
	array<Critter@>crs;
	uint num=GetAllOnlinePlayers(crs);
	uint index=0;
	for(uint i=0;i<num;i++)
	{
		if(IsMember(faction,crs[i]))
		{
			if(!found)
			{
				found=true;
				player.Say((11),"Listing members from faction "+faction+" that are online:");
			}
			index++;
			player.Say((11),"["+index+"] "+GetCritterInfo(crs[i]));
		}
	}
	
	if(!found)
	player.Say((11),"Found no members from faction "+faction+" online.");
}

void ExecFindItemsCommand(array<string@>@command,Critter&player)
{
	int owner=0;
	bool OwnerSpecified=false;
	StrToInt(GetParameterString(command,"-o"),owner);
	if(GetIndexOfString(command,"-o")!=-1)
	OwnerSpecified=true;
	
	if(GetIndexOfString(command,"-pid")==-1)
	{
		player.Say((11),"No PID given. Use -pid <pid>");
		return;
	}
	
	uint pid=0;
	string pidString=GetParameterString(command,"-pid");
	
	uint From=0;
	StrToInt(GetParameterString(command,"-f"),From);
	
	uint KeyId=0;
	StrToInt(GetParameterString(command,"-k"),KeyId);
	
	uint To=0;
	StrToInt(GetParameterString(command,"-t"),To);
	
	uint Min=0;
	StrToInt(GetParameterString(command,"-min"),Min);
	
	bool noInv=(GetIndexOfString(command,"-skipinventory")>0);
	bool noCont=(GetIndexOfString(command,"-skipcontainer")>0);
	bool noHex=(GetIndexOfString(command,"-skipground")>0);
	
	bool parsed=StrToInt(pidString,pid);
	
	if(pidString=="")
	return;
	if(!parsed)
	{
		if(!GetItemPid(pidString,pid))
		{
			player.Say((11),"Item does not exist");
			return;
		}
	} 
	
	if(pid==0&&!OwnerSpecified)
	return;
	
	player.Say((11),"Searching for items with PID "+pid+(owner>0?" spawned by "+owner:"")+".");
	
	array<Item@>items;
	uint n=0;
	n=GetAllItems(pid,items);
	
	if(To==0)
	To=n;
	if(From==0)
	From=1;
	
	uint found=0;
	uint count=1;
	for(uint i=From-1;i<To;i++)
	{
		if(i>=items.length())
		break;
		
		if(KeyId>0&&items[i].LockerId!=KeyId)
		continue;
		
		if(noInv&&items[i].Accessory==(1))
		continue;
		
		if(noCont&&items[i].Accessory==(3))
		continue;
		
		if(noHex&&items[i].Accessory==(2))
		continue;
		
		if((!OwnerSpecified||(int((items[i].Val9)&(~(0x80000000))))==owner))
		{
			string ownerInfo="";
			int spawnerId=(int((items[i].Val9)&(~(0x80000000))));
			if(!OwnerSpecified&&spawnerId>0)
			{
				string sOwner=GetSafePlayerName(spawnerId);
				ownerInfo=" (spawned:"+(sOwner=="[player not found]"?""+spawnerId:sOwner+"("+spawnerId+")")+")";
			}
			else if(pid==0)
			{
				ownerInfo=" PID("+items[i].GetProtoId()+")";
			}
			
			count=items[i].GetCount();
			if(count>=Min)
			{
				found++;
				string pref="["+((From-1)+found)+"] "; 
				
				if(items[i].Accessory==(1))
				player.Say((11),pref+count+" item"+(count>1?"s":"")+" ("+items[i].Id+") on critter "+items[i].CritId+ownerInfo);
				else if(items[i].Accessory==(3))
				{
					Item@cont=GetItem(items[i].ContainerId);
					player.Say((11),pref+count+" item"+(count>1?"s":"")+" ("+items[i].Id+") in container "+items[i].ContainerId+(!(@cont!=null)?"(bugged) ":"")+" in map "+cont.MapId+" ["+cont.HexX+","+cont.HexY+"]"+ownerInfo);
				}
				else if(items[i].Accessory==(2))
				player.Say((11),pref+count+" item"+(count>1?"s":"")+" ("+items[i].Id+") on ground in map "+items[i].MapId+" ["+items[i].HexX+","+items[i].HexY+"]"+ownerInfo);
				else
				player.Say((11),pref+"Didn't find item. Strange.");
			}
		}
	}
	if(found==0)
	player.Say((11),"Found no items.");
}   

void ExecSayCommand(array<string@>@command,Critter&player,Critter@target,int sayType)
{
	if(sayType==(41))
	player.Say((11),"Flashing...");
	else
	player.Say((11),"Saying...");
	
	string msg=GetParameterString(command,"-m");
	
	if(sayType==(41))
	{
		target.Say(sayType,"flash");
		return;
	}
	if(msg!="")
	target.Say(sayType,msg);
	else
	player.Say((11),"Nothing to say");
}                                                                                                                                                                                                                                              

void ExecSetAnimCommand(array<string@>@command,Critter&player,Critter@target,bool mass)
{
	if(command.length()<4)
	{
		player.Say((11),"Missing arguments.");
		return;
	}
	
	int anim1=0;
	int anim2=0;
	
	StrToInt(command[2],anim1);
	StrToInt(command[3],anim2);
	
	player.Say((11),"Dance for me!");
	if(mass)
	{
		array<Critter@>crits;
		uint num=player.GetCritters(false,(0x0F),crits);
		for(uint i=0;i<num;i++)
		{
			if(!GodOfTheRealm(crits[i].Id))
			crits[i].SetAnims(0,anim1,anim2);
		}
		
	}
	else
	target.SetAnims(0,anim1,anim2);
}   

void ExecDisguiseCommand(array<string@>@command,Critter&player,Critter@target)
{
	player.Say((11),"Wearing disguise...");
	
	if(command.length()<3)
	{
		player.Say((11),"Incorrect number of parameters");
		return;
	}
	uint bt=player.CrType;
	bool res=false;
	
	bool parsed=StrToInt(command[2],bt);
	
	if(!parsed)
	{
		if(!GetBaseType(command[2],bt))
		{
			player.Say((11),"Basetype does not exist");
			return;
		}
	}
	player.Say((11),"Changing from: "+target.CrType+" to "+bt);
	res=target.ChangeCrType(bt);
	
	if(!res)
	player.Say((11),"Couldn't change appearance");
	else
	{
		target.StatBase[(112)]=bt;
		target.DisguisedBy=player.Id;
	}
}

void ExecDisguiseInfoCommand(array<string@>@command,Critter&player)
{
	array<Critter@>players;
	uint all=GetAllOnlinePlayers(players);
	for(uint p=0;p<all;p++)
	{
		
		if(GodOfTheRealm(players[p].Id))
		continue;
		
		if(players[p].GetAccess()>(0))
		continue; 
		
		if(players[p].StatBase[(71)]==(0)&&
		(players[p].StatBase[(112)]==((69))||
		players[p].StatBase[(112)]==(11)||
		players[p].StatBase[(112)]==(106)||
		players[p].StatBase[(112)]==(123)))
		continue;
		
		if((players[p].StatBase[(71)]==(1)&&
		players[p].StatBase[(112)]==((4))))
		continue;
		
		string info=players[p].Name+"("+players[p].Id+"): CritterType "+
		players[p].StatBase[(112)];
		
		if(int(players[p].CrType)!=players[p].StatBase[(112)])
		info+=" ("+players[p].CrType+")";
		
		if(players[p].DisguisedBy>0&&(players[p].DisguisedBy!=players[p].Id))
		{
			info+=" by ";
			string@name=GetSafePlayerName(players[p].DisguisedBy);
			
			if((@name!=null))
			info+=name+" ";
			else
			info+="??? ";
			
			info+="("+players[p].DisguisedBy+")";
		}
		player.Say((11),info);
	}
	
} 

void ExecConditionCommand(array<string@>@command,Critter&player,Critter@target)
{
	if(command.length()<2)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	uint id=GetPlayerId(command[2]);
	
	if(id==0)
	{
		player.Say((11),"Invalid player");
	}
	else
	{
		Critter@target=GetCritter(id);
		if(!(@target!=null))
		{
			player.Say((11),"Invalid player");
		}
		else
		{
			player.Say((11),"Conditions of "+command[2]+":");
			player.Say((11),""+GetConditionOfCritter(target));
			player.Say((11),""+GetExtConditionOfCritter(target));
		}
	}
}

void ExecBroadcastCommand(array<string@>@command,Critter&player)
{                                       
	
	IBroadcastBuffer@msg;
	
	array<IBroadcastBuffer@>buf;
	FindBroadcastBufferByGM(player.Id,buf);
	string msgs=" broadcast message(s)";
	string no_msgs="You don't have"+msgs+" in buffer.";  
	
	if(GetIndexOfString(command,"-delete")>=0)
	{
		if(buf.length()==0)
		{
			player.Say((11),no_msgs);
			return;
		}
		else
		{
			player.Say((11),"Deleting"+msgs);
			for(uint b=0;b<buf.length();b++)
			{
				buf[b].ResetStart();
				buf[b].SetLifetime(0);
				buf[b].ToDelete();
			}
		}
		return;
	}
	else if(GetIndexOfString(command,"-test")>=0)
	{
		if(buf.length()==0)
		{
			player.Say((11),no_msgs);
			return;
		}
		else
		{
			player.Say((11),"Testing"+msgs);
			for(uint b=0;b<buf.length();b++)
			{
				buf[b].ResetStart();
				buf[b].Send(player);
				buf[b].SetStart(-1);
			}
		}
		return;
	}
	else if(GetIndexOfString(command,"-send")>=0)
	{
		if(buf.length()==0)
		{
			player.Say((11),no_msgs);
			return;
		}
		else
		{
			player.Say((11),"Sending"+msgs);
			for(uint b=0;b<buf.length();b++)
			{
				buf[b].ResetStart();
				buf[b].SendToAll();
				buf[b].UnsetGM();
			}
		}
		return;
	}
	
	bool wait=(GetIndexOfString(command,"-wait")!=-1);
	
	string message=GetParameterString(command,"-m");
	if(message=="")
	{
		player.Say((11),"You didn't enter a message. Maybe you forgot to use -m ?");
		return;
	}
	
	array<int>data;
	if(buf.length()==0)
	{
		@msg=AddBroadcastBuffer((1),0,0,"Server message: "+message,data,0,(0));
		if(wait)
		msg.SetStart(-1);
	}
	else if(buf.length()==1)
	{
		@msg=@buf[0];
		msg.AppendMessage("\n"+message);
		wait=true;
	}
	else
	{
		player.Say((11),"More than one broadcast assigned to you, cannot continue.");
		return;
	}
	msg.SetGM(player.Id);
	
	int showtime=0;
	string[]t={"-t","-time"};
	if(StrToInt(GetParameterString(command,t),showtime))
	showtime=((showtime)*__TimeMultiplier);
	else
	showtime=((40)*__TimeMultiplier)+((message.length()*100)*__TimeMultiplier/1000);
	msg.SetTime(showtime);
	
	string[]sf={"-f","-filter"};
	string f=GetParameterString(command,sf);
	
	bool ilog=true;
	
	if(f!="")
	{
		array<string@>@filters=split(f,",");
		if(filters.length()>0)
		{
			ilog=false;
			for(uint f=0;f<filters.length();f++)
			{
				
				if(filters[f]=="tester")
				msg.SetFilter((0x00000001));
				else if(filters[f]=="moder")
				msg.SetFilter((0x00000002));
				else if(filters[f]=="admin")
				msg.SetFilter((0x00000004));
				else if(filters[f]=="auth"||filters[f]=="authenticated")
				msg.SetFilter(((0x00000001)));
				else if(filters[f]=="god")
				msg.SetFilter((0x00000008));
				else if(filters[f]=="mortal")
				msg.SetFilter((0x00000010));
				else if(filters[f]=="female")
				msg.SetFilter((0x00000020));
				else if(filters[f]=="male")
				msg.SetFilter((0x00000040));
				else if(filters[f]=="wm"||filters[f]=="worldmap")
				msg.SetFilter((0x00000002));
				
				else if(substring(filters[f],0,3)=="map")
				{
					array<string@>@map=split(filters[f],":");
					if(map.length()==1)
					{
						if((@player.GetMap()!=null))
						msg.SetFilter((0x00001000),player.GetMap().Id);
						else
						{
							player.Say((11),"Invalid map.");
							return;
						}
					}
					else if(map.length()==2)
					{
						int mapId=0;
						StrToInt(map[1],mapId);
						if(mapId>0)
						{
							if(!(@GetMap(mapId)!=null))
							{
								player.Say((11),"Invalid map id: "+mapId);
								return;
							}
							else
							msg.SetFilter((0x00001000),mapId);
						}
						else
						{
							if(map[1]=="any")
							{
								msg.SetFilter((0x00000100));
							}
							else
							{
								player.Say((11),"Invalid argument for filter 'map'");
								return;
							}
						}
					}
					else
					{
						player.Say((11),"Wrong number of arguments for filter 'map'");
						return;
					}
				}
				else if(substring(filters[f],0,3)=="loc")
				{
					array<string@>@loc=split(filters[f],":");
					if(loc.length()==1)
					{
						if((@player.GetMap()!=null)&&(@player.GetMap().GetLocation()!=null))
						msg.SetFilter((0x00000400),player.GetMap().GetLocation().Id);
						else
						{
							player.Say((11),"Invalid map/location.");
							return;
						}
					}
					else if(loc.length()==2)
					{
						int locId=0;
						StrToInt(loc[1],locId);
						if(locId>0)
						{
							if(!(@GetLocation(locId)!=null))
							{
								player.Say((11),"Invalid location id: "+locId);
								return;
							}
							else
							msg.SetFilter((0x00000400),locId);
						}
						else
						{
							player.Say((11),"Invalid argument for filter 'loc'");
							return;
						}
					}
					else
					{
						player.Say((11),"Wrong number of arguments for filter 'loc'");
						return;
					}
				}
				else if(substring(filters[f],0,3)=="lvl")
				{
					array<string@>@lvl=split(filters[f],":");
					if(lvl.length()==1)
					{
						player.Say((11),"Level not given.");
						return;
					}
					else if(lvl.length()==2)
					{
						int lvlNum=0;
						if(StrToInt(lvl[1],lvlNum))
						{
							if(lvlNum<1)
							{
								player.Say((11),"Invalid level: "+lvlNum);
								return;
							}
							else
							msg.SetFilter((0x00000200),lvlNum);
						}
						else
						{
							player.Say((11),"Invalid argument for filter 'lvl'");
							return;
						}
					}
					else
					{
						player.Say((11),"Wrong number of arguments for filter 'lvl'");
						return;
					}
				}
				else if(substring(filters[f],0,7)=="faction"||substring(filters[f],0,4)=="gang")
				{
					array<string@>@faction=split(filters[f],":");
					if(faction.length()==1)
					{
						player.Say((11),"Faction not given.");
						return;
					}
					else if(faction.length()==2)
					{
						int factionId=0;
						if(StrToInt(faction[1],factionId))
						{
							if(factionId<=1)
							{
								player.Say((11),"Invalid faction id: "+factionId);
								return;
							}
							else
							msg.SetFilter((0x00002000),factionId);
						}
						else
						{
							player.Say((11),"Invalid argument for filter 'faction'");
							return;
						}
					}
					else
					{
						player.Say((11),"Wrong number of arguments for filter 'faction'");
						return;
					}
				}
			}
		}
	}
	
	string[]cf={"-c","-color"};
	int c=0;
	StrToInt(GetParameterString(command,cf),c);
	
	msg.SetSetup(c);
	
	if(wait)
	{
		player.Say((11),"Broadcast buffered:");
		player.Say((11),msg.GetMessage());
	}
	else
	{
		if(ilog)
		ILog("broadcast",msg.GetMessage());
		msg.SendToAll();
	}
} 

void ExecSetFactionCommand(array<string@>@command,Critter&player,Critter@target)
{
	player.Say((11),"Setting faction on this map");
	if(command.length()<3)
	player.Say((11),"Please, specify faction id");
	else
	{
		uint id=0;
		if(StrToInt(command[2],id))
		player.GetMap().SetData((0),id);
		else
		player.Say((11),"Wrong id");
	}
}

void ExecSetLocVisibility(array<string@>@command,Critter&player)
{
	if(command.length()<3)
	player.Say((11),"Choose visibility flag. 1=visible, 0=hidden.");
	
	uint flag=0;
	if(!StrToInt(command[2],flag))
	{
		player.Say((11),"Error.");
		return;
	}
	
	Location@loc=player.GetMap().GetLocation();
	if(!(@loc!=null))
	{
		player.Say((11),"Are you on the worldmap? This command can only be applied to a location.");
		return;
	}
	
	if(flag==0)
	{
		loc.Visible=false;
	}
	else
	{
		loc.Visible=true;
	}
	
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players); 
	
	for(uint i=0;i<num;i++)
	{
		if(!(@players[i]!=null))
		continue;
		if(!players[i].IsPlayer())
		continue;
		if(flag==0)
		players[i].SetKnownLoc(false,loc.Id);
		else
		players[i].SetKnownLoc(true,loc.Id);
	}
	if(flag==0)
	player.Say((11),"Location hidden.");
	else
	player.Say((11),"Location shown.");
	
	loc.Update();
}

void ExecSetMapDataCommand(array<string@>@command,Critter&player)
{
	if(command.length()<4)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	int Index=0;
	bool parsed=StrToInt(command[2],Index);
	if(!parsed)
	{
		if(!GetMapData(command[2],Index))
		{
			player.Say((11),"Mapdata define does not exist");
			return;
		}
	}
	int Value=0;
	if(!StrToInt(command[3],Value))
	{
		player.Say((11),"Invalid value.");
		return;
	}
	Map@map=player.GetMap();
	map.SetData(Index,Value);
	player.Say((11),"Mapdata set.");
}

void ExecSetTurnbasedCombat(Critter&player,bool enable)
{
	Map@map=player.GetMap();
	if((@map!=null))
	{
		map.SetTurnBasedAvailability(enable);
		if(enable)
		player.Say((11),"TB in the map enabled.");
		else
		player.Say((11),"TB in the map disabled.");
	}
}

void ExecMapDismantling(Critter&player,bool enable)
{
	Map@map=player.GetMap();
	if((@map!=null))
	{
		if((!enable&&((map.GetData((10))&((0x00000040)))!=0))||
		(enable&&!((map.GetData((10))&((0x00000040)))!=0)))
		{
			player.Say((11),"Dismantling already "+(enable?"en":"dis")+"abled.");
			return;
		}
		if(enable)
		map.SetData((10),map.GetData((10))&(~((0x00000040))));
		else
		map.SetData((10),map.GetData((10))|((0x00000040)));
		player.Say((11),"Dismantling "+(enable?"en":"dis")+"abled.");
	}
	else
	{
		player.Say((11),"Not on worldmap.");
	}
}

void ExecMapPvp(Critter&player,bool enable)
{
	Map@map=player.GetMap();
	if((@map!=null))
	{
		if((!enable&&((map.GetData((10))&((0x00000020)))!=0))||
		(enable&&!((map.GetData((10))&((0x00000020)))!=0)))
		{
			player.Say((11),"PvP already "+(enable?"en":"dis")+"abled.");
			return;
		}
		if(enable)
		map.SetData((10),map.GetData((10))&(~((0x00000020))));
		else
		map.SetData((10),map.GetData((10))|((0x00000020)));
		player.Say((11),"PvP "+(enable?"en":"dis")+"abled.");
	}
	else
	{
		player.Say((11),"Not on worldmap.");
	}
}

void ExecMapGrids(Critter&player,bool enable)
{
	Map@map=player.GetMap();
	if((@map!=null))
	{
		if((!enable&&((map.GetData((10))&((0x00000080)))!=0))||
		(enable&&!((map.GetData((10))&((0x00000080)))!=0)))
		{
			player.Say((11),"Exit grids already "+(enable?"en":"dis")+"abled.");
			return;
		}
		if(enable)
		{
			map.SetData((10),map.GetData((10))&(~((0x00000080))));
			map.SetEvent((4),"_DoNothing");
			map.SetLoopTime(3,uint(-1));
			SetTimeoutForAll(map,(239),0);
		}
		else
		{ 
			
			map.SetData((10),map.GetData((10))|((0x00000080)));
			map.SetEvent((4),"_LockMap");
			map.SetLoopTime(3,500);
			SetTimeoutForAll(map,(239),((2238)*__TimeMultiplier));
		}
		
		player.Say((11),"Exit grids "+(enable?"en":"dis")+"abled.");
	}
	else
	{
		player.Say((11),"Not on worldmap.");
	}
}

void ExecClearEnemyStackCommand(array<string@>@command,Critter&player,Critter@target,bool all)
{
	if(!(@player.GetMap()!=null))
	{
		player.Say((11),"Not here.");
		return;
	}
	
	if(all)
	{
		ClearEnemyStacksOnMap(player.GetMap());
		player.Say((11),"Cleared enemy stack of all critters on this map");
	}
	else
	{
		if(target.IsPlayer())
		{
			player.Say((11),"Target is not an NPC. Only NPCs have enemy stacks");
			return;
		}
		
		ClearEnemyStack(target);
		player.Say((11),"Cleared target enemy stack");
	}
}

void ExecCheckBankCommand(array<string@>@command,Critter&player)
{
	string bankid=GetParameterString(command,"-b");
	int id=0;
	StrToInt(bankid,id);
	
	if(id>(6)-1||id<0)
	{
		player.Say((11),"Invalid bank ID");
		return;
	}
	
	string sid="";
	switch(id)
	{
		case 0:
		sid="Vault City";
		break;
		case 1:
		sid="Redding";
		break;
		case 2:
		sid="Broken Hills";
		break;
		case 3:
		sid="San Francisco";
		break;
		case 4:
		sid="Shady Sands";
		break;
		case 5:
		sid="Hub";
		break;
		default:
		sid="Unknown";
		break;
	}
	
	player.Say((11),"Bank "+id+" ("+sid+"):");
	player.Say((11),"Money reserves: "+"$"+BankGetTotalMoney(id));
	player.Say((11),"Accounts: "+BankGetNumberOfAccounts(id));
}

void ExecCheckBanksCommand(array<string@>@command,Critter&player)
{
	command[1]="checkbank";
	command.resize(3);
	
	for(uint b=0;b<(6);b++)
	{
		command[3]=""+b;
		ExecCheckBankCommand(command,player);
	}
}

void PrintAccountInfo(Critter&player,uint bank,uint acc,uint filtersum,bool verbose)
{
	if(BankGetAccountBalance(bank,acc)<int(filtersum))
	return;
	
	uint accountowner=BankGetAccountOwner(bank,acc);
	player.Say((11),"Owner: "+GetSafePlayerName(accountowner)+" ("+accountowner+")");
	player.Say((11),"Balance: "+BankGetAccountBalance(bank,acc));
	
	if(verbose)
	{
		player.Say((11),"Account Type: "+BankGetAccountType(bank,acc));
		player.Say((11),"Access Count: "+BankGetAccessCount(bank,acc));
	}
}

void ExecCheckBankAccount(array<string@>@command,Critter&player,bool All)
{
	string bankid=GetParameterString(command,"-b");
	string accid=GetParameterString(command,"-n");
	string filtersum=GetParameterString(command,"-f");
	int id=0;
	int aid=0;
	int sum=0;
	StrToInt(bankid,id);
	StrToInt(accid,aid);
	StrToInt(filtersum,sum);
	
	bool verbose=(GetIndexOfString(command,"-v")!=-1);
	
	if(uint(id)>(6)-1||id<0)
	{
		player.Say((11),"Invalid bank ID");
		return;
	}
	
	if(All)
	{
		for(uint i=0;i<BankGetNumberOfAccounts(id);i++)
		{
			PrintAccountInfo(player,id,i,sum,verbose);
		}
	}
	else
	{
		if(uint(id)>uint(BankGetNumberOfAccounts(id))||id<0)
		{
			player.Say((11),"Invalid account ID.");
			return;
		}
		
		PrintAccountInfo(player,id,aid,sum,verbose);
	}
}

void ExecBankMoney(array<string@>@command,Critter&player,bool add)
{
	string bankid=GetParameterString(command,"-b");
	int id=0;
	StrToInt(bankid,id);
	
	if(id>(6)-1||id<0)
	{
		player.Say((11),"Invalid bank ID");
		return;
	}
	
	string stramount=GetParameterString(command,"-a");
	int amount=0;
	StrToInt(stramount,amount);
	
	if(add)
	BankAddMoney(id,amount);
	else
	BankRemoveMoney(id,amount);
}

void ExecCheckTownCommand(array<string@>@command,Critter&player)
{
	string townid=GetParameterString(command,"-n");
	int id=0;
	StrToInt(townid,id);
	
	ITown@town=GetTown(id);
	if(!((@town!=null)))
	{
		player.Say((11),"Invalid town ID");
		return;
	}
	
	uint faction=town.GetControllingFaction();
	string factionname;
	GetFactionNameStr(faction,factionname);
	
	if(faction==0)
	player.Say((11),"Current controlling faction: None");
	else
	{
		player.Say((11),"Current controlling faction: "+factionname+" ("+faction+")");
		player.Say((11),"Number of Controlcycles: "+town.GetControlCycles());
		player.Say((11),"Number of NPCs killed during this regime: "+town.GetNumberOfKilledNPCs());
	}
}

void ExecGainTownControlCommand(array<string@>@command,Critter&player)
{
	string townid=GetParameterString(command,"-n");
	int id=0;
	StrToInt(townid,id);
	ITown@town;
	
	if(id==0)
	@town=RetrieveTown(player);
	else
	@town=GetTown(id);
	
	if(!(@town!=null))
	player.Say((11),"Invalid town");
	
	town.GainControl(player);
}

void ExecResetTownCommand(array<string@>@command,Critter&player,bool all)
{
	if(!all)
	{
		string townid=GetParameterString(command,"-n");
		int id=0;
		StrToInt(townid,id);
		
		ITown@town=GetTown(id);
		if(!((@town!=null)))
		{
			player.Say((11),"Invalid town ID");
			return;
		}
		town.ResetControl();
		SetBestScore((29)+id,null,"");
	}
	else
	{
		for(uint i=1;i<=GetTownCount();i++)
		{
			ITown@town=GetTown(i);
			if(@town!=null)
			town.ResetControl();
			SetBestScore((29)+i,null,"Unknown");
		}
	}
	player.Say((11),"Done.");
}   

void _Kill(Critter&killer,Critter&victim)
{
	if(!GodOfTheRealm(victim.Id))
	victim.ToDead(GetRandomDeathAnimation(),null);
}                               

void ExecSetPerkCommand(array<string@>@command,Critter&player,Critter&target)
{
	player.Say((11),"Executing SetPerk command");
	
	int id=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],id);
	
	if(!parsed)
	{
		if(!GetVarId(command[2],id))
		{
			player.Say((11),"LVAR does not exist");
			return;
		}
	}
	int val=0;
	if(!StrToInt(command[3],val))
	{
		player.Say((11),"Wrong value");
		return;
	}
	player.PerkBase[id]=val;
}

void ExecPerkAdjust(array<string@>@command,Critter@player,Critter@target)
{
	int perk=0;
	StrToInt(GetParameterString(command,"-k"),perk);
	
	int level=0;
	StrToInt(GetParameterString(command,"-l"),level);
	
	target.PerkBase[perk]=level;
	player.Say((11),"Perk "+perk+" set to level "+level);
}

void ExecProfAdjust(array<string@>@command,Critter@player,Critter@target)
{
	int perk=0;
	StrToInt(GetParameterString(command,"-k"),perk);
	
	int level=0;
	StrToInt(GetParameterString(command,"-l"),level);
	
	target.PerkBase[perk]=level;
	player.Say((11),"Profession "+perk+" set to level "+level);
}

void ExecCriticalChance(array<string@>@command,Critter@player,Critter@target)
{
	int level=0;
	StrToInt(GetParameterString(command,"-l"),level);
	target.StatBase[(14)]=level;
}

void ExecSetReputationCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Adjusting reputation for "+target.Name);
	
	int repIdx=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	StrToInt(command[2],repIdx);
	
	int inc=0;
	StrToInt(GetParameterString(command,"-i"),inc);
	int dec=0;
	StrToInt(GetParameterString(command,"-d"),dec);
	int val=0;
	StrToInt(GetParameterString(command,"-v"),val);
	if(inc>0)
	target.ReputationBase[repIdx]+=inc;
	else if(dec>0)
	target.ReputationBase[repIdx]-=dec;
	else
	target.ReputationBase[repIdx]=val;
}
void ExecResetReputationsCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Resetting reputations for "+target.Name);
	for(uint i=0;i<((__ReputationEnd)-(__ReputationBegin)+1);i++)
	target.ReputationBase[i]=int(0x80000000);
}   

void ExecSafeRegenCommand(array<string@>@command,Critter@player)
{
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"No matter how much you try, you can't regenerate the world.");
		return;
	}
	
	player.Say((11),"Safe-regenerating the location...");
	
	Location@loc=map.GetLocation();
	array<Map@>maps;
	uint numMaps=loc.GetMaps(maps); 
	
	Item@buffer=player.AddItem((132),1);
	
	array<uint>pids; 
	
	for(uint i=0;i<numMaps;i++)
	{
		for(uint16 x=0;x<maps[i].GetWidth();x++)
		{
			for(uint16 y=0;y<maps[i].GetHeight();y++)
			{
				array<Item@>items;
				uint num=maps[i].GetItems(x,y,items);
				for(uint j=0;j<num;j++)
				{
					if(items[j].GetType()==(8))
					{
						pids.insertLast(items[j].GetProtoId());
						
						MoveItem(items[j],0,buffer,maps[i].GetHeight()*y+x);
					}
				}
			}
		}
		
		array<Critter@>crits;
		uint num=maps[i].GetCritters(0,(0x0F)|(0x20),crits);
		for(uint i=0;i<num;i++)
		{
			if(!(((crits[i].Mode[(534)]&((0x00000020)))!=0)))
			continue;
			
			TransferToNPCMap(crits[i]);
		}
	}
	loc.Reload();
	
	for(uint i=0;i<numMaps;i++)
	{
		array<Critter@>crits;
		uint num=maps[i].GetCritters(0,(0x0F)|(0x20),crits);
		for(uint i=0;i<num;i++)
		crits[i].ChangeCrType(crits[i].StatBase[(112)]);
		
		for(uint16 x=0;x<maps[i].GetWidth();x++)
		{
			for(uint16 y=0;y<maps[i].GetHeight();y++)
			{
				array<Item@>items;
				uint num=maps[i].GetItems(x,y,items);
				if(num>0)
				{
					for(uint j=0;j<num;j++)
					{
						if(items[j].GetType()==(8))
						{
							
							Item@oldContainer=buffer.GetItem(items[j].GetProtoId(),maps[i].GetHeight()*y+x);
							array<Item@>content;
							uint contentCount=oldContainer.GetItems(0,content);
							for(uint k=0;k<contentCount;k++)
							{
								MoveItem(content[k],0,items[j],0);
							}
						}
					}
				}
				
				else
				{  
					
				}
			}
		}
	}
	DeleteItem(buffer);
	player.Say((11),"Done.");
}   

void ExecRemoveItemsCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Executing RemoveItems command");
	int pid=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool deleteAll=(GetIndexOfString(command,"-global")!=-1); 
	
	bool parsed=StrToInt(command[2],pid);
	
	if(!parsed)
	{
		if(!GetItemPid(command[2],pid))
		{
			player.Say((11),"Item does not exist");
			return;
		}
	}
	uint num=0;
	if(pid!=0)
	{
		array<Item@>items;
		if(deleteAll)
		{
			player.Say((11),"Removing ALL items with pid: "+pid);
			num=GetAllItems(pid,items);
		}
		else
		{
			player.Say((11),"Removing items with pid: "+pid);
			Map@map=player.GetMap();
			if(!(@map!=null))
			{
				player.Say((11),"Can't delete local items while on worldmap.");
				return;
			}
			num=map.GetItems(pid,items);
		}
		
		DeleteItems(items);
		player.Say((11),"Done - removed "+num+" items.");
	}
	else
	player.Say((11),"Please specify proto id number.");
}  

void ExecCountItemsCommand(array<string@>@command,Critter@player)
{
	int pid=0;
	if(command.length()<3)
	{
		player.Say((11),"Wrong number of parameters");
		return;
	}
	
	bool parsed=StrToInt(command[2],pid);
	
	if(!parsed)
	{
		if(!GetItemPid(command[2],pid))
		{
			player.Say((11),"Item does not exist");
			return;
		}
	}
	uint num=0;
	uint totalNum=0;
	if(pid!=0)
	{
		array<Item@>items;
		num=GetAllItems(pid,items);
		if(num>0)
		{
			for(uint i=0;i<num;i++)
			totalNum+=items[i].IsStackable()?items[i].GetCount():1;
		}
		player.Say((11),"Number of items with pid("+pid+"): |0xffffffff "+num+".");
		uint totalCount=WorldItemCount(pid);
		if(totalNum>0||totalCount>0)
		player.Say((11),"Total number: |0xffffffff "+totalNum+" or "+totalCount+".");
	}
	else
	player.Say((11),"Please specify proto id number.");
}  

void ExecVirtualMoneyCommand(array<string@>@command,Critter@player)
{
	uint banks=BanksGetTotalMoney();
	int encounters=WorldmapGetTotalValue();
	
	player.Say((11),"Money kept in banks: "+banks);
	player.Say((11),"Value in encounters store: "+encounters);
	player.Say((11),"--------");
	uint sum=banks+encounters;
	player.Say((11),"Total: "+sum);
}  

void ExecZoneCommand(array<string@>@command,Critter@player)
{
	int v=0;
	IZone@zone=GetZone(player.WorldX,player.WorldY);
	
	if(StrToInt(GetParameterString(command,"-a"),v))
	{
		zone.AddValue(v);
		player.Say((11),"Added "+v+" to zone's value.");
	}
	else if(StrToInt(GetParameterString(command,"-i"),v))
	{
		
		player.Say((11),"Injected "+v+" to nearby encounters' store.");
	}
	else if(StrToInt(GetParameterString(command,"-r"),v))
	{
		zone.SubValue(v);
		player.Say((11),"Substracted "+v+" from zone's value.");
	}
	else if(StrToInt(GetParameterString(command,"-s"),v))
	{
		zone.SetValue(v);
		player.Say((11),"Set zone's value to: "+v);
	}
	else
	{
		player.Say((11),"Current zone's value: "+zone.GetValue());
	}
}

void ExecSuicideCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Goodbye cruel world...");
	player.ToDead(GetRandomDeathAnimation(),null);
}

void ExecGetLeaderTimeCommand(array<string@>@command,Critter@player)
{
	uint faction=GetGroupIndex(player);
	if(faction==(1))
	player.Say((11),"You are not member of any faction");
	else
	player.Say((11),"Leader time left: "+(GetLeaderTime(faction)-(__FullSecond)));
}

void ExecGetClaimTimeCommand(array<string@>@command,Critter@player)
{
	uint faction=GetGroupIndex(player);
	if(faction==(1))
	player.Say((11),"You are not member of any faction");
	else
	player.Say((11),"Claim time left: "+(GetClaimTime(faction)-(__FullSecond)));
}

void ExecGetClaimCommand(array<string@>@command,Critter@player)
{
	uint faction=GetGroupIndex(player);
	if(faction==(1))
	player.Say((11),"You are not member of any faction");
	else
	{
		uint id=GetClaimId(faction);
		if(id==0)
		player.Say((11),"No claim");
		else
		player.Say((11),"Claimee: "+GetSafePlayerName(id));
	}
}

void ExecMakeEncounterCommand(array<string@>@command,Critter@player)
{
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"Not on the worldmap");
		return;
	} 
	
	if(map.GetData((0))!=0)
	{
		player.Say((11),"This map belongs to a faction. Cannot force the encounter.");
		return;
	}
	
	map.SetEvent((5),"_ForceEncounter");
	map.SetLoopTime(4,5000);
}

void ExecMapInfoCommand(array<string@>@command,Critter@player)
{
	int id=0;
	StrToInt(GetParameterString(command,"-m"),id);
	
	player.Say((11),(id==0?"Listing information about this map:":"Listing information about map "+id+":"));
	if(id==0)
	id=player.GetMapId();
	Map@map=GetMap(id);
	if(!(@map!=null))
	{
		player.Say((11),"Invalid map.");
		return;
	}
	Location@loc=map.GetLocation();
	
	player.Say((11),"Map Id: "+id);
	player.Say((11),"Map PID: "+map.GetProtoId());
	player.Say((11),"Location PID: "+loc.GetProtoId());
	
	if(IsTent(map))
	{
		string@owner=GetSafePlayerName(map.GetData((20)));
		player.Say((11),"This is a tent map, owned by: "+owner+" ("+map.GetData((20))+")");
	}
	if(map.GetData((9))>0)
	{
		string@spawner=GetSafePlayerName(map.GetData((9)));
		player.Say((11),"This map was spawned by: "+spawner+" ("+map.GetData((9))+") "+(((__FullSecond)-map.GetData((1)))/(60*60))+" hours ago.");
	}
	if(((map.GetData((10))&((0x00000002)))!=0))
	player.Say((11),"Spectation is enabled on this map.");
	if(((map.GetData((10))&((0x00000040)))!=0))
	player.Say((11),"Dismantling is disabled on this map.");
	if(((map.GetData((10))&((0x00000020)))!=0))
	player.Say((11),"PvP is disabled on this map.");
	if(((map.GetData((10))&((0x00000080)))!=0))
	player.Say((11),"Exit grids are disabled on this map.");
}

void ExecGetLeaderCommand(array<string@>@command,Critter@player)
{
	uint faction=GetGroupIndex(player);
	if(faction==(1))
	player.Say((11),"You are not member of any faction");
	else
	{
		uint id=GetLeaderId(faction);
		if(id==0)
		player.Say((11),"No leader");
		else
		player.Say((11),"Leader: "+GetSafePlayerName(id));
	}
}

void ExecClearTimeoutsCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Clearing timeouts");
	DropTimeouts(target);
}

void ExecClearAllTimeoutsCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Dropping timeouts for all online players.");
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	for(uint i=0;i<num;i++)
	{
		DropTimeouts(players[i]);
	}
	player.Say((11),"Done.");
}

void ExecDeathIncarnateCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Death walks the earth as "+target.Name);
	target.SetEvent((4),"_Kill");
}

void ExecNormalDeadlyCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),target.Name+" is now a mere mortal again");
	target.SetEvent((4),"");
}

void ExecMoveCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Move it, move it");
	
	target.MoveRandom();
}

void ExecKillMobsCommand(array<string@>@command,Critter@player)
{
	array<Critter@>critters;
	uint num=player.GetCritters(false,(0x0F),critters);
	
	player.Say((11),"Killing all mobs in sight...");
	
	for(uint i=0;i<num;i++)
	{
		if(critters[i].IsPlayer())
		continue;
		
		if(!critters[i].IsDead())
		critters[i].ToDead(GetRandomDeathAnimation(),null);
	}
}

void ExecRespawnCommand(array<string@>@command,Critter@player,Critter@target)
{
	if((@target!=null))
	{
		player.Say((11),"Raise!");
		if(target.IsPlayer()&&target.GetAccess()==(0))
		target.ModeBase[(532)]=0;
		target.ToLife();
		Heal(target);
	}
}

void ExecRespawnAllCommand(array<string@>@command,Critter@player)
{
	array<Critter@>critters;
	uint num=player.GetCritters(false,(0x04),critters);
	
	player.Say((11),"Respawning all critters in sight");
	
	for(uint i=0;i<num;i++)
	{
		critters[i].ToLife();
		if(critters[i].IsPlayer()&&critters[i].GetAccess()==(0))
		critters[i].ModeBase[(532)]=0;
	}
}

void ExecHealCommand(array<string@>@command,Critter@player,Critter@target)
{
	if((@target!=null))
	{
		player.Say((11),"Healing...");
		Heal(target);
	}
}

void ExecHealAllCommand(array<string@>@command,Critter@player)
{
	array<Critter@>critters;
	uint num=player.GetCritters(false,(0x01),critters);
	
	player.Say((11),"Healing all critters in sight");
	
	for(uint i=0;i<num;i++)
	{
		Heal(critters[i]);
	}
}

void ExecRespawnAllPlayersCommand(array<string@>@command,Critter@player,Critter@target)
{
	array<Critter@>critters;
	uint num=player.GetCritters(false,(0x04),critters);
	
	player.Say((11),"Respawning all players in sight");
	
	for(uint i=0;i<num;i++)
	{
		if(!critters[i].IsPlayer())
		continue;
		critters[i].ToLife();
	}
}

void ExecDevEnableCommand(array<string@>@command,Critter@player)
{
	if(player.GetAccess()>=(1))
	player.RunClientScript("client_dev_menu@Authorize",0,0,0,null,null);
}

void ExecAntiblockCommand(array<string@>@command,Critter@player)
{
	if(ItemOnHex((825),player.GetMap(),player.HexX,player.HexY))
	{
		player.Say((11),"Removing antiblock...");
		Item@tr=player.GetMap().GetItem(player.HexX,player.HexY,(825));
		if((tr.Val0)==(1))
		DeleteItem(tr);
	}
	else
	{
		if((@player.GetMap()!=null))
		{
			player.Say((11),"Placing antiblock...");
			Item@tr=player.GetMap().AddItem(player.HexX,player.HexY,(825),1);
			TriggerInit(tr,(1),0,2,1);
		}
	}
}   

void ExecSpawnPointCommand(array<string@>@command,Critter@player)
{
	
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"Dynamic spawnpoints can't be created here.");
		return;
	}
	
	uint16 hx=player.HexX;
	uint16 hy=player.HexY;
	
	int minigameTeam=0;
	int minigameId=0;
	
	uint capturableBy=0;
	uint captureFlags=0;
	uint captureTime=30;
	
	bool visible=false;
	
	bool link=false;     
	
	uint transportToMap=0;  
	
	cheatGetOption(command,hx,"-x");
	cheatGetOption(command,hy,"-y");
	cheatGetOption(command,capturableBy,"-c");
	cheatGetOption(command,captureFlags,"-o");
	cheatGetOption(command,captureTime,"-s");
	cheatGetOption(command,visible,"-v");
	cheatGetOption(command,link,"-l");
	cheatGetOption(command,transportToMap,"-m"); 
	
	string team=GetParameterString(command,"-t");
	if(team=="spectator"||team=="s")
	minigameId=15;
	else if(StrToInt(team,minigameTeam))
	{
		minigameId=15;
		minigameTeam=(((minigameTeam)>(15))?(15):(((minigameTeam)<(0))?(0):(minigameTeam)));
	}
	
	Item@existing=map.GetItem(hx,hy,(821));
	if(!(@existing!=null))
	{
		player.Say((11),"Placing respawn point..."); 
		
		Item@lastDSpawn=null;
		if(link)
		{
			array<Item@>dSpawns;
			uint dSpawnsNum=map.GetItems((821),dSpawns);
			if(dSpawnsNum>0)
			{
				uint dSpawnsHighestId=0;
				for(uint i=0;i<dSpawnsNum;i++)
				{
					if(dSpawns[i].Id>dSpawnsHighestId)
					dSpawnsHighestId=dSpawns[i].Id;
				}
				@lastDSpawn=map.GetItem(dSpawnsHighestId);
			}
		} 
		
		Item@spawn=map.AddItem(hx,hy,(821),1);
		spawn.Val0=(minigameId<<4)|minigameTeam;
		spawn.Val1=(captureTime<<24)|(captureFlags<<16)|capturableBy;
		if((@lastDSpawn!=null))
		{
			spawn.Val3=lastDSpawn.Id;
			lastDSpawn.Val4=spawn.Id;
		}
		spawn.Val5=transportToMap; 
		
		spawn.AnimStayBegin=minigameTeam;
		spawn.AnimStayEnd=minigameTeam;
		spawn.AnimShowBegin=minigameTeam;
		spawn.AnimShowEnd=minigameTeam;
		spawn.AnimHideBegin=minigameTeam;
		spawn.AnimHideEnd=minigameTeam; 
		
		if(capturableBy>0)
		{
			((spawn.Flags)=(spawn.Flags)|((0x10000000)));
			
		} 
		
		if(visible)
		{
			(spawn.Flags=((spawn.Flags)&(~((0x00000001)))));
			spawn.Update();
		}
	}
	else
	{
		player.Say((11),"Removing spawn point...");
		DeleteItem(existing);
	}
}

void ExecKillerAdminCommand(array<string@>@command,Critter@player)
{
	if(player.Mode[(535)]>0)
	{
		player.Say((11),"Normal admin");
		player.ModeBase[(535)]=0;
		
	}
	else
	{
		player.Say((11),"Killer admin");
		player.ModeBase[(535)]=1;
	}
}

void ExecHideMapCommand(array<string@>@command,Critter@player)
{
	Location@loc=player.GetMap().GetLocation();
	loc.GeckVisible=false;
	loc.Visible=false; 
	
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players); 
	
	for(uint i=0;i<num;i++)
	{
		if(!(@players[i]!=null))
		continue;
		if(!players[i].IsPlayer())
		continue;
		
		players[i].SetKnownLoc(false,loc.Id);
	}
}

void ExecClearAllIllegalFlagsCommand(array<string@>@command,Critter@player)
{
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	for(uint i=0;i<num;i++)
	{
		ClearIllegalFlags(players[i]);
	}
}

void ExecListAuthenticatedCommand(array<string@>@command,Critter@player)
{
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	for(uint i=0;i<num;i++)
	{
		if(!GodOfTheRealm(player.Id)&&GodOfTheRealm(players[i].Id)&&((players[i].Mode[(534)]&((0x00020000)))!=0))
		continue;
		
		if(players[i].GetAccess()==(0))
		continue;
		
		if(player.GetAccess()<players[i].GetAccess())
		continue;
		
		player.Say((11),GetSafePlayerName(players[i].Id)+" ("+players[i].Id+")"+"("+players[i].GetMapId()+") - "+GetAuthString(players[i]));
	}
}

void ExecResetAllDisguisesCommand(array<string@>@command,Critter@player)
{
	player.Say((11),"Resetting basetypes for all players online...");
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	for(uint i=0;i<num;i++)
	{
		bool isMale=(players[i].StatBase[(71)]==(0));
		uint baseType=(isMale?((69)):((4)));
		uint crType=baseType;
		Item@armor=players[i].GetItem(0,(3));
		
		if((@armor!=null))
		{
			switch(GetCritterAnimType(crType))
			{
				case(0):
				crType=(isMale?armor.Proto.Armor_CrTypeMale:armor.Proto.Armor_CrTypeFemale);
				break;    
				
			}
		}
		
		players[i].ChangeCrType(crType);
		players[i].StatBase[(112)]=baseType;
		players[i].DisguisedBy=0;
	}
	player.Say((11),"Done.");
}   

void ExecDropDrugsCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Removing drug effects from: "+target.Name);
	DropDrugEffects(target,true);
}

void ExecZonePlayersCommand(array<string@>@command,Critter@player)
{
	array<Critter@>@players=WorldmapGetPlayers(((player.WorldX)/(50)),((player.WorldY)/(50)));
	player.Say((11),""+players.length()+" players in zone:");
	for(uint i=0,j=players.length();i<j;i++)
	player.Say((11),players[i].Name);
}

void ExecListCommandsCommand(array<string@>@command,Critter@player)
{
	if(IsAdmin(player))
	{
		for(uint i=0,j=commandlist.length();i<j;i++)
		player.Say((11),commandlist[i]);
	}
	else if(IsGM(player))
	{
		for(uint i=0,j=gmcommandlist.length();i<j;i++)
		player.Say((11),gmcommandlist[i]);
	}
	else
	{
		for(uint i=0,j=testercommandlist.length();i<j;i++)
		player.Say((11),testercommandlist[i]);
	}
}

uint GMTrack(uint targetId,string@message)
{
	if(targetId==0||GodOfTheRealm(targetId)||
	!(@message!=null)||message.length()==0)
	return(0);
	
	IConfigVar@var=GetConfigVar("config/Cheats.cfg","Tracking",""+targetId);
	
	if(!(@var!=null))
	return(0);
	
	array<string@>@hunters=split(var.GetValue(),",");
	if(hunters.length()==0)
	return(0);
	
	Critter@target=GetCritter(targetId);
	if(!(@target!=null))
	return(0);
	
	uint color=uint(4291317840);
	stringReplaceText(message,"TARGET",target.Name+"("+target.Id+")");
	
	uint huntersFound=0;
	for(uint h=0,hcount=hunters.length();h<hcount;h++)
	{
		uint hunterId=0;
		if(!StrToInt(hunters[h],hunterId))
		continue;
		
		if(hunterId==0)
		continue;
		
		Critter@hunter=GetCritter(hunterId);
		if(!(@hunter!=null))
		continue;
		
		if(GodOfTheRealm(target.Id)||target.GetAccess()>target.GetAccess())
		{
			target.Say((11),"|"+color+" > "+hunter.Name+" was trying to track you when you was offline.");
			IConfigVar@var=GetConfigVar("config/Cheats.cfg","Tracking",""+target.Id);
			if(!(@var!=null))
			{
				target.Say((11),"|"+color+" > Error #1 during removing you from list.");
			}
			else
			{
				array<string>innocent=var.GetValueAsArray(",");
				do{uint _len=innocent.length();for(uint _i=0;_i<_len;_i++)
					while(innocent[_i]==""+target.Id){innocent.removeAt(_i);_len--;}}while(false);
				if(Present(""+target.Id,innocent))
				{
					target.Say((11),"|"+color+"> Error #2 during removing you from list.");
				}
				else
				{
					do{array<string>__tmp;for(uint __a=0;__a<innocent.length();__a++){bool __p=true;for(uint __b=0;__b<__tmp.length();__b++){if(__tmp[__b]==innocent[__a]){__p=false;break;}}if(__p)
							__tmp.insertLast(innocent[__a]);}innocent=__tmp;}while(false);
					innocent.sortAsc();
					var.SetValue(innocent);
					SaveConfig("config/Cheats.cfg");
					target.Say((11),"|"+color+"> Successfully removed you from list.");
				}
			}
			continue;
		}
		
		hunter.Say((11),"|"+color+" > "+message);
		huntersFound++;
	}
	
	return(huntersFound);
}

Critter@GetCritterArgument(array<string@>&command)
{
	Critter@target=null;
	
	uint id=0;
	string targetName=GetParameterString(command,"-p");
	string npcId=GetParameterString(command,"-n");
	StrToInt(targetName,id);
	
	if(targetName!="")
	{
		if(id==0)
		@target=GetPlayer(targetName);
		else
		@target=GetCritter(id);
		
	}
	if(npcId!="")
	{
		StrToInt(npcId,id);
		if(id!=0)
		@target=GetCritter((5000000)+id);
	}
	
	return(target);
}

void ExecTrackPlayerCommand(array<string@>@command,Critter@player,Critter@target)
{
	string offline=GetParameterString(command,"-offline");
	
	if(offline.length()==0)
	{
		if(player.Id==target.Id)
		{
			player.Say((11),"Invalid target. Use trackplayer -offline [target name] to track not logged player.");
			return;
		}
	}
	else
	{
		uint id=GetPlayerId(offline);
		if(id==0)
		{
			player.Say((11),"No such player exists in this world.");
			return;
		}
		
		return;
	}
	
	if(GodOfTheRealm(target.Id)||player.GetAccess()<target.GetAccess())
	{
		player.Say((11),"You are not authorized to track this person.");
		target.Say((11),player.Name+" was trying to track you.");
		return;
	}
	
	IConfigVar@var=GetConfigVar("config/Cheats.cfg","Tracking",""+target.Id);
	array<string>hunters=var.GetValueAsArray(",");
	
	if(Present(""+player.Id,hunters))
	{
		player.Say((11),"You are already tracking that person.");
		return;
	}
	
	hunters.insertLast(""+player.Id);
	do{array<string>__tmp;for(uint __a=0;__a<hunters.length();__a++){bool __p=true;for(uint __b=0;__b<__tmp.length();__b++){if(__tmp[__b]==hunters[__a]){__p=false;break;}}if(__p)
			__tmp.insertLast(hunters[__a]);}hunters=__tmp;}while(false);
	hunters.sortAsc();
	var.SetValue(hunters);
	SaveConfig("config/Cheats.cfg");
	
	player.Say((11),"You are now tracking "+target.Name);
}

void ExecStopTrackPlayerCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"Target not found.");
		return;
	}
	
	player.Say((11),"You've now stopped tracking "+target.Name);
	SetLvar(target,(4124),0);
}

void ExecListTrackedPlayersCommand(array<string@>@command,Critter@player)
{
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	
	for(uint i=0;i<num;i++)
	{
		if(players[i].GetAccess()==(3))
		continue;
		
		uint id=GetLvar(players[i],(4124));
		if(id!=0)
		{
			Critter@tracker=GetCritter(id);
			if((@tracker!=null)&&player.GetAccess()<tracker.GetAccess())
			continue;
			
			player.Say((11),GetSafePlayerName(players[i].Id)+" is tracked by "+GetSafePlayerName(id));
		}
	}
}

void ExecRotateCommand(array<string@>@command,Critter@player,Critter@target)
{
	int dir=Random(0,5);
	StrToInt(GetParameterString(command,"-dir"),dir);
	
	if(target.IsNpc())
	target.SetHomePos(target.HexX,target.HexY,dir);
	target.SetDir(dir);
}

void ExecStartEventCommand(array<string@>@command,Critter@player)
{
	SetGvar((1234),1);
	player.Say((11),"Event started, all critters and items added from this point can be deleted by stopping event.");
}

void ExecStopEventCommand(array<string@>@command,Critter@player)
{
	SetGvar((1234),0);
	uint numdelete=0;
	for(uint i=0;i<eventCritters.length();i++)
	{
		Critter@cr=GetCritter(eventCritters[i]);
		if((@cr!=null))
		{
			DeleteNpc(cr);
			numdelete++;
		}
	}
	eventCritters.resize(0);
	
	player.Say((11),"Deleted "+numdelete+" critter that were part of the event.");
	
	numdelete=0;
	for(uint y=0;y<eventItems.length();y++)
	{
		Item@item=::GetItem(eventItems[y]);
		if((@item!=null))
		{
			DeleteItem(item);
			numdelete++;
		}
	}
	eventItems.resize(0);
	
	player.Say((11),"Deleted "+numdelete+" items that were part of the event.");
	player.Say((11),"Event cleanup completed.");
}

void PrintTentList(Critter&player,Critter&target,bool short)
{
	int tentid=GetLvar(target,(3005));
	if(tentid==0)
	player.Say((11),target.Name+" has no tent.");
	else
	{
		Location@loc=GetLocation(tentid);
		if((@loc!=null))
		{
			Map@map=loc.GetMapByIndex(0);
			if((@map!=null))
			{
				if(short)
				player.Say((11),target.Name+" - ("+map.Id+")("+map.GetProtoId()+")");
				else
				{
					player.Say((11),"Tent info for "+target.Name+": ");
					player.Say((11),"Map ID: "+map.Id);
					player.Say((11),"Map PID: "+map.GetProtoId());
				}
			}
		}
		else
		{
			player.Say((11),target.Name+" has no tent.");
		}
	}
}

void ExecTentInfoCommand(array<string@>@command,Critter@player,Critter@target)
{
	PrintTentList(player,target,false);
}

void ExecTentListCommand(array<string@>@command,Critter@player)
{
	array<Critter@>players;
	uint num=GetAllOnlinePlayers(players);
	player.Say((11),"<Name> - (<MapID>)(<MapPID>)");
	for(uint i=0;i<num;i++)
	PrintTentList(player,players[i],true);
}

void ExecListMapsCommand(array<string@>@command,Critter@player)
{
	uint pid=0;
	StrToInt(GetParameterString(command,"-pid"),pid);
	
	if(pid>0)
	{
		array<Map@>maps;
		uint num=GetAllMaps(0,maps);
		if(num==0)
		{
			player.Say((11),"No maps found for PID "+pid);
			return;
		}
		if((@maps!=null))
		{
			for(uint x=0;x<num;x++)
			{
				if((@maps[x]!=null))
				{
					if(maps[x].GetProtoId()==pid)
					{
						player.Say((11),"PID "+pid+": "+maps[x].Id);
					}
				}
			}
		}
	}
}

void ExecShowHandsCommand(array<string@>@command,Critter@player,Critter@target)
{
	uint8 dummy=0;
	for(int s=(1);s<(255);s++)
	{
		Item@item=target.GetItem(0,s);
		if((@item!=null))
		{
			string slot="Slot";
			switch(s)
			{
				case(1):
				slot="Active hand";
				break;
				case(2):
				slot="Second hand";
				break;
				case(3):
				slot="Armor";
				break;
				case(4):
				slot="Helmet";
				break;
				case(5):
				slot="Trophy";
				break;
			}
			string name="";
			player.Say((11),slot+"("+s+"): "+name+" ("+item.GetProtoId()+","+item.Id+")");
		}
	}
}

void ExecNameToIdCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(target.Id>0)
	player.Say((11),"Player("+GetSafePlayerName(target.Id)+"): "+target.Id);
	else
	player.Say((11),"Player doesn't exist.");
}

void ExecIdToNameCommand(array<string@>@command,Critter@player)
{
	uint id=0;
	if(command.length()<3)
	return;
	StrToInt(command[2],id);
	string name=GetSafePlayerName(id);
	if(name=="[player not found]")
	player.Say((11),"Player don't exists.");
	else
	player.Say((11),"Player("+id+"): "+name);
}

void ExecListFollowersCommand(array<string@>@command,Critter@player,Critter@target)
{
	uint count=0;
	bool first=true;
	for(uint i=(900);i<=(924);i++)
	{
		if(target.Followers[i]!=0)
		{
			Critter@cr=GetCritter(target.Followers[i]);
			if(!(@cr!=null))
			{
				target.FollowersBase[i]=0;
				continue;
			}
			
			if(first)
			{
				player.Say((11),"Listing "+GetSafePlayerName(target.Id)+"'s followers:");
				first=false;
			}
			player.Say((11),"Follower #"+(i-(900)+1)+": "+(target.Followers[i]));
			count++;
		}
	}
	if(first)
	player.Say((11),GetSafePlayerName(target.Id)+" has no followers.");
}                        

bool BlockerSetProto(Item@blocker,bool visible)
{
	bool success=false;
	
	if(visible)
	{
		if(blocker.ChangeProto(((484))))
		{
			((blocker.Flags)=(blocker.Flags)|((0x00000800)));
			success=true;
		}
	}
	else
	{
		if(blocker.ChangeProto(((820))))
		{
			(blocker.Flags=((blocker.Flags)&(~((0x00000800)))));
			success=true;
		}
	}
	(blocker.Flags=((blocker.Flags)&(~((0x00000004)))));
	(blocker.Flags=((blocker.Flags)&(~((0x10000000)))));
	(blocker.Flags=((blocker.Flags)&(~((0x08000000)))));
	blocker.Val8=(92);
	blocker.Update();
	return success;
}    

bool BlockerCreate(Critter@creator,Map@map,uint16 x,uint16 y,int group,bool safe,bool visible)
{
	Item@blocker=map.AddItem(x,y,((820)),1);
	
	if((@blocker!=null))
	{
		blocker.Val4=group;
		creator.Say((11),"      Blocker created at hex "+x+","+y);
		if(BlockerSetProto(blocker,visible)==false)
		{
			creator.Say((11),"|0xCC0000 "+"WARNING: Can't change proto of blocker at hex: "+x+","+y);
		}
		if(safe)
		{
			(blocker.Flags=((blocker.Flags)&(~((0x00000008)))));
		}
		return true;
	}
	else
	{
		creator.Say((11),"|0xCC0000 "+"WARNING: Can't spawn blocker at hex: "+x+","+y);
		return false;
	}
}  

void BlockerDelete(Critter@deleter,uint16 pid,uint group,bool deleteAll)
{
	
	Map@blockerMap=deleter.GetMap();
	
	array<Item@>blockers;
	uint blockersNum=blockerMap.GetItems(pid,blockers);
	
	for(uint i=0;i<blockersNum;i++)
	{
		if(uint(blockers[i].Val8)==(92)&&(deleteAll||uint(blockers[i].Val4)==group))
		{
			deleter.Say((11),"Removing blocker ["+blockers[i].Val4+"]: "+blockers[i].HexX+","+blockers[i].HexY);
			blockerMap.RunEffect((4008),blockers[i].HexX,blockers[i].HexY,0);
			DeleteItem(blockers[i]);
		}
	}
	
}  

void ExecBlockersCommand(array<string@>@command,Critter@player,Critter@target)
{  
	
	string argSubcommand="help";  
	
	if(command.length()>2)
	{
		argSubcommand=command[2];
	}   
	
	if(command.length()>3)
	{
		if(command[3]=="all")
		{
			player.Say((11),"|0xCC0000 "+"WARNING: Deprecated argument.");
			player.Say((11),"|0xCC0000 "+"Use "+"|0xFF4400 "+"-all "+"|0xCC0000 "+"option instead to select all blockers.");
			return;
		}
	}  
	
	Map@optMap=player.GetMap();
	uint16 optX=target.HexX;
	uint16 optY=target.HexY;
	uint optGroup=0;
	uint optRadius=1;
	bool optSafe=false;
	bool optVisible=false;
	bool optAll=false;     
	
	if(argSubcommand=="help"||argSubcommand=="-help")
	{
		player.Say((11),"------------------------------------------\n"+"|0xFFFFFF "+"   command blockers");
		string shelp="------------------------------------------\n"
		"|0xBBBBBB "+"Allows blocking hexes to prevent players from accessing places, critters or items on a map.\n"
		"|0xFFFFFF "+"Syntax:\n"
		"|0x00FFFF "+"`blockers [subcommand] (options)\n"
		"|0xFFFFFF "+"Arguments:\n"
		"|0x00FFFF "+"[subcommand]"
		"|0xBBBBBB "+" : Specifies blocker action to perform. Possible values:\n"
		"|0x00BBBB "+"    add"
		"|0xBBBBBB "+" : Create a single blocker on a hex\n"
		"|0x00BBBB "+"    around"
		"|0xBBBBBB "+" : Create blockers around a hex\n"
		"|0x00BBBB "+"    to"
		"|0xBBBBBB "+" : Create line of blockers to a hex\n"
		"|0x00BBBB "+"    delete"
		"|0xBBBBBB "+" : Delete blockers\n"
		"|0x00BBBB "+"    show"
		"|0xBBBBBB "+" : Make blockers visible\n"
		"|0x00BBBB "+"    hide"
		"|0xBBBBBB "+" : Make blockers invisible\n"
		"|0x00BBBB "+"    list"
		"|0xBBBBBB "+" : Display list of blockers\n"
		"|0xFFFFFF "+"Options:\n"
		"|0x00FFFF "+"-g [group]"
		"|0xBBBBBB "+" : Specify group of created blockers (add, around) or perform a command on all blockers in the group (delete, show, hide, list)\n"
		"|0x00FFFF "+"-all"
		"|0xBBBBBB "+" : Perform a command on all blockers in the map (delete, show, hide, list)\n"
		"|0x00FFFF "+"-x [hexx] -y [hexy]"
		"|0xBBBBBB "+" : Coordinates of created blocker (add) or center of blocker hexagon (around) or end of blocker line (to)\n"
		"|0x00FFFF "+"-r [radius]"
		"|0xBBBBBB "+" : Radius of blocker hexagon (around)\n"
		"|0x00FFFF "+"-p [id]"
		"|0xBBBBBB "+" : Id of player to block or use the player coords as line end (around, to)\n"
		"|0x00FFFF "+"-n [id]"
		"|0xBBBBBB "+" : Id of NPC to block or use the NPC coords as line end (around, to)\n"
		"|0x00FFFF "+"-s"
		"|0xBBBBBB "+" : Created blockers will block aim (add, around)\n"
		"|0x00FFFF "+"-v"
		"|0xBBBBBB "+" : Created blockers will be visible (add, around, to)";
		player.Say((11),shelp);
		return;
	}  
	
	if(!(@optMap!=null))
	{
		player.Say((11),"|0xCC0000 "+"WARNING: Can't block whole California, sorry.");
		return;
	}   
	
	else if(argSubcommand=="add")
	{
		cheatGetOption(command,optX,"-x");
		cheatGetOption(command,optY,"-y");
		player.Say((11),"Placing a blocker at hex "+optX+","+optY);
		player.Say((11),"   Group: "+cheatGetOption(command,optGroup,"-g"));
		player.Say((11),"   Safe: "+cheatGetOption(command,optSafe,"-s"));
		player.Say((11),"   Visible: "+cheatGetOption(command,optVisible,"-v"));
		
		BlockerCreate(player,optMap,optX,optY,optGroup,optSafe,optVisible);
	}   
	
	else if(argSubcommand=="around")
	{
		cheatGetOption(command,optX,"-x");
		cheatGetOption(command,optY,"-y");
		player.Say((11),"Placing blockers around hex "+optX+","+optY);
		player.Say((11),"   Group: "+cheatGetOption(command,optGroup,"-g"));
		player.Say((11),"   Radius: "+cheatGetOption(command,optRadius,"-r"));
		player.Say((11),"   Safe: "+cheatGetOption(command,optSafe,"-s"));
		player.Say((11),"   Visible: "+cheatGetOption(command,optVisible,"-v"));  
		
		if(optRadius==0)
		{
			player.Say((11),"|0xCC0000 "+"ERROR: Can't create hexagon with radius 0");
			return;
		}
		
		uint16 stepX=optX;
		uint16 stepY=optY;  
		
		optMap.MoveHexByDir(stepX,stepY,4,optRadius);
		for(uint8 stepDir=0;stepDir<6;stepDir++)
		{
			for(uint step=0;step<optRadius;step++)
			{
				optMap.MoveHexByDir(stepX,stepY,stepDir,1);
				BlockerCreate(player,optMap,stepX,stepY,optGroup,optSafe,optVisible);
			}
		}
	}    
	
	else if(argSubcommand=="to")
	{
		cheatGetOption(command,optX,"-x");
		cheatGetOption(command,optY,"-y");
		player.Say((11),"Placing line of blockers to hex "+optX+","+optY);
		player.Say((11),"   Group: "+cheatGetOption(command,optGroup,"-g"));
		player.Say((11),"   Visible: "+cheatGetOption(command,optVisible,"-v"));
		
		uint distance=GetDistantion(player.HexX,player.HexY,optX,optY);
		
		if(distance<1)
		{
			player.Say((11),"|0xCC0000 "+"ERROR: Can't create line with length 0");
			return;
		}  
		
		uint16 saveX=optX;
		uint16 saveY=optY;  
		
		uint16 lastX=0;
		uint16 lastY=0;
		
		for(uint8 step=1;step<=distance;step++)
		{
			optMap.GetHexCoord(player.HexX,player.HexY,optX,optY,0.0f,step);
			if(lastX==optX&&lastY==optY)
			{
				break;
			}
			BlockerCreate(player,optMap,optX,optY,optGroup,optSafe,optVisible);
			lastX=optX;
			lastY=optY;
			optX=saveX;
			optY=saveY;
		}
	}   
	
	else if(argSubcommand=="delete"||argSubcommand=="remove")
	{
		cheatGetOption(command,optGroup,"-g");
		cheatGetOption(command,optAll,"-all");
		
		BlockerDelete(player,((484)),optGroup,optAll);
		BlockerDelete(player,((820)),optGroup,optAll);
	}   
	
	else if(argSubcommand=="show"||argSubcommand=="hide")
	{
		cheatGetOption(command,optGroup,"-g");
		cheatGetOption(command,optAll,"-all");
		
		uint16 proto=((820));
		bool show=true;
		if(argSubcommand=="hide")
		{
			proto=((484));
			show=false;
		}
		
		array<Item@>blockers;
		uint blockersNum=optMap.GetItems(proto,blockers);
		
		for(uint i=0;i<blockersNum;i++)
		{
			if(uint(blockers[i].Val8)==(92)&&(optAll||uint(blockers[i].Val4)==optGroup))
			{
				BlockerSetProto(blockers[i],show);
			}
		}
	}   
	
	else if(argSubcommand=="list")
	{
		cheatGetOption(command,optGroup,"-g");
		cheatGetOption(command,optAll,"-all");
		
		array<Item@>blockers;
		uint blockersNum=optMap.GetItems(0,blockers);
		uint count=0;
		
		for(uint i=0;i<blockersNum;i++)
		{
			if(uint(blockers[i].Val8)==(92)&&(optAll||uint(blockers[i].Val4)==optGroup))
			{
				count+=1;
				player.Say((11),count+". Blocker ["+blockers[i].Val4+"]: "+blockers[i].HexX+","+blockers[i].HexY);
			}
		}
	}  
	
	else
	{
		player.Say((11),"|0xCC0000 "+"ERROR: Unknown argument: "+"|0xFF4400 "+argSubcommand);
		player.Say((11),"|0xCC0000 "+"Type "+"|0xFF4400 "+"`blockers -help "+"|0xCC0000 "+"to display command help.");
		return;
	}
} 

void ExecLogCommand(array<string@>@command,Critter@player)
{
	string s=GetParameterString(command,"-m");
	if(s=="")
	player.Say((11),"No text specified. Did you forget to use -m?");
	FLog((1),s);
	GMLog(player," log call: "+s);   
	
}

void ExecClearInventoryCommand(array<string@>@command,Critter@player,Critter@target)
{
	array<Item@>items;
	int count=target.GetItems((0),items);
	if(count>0)
	{
		player.Say((11),"Removing "+count+" items from "+target.Name);
		player.Animate(0,(28),null,true,true);
		DeleteItems(items);
	}
	else
	player.Say((11),target.Name+" has no items!");
}

void ExecDropItemsCommand(array<string@>@command,Critter@player,Critter@target)
{
	array<Item@>items;
	int count=target.GetItems((0),items);
	if(count>0)
	{
		player.Say((11),"Dropping "+count+" items from "+target.Name);
		player.Animate(0,(27),null,true,true);
		MoveItems(items,player.GetMap(),player.HexX,player.HexY);
	}
	else
	player.Say((11),"Nothing to drop.");
}

void ExecPickItemsCommand(array<string@>@command,Critter@player,Critter@target)
{
	Map@map=target.GetMap();
	array<Item@>items;
	if((@map!=null))
	{
		int count=map.GetItems(target.HexX,target.HexY,items);
		if(count>0)
		{
			player.Say((11),"Picking "+count+" items for "+target.Name);
			if(target.Id==player.Id)
			player.Animate(0,(27),null,true,true);
			else
			player.Animate(0,(28),null,true,true);
			MoveItems(items,player);
		}
		else
		player.Say((11),"Nothing to pick up for "+target.Name+".");
	}
	else
	{
		player.Say((11),"Target on worldmap.");
	}
}  

Item@FindItem(Critter@player,uint itemId)
{
	
	Item@item=player.GetItemById(itemId);
	if((@item!=null))
	{  
		
		return(item);
	} 
	
	Map@map=player.GetMap();
	if((@map!=null))
	{
		uint homeMap=map.Id;
		@item=map.GetItem(itemId);
		if((@item!=null))
		{  
			
			return(item);
		}
		
		Location@location=map.GetLocation();
		if((@location!=null))
		{
			for(uint m=0;m<location.GetMapCount();m++)
			{
				Map@checkmap=location.GetMapByIndex(m);
				
				if(checkmap.Id==homeMap)
				continue;
				@item=checkmap.GetItem(itemId);
				if((@item!=null))
				{  
					
					return(item);
				}
			}
		}
	} 
	
	uint16 dummy=0;
	array<Item@>items;
	uint count=GetAllItems(dummy,items);
	for(uint i=0;i<count;i++)
	{
		if(items[i].Id==itemId)
		{  
			
			return(items[i]);
		}
	}
	return(null);
}

uint[]item_flags=
{
	(0x00000001),
	(0x00000002),
	(0x00000004),
	(0x00000008),
	(0x00000010),
	(0x00000020),
	(0x00000040),
	(0x00000080),
	(0x00000100),
	(0x00000200),
	(0x00000400),
	(0x00000800),
	(0x00001000),
	(0x00002000),
	(0x00004000),
	(0x00008000),
	(0x00010000),
	(0x00020000),
	(0x00040000),
	(0x00080000),
	(0x00100000),
	(0x00200000),
	(0x00400000),
	(0x00800000),
	(0x01000000),
	(0x02000000),
	(0x04000000),
	(0x08000000),
	(0x10000000),
	(0x20000000),
	(0x40000000),
	(0x80000000)
};

string[]item_flagnames=
{
	"hidden",
	"flat",
	"no_block",
	"shoot_thru",
	"light_thru",
	"multi_hex",
	"wall_trans_end",
	"two_hands",
	"big_gun",
	"always_view",
	"has_timer",
	"bad_item",
	"no_highlight",
	"show_anim",
	"show_anim_ext",
	"light",
	"geck",
	"trap",
	"no_light_influence",
	"no_loot",
	"no_steal",
	"gag",
	"colorize",
	"colorize_inv",
	"can_use_on_smth",
	"can_look",
	"can_talk",
	"can_pickup",
	"can_use",
	"holodisk",
	"radio",
	"cached"
}; 

string GetParameterString(array<string@>@search,array<string>&this)
{
	if(this.length()==0)
	return("");
	
	for(uint i=0;i<search.length();i++)
	{
		if(search.length()<(i+1))
		break;
		for(uint t=0;t<this.length();t++)
		{
			if(search[i]==this[t]&&search.length()>(i+1))
			{
				return(search[i+1]);
			}
		}
		
	}
	return("");
} 

int GetIndexOfString(array<string>&search,string&this)
{
	for(uint i=0;i<search.length();i++)
	{
		if(search[i]==this)
		return(i);
	}
	;
	return(-1);
} 

int GetIndexOfString(array<string@>@search,array<string>&this)
{
	for(uint i=0;i<search.length();i++)
	{
		for(uint t=0;t<this.length();t++)
		{
			if(search[i]==this[t])
			{
				return(i);
			}
		}
	}
	;
	return(-1);
}
void ExecItemFlagsCommand(array<string@>@command,Critter@player)
{
	if(item_flags.length()!=item_flagnames.length())
	{
		player.Say((11),"Internal error: item_flags.length() != item_flagnames.length() -> "+item_flags.length()+" != "+item_flagnames.length());
		player.Say((11),"Blame random dev.");
		return;
	}
	
	if(command.length()<3)
	{
		player.Say((11),"Missing arguments.");
		return;
	}
	
	int itemId=0;
	Item@item;
	if(command[2]=="get"||command[2]=="set"||command[2]=="unset")
	{
		if(command.length()<4)
		{
			player.Say((11),"Missing arguments for '"+command[2]+"'");
			return;
		}
		if(StrToInt(command[3],itemId))
		{
			@item=FindItem(player,itemId);
			if(!(@item!=null))
			{
				player.Say((11),"Can't find item, id "+itemId);
				return;
			}
		}
		else
		{
			player.Say((11),"Wrong item id.");
			return;
		}
	}
	
	if(command[2]=="get")
	{
		player.Say((11),"Item "+itemId+" flags ("+item.Flags+"):");
		for(uint f=0;f<item_flags.length();f++)
		{
			if((((item.Flags)&(item_flags[f]))!=0))
			{
				player.Say((11),"  "+(item_flagnames.length()>=(f+1)?item_flagnames[f]:"???")+" ("+item_flags[f]+")");
			}
		}
	}
	else if(command[2]=="set"||command[2]=="unset")
	{
		if(command.length()!=5)
		{
			player.Say((11),"Wrong number of arguments");
			return;
		}
		
		int index=GetIndexOfString(item_flagnames,command[4]);
		if(index==-1)
		{
			player.Say((11),"Unknown flag: "+command[4]);
			return;
		}
		
		player.Say((11),(command[2]=="set"?"S":"Uns")+"etting flag "+command[4]+" for item "+itemId);
		if(command[2]=="set")
		((item.Flags)=(item.Flags)|(item_flags[index]));
		else
		(item.Flags=((item.Flags)&(~(item_flags[index]))));
		item.Update();   
		
	}
	else if(command[2]=="list")
	{
		player.Say((11),"Item flags list:");
		for(uint f=0;f<item_flags.length();f++)
		{
			player.Say((11),"  "+item_flagnames[f]+" ("+item_flags[f]+")");
		}
		return;
	}
	else
	{
		player.Say((11),"Unknown mode "+command[2]);
		return;
	}
}

void ExecItemProtoCommand(array<string@>@command,Critter@player)
{
	int itemId=0;
	string[]sitem={"-i","-item"};
	
	if(StrToInt(GetParameterString(command,sitem),itemId))
	{
		Item@item=FindItem(player,itemId);
		if((@item!=null))
		{
			uint16 proto=0;
			string[]sproto={"-pid","-proto","-protoid"};
			uint16 ammocount=0;
			string[]sammocount={"-ammocount"};
			int16 dir=0;
			string[]sdir={"-dir","-direction"};
			int16 offsetx=0,offsety=0;
			string[]soffsetx={"-ox","-offsetx"};
			string[]soffsety={"-oy","-offsety"};
			
			string[]spicmap={"-picmap"};
			string[]spicinv={"-picinv"};
			string[]spic={"-pic"};
			
			int wear=0;
			string[]swear={"-w","-wear"};
			
			string picmap=GetParameterString(command,spicmap);
			string picinv=GetParameterString(command,spicinv);
			string pic=GetParameterString(command,spic);
			if(pic!="")
			{
				picmap=pic;
				picinv=pic;
			}
			
			if(StrToInt(GetParameterString(command,sproto),proto))
			{
				player.Say((11),"Changing item proto to: "+proto);
				if(item.ChangeProto(proto))
				{
					player.Say((11),"Sim salabim!");
					item.Update();
				}
				else
				player.Say((11),"Can't change item proto");
			}
			else
			{};
			
			if(StrToInt(GetParameterString(command,sammocount),ammocount))
			{
				player.Say((11),"Changing item ammo count to: "+ammocount);
				item.AmmoCount=ammocount;
				item.Update();
			}
			else
			{};
			
			if(picmap!="")
			{
				player.Say((11),"Changing map picture to: "+picmap);
				item.PicMap=GetStrHash(picmap);
				item.Update();
			}
			
			if(picinv!="")
			{
				player.Say((11),"Changing inventory picture to: "+picinv);
				item.PicInv=GetStrHash(picinv);
				item.Update();
			}
			else
			{}; 
			
			if(StrToInt(GetParameterString(command,sdir),dir))
			{
				player.Say((11),"Changing item directory to: "+dir);
				item.Dir=dir;
				item.Update();
			}
			else
			{};
			
			if(StrToInt(GetParameterString(command,soffsetx),offsetx))
			{
				player.Say((11),"Changing item offset x to: "+offsetx);
				item.OffsetX=offsetx;
				item.Update();
			}
			else
			{};
			
			if(StrToInt(GetParameterString(command,soffsety),offsety))
			{
				player.Say((11),"Changing item offset y to: "+offsety);
				item.OffsetY=offsety;
				item.Update();
			}
			else
			{};
			
			if(StrToInt(GetParameterString(command,swear),wear))
			{
				wear=(((wear)>(100))?(100):(((wear)<(0))?(0):(wear)));
				player.Say((11),"Changing wear to: "+wear+"%");
				SetWear(item,wear);
				item.Update();
			}
			else
			{};
		}
		else
		{
			player.Say((11),"Item not found. ");
			return;
		}
	}
}

void ExecItemLightCommand(array<string@>@command,Critter@player)
{
	int itemId=0;
	string[]sitem={"-i","-item"};
	
	if(StrToInt(GetParameterString(command,sitem),itemId))
	{
		Item@item=FindItem(player,itemId);
		if((@item!=null))
		{
			int arg=0;
			string[]sintensity={"-int","-intensity"};
			string[]sradius={"-r","-radius"};
			string[]sflags={"-f","-flags"};
			string[]scolor={"-c","-color"};
			if(StrToInt(GetParameterString(command,sintensity),arg))
			item.LightIntensity=arg;
			if(StrToInt(GetParameterString(command,sradius),arg))
			item.LightDistance=arg;
			if(StrToInt(GetParameterString(command,sflags),arg))
			item.LightFlags=arg;
			if(StrToInt(GetParameterString(command,scolor),arg))
			item.LightColor=arg;
			item.Update();
		}
		else
		{
			player.Say((11),"Item not found. ");
			return;
		}
	}
	else
	player.Say((11),"Missing -i argument.");
}

void ExecSetLexemCommand(array<string@>@command,Critter@player,Critter@target)
{
	int itemId=0;
	string[]sitem={"-i","-item"};
	
	string[]slexem={"-l","-lexem"};
	string lexem=GetParameterString(command,slexem);
	string what=GetParameterString(command,"-m");
	
	if(lexem.length()==0)
	{
		player.Say((11),"No lexem given.");
		return;
	}
	else if(lexem[0]!=36)
	{
		player.Say((11),"Invalid lexem name <"+lexem+">");
		return;
	}
	
	if(StrToInt(GetParameterString(command,sitem),itemId))
	{
		Item@item=FindItem(player,itemId);
		if((@item!=null))
		{
			if(what.length()==0)
			{
				player.Say((11),"Removing item lexem "+lexem);
				UnsetLexem(item,lexem);
			}
			else
			{
				if(what.length()>=127)
				{
					player.Say((11),"Lexem too long");
					return;
				}
				player.Say((11),"Setting item lexem "+lexem+": "+what);
				SetLexem(item,lexem,what);
			}
		}
		else
		{
			player.Say((11),"Item not found. ");
			return;
		}
	}
	else
	{
		if(what.length()==0)
		{
			player.Say((11),"Removing "+target.Name+"("+target.Id+") lexem "+lexem);
			UnsetLexem(target,lexem);
		}
		else
		{
			if(target.Id!=player.Id&&target.IsPlayer()&&
			!GodOfTheRealm(player.Id))
			{
				player.Say((11),"Invalid target.");
				return;
			}
			
			if(what.length()>=127)
			{
				player.Say((11),"Lexem too long");
				return;
			}
			
			player.Say((11),"Setting "+target.Name+"("+target.Id+") lexem "+lexem+": "+what);
			SetLexem(target,lexem,what);
		}
	}
}

void ExecLockCarCommand(array<string@>@command,Critter@player,bool lock)
{
	int itemId=0;
	string[]sitem={"-i","-item"};
	
	if(StrToInt(GetParameterString(command,sitem),itemId))
	{
		Item@item=FindItem(player,itemId);
		if((@item!=null))
		{
			if(item.GetType()!=(13))
			{
				player.Say((11),"It's not a car.");
				return;
			}
			
			string un="";
			if(lock)
			((item.Val0)=(item.Val0)|((0x0002)));
			else
			{
				un="un";
				(item.Val0=((item.Val0)&(~((0x0002)))));
			}
			player.Say((11),"Car "+un+"locked.");
			
		}
		else
		player.Say((11),"Car not found. ");
	}
	else
	player.Say((11),"Missing -item argument.");
}

void ExecGetItemsCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"Invalid target.");
		return;
	}
	
	string[]sinv={"-i","-inv","-inventory","-all"};
	string[]sarmor={"-a","-armor","-all"};
	string[]shead={"-h3","-head","-helmet","-all"};
	string[]shand1={"-h1","-hand1","-hands","-all"};
	string[]shand2={"-h2","-hand2","-hands","-all"};
	
	bool inv=(GetIndexOfString(command,sinv)!=-1);
	bool armor=(GetIndexOfString(command,sarmor)!=-1);
	bool head=(GetIndexOfString(command,shead)!=-1);
	bool hand1=(GetIndexOfString(command,shand1)!=-1);
	bool hand2=(GetIndexOfString(command,shand2)!=-1);
	
	if(!inv&&!armor&&!hand1&&!hand2&&!head)
	{
		player.Say((11),"Nothing to transfer.");
		return;
	}    
	
	array<Item@>items;
	uint count=0;
	
	if(inv)
	count+=target.GetItems((0),items);
	if(armor)
	count+=target.GetItems((3),items);
	if(head)
	count+=target.GetItems((4),items);
	if(hand1)
	count+=target.GetItems((1),items);
	if(hand2)
	count+=target.GetItems((2),items);
	
	if(count>0)
	{
		player.Say((11),"Transfering "+count+" items from "+target.Name);
		player.Animate(0,(28),null,true,true);
		MoveItems(items,player);
	}
	else
	player.Say((11),target.Name+" has no items in given slot(s)");
} 

void ExecCoreCheats(array<string@>@command,Critter@player)
{
	int cheats=0;
	
	if(command.length()<3)
	{
		player.Say((11),"Wrong numer of arguments.");
		return;
	}
	else if(command[2]=="set"&&command.length()<4)
	{
		player.Say((11),"Wrong numer of arguments for 'set' mode.");
		return;
	}
	
	if(command[2]=="reset"||command[2]=="set")
	{
		((cheats)=(cheats)|((0x0000000001)|(0x0000000002)|(0x0000000004)|(0x0000000008)|(0x0000000010)|(0x0000000020)|(0x0000000080)));
	}
	
	if(command[2]=="reset")
	{
		
	}
	else if(command[2]=="set")
	{
		if(GetIndexOfString(command,"+"+"tile")!=-1){((cheats)=(cheats)|((0x0000000001)));}else if(GetIndexOfString(command,"-"+"tile")!=-1){(cheats=((cheats)&(~((0x0000000001)))));};
		if(GetIndexOfString(command,"+"+"roof")!=-1){((cheats)=(cheats)|((0x0000000002)));}else if(GetIndexOfString(command,"-"+"roof")!=-1){(cheats=((cheats)&(~((0x0000000002)))));};
		if(GetIndexOfString(command,"+"+"item")!=-1){((cheats)=(cheats)|((0x0000000004)));}else if(GetIndexOfString(command,"-"+"item")!=-1){(cheats=((cheats)&(~((0x0000000004)))));};
		if(GetIndexOfString(command,"+"+"scen")!=-1){((cheats)=(cheats)|((0x0000000008)));}else if(GetIndexOfString(command,"-"+"scen")!=-1){(cheats=((cheats)&(~((0x0000000008)))));};
		if(GetIndexOfString(command,"+"+"wall")!=-1){((cheats)=(cheats)|((0x0000000010)));}else if(GetIndexOfString(command,"-"+"wall")!=-1){(cheats=((cheats)&(~((0x0000000010)))));};
		if(GetIndexOfString(command,"+"+"crit")!=-1){((cheats)=(cheats)|((0x0000000020)));}else if(GetIndexOfString(command,"-"+"crit")!=-1){(cheats=((cheats)&(~((0x0000000020)))));};
		if(GetIndexOfString(command,"+"+"fast")!=-1){((cheats)=(cheats)|((0x0000000040)));}else if(GetIndexOfString(command,"-"+"fast")!=-1){(cheats=((cheats)&(~((0x0000000040)))));};
		if(GetIndexOfString(command,"+"+"npcnames")!=-1){((cheats)=(cheats)|((0x0000000080)));}else if(GetIndexOfString(command,"-"+"npcnames")!=-1){(cheats=((cheats)&(~((0x0000000080)))));};
		if(GetIndexOfString(command,"+"+"critid")!=-1){((cheats)=(cheats)|((0x0000000100)));}else if(GetIndexOfString(command,"-"+"critid")!=-1){(cheats=((cheats)&(~((0x0000000100)))));};    
		
	}
	else
	{
		player.Say((11),"Invalid switch: "+command[2]);
		return;
	}
	
	player.RunClientScript("_CC",cheats,0,0," ",null);
}

void ExecFindCharsCommand(array<string@>@command,Critter@player)
{
	string halp="Usage: findchars [param] [< <= == != >= >] [value]";
	int param=0;
	int value=0;  
	
	if(command.length()<3||!StrToInt(command[2],param))
	{
		player.Say((11),halp);
		return;
	}
	if(param<0)
	{
		player.Say((11),halp);
		player.Say((11),"[param] cannot be less than 0");
		return;
	}
	if(!(command[3]=="<"||command[3]==">"||
	command[3]=="<="||command[3]==">="||command[3]=="=="||
	command[3]=="!="))
	{
		player.Say((11),halp);
		return;
	}
	if(!StrToInt(command[4],value))
	{
		player.Say((11),halp);
		return;
	} 
	
	array<Critter@>players;
	uint n=GetAllOnlinePlayers(players);
	uint found=0;
	for(uint p=0;p<players.length();p++)
	{  
		
		if(GodOfTheRealm(players[p].Id)&&((players[p].Mode[(534)]&((0x00020000)))!=0))
		continue; 
		
		if(player.GetAccess()<players[p].GetAccess())
		continue;
		
		if(command[3]=="<"&&players[p].Param[param]<value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
		else if(command[3]=="<="&&players[p].Param[param]<=value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
		else if(command[3]==">"&&players[p].Param[param]>value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
		else if(command[3]==">="&&players[p].Param[param]>=value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
		else if((command[3]=="==")&&players[p].Param[param]==value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
		else if(command[3]=="!="&&players[p].Param[param]!=value)
		{
			player.Say((11),GetSafePlayerName(players[p].Id)+" ("+players[p].Id+")"+"("+players[p].GetMapId()+") - "+GetAuthString(players[p]));
			found++;
		}
	}
	player.Say((11),"Found "+found+" player"+(found==1?"":"s")+".");
}

void ExecFindNpcCommand(array<string@>@command,Critter@player)
{
	if(command.length()<3)
	{
		player.Say((11),"Missing arguments");
		return;
	}
	
	if(command[2]=="list")
	{
		if(INPC.length()>0)
		{
			player.Say((11),"\nImportant NPCs:");
			for(uint i=0;i<INPC.length();i++)
			{
				string names="";
				for(uint n=0;n<INPC[i].names.length();n++)
				{
					if(n>0)
					names+=",";
					names+=INPC[i].names[n];
				}
				
				player.Say((11),
				"["+
				(INPC[i].protoId<1000?" ":"")+
				(INPC[i].protoId<100?" ":"")+
				(INPC[i].protoId<10?" ":"")+
				INPC[i].protoId+
				","+
				(INPC[i].dialogId<10000?" ":"")+
				(INPC[i].dialogId<1000?" ":"")+
				(INPC[i].dialogId<100?" ":"")+
				(INPC[i].dialogId<10?" ":"")+
				INPC[i].dialogId+
				"] "+
				names);
			}
			player.Say((11),"Total "+INPC.length()+" NPCs");
		}
	}
	else
	{
		array<CNPC@>list;
		for(uint i=0;i<INPC.length();i++)
		{
			for(uint n=0;n<INPC[i].names.length();n++)
			{
				if(strlwr(INPC[i].names[n])==strlwr(command[2]))
				{
					list.insertLast(INPC[i]);
					break;
				}
			}
		}
		if(list.length()>0)
		{
			player.Say((11),"NPC \""+command[2]+"\" ("+list.length()+")");
			for(uint l=0;l<list.length();l++)
			{
				if(!(@list[l]!=null))
				continue;
				array<Critter@>npcs;
				GetAllNpc(list[l].protoId,npcs);
				if(npcs.length()>0)
				{
					for(uint n=0;n<npcs.length();n++)
					{
						if(list[l].IsImportant(npcs[n]))
						{
							uint map=npcs[n].GetMapId();
							player.Say((11)," "+
							npcs[n].Id+
							(map>0
							?" map:"+map+":"+npcs[n].HexX+","+npcs[n].HexY
							:"worldmap:"+npcs[n].WorldX+","+npcs[n].WorldY)
							);
						}
					}
				}
				else
				{
					player.Say((11),"Can't find any \""+command[2]+"\"");
				}
			}
		}
		else
		{
			player.Say((11),"Unknown NPC \""+command[2]+"\"");
		}
	}
} 

void ExecResetWorldMapCommand(array<string@>@command,Critter@player)
{
	for(uint x=0;x<__GlobalMapWidth;x++)
	{
		for(uint y=0;y<__GlobalMapHeight;y++)
		{
			player.SetFog(x,y,(3));
		}
	}
}

void ExecPlayMusicCommand(array<string@>@command,Critter@player)
{
	string[]smusic={"-m","-music"};
	string music=GetParameterString(command,smusic);
	if(music=="")
	{
		player.Say((11),"Missing music filename.");
		return;
	}
	else
	{
		if((@player.GetMap()!=null))
		{
			player.Say((11),"Playing: "+music);
			array<Critter@>critters;
			
			uint allcrit=player.GetMap().GetCritters(0,(0x0F)|(0x10),critters);
			for(uint c=0;c<allcrit;c++)
			{
				critters[c].RunClientScript("_PlayMusic",0,0,0,music,null);
			}
		}
		else
		{
			player.Say((11),"Invalid map.");
			return;
		}
	}
	return;
}

void ExecPlaySoundCommand(array<string@>@command,Critter@player,bool speech)
{
	string[]ssound={"-s","-sound"};
	string sound=GetParameterString(command,ssound);
	if(sound=="")
	{
		player.Say((11),"Missing sound filename.");
		return;
	}
	else
	{
		Map@map=player.GetMap();
		if((@map!=null))
		{
			if(GetIndexOfString(command,"-x")!=-1||
			GetIndexOfString(command,"-y")!=-1||
			GetIndexOfString(command,"-r")!=-1)
			{
				string sx=GetParameterString(command,"-x");
				int x=0;
				string sy=GetParameterString(command,"-y");
				int y=0;
				string[]sradius={"-r","-radius"};
				string sr=GetParameterString(command,sradius);
				int r=0;
				StrToInt(sx,x);
				StrToInt(sy,y);
				StrToInt(sr,r);
				if(x==0&&sx!="0")
				x=player.HexX;
				if(y==0&&sy!="0")
				y=player.HexY;
				if(r==0)
				r=10;
				map.PlaySound((speech?"sound\\speech\\":"")+sound,x,y,r);
				return;
			}
			else
			{
				map.PlaySound((speech?"sound\\speech\\":"")+sound);
				return;
			}
		}
		else
		{
			player.Say((11),"Invalid map.");
			return;
		}
	}
}

void ExecGetRequestsCommand(array<string@>@command,Critter@player)
{
	Broadcast_DumpRequestHelpBuffer(player);
}     

void ExecParamCommand(array<string@>@command,Critter@player,Critter@target)
{
	if(command.length()>=4)
	{
		int control=0;
		int param=-1;
		bool ok=false;
		if(!StrToInt(command[2],control))
		{
			player.Say((11),"Wrong arguments.");
			return;
		}
		else
		{
			if(control!=0)
			{
				player.Say((11),"Invalid param group.");
				return;
			}
		}
		
		if(StrToInt(command[3],param))
		{
			if(param<0||param>999)
			{
				player.Say((11),"Invalid param number.");
				return;
			}
			if(target.Id==player.Id||(player.GetAccess()>=(3)&&target.IsNpc()))
			{
				if(player.GetAccess()==(1)&&!Present(param,testerparamlist))
				{
					player.Say((11),"You can't view or edit this param.");
					return;
				}
				
				int value=0;
				bool haveValue=false;
				if(command.length>=5)
				{
					haveValue=true;
					if(!StrToInt(command[4],value))
					{
						player.Say((11),"Invalid value argument <"+command[4]+">");
						return;
					}
				}
				
				if(!haveValue)
				{
					player.Say((11),"Param "+param+" of critter "+target.Name+"("+target.Id+"): "+target.Param[param]);
					return;
				}
				
				int oldValue=target.Param[param]; 
				
				switch(param)
				{
					case(70):
					{
						SetLvar(target,(9002),__Year-value);
						SynchronizeAge(target);
						if(oldValue!=target.Param[(70)])
						player.Say((11),"SynchronizeAge "+target.Name+"("+target.Id+"): "+oldValue+" -> "+target.Param[(70)]);
					};
					break;
					
					default:
					target.ParamBase[param]=value;
					break;
				}
				
				player.Say((11),"Changed param "+param+" of critter "+target.Name+"("+target.Id+"): "+oldValue+" -> "+target.Param[param]); 
				
				switch(param)
				{
					case(112):
					target.DisguisedBy=player.Id;
					break;
				}
			}
			else
			{
				player.Say((11),"Wrong target: "+target.Name+"("+target.Id+")");
				return;
			}
		}
		else
		{
			player.Say((11),"Wrong arguments.");
			return;
		}
	}
	else
	{
		player.Say((11),"Missing arguments.");
	}
}

void ExecGetColorCommand(array<string@>@command,Critter@player)
{
	if(command.length()<5)
	{
		player.Say((11),"Missing arguments.");
		return;
	}
	
	int r=0;
	int g=0;
	int b=0;
	if(StrToInt(command[2],r)&&
	StrToInt(command[3],g)&&
	StrToInt(command[4],b))
	{
		int color=(uint((0xFF<<24)|(((r)&0xFF)<<16)|(((g)&0xFF)<<8)|((b)&0xFF)));
		
		bool isAlpha=false;
		uint8 a=0;
		if(command.length()>=6&&StrToInt(command[5],a))
		{
			isAlpha=true;
			color=((((color)|0xFF000000)^0xFF000000)|((a)&0xFF)<<24);
		}
		
		player.Say((11),"Color: "+r+","+g+","+b);
		if(isAlpha)
		player.Say((11),"Alpha: "+a);
		player.Say((11),"Number: "+color);
	}
	else
	player.Say((11),"Wrong arguments.");
}

void ExecLastSpawnedCommand(array<string@>@command,Critter@player,Critter@target)
{
	player.Say((11),"Last spawned by "+target.Name+":");
	if((GodOfTheRealm(target.Id)||target.GetAccess()>player.GetAccess())&&
	target.Id!=player.Id)
	{
		player.Say((11),"No idea.");
		return;
	}
	
	if(target.LastSpawnedCritter==0&&
	target.LastSpawnedItem==0&&
	target.LastSpawnedLocation==0)
	{
		player.Say((11),"Nothing, "+GenderString(player,"he's","she's","it's")+" clean!");
		return;
	}
	
	if(target.LastSpawnedItem>0)
	player.Say((11),"Item: "+target.LastSpawnedItem);
	if(target.LastSpawnedCritter>0)
	player.Say((11),"Critter: "+target.LastSpawnedCritter);
	if(target.LastSpawnedLocation>0)
	player.Say((11),"Location: "+target.LastSpawnedLocation);
}

string@spaces(int num)
{
	if(num<1)
	return" ";
	string result="";
	result.resize(num);
	for(int s=0;s<num;s++)
	result[s]=32;
	return result;
}

void ExecGameInfoCommand(array<string@>@command,Critter@player)
{
	if(command.length()<3)
	{
		player.Say((11),"Invalid arguments");
		return;
	}
	
	int gameinfo=0;
	StrToInt(command[2],gameinfo);
	
	if(gameinfo==1)
	{
		array<Critter@>players;
		uint all=GetAllOnlinePlayers(players);
		uint num=all;
		for(uint p=0;p<all;p++)
		{
			if(!(@players[p]!=null))
			continue;
			
			if(WrathOfTheGod(players[p]))
			num--;
		}
		
		player.Say((11),"Players in game: "+num);
		player.Say((11),"Connections: "+all);
		
		player.Say((11),"Name                 Id        Ip              Online  Cond     X     Y     Location (Id, Pid)             Map (Id, Pid)                  Level");
		
		for(uint p=0;p<all;p++)
		{
			if(!(@players[p]!=null))
			continue;
			
			if(WrathOfTheGod(players[p]))
			continue;
			
			string line="";
			
			string ip=IpToString(players[p].GetIp());
			string online=(players[p].GetSocket()==-1?"Disconnect":"Yes");
			string cond="";
			switch(players[p].Cond)
			{
				case(1):
				cond="Life";
				break;
				case(2):
				cond="Knockout";
				break;
				case(3):
				cond="Dead";
				break;
				default:
				cond="Unknown";
				break;
			}
			int x=0;
			int y=0;
			string locname="";
			string mapname="";
			if(players[p].GetMapId()==0)
			{
				x=players[p].WorldX;
				y=players[p].WorldY;
				locname="Global map";
			}
			else
			{
				x=players[p].HexX;
				y=players[p].HexY;
				
				Map@map=players[p].GetMap();
				Location@loc=map.GetLocation();
				
				map.ProtoName(mapname);
				loc.ProtoName(locname);
				
				mapname+=" ("+map.Id+", "+map.GetProtoId()+")";
				locname+=" ("+loc.Id+", "+loc.GetProtoId()+")";
			}
			
			if(ip.length()==0)
			ip="0.0.0.0"; 
			
			line+=players[p].Name+spaces(21-players[p].Name.length());
			
			line+=players[p].Id+spaces(10-numDigits(players[p].Id));
			
			line+=ip+spaces(16-ip.length());
			
			line+=online+spaces(11-online.length());
			
			line+=cond+spaces(9-cond.length());
			
			line+=x+spaces(6-numDigits(x));
			line+=y+spaces(6-numDigits(y));
			
			line+=locname+spaces(31-locname.length());
			line+=mapname+spaces(31-mapname.length());
			
			line+=players[p].Param[(77)]+spaces(4-numDigits(players[p].Param[(77)])); 
			
			player.Say((11),line);
		}
	}
	else
	player.Say((11),"Not implemented.");
}

void ExecLastRegisteredCommand(array<string@>@command,Critter@player)
{
	int id=GetGvar((9009));
	
	if(id==0)
	{
		player.Say((11),"GVAR missing");
		return;
	}
	
	string@name=GetSafePlayerName(id);
	if(!(@name!=null))
	name="???";
	
	player.Say((11),"Newest character: "+name+" ("+id+")");
}

void ExecAccessListCommand(array<string@>@command,Critter@player)
{
	
	if(!WrathOfTheGod(player))
	{
		player.Say((11),"No.");
		return;
	} 
	
	if(command.length()<3)
	{
		player.Say((11),"Missing parameters");
		return;
	}
	
	{
		LoadConfig("config/GetAccess.cfg");
		IConfigFile@config=GetConfigFile("config/GetAccess.cfg");
		if(!(@config!=null))
		{
			__CompilerLog("ERROR Can't load config/GetAccess.cfg");
			player.Say((11),"INVALID GETACCESS CONFIG. PANIC.");
			return;
		}
		{};
	}
	
	string option=command[2];
	
	if(option=="help")
	{
		player.Say((11),"Available commands:");
		player.Say((11)," allowregistration [nick]");
		player.Say((11)," disallowregistration [nick]");
		player.Say((11)," list");
		
	}
	else if(option=="allowregistration")
	{
		if(command.length()<4)
		{
			player.Say((11),"Missing parameters (required: nickname)");
			return;
		}
		if(!(@GetConfigSection("config/GetAccess.cfg",command[3],true)!=null))
		{
			player.Say((11),"No such user exists - "+command[3]);
			return;
		}
		SetConfigValue("config/GetAccess.cfg",command[3],"Reserved","false");
		SaveConfig("config/GetAccess.cfg");
		
		string msg="Allowed registration of "+command[3];
		__CompilerLog(msg+" : "+player.Name+"("+player.Id+")");
		player.Say((11),msg);
	}
	else if(option=="disallowregistration")
	{
		if(command.length()<4)
		{
			player.Say((11),"Missing parameters (required: nickname)");
			return;
		}
		if(!(@GetConfigSection("config/GetAccess.cfg",command[3],true)!=null))
		{
			player.Say((11),"No such user exists: "+command[3]);
			return;
		}
		SetConfigValue("config/GetAccess.cfg",command[3],"Reserved","true");
		SaveConfig("config/GetAccess.cfg");
		
		string msg="Disallowed registration of "+command[3];
		__CompilerLog(msg+" : "+player.Name+"("+player.Id+")");
		player.Say((11),msg);
	}
	else if(option=="list")
	{
		IConfigFile@config=GetConfigFile("config/GetAccess.cfg");
		array<string>sections;
		config.GetSections(sections);
		if(sections.length()>0)
		{
			player.Say((11),"Hall of Fame");
			sections.sortAsc();
			for(uint s=0;s<sections.length();s++)
			{
				string@res=GetConfigValue("config/GetAccess.cfg",sections[s],"Reserved");
				player.Say((11)," "+sections[s]+((@res!=null)?" (reserved)":""));
			}
		}
		else
		{
			player.Say((11),"Nobody in access list. What are you doing here?");
			return;
		}
	}        
	
}

void ExecReservedNicknameCommand(array<string@>@command,Critter@player)
{
	LoadConfig("config/ReservedNicknames.cfg");
	
	if(command.length()<3)
	{
		player.Say((11),"Missing parameters");
		return;
	}
	
	IConfigSection@section=GetConfigSection("config/ReservedNicknames.cfg","Reserved");
	
	if(command[2]=="list")
	{
		if(!(@section!=null))
		player.Say((11),"No reserved nicknames found.");
		else
		{
			array<string>nicknames;
			section.GetVars(nicknames);
			if(nicknames.length()>0)
			{
				nicknames.sortAsc();
				player.Say((11),"Reserved nickname"+(nicknames.length()>1?"s":"")+" ("+nicknames.length()+"):");
				for(uint n=0,ncount=nicknames.length();n<ncount;n++)
				{
					player.Say((11),nicknames[n]);
				}
				player.Say((11),"Reserving "+nicknames.length()+" nickname"+(nicknames.length()>1?"s":"")+".");
			}
			else
			player.Say((11),"No reserved nicknames found.");
		}
		return;
	}
	
	if(command.length()<4||command[3].length()==0)
	{
		player.Say((11),"Missing parameters");
		return;
	} 
	
	if(command[2]=="add")
	{
		IConfigVar@var=GetConfigVar("config/ReservedNicknames.cfg","Reserved",command[3],false);
		if((@var!=null))
		section.DeleteVar(var.GetName());
		SetConfigValue("config/ReservedNicknames.cfg","Reserved",command[3],"1");
		SaveConfig("config/ReservedNicknames.cfg");
		player.Say((11),"Nickname <"+command[3]+"> reserved.");
	}
	else if(command[2]=="delete")
	{
		if(!(@section!=null))
		player.Say((11),"No reserved nicknames found.");
		
		IConfigVar@var=GetConfigVar("config/ReservedNicknames.cfg","Reserved",command[3],false);
		if((@var!=null))
		{
			section.DeleteVar(var.GetName());
			SaveConfig("config/ReservedNicknames.cfg");
			player.Say((11),"Nickname <"+var.GetName()+"> no longer reserved.");
		}
		else
		player.Say((11),"Nickname not reserved.");
	}
}

void ExecToGlobal(Critter@player,Critter@target)
{
	if(target.Id!=player.Id&&
	((player.GetAccess()<(2))||GodOfTheRealm(target.Id)))
	{
		player.Say((11),"No.");
		return;
	}
	
	string who=target.Name+"("+target.Id+")";
	
	if(!(@target.GetMap()!=null))
	{
		player.Say((11),who+" already on worldmap.");
		return;
	}
	;
	
	player.Say((11),"Moving "+who+" to worldmap.");
	target.TransitToGlobal(false);
}

void ExecCCD(array<string@>@command,Critter@player)
{
	
	if(!GodOfTheRealm(player.Id))
	{
		player.Say((11),"No.");
		return;
	} 
	
	string ccd=GetParameterString(command,"-m");
	if(ccd.length()==0||ccd=="NONE")
	{
		player.Say((11),"CCD removed");
		UnsetLexem(player,"$~");
	}
	else
	{
		player.Say((11),"CCD: "+ccd);
		SetLexem(player,"$~",ccd);
	}
}

void ExecFactionNews(array<string@>@command,Critter@player)
{
	int id=-1;
	if(!StrToInt(GetParameterString(command,"-f"),id))
	{
		player.Say((11),"You must specify faction id.");
		return;
	}
	if(id<=0)
	{
		player.Say((11),"Invalid id.");
		return;
	}
	if(!FactionExists(id))
	{
		player.Say((11),"Faction does not exists");
		return;
	}
	
	IFaction@faction=GetFaction(id);
	if((@faction!=null))
	{
		uint count=GetFactionNewsCount(id);
		player.Say((11),"Found "+count+" news");
		for(uint index=0;index<count;index++)
		{
			uint type=0;
			uint master=0,slave=0;
			uint16 year;
			uint8 month,day,hour,minute;
			if(GetFactionNews(id,index,master,slave,type,year,month,day,hour,minute))
			{
				string timestamp=day+"."+month+"."+year+" "+hour+":"+(minute<10?"0":"")+minute;
				string masterName=GetSafePlayerName(master,"("+master+")","Player "+master);
				string slaveName=GetSafePlayerName(slave,"("+slave+")","Player "+slave);
				
				switch(type)
				{
					case(1):
					player.Say((11),timestamp+" "+masterName+" joined the faction");
					break;
					case(2):
					player.Say((11),timestamp+" "+masterName+" resigned from being a member");
					break;
					case(3):
					player.Say((11),timestamp+" "+slaveName+" was expelled by "+masterName);
					break;
					case(4):
					player.Say((11),timestamp+" "+slaveName+" was promoted by "+masterName);
					break;
					case(7):
					player.Say((11),timestamp+" "+slaveName+" was demoted by "+masterName);
					break;
					case(9):
					player.Say((11),timestamp+" "+masterName+" claimed leadership");
					break;
					case(10):
					player.Say((11),timestamp+" "+masterName+" became new leader");
					break;
					case(11):
					player.Say((11),timestamp+" "+masterName+" was overthrown");
					break;
					default:
					player.Say((11),timestamp+" UNKNOWN NEWS TYPE <"+type+"> idx<"+index+">");
					break;
				}
			}
		}
	}
	else
	player.Say((11),"Invalid faction");
}

void ExecRunDialog(array<string@>@command,Critter@player,Critter@target)
{
	if(player.Id==target.Id)
	{
		player.Say((11),"Talking to self not implemented.");
		return;
	}
	else if(!target.IsNpc())
	{
		player.Say((11),"Please use *chat* to talk with other players.");
		return;
	}
	
	uint dialog=0;
	if(StrToInt(GetParameterString(command,"-d"),dialog))
	{
		player.Say((11),"Starting dialog "+dialog+" with "+target.Name);
		if(!RunDialog(player,target,dialog,true))
		player.Say((11),"Dialog error.");
	}
	else
	{
		player.Say((11),"Starting default dialog with "+target.Name);
		if(!RunDialog(player,target,true))
		player.Say((11),"Dialog error.");
	}
}

void ExecFOArt(array<string@>@command,Critter@player)
{
	string filename=GetParameterString(command,"-f");
	if(filename.length()==0)
	{
		player.Say((11),"Missing filename.");
		return;
	}
	
	player.RunClientScript("client_messages@_foart",0,0,0,filename,null);
}

void ExecTeamCommand(array<string@>@command,Critter@player,Critter@target)
{
	
	int minigameTeam=0;
	int minigameId=15;
	int minigameFlags=0;
	uint radius=0;
	bool all=false;
	bool info=false;
	bool persistent=false; 
	
	cheatGetOption(command,all,"-all");
	cheatGetOption(command,radius,"-r");
	cheatGetOption(command,persistent,"-s");
	array<Critter@>targets;
	
	if(all)
	{
		Map@map=target.GetMap();
		if(!(@map!=null))
		targets.insertLast(target);
		else
		map.GetCritters(0,(0x10)|(0x0F),targets);
	}
	else
	{
		if(radius<=0)
		targets.insertLast(target);
		
		else
		{
			Map@map=target.GetMap();
			if(!(@map!=null))
			targets.insertLast(target);
			else
			map.GetCrittersHex(target.HexX,target.HexY,radius,(0x10)|(0x0F),targets);
		}
	} 
	
	if(command.length()>2)
	{
		if(command[2]=="none"||command[2]=="n")
		minigameId=0;
		else if(command[2]=="spectator"||command[2]=="s")
		minigameTeam=0;
		else
		{
			if(StrToInt(command[2],minigameTeam))
			{
				if(minigameTeam<1||minigameTeam>15)
				{
					player.Say((11),"Error: Invalid team number.");
					return;
				}
			}
			else
			info=true;
		}
		if(persistent)
		((minigameFlags)=(minigameFlags)|((0x1)));
	}
	else
	info=true; 
	
	if(info)
	{
		player.Say((11),"Team Info:");
		for(int i=0,j=targets.length();i<j;i+=1)
		{
			int minigameData=targets[i].Param[(147)];
			int team=((minigameData)&0xF);
			if(minigameData==0)
			player.Say((11),GetSafePlayerName(targets[i].Id)+" : none");
			else
			{
				if(team==0)
				player.Say((11),GetSafePlayerName(targets[i].Id)+" : spectator");
				else
				player.Say((11),GetSafePlayerName(targets[i].Id)+" : "+team);
			}
		}
	}
	else
	for(int i=0,j=targets.length();i<j;i+=1)
	{
		
		if((targets[i].GetAccess()!=(0))&&(all||radius>0))
		continue;
		SetMinigame(targets[i],minigameTeam,minigameId,minigameFlags,0);
	}
}       

enum auraNumber
{
	AURA_RESERVED=0,
	AURA_KNOCKBACK_ALL,
	AURA_KNOCKBACK_NPC,
	AURA_KNOCKBACK_PLAYER,
	AURA_KILL_ALL,
	AURA_KILL_NPC,
	AURA_KILL_PLAYER,
	AURA_SKIN_RANDOM,
	AURA_SKIN_RESET,
	AURA_GOLGOTHA,
	AURA_FOREST,
	AURA_SNOWQUEEN,
	AURA_GRAVITATION_WELL,
	AURA_SKIN_RANDOM_SAFE
};

string[]auraSwitch=
{
	"",
	"-knockback",
	"-knockbacknpc",
	"-knockbackplayer",
	"-kill",
	"-killnpc",
	"-killplayer",
	"-randomskin",
	"-resetskin",
	"-golgotha",
	"-forest",
	"-snowqueen",
	"-gravitationwell"
};

string[]auraName=
{
	"RESERVED",
	"Knockback aura, all critters",
	"Knockback aura, NPCs only",
	"Knockback aura, players only",
	"Death aura, all critters",
	"Death aura, NPCs only",
	"Death aura, players only",
	"Skin aura, apply random, players only",
	"Skin aura, reset, players only",
	"Golgotha aura, spawns stakes",
	"Forest aura, spawns trees",
	"Snow Queen aura, all critters",
	"Gravitation Well aura, all critters"
};

void ExecAuraCommand(array<string@>@command,Critter@player)
{
	auraNumber aura;
	
	bool on=Present("-on",command),off=Present("-off",command);
	
	if(on&&off)
	{
		player.Say((11),"Cannot use -on and -off switches at same time");
		return;
	}
	else if(!on&&!off)
	{
		player.Say((11),"Enabling: `aura -on [auraSwitch], see below");
		player.Say((11),"Disabling: `aura -off");
		player.Say((11),"Available:");
		for(uint a=1,alen=auraSwitch.length();a<alen;a++)
		{
			player.Say((11),auraSwitch[a]);
			player.Say((11),"  "+auraName[a]);
		}
		return;
	}
	
	if(on)
	{
		if(Present(auraSwitch[AURA_KNOCKBACK_ALL],command))
		aura=AURA_KNOCKBACK_ALL;
		else if(Present(auraSwitch[AURA_KNOCKBACK_NPC],command))
		aura=AURA_KNOCKBACK_NPC;
		else if(Present(auraSwitch[AURA_KNOCKBACK_PLAYER],command))
		aura=AURA_KNOCKBACK_PLAYER;
		else if(Present(auraSwitch[AURA_KILL_ALL],command))
		aura=AURA_KILL_ALL;
		else if(Present(auraSwitch[AURA_KILL_NPC],command))
		aura=AURA_KILL_NPC;
		else if(Present(auraSwitch[AURA_KILL_PLAYER],command))
		aura=AURA_KILL_PLAYER;
		else if(Present(auraSwitch[AURA_SKIN_RANDOM],command))
		aura=AURA_SKIN_RANDOM;
		else if(Present(auraSwitch[AURA_SKIN_RESET],command))
		aura=AURA_SKIN_RESET;
		else if(Present(auraSwitch[AURA_GOLGOTHA],command))
		aura=AURA_GOLGOTHA;
		else if(Present(auraSwitch[AURA_FOREST],command))
		aura=AURA_FOREST;
		else if(Present(auraSwitch[AURA_SNOWQUEEN],command))
		aura=AURA_SNOWQUEEN;
		else if(Present(auraSwitch[AURA_GRAVITATION_WELL],command))
		aura=AURA_GRAVITATION_WELL;
		else if(Present(auraSwitch[AURA_SKIN_RANDOM_SAFE],command))
		aura=AURA_SKIN_RANDOM_SAFE;		
		else
		{
			player.Say((11),"Missing/unknown aura switch");
			return;
		}
		
		player.Say((11),"Enabled: "+auraName[aura]);
		player.EraseTimeEvents((1337));
		player.AddTimeEvent("cte_Aura",((1)*__TimeMultiplier),(1337),aura);
	}
	else if(off)
	{
		player.Say((11),"Removing current aura");
		player.EraseTimeEvents((1337));
		return;
	}
}

uint cte_Aura(Critter&cr,int identifier,uint&value)
{
	Map@map=cr.GetMap();
	
	if(!(@map!=null))
	return(((5)*__TimeMultiplier));
	
	int aura=value;
	if(!EnumContains("auraNumber",aura)||aura==AURA_RESERVED)
	{
		cr.Say((11),"Unknown aura<"+aura+">, disabling");
		return(0);
	}
	
	int flags=0;
	uint radius=5;
	uint findCritters=0,foundCritters=0;
	uint pulse=((1)*__TimeMultiplier);
	
	switch(aura)
	{
		case AURA_KNOCKBACK_ALL:
		((flags)=(flags)|((0x01)|(0x04)|(0x02)|(0x10)));
		findCritters=(0x01);
		break;
		
		case AURA_KNOCKBACK_NPC:
		((flags)=(flags)|((0x01)|(0x04)|(0x02)));
		findCritters=(0x01)|(0x20);
		break;
		
		case AURA_KNOCKBACK_PLAYER:
		((flags)=(flags)|((0x01)|(0x04)|(0x02)|(0x10)));
		findCritters=(0x01)|(0x10);
		break;
		
		case AURA_KILL_ALL:
		((flags)=(flags)|((0x01)|(0x08)|(0x02)|(0x10)));
		findCritters=(0x01);
		break;
		
		case AURA_KILL_NPC:
		((flags)=(flags)|((0x01)|(0x08)|(0x02)));
		findCritters=(0x01)|(0x20);
		break;
		
		case AURA_KILL_PLAYER:
		((flags)=(flags)|((0x01)|(0x08)|(0x02)|(0x10)));
		findCritters=(0x01)|(0x10);
		break;
		
		case AURA_SKIN_RANDOM:
		((flags)=(flags)|((0x01)|(0x04)|(0x02)));   
		
		findCritters=(0x01)|(0x10);
		
		break;
		
		case AURA_SKIN_RESET:
		((flags)=(flags)|((0x01)|(0x08)|(0x02)|(0x10)));   
		
		findCritters=(0x01)|(0x10);
		
		break;
		
		case AURA_GOLGOTHA:
		case AURA_FOREST:
		break;
		
		case AURA_SNOWQUEEN:
		((flags)=(flags)|((0x02)|(0x10)));
		findCritters=(0x01);
		pulse=((5)*__TimeMultiplier);
		break;
		
		case AURA_GRAVITATION_WELL:
		((flags)=(flags)|((0x04)|(0x02)|(0x10)|(0x20)));
		findCritters=(0x01);
		radius=20;
		break;
		
		case AURA_SKIN_RANDOM_SAFE:
		((flags)=(flags)|((0x01)|(0x04)|(0x02)));   		
		findCritters=(0x01)|(0x10);		
		break;
		
		default:
		((flags)=(flags)|((0x01)));
		break;
	}
	
	array<Critter@>crits;
	if((((flags)&((0x02)))!=0))
	{
		foundCritters=map.GetCrittersHex(cr.HexX,cr.HexY,radius,findCritters,crits);
		for(uint c=0;c<foundCritters;c++)
		{
			if(crits[c].Id==cr.Id)
			{
				crits.removeAt(c);
				foundCritters--;
				break;
			}
		}
	}
	
	if((((flags)&((0x01)))!=0))
	{
		uint16 stepX=cr.HexX;
		uint16 stepY=cr.HexY;
		
		map.MoveHexByDir(stepX,stepY,4,radius);
		for(uint8 stepDir=0;stepDir<6;stepDir++)
		{
			for(uint step=0;step<radius;step++)
			{
				map.MoveHexByDir(stepX,stepY,stepDir,1);
				map.RunEffect((4008),stepX,stepY,0);
			}
		}
		
		if(foundCritters>0)
		map.RunEffect((4008),cr.HexX,cr.HexY,(((foundCritters/radius)>(radius-1))?(radius-1):(((foundCritters/radius)<(0))?(0):(foundCritters/radius))));
	}
	
	if((((flags)&((0x02)))!=0))
	{
		int[]knock={(118),(113)};
		int[]death={(113),(114),(118),(119)};
		
		for(uint c=0;c<foundCritters;c++)
		{
			if(!(@crits[c]!=null))
			continue;
			
			if(crits[c].IsPlayer()&&(((flags)&((0x10)))!=0)&&crits[c].GetAccess()==(3))
			continue;
			
			if(!GodOfTheRealm(crits[c].Id))
			{
				if((((flags)&((0x04)))!=0)||(((flags)&((0x08)))!=0)||(((flags)&((0x20)))!=0))
				{
					uint16 knockbackX=cr.HexX,knockbackY=cr.HexY;
					if((((flags)&((0x20)))!=0))
					map.GetHexCoordWall(crits[c].HexX,crits[c].HexY,knockbackX,knockbackY,0.0f,Random(radius,radius*2)-(crits[c].Stat[(0)]/4));
					else
					map.GetHexCoordWall(crits[c].HexX,crits[c].HexY,knockbackX,knockbackY,(Random(180-Random(0,25),180+Random(0,25))),Random(radius,radius*2)-(crits[c].Stat[(0)]/4));
					
					map.PlaySound("was1xxx"+Random(1,2),crits[c].HexX,crits[c].HexY,5);
					map.RunEffect((4008),crits[c].HexX,crits[c].HexY,0);
					
					if((((flags)&((0x08)))!=0))
					crits[c].ToKnockout(0,0,0,0,knockbackX,knockbackY);
					else
					crits[c].ToKnockout(knock[Random(0,knock.length()-1)],(100),(88),crits[c].Stat[(8)]-Random(0,crits[c].Stat[(6)]/2),knockbackX,knockbackY);
				} 
				
				if(aura==AURA_KILL_ALL||aura==AURA_KILL_NPC||aura==AURA_KILL_PLAYER)
				{
					crits[c].ToDead(death[Random(0,death.length()-1)],null);
				}
				else if(aura==AURA_SKIN_RANDOM)
				{  
					
					uint skin=Random(1,134);
					if(crits[c].ChangeCrType(skin))
					{
						crits[c].StatBase[(112)]=skin;
						crits[c].DisguisedBy=cr.Id;
					}
				}
				else if(aura==AURA_SKIN_RESET)
				{
					bool isMale=(crits[c].StatBase[(71)]==(0));
					uint baseType=(isMale?((69)):((4)));
					uint crType=baseType;
					
					Item@armor=crits[c].GetItem(0,(3));
					if((@armor!=null))
					{
						switch(GetCritterAnimType(crType))
						{
							case(0):
							crType=(isMale?armor.Proto.Armor_CrTypeMale:armor.Proto.Armor_CrTypeFemale);
							break;
						}
					}
					
					crits[c].ChangeCrType(crType);
					crits[c].StatBase[(112)]=baseType;
					crits[c].DisguisedBy=0;
				}
				else if(aura==AURA_SNOWQUEEN)
				{
					if(crits[c].IsPlayer())
					crits[c].RunClientScript("client_timeouts@_add_unsafe",30,0,0,"Frozen",null);
					
					MapMessageEx((0),(2),crits[c],"frozen",crits[c].HexX,crits[c].HexY,255,(uint((0xFF<<24)|(((255)&0xFF)<<16)|(((255)&0xFF)<<8)|((255)&0xFF))),true,-50,50,-20,-50);
					crits[c].Wait(30000);
				}
				else if(aura==AURA_SKIN_RANDOM_SAFE)
				{  
					
					//uint skin=Random(1,134);
					uint skin=0;
					uint los=Random(1,4);
					if(los==1) skin=Random(15,29);
					if(los==2) skin=Random(51,64);
					if(los==3) skin=Random(72,83);
					if(los==4) skin=Random(87,98);

					if(crits[c].ChangeCrType(skin))
					{
						crits[c].StatBase[(112)]=skin;
						crits[c].DisguisedBy=cr.Id;
					}
				}				
			}
		}
	}
	else
	{
		array<Item@>items;
		{
			array<Item@>tempItems;
			int foundItems=map.GetItems(cr.HexX,cr.HexY,radius,(820),tempItems);
			for(int i=0;i<foundItems;i++)
			{
				if(tempItems[i].Val8==(2872))
				items.insertLast(tempItems[i]);
			}
		}
		
		if(items.length()>=radius*2)
		return(((1)*__TimeMultiplier));
		
		if(aura==AURA_GOLGOTHA)
		{
			Item@stake=map.AddItem(cr.HexX+Random(-radius,radius),cr.HexY+Random(-radius,radius),(820),1);
			if((@stake!=null))
			{
				int num=Random(1,12);
				stake.PicMap=GetStrHash("art\\scenery\\stake"+(num<10?"0":"")+num+".frm");
				stake.PicInv=GetStrHash("art\\scenery\\stake"+(num<10?"0":"")+num+".frm");
				stake.Val8=(2872);
				{if((@stake!=null))
					stake.Val9=(int((cr.Id)|(0x80000000)));};
				stake.Update();
			}
		}
		else if(aura==AURA_FOREST)
		{
			Item@tree=map.AddItem(cr.HexX+Random(-radius,radius),cr.HexY+Random(-radius,radius),(820),1);
			if((@tree!=null))
			{
				int num=Random(1,11);
				tree.PicMap=GetStrHash("art\\scenery\\tree"+num+".frm");
				tree.PicInv=GetStrHash("art\\scenery\\tree"+num+".frm");
				tree.Val8=(2872);
				{if((@tree!=null))
					tree.Val9=(int((cr.Id)|(0x80000000)));};
				tree.Update();
			}
		}
	}
	
	cr.RefreshVisible();
	return(pulse);
}

void ExecAuraCleanupCommand(array<string@>@command,Critter@player)
{
	Map@map=player.GetMap();
	if(!(@map!=null))
	{
		player.Say((11),"Not on worldmap.");
		return;
	}
	
	array<Item@>items;
	uint count=map.GetItems((820),items);
	uint deleted=0;
	for(uint i=0;i<count;i++)
	{
		if(items[i].Val8==(2872))
		{
			DeleteItem(items[i]);
			deleted++;
		}
	}
	
	player.Say((11),"Removed "+deleted+" item"+(deleted>1?"s":""));
} 

bool IsAdmin(Critter&player)
{
	return player.GetAccess()>=(3);
}

bool IsGM(Critter&player)
{
	return player.GetAccess()>=(2);
}

int AllowParameterIfAccess(int access,uint parameter,Critter&fromCr,Critter&toCr)
{
	if(access<=(0)||toCr.GetAccess()<access)
	return(0);
	
	return(fromCr.Param[parameter]);
}

int AllowParameterIfTester(uint parameter,Critter&fromCr,Critter&toCr)
{
	return(AllowParameterIfAccess((1),parameter,fromCr,toCr));
}

int AllowParameterIfModer(uint parameter,Critter&fromCr,Critter&toCr)
{
	return(AllowParameterIfAccess((2),parameter,fromCr,toCr));
}

int AllowParameterIfAdmin(uint parameter,Critter&fromCr,Critter&toCr)
{
	return(AllowParameterIfAccess((3),parameter,fromCr,toCr));
}

int AllowParameterIfGod(uint parameter,Critter&fromCr,Critter&toCr)
{
	if(!GodOfTheRealm(toCr.Id))
	return(0);
	
	return(fromCr.Param[parameter]);
}   

void unsafe_ExecCommand(Critter&player,int p0,int p1,int p2,string@commandString,array<int>@data)
{
	if(player.GetAccess()<(1))
	return;
	if(GetLvar(player,(4125))==0)
	{
		SetLvar(player,(4125),1);
		SetCritterEvents(player);
	}
	
	ExecCommand(player,p0,p1,p2,commandString,data);
}

void ExecCommand(Critter&player,int p0,int p1,int p2,string@commandString,array<int>@data)
{
	if(player.GetAccess()<(1))
	return;
	if(!(@commandString!=null))
	return;
	
	ExecCommand(player,commandString);
} 

bool ExecCommand(Critter&player,string@commandString)
{
	if(player.GetAccess()<(1))
	return(false);
	if(!(@commandString!=null))
	return(false);
	
	if(stringReplaceText(commandString,"|","")>0)
	{
		player.Say((11),""+(uint((0xFF<<24)|(((255)&0xFF)<<16)|(((0)&0xFF)<<8)|((0)&0xFF)))+" Illegal character found, command ignored.");
		return(false);
	}
	
	Preprocess(player,commandString);
	
	array<string@>@command=split(commandString," ");
	string name=GetSafePlayerName(player.Id);
	uint id=0;
	
	string targetName=GetParameterString(command,"-p");
	string npcId=GetParameterString(command,"-n");
	
	StrToInt(targetName,id);
	
	Critter@target;
	uint targetId=0; 
	
	if(targetName!="")
	{
		if(id==0)
		{
			@target=GetPlayer(targetName);
			targetId=GetPlayerId(targetName);
		}
		else
		{
			
			@target=GetCritter(id);
			targetId=id;
		}
	}
	if(npcId!="")
	{
		StrToInt(npcId,id);
		if(id!=0)
		@target=GetCritter((5000000)+id);
	}
	
	if(!(@target!=null))
	{
		{;};
		@target=@player;
		targetId=player.Id;
	}
	
	if((command[1]=="init")&&(!CheatsInitialized))
	{
		player.Say((11),"Running Init");
		InitCheats(false);
		return(true);
	}
	
	if(!GodOfTheRealm(player.Id)&&GodOfTheRealm(target.Id)&&((target.Mode[(534)]&((0x00020000)))!=0))
	{
		@target=@player;
		targetId=player.Id;
	}  
	
	if(!IsAllowed(player.Id,command[1]))
	{
		player.Say((11),"Unknown command or insufficient privileges.");
		return(false);
	}           
	
	if(command[1]=="accesslist")
	{
		ExecAccessListCommand(command,player);
	}
	else if(command[1]=="addbankmoney")
	{
		ExecBankMoney(command,player,true);
	}
	else if(command[1]=="addfollower")
	{
		ExecAddNpcCommand(command,player,target,false,true);
	}
	else if(command[1]=="addmob")
	{
		ExecAddNpcCommand(command,player,target,true,false);
	}
	else if(command[1]=="addnpc")
	{
		ExecAddNpcCommand(command,player,target,false,false);
	}
	else if(command[1]=="airstrike")
	{
		ExecAirstrikeCommand(command,player,target);
	}
	else if(command[1]=="alts")
	{
		ExecAltsCommand(command,player);
	}
	
	else if(command[1]=="antiblock")
	{
		ExecAntiblockCommand(command,player);
	}
	else if(command[1]=="aura")
	{
		ExecAuraCommand(command,player);
	}
	else if(command[1]=="auracleanup")
	{
		ExecAuraCleanupCommand(command,player);
	}
	else if(command[1]=="spawnpoint")
	{
		ExecSpawnPointCommand(command,player);
	}
	else if(command[1]=="append")
	{
		ExecSayCommand(command,player,target,(13));
	}
	else if(command[1]=="bc")
	{
		ExecBroadcastCommand(command,player);
	}
	else if(command[1]=="blockers")
	{
		ExecBlockersCommand(command,player,target);
	}
	else if(command[1]=="broadcast")
	{
		ExecBroadcastCommand(command,player);
	}
	else if(command[1]=="changefaction")
	{
		ExecChangeFactionCommand(command,player,target);
	}
	else if(command[1]=="changerank")
	{
		ExecChangeRankCommand(command,player,target);
	}
	else if(command[1]=="checkbank")
	{
		ExecCheckBankCommand(command,player);
	}
	else if(command[1]=="checkbanks")
	{
		ExecCheckBanksCommand(command,player);
	}
	else if(command[1]=="checkbankaccount")
	{
		ExecCheckBankAccount(command,player,false);
	}
	else if(command[1]=="checkbankaccounts")
	{
		ExecCheckBankAccount(command,player,true);
	}
	else if(command[1]=="checktown")
	{
		ExecCheckTownCommand(command,player);
	}
	else if(command[1]=="cleanup")
	{
		ExecCleanupCommand(command,player);
	}
	else if(command[1]=="clearallillegalflags")
	{
		ExecClearAllIllegalFlagsCommand(command,player);
	}
	else if(command[1]=="clearenemystack")
	{
		ExecClearEnemyStackCommand(command,player,target,false);
	}
	else if(command[1]=="clearenemystacks"||command[1]=="ces")
	{
		ExecClearEnemyStackCommand(command,player,target,true);
	}
	else if(command[1]=="clearinventory")
	{
		ExecClearInventoryCommand(command,player,target);
	}
	else if(command[1]=="clearillegalflags")
	{
		ClearIllegalFlags(target);
	}
	else if(command[1]=="cleartimeouts"||command[1]=="cto")
	{
		ExecClearTimeoutsCommand(command,player,target);
	}
	else if(command[1]=="clone")
	ExecCloneCommand(command,player,target);
	else if(command[1]=="condition")
	{
		ExecConditionCommand(command,player,target);
	}
	else if(command[1]=="controlmobs")
	{
		ExecControlMobsCommand(command,player,target);
	}
	else if(command[1]=="controlnpc")
	{
		ExecControlNpcCommand(command,player,target);
	}
	else if(command[1]=="corecheats")
	{
		ExecCoreCheats(command,player);
	}
	else if(command[1]=="countitems")
	{
		ExecCountItemsCommand(command,player);
	}
	else if(command[1]=="createlocation")
	{
		ExecCreateLocationCommand(command,player);
	}
	else if(command[1]=="criticalchance")
	{
		ExecCriticalChance(command,player,target);
	}
	else if(command[1]=="critterinfo"||command[1]=="crinfo")
	{
		ExecCritterInfoCommand(command,player,target);
	}
	else if(command[1]=="damage")
	{
		ExecDamageCommand(command,player,target);
	}
	else if(command[1]=="deathincarnate")
	{
		ExecDeathIncarnateCommand(command,player,target);
	}
	else if(command[1]=="deathmatch")
	{
		ExecDeathmatchCommand(command,player);
	}
	else if(command[1]=="deletelocation")
	{
		ExecDeleteLocationCommand(command,player);
	}
	else if(command[1]=="devenable")
	{
		ExecDevEnableCommand(command,player);
	}
	else if(command[1]=="dialog")
	{
		ExecSayCommand(command,player,target,(12));
	}
	else if(command[1]=="disabledismantling")
	{
		ExecMapDismantling(player,false);
	}
	else if(command[1]=="disablegrids")
	{
		ExecMapGrids(player,false);
	}
	else if(command[1]=="disablepvp")
	{
		ExecMapPvp(player,false);
	}
	else if(command[1]=="disabletb")
	{
		ExecSetTurnbasedCombat(player,false);
	}
	else if(command[1]=="disguise")
	{
		ExecDisguiseCommand(command,player,target);
	}
	else if(command[1]=="disguiseinfo")
	{
		ExecDisguiseInfoCommand(command,player);
	}
	else if(command[1]=="dismiss")
	{
		ExecDismissCommand(command,player,target,false);
	}
	else if(command[1]=="dismissteam")
	{
		ExecDismissCommand(command,player,target,true);
	}
	else if(command[1]=="dropalltimeouts")
	{
		ExecClearAllTimeoutsCommand(command,player);
	}
	else if(command[1]=="dropitems")
	{
		ExecDropItemsCommand(command,player,target);
	}
	else if(command[1]=="dropdrugs")
	{
		ExecDropDrugsCommand(command,player,target);
	}
	else if(command[1]=="emote")
	{
		ExecSayCommand(command,player,target,(5));
	}
	else if(command[1]=="emoteh")
	{
		ExecSayCommand(command,player,target,(6));
	}
	else if(command[1]=="explode")
	{
		ExecExplodeCommand(command,player,target);
	}
	else if(command[1]=="enabledismantling")
	{
		ExecMapDismantling(player,true);
	}
	else if(command[1]=="enablegrids")
	{
		ExecMapGrids(player,true);
	}
	else if(command[1]=="enablepvp")
	{
		ExecMapPvp(player,true);
	}
	else if(command[1]=="enabletb")
	{
		ExecSetTurnbasedCombat(player,true);
	}
	else if(command[1]=="factionnews")
	{
		ExecFactionNews(command,player);
	}
	else if(command[1]=="factioninfo")
	{
		ExecFactionInfoCommand(command,player,target,false);
	}
	else if(command[1]=="factiononline")
	{
		ExecFactionOnlineCommand(command,player);
	}
	else if(command[1]=="findchars")
	ExecFindCharsCommand(command,player);
	else if(command[1]=="finditems")
	{
		ExecFindItemsCommand(command,player);
	}
	else if(command[1]=="findnpc")
	{
		ExecFindNpcCommand(command,player);
	}
	else if(command[1]=="flash")
	{
		ExecSayCommand(command,player,target,(41));
	}
	else if(command[1]=="foart")
	{
		ExecFOArt(command,player);
	}
	else if(command[1]=="gaintowncontrol")
	{
		ExecGainTownControlCommand(command,player);
	}
	else if(command[1]=="gameinfo")
	{
		ExecGameInfoCommand(command,player);
	}
	else if(command[1]=="getcolor")
	{
		ExecGetColorCommand(command,player);
	}
	else if(command[1]=="getclaim")
	{
		ExecGetClaimCommand(command,player);
	}
	else if(command[1]=="getclaimtime")
	{
		ExecGetClaimTimeCommand(command,player);
	}
	else if(command[1]=="getleader")
	{
		ExecGetLeaderCommand(command,player);
	}
	else if(command[1]=="getitems")
	{
		ExecGetItemsCommand(command,player,target);
	}
	else if(command[1]=="getleadertime")
	{
		ExecGetLeaderTimeCommand(command,player);
	}
	else if(command[1]=="getrequests")
	{
		ExecGetRequestsCommand(command,player);
	}
	else if(command[1]=="getuvar")
	{
		ExecGetUVarCommand(command,player,target);
	}
	else if(command[1]=="getvar")
	{
		ExecGetVarCommand(command,player,targetId);
	}
	else if(command[1]=="give")
	{
		ExecGiveCommand(command,player,target);
	}
	else if(command[1]=="givekey")
	{
		ExecGiveKeyCommand(command,player,target);
	}
	else if(command[1]=="goto")
	ExecGoToCommand(command,player,target,false);
	else if(command[1]=="gototeam")
	ExecGoToCommand(command,player,target,true);
	else if(command[1]=="heal")
	{
		ExecHealCommand(command,player,target);
	}
	else if(command[1]=="healall")
	{
		ExecHealAllCommand(command,player);
	}
	
	else if(command[1]=="hideloc")
	ExecLocVisCommand(command,player,target,false);
	else if(command[1]=="hidemap")
	{
		ExecHideMapCommand(command,player);
	}
	else if(command[1]=="iddqd")
	{
		ExecGodCommand(command,player);
	}
	else if(command[1]=="idkfa")
	{
		ExecIDKFACommand(command,player,target);
	}
	else if(command[1]=="id2name")
	{
		ExecIdToNameCommand(command,player);
	}
	else if(command[1]=="inspect")
	{
		ExecInspectCommand(command,player);
	}
	else if(command[1]=="irradiate")
	{
		ExecIrradiateCommand(command,player,target);
	}
	else if(command[1]=="itemflags")
	{
		ExecItemFlagsCommand(command,player);
	}
	else if(command[1]=="itemlight")
	{
		ExecItemLightCommand(command,player);
	}
	else if(command[1]=="itemproto")
	{
		ExecItemProtoCommand(command,player);
	}
	else if(command[1]=="karma")
	{
		ExecKarmaCommand(command,player,target,false);
	}
	else if(command[1]=="karmateam")
	{
		ExecKarmaCommand(command,player,target,true);
	}
	else if(command[1]=="kill")
	{
		ExecKillCommand(command,player,target);
	}
	else if(command[1]=="killeradmin")
	{
		ExecKillerAdminCommand(command,player);
	}
	else if(command[1]=="killmobs")
	{
		ExecKillMobsCommand(command,player);
	}
	else if(command[1]=="lastregistered")
	{
		ExecLastRegisteredCommand(command,player);
	}
	else if(command[1]=="lastspawned")
	{
		ExecLastSpawnedCommand(command,player,target);
	}
	else if(command[1]=="log")
	{
		ExecLogCommand(command,player);
	}
	else if(command[1]=="listauthenticated"||command[1]=="la")
	{
		ExecListAuthenticatedCommand(command,player);
	}
	else if(command[1]=="listcommands")
	{
		ExecListCommandsCommand(command,player);
	}
	else if(command[1]=="listfactions")
	{
		ExecFactionInfoCommand(command,player,null,true);
	}
	else if(command[1]=="listfollowers")
	{
		ExecListFollowersCommand(command,player,target);
	}
	else if(command[1]=="listmaps")
	{
		ExecListMapsCommand(command,player);
	}
	else if(command[1]=="listplayers"||command[1]=="lp")
	{
		ExecListPlayersCommand(command,player);
	}
	else if(command[1]=="listtents")
	{
		ExecTentListCommand(command,player);
	}
	else if(command[1]=="listtracked"||command[1]=="lt")
	{
		ExecListTrackedPlayersCommand(command,player);
	}
	else if(command[1]=="lock")
	ExecLockCommand(command,player,target);
	else if(command[1]=="lockcar")
	ExecLockCarCommand(command,player,true);
	else if(command[1]=="makeencounter")
	{
		ExecMakeEncounterCommand(command,player);
	}
	else if(command[1]=="mapinfo")
	{
		ExecMapInfoCommand(command,player);
	}
	else if(command[1]=="modchar")
	{
		ExecModCharCommand(command,player,target);
	}
	else if(command[1]=="move")
	{
		ExecMoveCommand(command,player,target);
	}
	else if(command[1]=="name2id")
	{
		ExecNameToIdCommand(command,player,target);
	}
	else if(command[1]=="netmsg")
	{
		ExecSayCommand(command,player,target,(11));
	}
	else if(command[1]=="normaldeadly")
	{
		ExecNormalDeadlyCommand(command,player,target);
	}
	else if(command[1]=="numplayers")
	{
		player.Say((11),"There are "+GetNumberOfPlayersOnline()+" players online right now");
	}
	else if(command[1]=="param")
	{
		ExecParamCommand(command,player,target);
	}
	else if(command[1]=="perkadjust")
	{
		ExecPerkAdjust(command,player,target);
	}
	else if(command[1]=="pickitems")
	{
		ExecPickItemsCommand(command,player,target);
	}
	else if(command[1]=="phase")
	{
		ExecShiftCommand(command,player,target,false,true);
	}
	else if(command[1]=="phaseteam")
	{
		ExecShiftCommand(command,player,target,true,true);
	}
	else if(command[1]=="playerkarma")
	{
		ExecPlayerKarmaCommand(command,player,target,false);
	}
	else if(command[1]=="playmusic")
	{
		ExecPlayMusicCommand(command,player);
	}
	else if(command[1]=="playsound")
	{
		ExecPlaySoundCommand(command,player,false);
	}
	else if(command[1]=="playspeech")
	{
		ExecPlaySoundCommand(command,player,true);
	}
	else if(command[1]=="profadjust")
	{
		ExecProfAdjust(command,player,target);
	}
	else if(command[1]=="registerfaction")
	{
		ExecRegisterFactionCommand(command,player);
	}
	else if(command[1]=="removebankmoney")
	{
		ExecBankMoney(command,player,false);
	}
	else if(command[1]=="removefaction")
	ExecRemoveFactionCommand(command,player);
	else if(command[1]=="removeitems")
	{
		ExecRemoveItemsCommand(command,player);
	}
	else if(command[1]=="reservednickname")
	{
		ExecReservedNicknameCommand(command,player);
	}
	else if(command[1]=="resetalldisguises")
	{
		ExecResetAllDisguisesCommand(command,player);
	}
	else if(command[1]=="resetprices")
	{
		InitPrices();
	}
	else if(command[1]=="resetreputations")
	ExecResetReputationsCommand(command,player,target);
	else if(command[1]=="resettown")
	{
		ExecResetTownCommand(command,player,false);
	}
	else if(command[1]=="resettowns")
	{
		ExecResetTownCommand(command,player,true);
	}
	else if(command[1]=="resetworldmap")
	{
		ExecResetWorldMapCommand(command,player);
	}
	else if(command[1]=="respawn"||command[1]=="revive")
	{
		ExecRespawnCommand(command,player,target);
	}
	else if(command[1]=="respawnall"||command[1]=="reviveall")
	{
		ExecRespawnAllCommand(command,player);
	}
	else if(command[1]=="respawnallplayers"||command[1]=="reviveallplayers")
	{
		ExecRespawnAllCommand(command,player);
	}
	
	else if(command[1]=="rotate")
	{
		ExecRotateCommand(command,player,target);
	}
	else if(command[1]=="rundialog")
	{
		ExecRunDialog(command,player,target);
	}
	else if(command[1]=="saferegen")
	{
		ExecSafeRegenCommand(command,player);
	}
	else if(command[1]=="say")
	{
		ExecSayCommand(command,player,target,(1));
	}
	else if(command[1]=="sayh")
	{
		ExecSayCommand(command,player,target,(2));
	}
	else if(command[1]=="setanim")
	{
		ExecSetAnimCommand(command,player,target,false);
	}
	else if(command[1]=="masssetanim")
	{
		ExecSetAnimCommand(command,player,target,true);
	}
	else if(command[1]=="setfaction")
	{
		ExecSetFactionCommand(command,player,target);
	}
	else if(command[1]=="sethp")
	{
		ExecSetHPCommand(command,player,target);
	}
	else if(command[1]=="setlexem")
	{
		ExecSetLexemCommand(command,player,target);
	}
	else if(command[1]=="setperk")
	{
		ExecSetPerkCommand(command,player,target);
	}
	else if(command[1]=="setmapdata")
	{
		ExecSetMapDataCommand(command,player);
	}
	else if(command[1]=="setlocvisibility")
	{
		ExecSetLocVisibility(command,player);
	}
	else if(command[1]=="setreputation"||command[1]=="setrep")
	{
		ExecSetReputationCommand(command,player,target);
	}
	else if(command[1]=="settimeout"||command[1]=="sto")
	{
		ExecSetTimeoutCommand(command,player,target);
	}
	else if(command[1]=="setuvar")
	{
		ExecSetUVarCommand(command,player,target);
	}
	else if(command[1]=="setvar")
	{
		ExecSetVarCommand(command,player,targetId);
	}
	else if(command[1]=="shift")
	{
		ExecShiftCommand(command,player,target,false,false);
	}
	else if(command[1]=="shiftteam")
	{
		ExecShiftCommand(command,player,target,true,false);
	}
	else if(command[1]=="shout")
	{
		ExecSayCommand(command,player,target,(3));
	}
	else if(command[1]=="shouth")
	{
		ExecSayCommand(command,player,target,(4));
	}
	else if(command[1]=="showhands")
	{
		ExecShowHandsCommand(command,player,target);
	}
	else if(command[1]=="showloc")
	ExecLocVisCommand(command,player,target,true);
	else if(command[1]=="showvars")
	{
		ExecShowVarsCommand(command,player,target);
	}
	else if(command[1]=="slap")
	{
		ExecSlapCommand(command,player,target);
	}
	else if(command[1]=="massslap")
	{
		ExecMassSlapCommand(command,player,target);
	}
	else if(command[1]=="startevent")
	{
		ExecStartEventCommand(command,player);
	}
	else if(command[1]=="stopevent")
	{
		ExecStopEventCommand(command,player);
	}
	else if(command[1]=="stoptrackplayer")
	{
		ExecStopTrackPlayerCommand(command,player,target);
	}
	else if(command[1]=="spawncar")
	ExecSpawnCarCommand(command,player,target);
	else if(command[1]=="spawnitem")
	ExecSpawnItemCommand(command,player,target);
	else if(command[1]=="suicide")
	{
		ExecSuicideCommand(command,player);
	}
	else if(command[1]=="summon")
	{
		ExecSummonCommand(command,player,target,false);
	}
	else if(command[1]=="summonteam")
	{
		ExecSummonCommand(command,player,target,true);
	}
	else if(command[1]=="team")
	{
		ExecTeamCommand(command,player,target);
	}
	else if(command[1]=="teleport"||command[1]=="tp")
	{
		ExecTeleportCommand(command,player,target,false);
	}
	else if(command[1]=="teleporter")
	{
		ExecTeleporterCommand(command,player);
	}
	else if(command[1]=="teleportteam")
	{
		ExecTeleportCommand(command,player,target,true);
	}
	else if(command[1]=="tentinfo")
	{
		ExecTentInfoCommand(command,player,target);
	}
	else if(command[1]=="toglobal")
	{
		ExecToGlobal(player,target);
	}
	else if(command[1]=="trackplayer")
	{
		ExecTrackPlayerCommand(command,player,target);
	}
	
	else if(command[1]=="unlockcar")
	ExecLockCarCommand(command,player,false);
	else if(command[1]=="whisper")
	{
		ExecSayCommand(command,player,target,(7));
	}
	else if(command[1]=="whisperh")
	{
		ExecSayCommand(command,player,target,(8));
	}
	else if(command[1]=="virtualmoney")
	{
		ExecVirtualMoneyCommand(command,player);
	}
	else if(command[1]=="xp")
	{
		ExecXpCommand(command,player,target,false);
	}
	else if(command[1]=="xpteam")
	{
		ExecXpCommand(command,player,target,true);
	}
	else if(command[1]=="zeroext")
	{
		ExecZeroExtCommand(command,player,target);
	}
	else if(command[1]=="zone")
	{
		ExecZoneCommand(command,player);
	}
	else if(command[1]=="zoneplayers")
	{
		ExecZonePlayersCommand(command,player);
	}
	else
	{
		player.Say((11),"Unknown command or insufficient privileges.");
		return(false);
	}   
	
	return(true);
}

Serializator serializer;
void LoadEventSpawns()
{
	serializer.Clear();
	if(!serializer.Load("event_spawns"))
	return;
	
	serializer.Get(eventItems).Get(eventCritters);
}

void SaveEventSpawns()
{
	serializer.Clear();
	serializer.Set(eventItems).Set(eventCritters).Save("event_spawns");
}

void answer_Test(Critter&player,uint answerI,string&answerS)
{
	player.Say((11),""+answerI+", "+answerS);
}

bool _UseSkill(Item&item,Critter&crit,int skill)
{
	crit.Say((11),"Use: "+skill);
	if(skill==(209))
	{
		if(Random(0,9)==0)
		{
			crit.Say((11),"Picked");
			item.LockerCondition=(0x01);
			item.Update();
		}
		return true;
	}
	return false;
}

void checkbot(Critter&cr,int playerId,int,int)
{
	int id=cr.Id;
	id^=0x1B7D5C7E;
	Critter@tocheck=GetCritter(playerId);
	if(!(@tocheck!=null)||tocheck.IsNpc())
	{
		cr.Say((11),"Invalid player.");
		return;
	}
	tocheck.RunClientScript("client_main@_ResetTimer",id,Random(0,0xFF),Random(0,0xFFFF),null,null);
}  

void ip(Critter&cr,int,int,int)
{
	uint ip=cr.GetIp();
	cr.Say((11),"ip="+ip);
	if(ip>0)
	{
		string result="";
		for(uint i=0;i<4;i++)
		{
			result+=(i==0?"":".")+((ip>>(i*8))&0xFF);
		}
		cr.Say((11),"ip="+result);
	}
}  

class FakeCombat
{
	private uint target;
	private array<uint>result;
	
	FakeCombat()
	{
		this.Clear();
	}
	
	FakeCombat(Critter&cr)
	{
		this.Clear();
		this.Target(cr);
	}
	
	private void New(uint what)final
	{
		this.result.insertLast(what);
		this.result.insertLast(this.target);
	}
	
	FakeCombat@Clear()
	{
		this.target=0;
		this.result.resize(0);
		
		return(this);
	}
	
	FakeCombat@Target(Critter&cr)
	{
		this.target=cr.Id;
		
		return(this);
	}
	
	FakeCombat@Miss()
	{
		this.New((1));
		
		return(this);
	}
	
	FakeCombat@CritMiss(uint effects)
	{
		this.New((2));
		this.result.insertLast(effects);
		
		return(this);
	}
	
	FakeCombat@CritMissDamage(uint effects,uint damage)
	{
		this.New((3));
		this.result.insertLast(effects);
		this.result.insertLast(damage);
		
		return(this);
	}
	
	FakeCombat@Oops(uint who2)
	{
		this.New((12));
		this.result.insertLast(who2);
		
		return(this);
	}
	
	FakeCombat@Hit(uint damage)
	{
		this.New((4));
		this.result.insertLast(damage);
		
		return(this);
	}
	
	FakeCombat@HitRandomly()
	{
		this.New((13));
		
		return(this);
	}
	
	FakeCombat@HitDead(uint damage)
	{
		this.New((8));
		this.result.insertLast(damage);
		
		return(this);
	}
	
	FakeCombat@AimedHit(uint location,uint damage)
	{
		this.New((5));
		this.result.insertLast(location);
		this.result.insertLast(damage);
		
		return(this);
	}
	
	FakeCombat@AimedHitDead(uint location,uint damage)
	{
		this.New((9));
		this.result.insertLast(location);
		this.result.insertLast(damage);
		
		return(this);
	}
	
	FakeCombat@CritHit(uint damage,uint effect,uint message)
	{
		this.New((6));
		this.result.insertLast(damage);
		this.result.insertLast(effect);
		this.result.insertLast(message);
		
		return(this);
	}
	
	FakeCombat@CritHitDead(uint damage,uint effect,uint message)
	{
		this.New((10));
		this.result.insertLast(damage);
		this.result.insertLast(effect);
		this.result.insertLast(message);
		
		return(this);
	}
	
	FakeCombat@CritAimedHit(uint location,uint damage,uint effect,uint message)
	{
		this.New((7));
		this.result.insertLast(location);
		this.result.insertLast(damage);
		this.result.insertLast(effect);
		this.result.insertLast(message);
		
		return(this);
	}
	
	FakeCombat@CritAimedHitDead(uint location,uint damage,uint effect,uint message)
	{
		this.New((11));
		this.result.insertLast(location);
		this.result.insertLast(damage);
		this.result.insertLast(effect);
		this.result.insertLast(message);
		
		return(this);
	}
	
	bool Send()
	{
		Critter@_target=GetCritter(this.target);
		if((@_target!=null))
		{
			Critter@[]realTarget={_target};
			array<Critter@>crits;
			uint count=_target.GetMap().GetCrittersSeeing(realTarget,true,(0x0F)|(0x10),crits);
			for(uint c=0;c<count;c++)
			{
				this.Send(crits[c]); 
				
			}
			
			return(true);
		}
		
		return(false);
	}
	
	bool Send(Critter&cr)
	{
		if(cr.IsNotValid||cr.IsNpc())
		return(false);
		
		uint len=this.result.length();
		
		if(len>0)
		{
			this.result.insertAt(0,++len);
			cr.SendCombatResult(result);
			this.result.removeAt(0);
		}
		
		return(true);
	}                                           
	
};

void ItemEvent(Item&item,int event,string&function)
{
	Critter@spawner=GetCritter((int((item.Val9)&(~(0x80000000)))));
	if(!item.SetEvent(event,function))
	{
		if((@spawner!=null))
		spawner.Say((11),"Can't set script to \""+function+"\", removing item.");
		DeleteItem(item);
	}
	else
	{
		if((@spawner!=null))
		spawner.Say((11),"ItemEvent "+event+" for "+item.Id+" set to "+function);
	}
}

void ItemTypeEvent(Item&item,int type,int event,string&function)
{
	Critter@spawner=GetCritter((int((item.Val9)&(~(0x80000000)))));
	if(item.GetType()!=uint(type))
	{
		if((@spawner!=null))
		spawner.Say((11),"Invalid item type, removing item.");
		DeleteItem(item);
	}
	else
	{
		ItemEvent(item,event,function);
	}
}   

void weapon_disconnect(Item&item,bool firstTime)
{
	ItemTypeEvent(item,(3),(1),"weapon_function_disconnect");
}

void weapon_explode(Item&item,bool firstTime)
{
	ItemTypeEvent(item,(3),(1),"weapon_function_explode");
}

void weapon_kill(Item&item,bool firstTime)
{
	ItemTypeEvent(item,(3),(1),"weapon_function_kill");
}

void weapon_heal(Item&item,bool firstTime)
{
	ItemTypeEvent(item,(3),(1),"weapon_function_heal");
}        

void item_sound(Item&item,bool firstTime)
{
	ItemEvent(item,(7),"item_function_sound");
}  

bool weapon_function_disconnect(Item&item,Critter&sadist,Critter&victim)
{
	if(sadist.GetAccess()<(2))
	{
		sadist.Say((11),"No.");
		return(true);
	}
	
	if(victim.IsNpc())
	{
		sadist.Say((11),"You can't disconnect NPCs.");
		return(true);
	}
	
	if(sadist.GetAccess()<victim.GetAccess()||GodOfTheRealm(victim.Id))
	{
		sadist.Say((11),"No, you don't.");
		return(true);
	}
	
	LogCommandUsage(sadist,"ItemEventCheat: disconnected "+victim.Name+"<"+victim.Id+">");
	
	sadist.Animate(0,(55),item,true,false);
	victim.Disconnect();
	
	return(true);
} 

import void MapMessageEx(uint8 type,uint8 mode,Critter&target,string&text,uint16 hexX,uint16 hexY,uint8 delay,uint color,bool fade,int8 fromX,int8 toX,int8 fromY,int8 toY)from"utils";

bool weapon_function_explode(Item&item,Critter&sadist,Critter&victim)
{
	if(sadist.GetAccess()<(2))
	{
		sadist.Say((11),"No.");
		return(true);
	}
	
	if(victim.IsDead())
	{
		sadist.Say((11),GenderString(victim,"He","She","It")+"'s already as dead as possible.");
		return(true);
	}
	
	LogCommandUsage(sadist,"ItemEventCheat: exploded "+victim.Name+"<"+victim.Id+">");
	
	sadist.Animate(0,(55),item,true,false);
	AI_TrySayCombatText(victim,Random((10),(17)),true);
	victim.ToDead((117),null);
	
	return(true);
}

bool weapon_function_kill(Item&item,Critter&sadist,Critter&victim)
{
	if(sadist.GetAccess()<(2))
	{
		sadist.Say((11),"No.");
		return(true);
	}
	
	if(victim.IsDead())
	{
		sadist.Say((11),GenderString(victim,"He","She","It")+"'s already as dead as possible.");
		return(true);
	}
	
	LogCommandUsage(sadist,"ItemEventCheat: killed "+victim.Name+"<"+victim.Id+">");
	
	Map@map=victim.GetMap();
	const int mode_invulnerable=victim.Mode[(527)];
	
	if((@map!=null))
	{
		uint anim2=(55);
		if(IsGrenade(item))
		{
			anim2=(53);
			map.RunFlyEffect(item.GetProtoId(),sadist,victim,sadist.HexX,sadist.HexY,victim.HexX,victim.HexY);
			map.RunEffect((4027),victim.HexX,victim.HexY,1);
			map.RunEffect((4011),victim.HexX,victim.HexY,1);
		}
		else if(item.Proto.ProtoId==(13))
		{
			map.RunFlyEffect((4001),sadist,victim,sadist.HexX,sadist.HexY,victim.HexX,victim.HexY);
			map.RunEffect((4027),victim.HexX,victim.HexY,1);
			map.RunEffect((4011),victim.HexX,victim.HexY,1);
		}
		
		if(anim2>0)
		sadist.Animate(0,anim2,item,true,false);
		
		uint location=Random((1),(8));
		uint hp=Random(victim.Stat[(72)]+(((__DeadHitPoints)>0)?(__DeadHitPoints):(-(__DeadHitPoints))),
		(victim.Stat[(72)]+(((__DeadHitPoints)>0)?(__DeadHitPoints):(-(__DeadHitPoints))))*2);
		uint effect=0;
		
		if(location==(1)||location==(7))
		{
			if(Random(0,1)==0)
			((effect)=(effect)|((0x00000040)));
		}
		else if(location==(2))
		{
			if(Random(0,1)==0)
			((effect)=(effect)|((0x00000010)));
		}
		else if(location==(3))
		{
			if(Random(0,1)==0)
			((effect)=(effect)|((0x00000020)));
		}
		else if(location==(6))
		{
			if(Random(0,1)==0)
			((effect)=(effect)|((0x00000004)));
		}
		else if(location==(5))
		{
			if(Random(0,1)==0)
			((effect)=(effect)|((0x00000008)));
		}
		
		if(Random(0,(location==(4)?1:2))==0)
		((effect)=(effect)|((0x00000800)));
		
		FakeCombat@result=FakeCombat(victim);
		
		bool dead=(mode_invulnerable<=0);
		if(mode_invulnerable>0&&GodOfTheRealm(sadist.Id)&&sadist.GetAccess()==(3))
		dead=true;
		
		if(location>=(1)&&location<=(8))
		AI_TrySayCombatText(victim,location+9,true);
		
		if(dead)
		result.CritAimedHitDead(location,hp,effect,0);
		else
		result.CritAimedHit(location,hp,effect,0);
		
		result.Send();  
		
	}
	
	if(GodOfTheRealm(sadist.Id)&&sadist.GetAccess()==(3))
	{
		victim.ParamBase[(527)]=0;
		victim.ToDead(GetRandomDeathAnimation(),null);
		victim.ParamBase[(527)]=mode_invulnerable;
	}
	else
	victim.ToDead(GetRandomDeathAnimation(),null);
	
	return(true);
}

bool weapon_function_heal(Item&item,Critter&sadist,Critter&victim)
{
	if(sadist.GetAccess()<(2))
	{
		sadist.Say((11),"No.");
		return(true);
	}
	
	LogCommandUsage(sadist,"ItemEventCheat: healed "+victim.Name+"<"+victim.Id+">");
	
	sadist.Animate(0,(55),item,true,false);
	Heal(victim);
	
	return(true);
}               

void item_function_sound(Item&item,Critter&victim,bool entered,uint8 dir)
{
	string self="item "+item.Id+": ";
	uint16 hX=0,hY=0;
	Map@map=item.GetMapPosition(hX,hY);       
	
	string lexem=(entered?"$+":"$-");
	if(IsLexem(item,lexem))
	{
		int radius=5;
		if(IsLexem(item,"$!"))
		{
			StrToInt(GetLexem(item,"$!"),radius);
		}
		map.PlaySound(GetLexem(item,lexem),hX,hY,radius);
	}
}

void _ForceEncounter(Map&map)
{
	Location@loc=map.GetLocation();
	array<Critter@>crits;
	uint n=GetGlobalMapCritters(loc.WorldX,loc.WorldY,25,(0x01)|(0x10),crits);
	do{Critter@__temp;uint pos;for(uint __i=0;__i<crits.length()-1;__i++){pos=Random(__i,crits.length()-1);@__temp=crits[pos];@crits[pos]=crits[__i];@crits[__i]=__temp;}}while(false);
	for(uint i=0;i<n;i++)
	{
		Critter@cr=crits[i];
		if(!(@cr.GetFollowLeader()!=null)||cr.GetFollowLeader().Id!=cr.Id)
		continue;
		cr.TransitToMap(map.Id,0,true);
		map.SetLoopTime(4,uint(-1));
		map.SetEvent((5),"_DoNothing");
	}
}

void SetTimeoutForAll(Map&map,int timeout,int time)
{
	array<Critter@>crits;
	uint count=map.GetCritters(0,(0x0F),crits);
	
	for(uint c=0;c<count;c++)
	{
		crits[c].TimeoutBase[timeout]=((__FullSecond)+(time));
	}
}

void _LockMap(Map&map)
{
	SetTimeoutForAll(map,(239),((2238)*__TimeMultiplier)+((800)*__TimeMultiplier/1000));
}

void _DoNothing(Map&map)
{}                                                                                                                                                                                                        

