One House per Player
#1

I was trying to do this all day, but i didnt succeed I need that if a player has already a house and he tries to buy another one it writes "You already have a house".

Код:
	//Namo pirkimas
	else if(mode == 4)
	{
	print("namas");
	    new houseid = playerDB[playerid][rid][3];
        if(!strcmp(text,"taip",true))
		{
			if(GetPlayerMoneyA(playerid) < houseDB[houseid][nkaina])
			{
				SendClientMessage(playerid,RED,"* Jus neturite tiek pinigu.");
				return 0;
			}
			if(GetPlayerScore(playerid) < 3000)
			{
			SendClientMessage(playerid, RED, "* Jus negalite pirkti namo. Jusu per maza patirtis(3000xp)!!");
			return 1;
			}
                     if a player has a house
			{
			SendClientMessage(playerid, RED, "* You already have a house!");
			return 1;
			}

			//Zaidejas turi pakankamai pinigu, duodam jam nama!
			GivePlayerMoneyA(playerid,-houseDB[houseid][nkaina]);
			new name[MAX_PLAYER_NAME];
			GetPlayerName(playerid,name,sizeof(name));
			strmid(houseDB[houseid][owner_name],name,0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);
			houseDB[houseid][setting]=random(5);
			houseDB[houseid][krumeliai]=0;
//			houseDB[houseid][namehash]=tohash(name);
			
			//OK.... zaidejas nama turi ram'e. Bet reikia ir flat file.. so we dump
			new file[128];
			format(file,sizeof(file),"saves/house/%i",houseid);
			if(!fexist(file)) dini_Create(file);
			dini_Set(file,"owner_name",name);
			dini_IntSet(file,"hash",tohash(name));
			dini_IntSet(file,"setting",houseDB[houseid][setting]);
			dini_IntSet(file,"kaina",houseDB[houseid][nkaina]);
			dini_IntSet(file,"krumeliai",0);
			SendClientMessage(playerid, BLUE,"* Namas nupirktas!");
			SetPlayerScore(playerid,(GetPlayerScore(playerid)+1)+random(2));
			return 0;
		}
		
		SendClientMessage(playerid, RED,"* Namas nenupirktas.");
		return 0;
	}
houseDB.txt

Код:
enum hitem
{
	setting,
	nkaina,
	owner_name[MAX_PLAYER_NAME],
	krumeliai,
	bukle,
	dregme,
	amzius,
	namehash
}
new houseDB[256][hitem];

enum settings
{
	interior,
	Float:enter_pos[3]
}
new houseSETTINGS[5][settings];

stock PrepareHouseSystem()
{
	houseSETTINGS[0][interior]=10;
	houseSETTINGS[1][interior]=7;
	houseSETTINGS[2][interior]=15;
	houseSETTINGS[3][interior]=5;
	houseSETTINGS[4][interior]=9;

	houseSETTINGS[0][enter_pos][0]=2260.76;
	houseSETTINGS[0][enter_pos][1]=-1210.45;
	houseSETTINGS[0][enter_pos][2]=1049.02;

	houseSETTINGS[1][enter_pos][0]=225.4974;
	houseSETTINGS[1][enter_pos][1]=1023.3127;
	houseSETTINGS[1][enter_pos][2]=1084.0122;

	houseSETTINGS[2][enter_pos][0]=373.2839;
	houseSETTINGS[2][enter_pos][1]=1417.5103;
	houseSETTINGS[2][enter_pos][2]=1081.3281;

	houseSETTINGS[3][enter_pos][0]=230.9863;
	houseSETTINGS[3][enter_pos][1]=1114.4048;
	houseSETTINGS[3][enter_pos][2]=1080.9922;

	houseSETTINGS[4][enter_pos][0]=261.1820;
	houseSETTINGS[4][enter_pos][1]=1239.1514;
	houseSETTINGS[4][enter_pos][2]=1084.2578;
	
	new file[128]; print("Kraunami namai");
	for(new house=0; house<pickups[1][namai]+1; house++)
	{
		format(file,sizeof(file),"saves/house/%i",house);
		houseDB[house][nkaina]=350000+random(800000);
		if(!fexist(file)) 
		{
			strmid(houseDB[house][owner_name],"no",0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);
			continue;
		}
//		new uber[MAX_PLAYER_NAME];
//		uber = dini_Get(file,"owner_name");
//		strcat(houseDB[house][owner_name], dini_Get(file,"owner_name"));
		strmid(houseDB[house][owner_name],dini_Get(file,"owner_name"),0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);
//		houseDB[house][namehash]=dini_Int(file,"hash");
		houseDB[house][setting]=dini_Int(file,"setting");
		houseDB[house][krumeliai]=dini_Int(file,"krumeliai");
		houseDB[house][dregme]=dini_Int(file,"dregme");
		houseDB[house][bukle]=dini_Int(file,"bukle");
		houseDB[house][amzius]=dini_Int(file,"amzius");
		printf("Namas %i priklauso %s (vidaus ID: %i)",house,houseDB[house][owner_name],houseDB[house][setting]);
	}

	print("Kraunami bizniai");
	for(new house=pickups[0][bizniss]; house<pickups[1][bizniss]+1; house++)
	{
		format(file,sizeof(file),"saves/bussines/%i",house);
		if(!fexist(file)) 
		{
			strmid(bussinesDB[house][own_name],"no",0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);		
			continue;
		}
		strmid(bussinesDB[house][own_name],dini_Get(file,"owner_name"),0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);
		printf("Biznis %i priklauso %s",house,bussinesDB[house][own_name]);
	}
	
}
Reply
#2

