HouseSpawn
#1

Dear Guys,


I'm trying to make a system which allows a player to rent a room, and then spawn there each time he logs in.
I've created a system which saves the house's x, y, z positions, virtual room and interior using dini. And I've succeeded in finding a way to load it.

The problem is, the user loads in the house, but can't exit. Could someone help me please?


House Rentroom Function / Save housespawn position function
Код:
 	if(strcmp(cmd, "/rentroom", true) == 0)
	{
		if(IsPlayerConnected(playerid))
		{
			new Float:oldposx, Float:oldposy, Float:oldposz;
			new playername[MAX_PLAYER_NAME];
			GetPlayerName(playerid, playername, sizeof(playername));
			GetPlayerPos(playerid, oldposx, oldposy, oldposz);
			for(new h = 0; h < sizeof(HouseInfo); h++)
			{
				if(IsPlayerInRangeOfPoint(playerid,5.0, HouseInfo[h][hExteriorX], HouseInfo[h][hExteriorY], HouseInfo[h][hExteriorZ]) && HouseInfo[h][hOwned] == 1 &&  HouseInfo[h][hRentabil] == 1)
				{
					// if(PlayerInfo[playerid][pPhousekey] != 0 && strcmp(playername, HouseInfo[PlayerInfo[playerid][pPhousekey]][hOwner], true) == 0)
					// {
					//	SendClientMessage(playerid, COLOR_WHITE, "   You already own a House!");
					//	return 1;
					// }
					if(GetPlayerMoney(playerid) > HouseInfo[h][hRent])
					{
						PlayerInfo[playerid][pPhousekey] = h;
						GivePlayerMoney(playerid,-HouseInfo[h][hRent]);
						HouseInfo[h][hCash] = HouseInfo[h][hCash]+HouseInfo[h][hRent];
						SetPlayerInterior(playerid,HouseInfo[h][hInteriorID]);
						SetPlayerPos(playerid,HouseInfo[h][hInteriorX],HouseInfo[h][hInteriorY],HouseInfo[h][hInteriorZ]);
						GameTextForPlayer(playerid, "~w~Welcome Home~n~You can exit at any time by moving to this door and typing /exit", 5000, 3);
						PlayerInfo[playerid][pInt] = HouseInfo[h][hInteriorID];
						PlayerInfo[playerid][pVirtualWorld] = HouseInfo[h][hVirWorld];
						SetPlayerVirtualWorld(playerid, HouseInfo[h][hVirWorld]);
						PlayerInfo[playerid][InHouse] = h;
						SendClientMessage(playerid, COLOR_WHITE, "You can enter and exit here anytime.");
						SendClientMessage(playerid, COLOR_WHITE, "Type /help to review the new property help section.");
						
						new file[128], pname[MAX_PLAYER_NAME];
						new Float:x, Float:y, Float:z, Interior[ MAX_PLAYERS ], VirtualWorld[ MAX_PLAYERS ];
						GetPlayerName(playerid, pname, sizeof(pname));
						format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
						if(!dini_Exists(file))
						dini_Create(file);
						GetPlayerPos(playerid, x, y, z);
						dini_FloatSet(file, "posX", HouseInfo[h][hInteriorX]);
						dini_FloatSet(file, "posY", HouseInfo[h][hInteriorY]);
						dini_FloatSet(file, "posZ", HouseInfo[h][hInteriorZ]);
						dini_IntSet(file, "Interior", HouseInfo[h][hInteriorID]);
						dini_IntSet(file, "VirtualWorld", HouseInfo[h][hVirWorld]);
						
						
						SaveHouse(h);
						return 1;
					}
					else
					{
						SendClientMessage(playerid, COLOR_WHITE, "You don't have the cash to rent this House!");
						return 1;
					}
				}
			}
		}
		return 1;
	}







