cTerritory* Region;
void StoreItemRandomValue(P_ITEM pi,QString tmpreg){ // Function Created by Magius(CHE) for trade System	int max=0,min=0;	if( pi == NULL )		return;	if (pi->good<0) return;	if (tmpreg == "none" )	{		P_ITEM pio=GetOutmostCont(pi);		if (!pio) return;		cTerritory* Region;		if (pio->isInWorld())		{			Region = cAllTerritories::getInstance()->region( pio->pos.x, pio->pos.y );			if( Region != NULL )				tmpreg = Region->name();		}		else		{			P_CHAR pc=FindCharBySerial(pio->contserial);			if (!pc) return;			Region = cAllTerritories::getInstance()->region( pc->pos.x, pc->pos.y );			if( Region != NULL )				tmpreg = Region->name();		}		return;	}	if( pi->good<0 || pi->good>255 ) 		return;	cTerritory* Region = cAllTerritories::getInstance()->region( tmpreg );	min=Region->tradesystem_[pi->good].rndmin;	max=Region->tradesystem_[pi->good].rndmax;	if (max!=0 || min!=0)	{		pi->rndvaluerate=(int) RandomNum(min,max);	}}