I did it:

Код:
	//Namo pirkimas
	else if(mode == 4)
	{
	print("namas");
	    new houseid = playerDB[playerid][rid][3];
        if(!strcmp(text,"taip",true))
		{
			if(GetPlayerMoneyA(playerid) < houseDB[houseid][nkaina])
			{
				SendClientMessage(playerid,RED,"* Jus neturite tiek pinigu.");
				return 0;
			}
			if(GetPlayerScore(playerid) < 3000)
			{
			SendClientMessage(playerid, RED, "* Jus negalite pirkti namo. Jusu per maza patirtis(3000xp)!!");
			return 1;
			}
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(i, giveplayer, sizeof(giveplayer));
			for(new h = 0; h < sizeof(houseDB); h++)
			{
				if(strcmp(playername,houseDB[h][owner_name],true)==0)
				{
					SendClientMessage(playerid, RED, "* You already have a house!");
					return 1;
				}
			}
			//Zaidejas turi pakankamai pinigu, duodam jam nama!
			GivePlayerMoneyA(playerid,-houseDB[houseid][nkaina]);
			new name[MAX_PLAYER_NAME];
			GetPlayerName(playerid,name,sizeof(name));
			strmid(houseDB[houseid][owner_name],name,0,MAX_PLAYER_NAME,MAX_PLAYER_NAME);
			houseDB[houseid][setting]=random(5);
			houseDB[houseid][krumeliai]=0;
//			houseDB[houseid][namehash]=tohash(name);

			//OK.... zaidejas nama turi ram'e. Bet reikia ir flat file.. so we dump
			new file[128];
			format(file,sizeof(file),"saves/house/%i",houseid);
			if(!fexist(file)) dini_Create(file);
			dini_Set(file,"owner_name",name);
			dini_IntSet(file,"hash",tohash(name));
			dini_IntSet(file,"setting",houseDB[houseid][setting]);
			dini_IntSet(file,"kaina",houseDB[houseid][nkaina]);
			dini_IntSet(file,"krumeliai",0);
			SendClientMessage(playerid, BLUE,"* Namas nupirktas!");
			SetPlayerScore(playerid,(GetPlayerScore(playerid)+1)+random(2));
			return 0;
		}

		SendClientMessage(playerid, RED,"* Namas nenupirktas.");
		return 0;
	}
I hope i have helped
Reply
#3

It always says that i have a house even if i dont
Reply
#4

Set some PVar when player buys house, then delete it when player sell it, and when player tryed to buy house, check the pvar..
Reply
#5

And if the house file gets deleted for some reason? What will happen then?
Reply
#6

Bump....
Reply
#7

Bump..........
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)