House Spawnpos load function
Код:
                                new file[128], pname[MAX_PLAYER_NAME];
				new Float:x, Float:y, Float:z, HouseSpawnInterior, HouseVWorld;
				GetPlayerName(playerid, pname, sizeof(pname));
				format(file, sizeof(file), "\\SavePos\\%s.ini", pname);
				x = dini_Float(file, "posX");
				y = dini_Float(file, "posY");
				z = dini_Float(file, "posZ");
				HouseSpawnInterior = dini_Int(file, "Interior");
				HouseVWorld = dini_Int(file, "VirtualWorld");
				SetPlayerPos(playerid, x, y, z);
				SetPlayerInterior(playerid, HouseSpawnInterior);
				SetPlayerVirtualWorld(playerid, HouseVWorld);






House /enter function
Код:
	if(strcmp(cmd, "/enter", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
		{
		    new Float:shax, Float:shay, Float:shaz;
			new Float:shbx, Float:shby, Float:shbz;
			new Float:shcx, Float:shcy, Float:shcz;
			GetVehiclePos(EnterableShamals[0], shax, shay, shaz);
			GetVehiclePos(EnterableShamals[1], shbx, shby, shbz);
			GetVehiclePos(EnterableShamals[2], shcx, shcy, shcz);
	    for(new i = 0; i < sizeof(HouseInfo); i++)
		{
			if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ]))
 			{
				if(GetPlayerVirtualWorld( playerid) == 0)
  				{
  					if(HouseInfo[i][hLocked] == 0 || PlayerInfo[playerid][pScrew] >= 1)
     				{
   	    				if(PlayerInfo[playerid][pMask] == 1)
						{
    						format(string, sizeof(string), "* Stranger has entered the house.");
						}
      					else
						{
							format(string, sizeof(string), "* %s has entered the house.", sendername);
						}
      					ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
						PlayerInfo[playerid][InHouse] = i;
   						SetPlayerInterior( playerid, HouseInfo[i][hInteriorID]);
      					SetPlayerVirtualWorld( playerid, HouseInfo[i][hVirWorld]);
   						PlayerInfo[playerid][pVirtualWorld] = HouseInfo[i][hVirWorld];
      					SetPlayerPos( playerid, HouseInfo[i][hInteriorX], HouseInfo[i][hInteriorY], HouseInfo[i][hInteriorZ]);
   						if(HouseInfo[i][hRadio] > 0 && HouseInfo[i][hRadio] <= RADIOS)
       					{
							new cRadio = HouseInfo[i][hRadio];
			       			switch(cRadio)
							{
								case 1:
						    	{
						    	    StopAudioStreamForPlayer(playerid);
						    		PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1281016");
								}
								case 2:
						       	{
						       	    StopAudioStreamForPlayer(playerid);
						        	PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1979774");
								}
								case 3:
						        {
						            StopAudioStreamForPlayer(playerid);
						            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1283687");
								}
							}
						}
      					for(new x = 0; x <MAX_PLAYERS; x++)
	          			{
	          			    new id = PlayerInfo[x][pPhousekey];
      						if(HouseInfo[id][hAlarmSystem] == 1 && HouseInfo[id][hAlarmNumber] != 0 && AlarmOnline[id] == 0)
           					{
						   		for(new a = 0; a <MAX_PLAYERS; a++)
		                		{
                   					if(IsPlayerConnected(a))
			                    	{
			                    	    if(PlayerInfo[playerid][pScrew] >= 1 && HouseInfo[i][hLocked] == 1)
			                    	    {
                       						if(PlayerInfo[a][pPnumber] == HouseInfo[id][hAlarmNumber])
			                        		{
			                        		    new success = random(4);
                                 				if(success == 1)
			    								{
			    								    format(string, sizeof(string), "House Alarm: Someone has tryed to enter inside the house but failed!");
													SendCopMessage(COLOR_DBLUE,string);
                                                    PlayerInfo[playerid][pScrew] -= 1;
                                                    SendClientMessage(playerid, COLOR_GREY, "You failed to enter inside the house, run!");
	                								format(string, sizeof(string), "SMS: This is an automated message informing you that registrant %s's house alarm has been activated.",GetName(x));
													SendClientMessage(a, COLOR_YELLOW, string);
													if(IsACop(a))
													{
														SetPlayerCheckpoint(playerid, HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ], 3.0);
														CP[a] = 46488;
													}
													if(PlayerInfo[playerid][pWantedLevel] <= 6)
													{
														PlayerInfo[playerid][pWantedLevel] += 1;
														SetPlayerWantedLevel(playerid, PlayerInfo[playerid][pWantedLevel]);
													}
													PlayerInfo[playerid][pVirtualWorld] = 0;
		        									SetPlayerVirtualWorld(playerid, 0);
			        								SetPlayerInterior(playerid, HouseInfo[i][hExteriorID]);
			        								SetPlayerPos(playerid, HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ]);
												}
												else
												{
												    format(string, sizeof(string), "House Alarm: Someone has successfully entered inside the house!");
													SendCopMessage(COLOR_DBLUE,string);
        											PlayerInfo[playerid][pScrew] -= 1;
        											if(IsACop(a))
													{
														SetPlayerCheckpoint(playerid, HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ], 3.0);
														CP[a] = 46488;
													}
													if(PlayerInfo[playerid][pWantedLevel] <= 6)
													{
														PlayerInfo[playerid][pWantedLevel] += 1;
														SetPlayerWantedLevel(playerid, PlayerInfo[playerid][pWantedLevel]);
													}
        											SendClientMessage(playerid, COLOR_GREY, "You successfully enter inside the house!");
	                								format(string, sizeof(string), "SMS: This is an automated message informing you that registrant %s's house alarm has been activated.",GetName(x));
													SendClientMessage(a, COLOR_YELLOW, string);
												}
											}
										}
									}
								}
        					}
	        			}
					}
	        		else
	        		{
  	    				GameTextForPlayer(playerid, "~r~House is Locked!", 1000, 5);
					}
		    	}
			}
		}
