SA-MP Forums Archive
"/lock" Doesn't want to work. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: "/lock" Doesn't want to work. (/showthread.php?tid=76933)



"/lock" Doesn't want to work. - Verlix - 07.05.2009

Ok so, ive been browsing the forums for hours, got some code snippets and started making my /lock command. /lock will work inside the car, but not outside of it.

If anybody could help me out fixing this, I would appreciate it alot.

Код:
	if (strcmp("/lock", cmdtext, true, 5) == 0)
	{
	  GetPlayerName(playerid, sendername, sizeof(sendername));
		new carid=GetPlayerVehicleID(playerid);
		new carid1=GetClosestCar(playerid);
		if(IsPlayerInAnyVehicle(playerid))
		{
	    if(VehicleLocked[carid] == 0)
	 		{
				format(string, sizeof(string), "* %s presses a button inside his/her vehicle and locks their vehicle.", sendername);
	 			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				VehicleLocked[carid] = 1;
				VehicleLockedPlayer[playerid] = carid;
				
				new i;
				for (i=0;i<MAX_PLAYERS;i++)
				{
    		SetVehicleParamsForPlayer(carid,i,0,1);
    		}

			}
			else
			{
				format(string, sizeof(string), "* %s presses a button inside his/her vehicle and unlocks their vehicle.", sendername);
	 			ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				VehicleLocked[VehicleLockedPlayer[playerid]] = 0;
				VehicleLockedPlayer[playerid] = 999;
				
				new i;
				for (i=0;i<MAX_PLAYERS;i++)
				{
    		SetVehicleParamsForPlayer(carid,i,0,0);
    		}
			}
		}
		else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
 			new Float:x2,Float:y2,Float:z2;
			GetVehiclePos(VehicleLockedPlayer[playerid], x2, y2, z2);
			
			if(VehicleLocked[carid] == 0)
			{
 				if(PlayerToPoint(5.0,playerid,x2,y2,z2))
			  {
 					format(string, sizeof(string), "* %s uses his/her key to lock their vehicle.", sendername);
	 				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					VehicleLocked[carid] = 1;
					VehicleLockedPlayer[playerid] = carid;

					
					new i;
					for (i=0;i<MAX_PLAYERS;i++)
					{
    				SetVehicleParamsForPlayer(carid,i,0,1);
 					}
				}
			}
			else if(VehicleLocked[carid1] == 0)
			{
			  if(PlayerToPoint(5.0,playerid,x2,y2,z2))
			  {
 					format(string, sizeof(string), "* %s uses his/her key to unlock their vehicle.", sendername);
	 				ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
					VehicleLocked[VehicleLockedPlayer[playerid]] = 0;
					VehicleLockedPlayer[playerid] = 999;

					new i;
					for (i=0;i<MAX_PLAYERS;i++)
					{
    				SetVehicleParamsForPlayer(carid,i,0,0);
    			}
  			}
			}
 		}
		return 1;
	}
EDIT:

Heres the pastebin if you guys prefer that
http://pastebin.com/m7123bd54


Re: "/lock" Doesn't want to work. - Xeretta - 07.05.2009

I have a good command:
Quote:

if (strcmp(cmdtext, "/lock", true)==0)
{
new State;
new Float:X;
new Float:Y;
new Float:Z;
if(IsPlayerInAnyVehicle(playerid))
{
State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,COLOR_RED,"You can only lock when driving!");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
if(i != playerid)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playe rid),i, 0, 1);
}
}
SendClientMessage(playerid, COLOR_COP_ELITE, "Vehicle Locked!");
GetPlayerPos(playerid,X,Y,Z);
PlayerPlaySound(playerid,1056,X,Y,Z);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "You are not in a vehicle.");
return 1;
}
}
if (strcmp(cmdtext, "/destrancar", true)==0)
{
new State;
new Float:X;
new Float:Y;
new Float:Z;
if(IsPlayerInAnyVehicle(playerid))
{
State=GetPlayerState(playerid);
if(State!=PLAYER_STATE_DRIVER)
{
SendClientMessage(playerid,COLOR_RED,"You are not driving.");
return 1;
}
new i;
for(i=0;i<MAX_PLAYERS;i++)
{
SetVehicleParamsForPlayer(GetPlayerVehicleID(playe rid),i, 0, 0);
}
SendClientMessage(playerid, COLOR_COP_ELITE, "Vehicle Unlocked");
GetPlayerPos(playerid,X,Y,Z);
PlayerPlaySound(playerid,1057,X,Y,Z);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "You are not in any vehicle");
return 1;
}
}

EDIT: Change the color of the messages, as are the pattern of my Game Mode

Sorry for my bad english xD


Re: "/lock" Doesn't want to work. - Verlix - 08.05.2009

Thanks, but I have that working, I just really need to be able to do /lock outside of the car as well.

Anybody got any ideas on how to fix it?


Re: "/lock" Doesn't want to work. - Rks25 - 08.05.2009

Remove the IsPlayerInAnyVehicle check.


Re: "/lock" Doesn't want to work. - Verlix - 11.05.2009

How would that affect anything?

if(IsPlayerInAnyVehicle(playerid))
{
}
else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{


Re: "/lock" Doesn't want to work. - NeRoSiS - 11.05.2009

Because it means they can unlock th vehicle if they are not in a car too. That check stops /lock from working unless your in a vehicle.


Re: "/lock" Doesn't want to work. - Verlix - 11.05.2009

But that is impossible. It checks if they are in a vehicle: runs lock or unlock, if they are not, checks if they are on foot: runs lock or unlock.

I will try it when I get back later today though, thanks


Re: "/lock" Doesn't want to work. - devil614 - 13.05.2009

It's not hard...
Get the ID of the car first, then use that ID in a command that locks the doors for everyone except you [use a loop]
Same thing for unlocking...

How will you determine which car belongs to your player? After they enter it for the first time?