SA-MP Forums Archive
"enter" with key "C" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: "enter" with key "C" (/showthread.php?tid=365579)



"enter" with key "C" - bloodrocklee - 03.08.2012

Ok 'ombres....i got a really big problem...

Код:
if (PRESSED( KEY_CROUCH ))
    {
	new string[128];
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	for(new idx=0; idx<MAX_DOORS; idx++) // Dynamic Doors
	{
	    if(IsPlayerInRangeOfPoint(playerid, 2, DoorInfo[idx][dOX], DoorInfo[idx][dOY], DoorInfo[idx][dOZ]))
	    {
	        if(DoorInfo[idx][dIInt] == 83 && DoorInfo[idx][dIVW] == 8473 && BankBlock)
	        {
	            SendClientMessage(playerid, COLOR_GREY, "You can't enter the bank as it is being robbed at the moment.");
	            return 1;
	        }
	        if(DoorInfo[idx][dCInt])
	        {
	            GameTextForPlayer(playerid, "~w~Loading Objects", 1000, 3);
				TogglePlayerControllable(playerid, 0);
	            SetTimerEx("EnterExitTimer", 1000, false, "i", playerid);
	            PlayerInfo[playerid][pSpawnFreeze] = 1;
	        }
	        PlayerInfo[playerid][pSpawnFreeze] = 0;
	        SetPlayerInterior(playerid, DoorInfo[idx][dIInt]);
	        SetPlayerVirtualWorld(playerid, DoorInfo[idx][dIVW]);
	        SetPlayerFacingAngle(playerid, DoorInfo[idx][dIA]);
	        SetCameraBehindPlayer(playerid);
	        SetPlayerPos(playerid, DoorInfo[idx][dIX], DoorInfo[idx][dIY], DoorInfo[idx][dIZ]);
	        return 1;
	    }
	}
	for(new idx=1; idx<MAX_BIZ; idx++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 2, BizInfo[idx][bX], BizInfo[idx][bY], BizInfo[idx][bZ]))
		{
		    if(!BizInfo[idx][bStatus] && PlayerInfo[playerid][pBiz] != idx && !PlayerInfo[playerid][pVBiz]) return SendClientMessage(playerid, COLOR_GREY, "This business is closed.");
		    if(BizInfo[idx][bType] == 1) // 24/7 Business
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, -27.3025,-57.6649,1003.5469);
		        SetPlayerFacingAngle(playerid, 357.5915);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 6);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's 24/7 Market (( /list & /buy )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		    else if(BizInfo[idx][bType] == 2) // Clothes Shop Business
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, 207.0638,-139.9965,1003.5078);
		        SetPlayerFacingAngle(playerid, 356.3849);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 3);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's Clothes Shop (( /buyclothes & /buytoys )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		    else if(BizInfo[idx][bType] == 3) // Ammunation Business
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, 285.8044,-85.9956,1001.5229);
		        SetPlayerFacingAngle(playerid, 358.9898);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 4);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's Ammunation (( /list & /buy )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		    else if(BizInfo[idx][bType] == 4) // Club Business
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, 493.4252,-24.3061,1000.6797);
		        SetPlayerFacingAngle(playerid, 0.2432);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 17);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's Club (( /list & /buy )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		    else if(BizInfo[idx][bType] == 5) // Advertisement Agency
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, 834.1631,7.4883,1004.1797);
		        SetPlayerFacingAngle(playerid, 86.7239);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 3);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's Advertisement Agency (( /ad )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		    else if(BizInfo[idx][bType] == 6) // Fast Food
		    {
		        format(string, sizeof(string), "* %s pushes the door and enters the shop.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
		        SetPlayerPos(playerid, 372.3830,-133.2579,1001.4922);
		        SetPlayerFacingAngle(playerid, 0.4216);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 5);
		        SetPlayerVirtualWorld(playerid, idx+100);
		        format(string, sizeof(string), "** Welcome to %s's Fast Food (( /list /buy )) **", BizInfo[idx][bOwner]);
		        SendClientMessage(playerid, COLOR_ORANGE, string);
		        return 1;
		    }
		}
	}
	for(new idx=1; idx<MAX_HOUSES; idx++) // Dynamic Houses
	{
		if(IsPlayerInRangeOfPoint(playerid, 2, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]))
	    {
		    if(!HouseInfo[idx][hStatus] && PlayerInfo[playerid][pHouse] != idx && PlayerInfo[playerid][pVHouse] != idx) return SendClientMessage(playerid, COLOR_GREY, "This house is locked.");
	        format(string, sizeof(string), "* %s pushes the door and enters the house.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	        SetPlayerVirtualWorld(playerid, idx+500);
			if(HouseInfo[idx][hLevel] == 1)
			{
				SetPlayerPos(playerid, 243.9951,304.9418,999.1484);
		        SetPlayerFacingAngle(playerid, 267.0980);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 1);
			}
			else if(HouseInfo[idx][hLevel] == 2)
			{
				SetPlayerPos(playerid, 2259.6702,-1135.8542,1050.6328);
		        SetPlayerFacingAngle(playerid, 267.3974);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 10);
			}
			else if(HouseInfo[idx][hLevel] == 3)
			{
				SetPlayerPos(playerid, 2308.8254,-1212.8070,1049.0234);
		        SetPlayerFacingAngle(playerid, 359.8550);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 6);
			}
			else if(HouseInfo[idx][hLevel] == 4)
			{
				SetPlayerPos(playerid, 260.7436,1237.5563,1084.2578);
		        SetPlayerFacingAngle(playerid, 1.6415);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 9);
			}
			else if(HouseInfo[idx][hLevel] == 5)
			{
				SetPlayerPos(playerid, -42.5742,1405.6521,1084.4297);
		        SetPlayerFacingAngle(playerid, 359.1347);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 8);
			}
			else if(HouseInfo[idx][hLevel] == 6)
			{
				SetPlayerPos(playerid, 2468.6787,-1698.2617,1013.5078);
		        SetPlayerFacingAngle(playerid, 89.1791);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 2);
			}
			else if(HouseInfo[idx][hLevel] == 7)
			{
				SetPlayerPos(playerid, 2365.2183,-1135.4014,1050.8750);
		        SetPlayerFacingAngle(playerid, 359.8550);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 8);
			}
			else if(HouseInfo[idx][hLevel] == 8)
			{
				SetPlayerPos(playerid, 2270.1270,-1210.4855,1047.5625);
		        SetPlayerFacingAngle(playerid, 89.4224);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 10);
			}
			else if(HouseInfo[idx][hLevel] == 9)
			{
				SetPlayerPos(playerid, 2324.4424,-1149.2057,1050.7101);
		        SetPlayerFacingAngle(playerid, 0.7248);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 12);
			}
			else if(HouseInfo[idx][hLevel] == 10)
			{
				SetPlayerPos(playerid, 83.0863,1322.3020,1083.8662);
		        SetPlayerFacingAngle(playerid, 359.5183);
		        SetCameraBehindPlayer(playerid);
		        SetPlayerInterior(playerid, 9);
			}
	        return 1;
		}
	}
	return 1;
}
    else if(newkeys & KEY_CROUCH)
{
	new done, string[128];
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    for(new idx=0; idx<MAX_DOORS; idx++) // Dynamic Doors
	{
	    if(!done && IsPlayerInRangeOfPoint(playerid, 2, DoorInfo[idx][dIX], DoorInfo[idx][dIY], DoorInfo[idx][dIZ]) && GetPlayerVirtualWorld(playerid) == DoorInfo[idx][dIVW] && GetPlayerInterior(playerid) == DoorInfo[idx][dIInt])
	    {
	        if(BankRobber[playerid] && BankBlock && GetPlayerInterior(playerid) == 83 && GetPlayerVirtualWorld(playerid) == 8473)
	        {
	       	    new Rob = BankRobber[playerid]-1;
			    DisablePlayerCheckpoint(playerid);
				BankRobbersCount --;
				format(BankRobbers[Rob], MAX_PLAYER_NAME, "");
				DeliverMoney[playerid] = 0;
				//
				foreach(Player, i)
				{
				    if(BankRobber[i] || PlayerInfo[i][pFac] == 1)
				    {
						if(Rob == 0) TextDrawHideForPlayer(i, Textdraw1);
						else if(Rob == 1) TextDrawHideForPlayer(i, Textdraw2);
						else if(Rob == 2) TextDrawHideForPlayer(i, Textdraw3);
						else if(Rob == 3) TextDrawHideForPlayer(i, Textdraw4);
						else if(Rob == 4) TextDrawHideForPlayer(i, Textdraw5);
					}
				}
				format(string, sizeof(string), "** %s has went out of the bank before loading money and has failed the robbery. **", RPN(playerid));
				SendRobberyMessage(COLOR_LIGHTRED, string);
				SendCopMessage(COLOR_LIGHTRED, string);
				BankRobber[playerid] = 0;
				if(BankRobbersCount == 0)
				{
					TextDrawHideForAll(Textdraw0);
					TextDrawHideForAll(Textdraw1);
					TextDrawHideForAll(Textdraw2);
					TextDrawHideForAll(Textdraw3);
					TextDrawHideForAll(Textdraw4);
					TextDrawHideForAll(Textdraw5);
					BankRobbery = 0;
					RobberyStarted = 0;
					format(string, sizeof(string), "** The bank robbery has ended, $%d were stolen and $%d were saved. **", TotalStolen*10000, (TotalRobbers*10000-(TotalStolen*10000)));
					SendClientMessageToAll(COLOR_YELLOW, string);
					TotalRobbers = 0;
					new copsonline;
					foreach(Player, i)
					{
					    if(IsACop(i)) copsonline++;
					}
					foreach(Player, i)
					{
					    if(IsACop(i))
					    {
							new Saved = (TotalRobbers*10000-(TotalStolen*10000));
							GiveZaiatMoney(i, Saved/copsonline);
							format(string, sizeof(string), "** You have received your cut from the saved money. ($%d)", Saved/copsonline);
							SendClientMessage(i, COLOR_LIME, string);
					    }
					}
				}
	            return 1;
	        }
	        if(DoorInfo[idx][dCExt])
	        {
	            GameTextForPlayer(playerid, "~w~Loading Objects", 1000, 3);
				TogglePlayerControllable(playerid, 0);
	            SetTimerEx("EnterExitTimer", 1000, false, "i", playerid);
	            PlayerInfo[playerid][pSpawnFreeze] = 1;
	        }
	        PlayerInfo[playerid][pSpawnFreeze] = 0;
	        SetPlayerInterior(playerid, DoorInfo[idx][dOInt]);
	        SetPlayerVirtualWorld(playerid, DoorInfo[idx][dOVW]);
	        SetPlayerFacingAngle(playerid, DoorInfo[idx][dOA]);
	        SetCameraBehindPlayer(playerid);
	        SetPlayerPos(playerid, DoorInfo[idx][dOX], DoorInfo[idx][dOY], DoorInfo[idx][dOZ]);
	        done = 1;
	    }
	}
	if(IsPlayerInRangeOfPoint(playerid, 2, 243.9951,304.9418,999.1484) || IsPlayerInRangeOfPoint(playerid, 2, 2259.6702,-1135.8542,1050.6328) || IsPlayerInRangeOfPoint(playerid, 2, 2308.8254,-1212.8070,1049.0234) || IsPlayerInRangeOfPoint(playerid, 2, 260.7436,1237.5563,1084.2578)
	|| IsPlayerInRangeOfPoint(playerid, 2, -42.5742,1405.6521,1084.4297) || IsPlayerInRangeOfPoint(playerid, 2, 2468.6787,-1698.2617,1013.5078) || IsPlayerInRangeOfPoint(playerid, 2, 2365.2183,-1135.4014,1050.8750) || IsPlayerInRangeOfPoint(playerid, 2, 2270.1270,-1210.4855,1047.5625)
	|| IsPlayerInRangeOfPoint(playerid, 2, 2324.4424,-1149.2057,1050.7101) || IsPlayerInRangeOfPoint(playerid, 2, 83.0863,1322.3020,1083.8662)) // Houses
	{
	    new idx;
		idx = GetPlayerVirtualWorld(playerid)-500;
		if(!done && idx < MAX_HOUSES && HouseInfo[idx][hLevel])
		{
			format(string, sizeof(string), "* %s pushes the door and exits the house.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	        SetPlayerPos(playerid, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]);
	        SetPlayerInterior(playerid, 0);
	        SetPlayerVirtualWorld(playerid, 0);
	        done = 1;
        }
	}
    if(IsPlayerInRangeOfPoint(playerid, 2, -27.3025,-57.6649,1003.5469) || IsPlayerInRangeOfPoint(playerid, 2, 207.0638,-139.9965,1003.5078) || IsPlayerInRangeOfPoint(playerid, 2, 285.8044,-85.9956,1001.5229) || IsPlayerInRangeOfPoint(playerid, 2, 493.4252,-24.3061,1000.6797) || IsPlayerInRangeOfPoint(playerid, 2, 834.1631,7.4883,1004.1797) || IsPlayerInRangeOfPoint(playerid, 2, 372.3830,-133.2579,1001.4922)) // 24/7 || Clothes Shop || Ammunation || Club || Advertisement Agency || FastFood
	{
	    new idx;
		idx = GetPlayerVirtualWorld(playerid)-100;
		if(!done && idx < MAX_BIZ && BizInfo[idx][bType])
		{
			format(string, sizeof(string), "* %s pushes the door and exits the shop.", RPN(playerid));
			SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	        SetPlayerPos(playerid, BizInfo[idx][bX], BizInfo[idx][bY], BizInfo[idx][bZ]);
	        SetPlayerInterior(playerid, 0);
	        SetPlayerVirtualWorld(playerid, 0);
        }
        done = 1;
	}
	return 1;
}
Ok...and tha' problem is:
-enter WORKS (if (PRESSED( KEY_CROUCH )))
-exit DOESN'T WORK (if (newkeys == KEY_CROUCH))

when i press "C" to enter it sends me to tha' interior (that's good)
but when i attempt to exit i have to press "SPACE" than fasta' "C" but not in tha' same time...what should i use to press "C" in both situations? please help (REP+)