House Exit function

Код:
    	for(new i = 0; i < sizeof(HouseInfo); i++)
		{
  			if(IsPlayerInRangeOfPoint(playerid, 3, HouseInfo[PlayerInfo[playerid][InHouse]][hInteriorX], HouseInfo[PlayerInfo[playerid][InHouse]][hInteriorY], HouseInfo[PlayerInfo[playerid][InHouse]][hInteriorZ]))
  			{
				if(GetPlayerVirtualWorld(playerid) > 0)
 				{
					if(PlayerInfo[playerid][InHouse] != 0)
  					{
	    				if(PlayerInfo[playerid][pMask] == 1)
						{
    						format(string, sizeof(string), "* Stranger has left the house.");
						}
						else
						{
							format(string, sizeof(string), "* %s has left the house.", sendername);
						}
						ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
						PlayerInfo[playerid][pVirtualWorld] = 0;
						SetPlayerVirtualWorld( playerid, 0 );
						SetPlayerInterior( playerid, HouseInfo[PlayerInfo[playerid][InHouse]][hExteriorID]);
   						SetPlayerPos( playerid, HouseInfo[PlayerInfo[playerid][InHouse]][hExteriorX], HouseInfo[PlayerInfo[playerid][InHouse]][hExteriorY], HouseInfo[PlayerInfo[playerid][InHouse]][hExteriorZ]);
   						PlayerInfo[playerid][InHouse] = 0;
            		}
	            	else
	            	{
	                	if(PlayerInfo[playerid][pMask] == 1)
						{
					    	format(string, sizeof(string), "* Stranger has left the house.");
						}
						else
						{
							format(string, sizeof(string), "* %s has left the house.", sendername);
						}
						ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
             			PlayerInfo[playerid][pVirtualWorld] = 0;
		        		SetPlayerVirtualWorld(playerid, 0);
			        	SetPlayerInterior(playerid, HouseInfo[i][hExteriorID]);
			        	SetPlayerPos(playerid, HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ]);
            		}
            		StopAudioStreamForPlayer(playerid);
		   	 	}
			}
   		}
Reply
#2

I quickly checked it, and can it be because you forgot the
Код:
 PlayerInfo[playerid][InHouse]
variable in the loading of the position?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)