Re: "enter" with key "C" - andmeida10 - 03.08.2012

You also have to set the positions to exit... And the interior


Re: "enter" with key "C" - bloodrocklee - 03.08.2012

yea...ya're really funny


Re: "enter" with key "C" - Vince - 03.08.2012

Please tell me why you are using bitiwise comparison for the entering (the define) and logical comparison for the exiting? Wouldn't it make more sense to also use bitwise comparison (the define) for exiting?


Re: "enter" with key "C" - bloodrocklee - 03.08.2012

Sorry i can't get cho'r point man....


Re: "enter" with key "C" - bloodrocklee - 03.08.2012

ok i've got cho'r point let me try


Re: "enter" with key "C" - bloodrocklee - 03.08.2012

still bugged....


Re: "enter" with key "C" - Misiur - 03.08.2012

You need to introduce some new variable or some additional conditional to check whether player is in interior, or he is not
pawn Код:
if (PRESSED( KEY_CROUCH ))
{
    if(some checking if not in interior)
    {
        tha' enter script...ya don't need to know :D
        return 1;
    } else {
        tha' exit script...ya don't need to know :D
        return 1;
    }
}



Re: "enter" with key "C" - Hiddos - 03.08.2012

The crouch key (on-foot) is not used in vehicles (pressing C does no action when pressed in a car). Because it now is just another of those keys (like b, q, x, etc), it does not trigger OnPlayerKeyStateChange (or get listed in GetPlayerKeys).

It might be a bit hard to fully understand, but that's the way it is.

Edit: The value of KEY_CROUCH (2, or 0b10) is used in vehicles, but under a different key. In vehicles, it's the horn (by default H or caps lock).


Re: "enter" with key "C" - SEnergy - 03.08.2012

pawn Код:
if (PRESSED(KEY_CROUCH))
    {
        if (GetPlayerInterior(playerid) == 0)
        {
            //stuff
        }
    }