"/lock" Doesn't want to work.
#1

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
Reply
#2

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
Reply
#3

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?
Reply
#4

Remove the IsPlayerInAnyVehicle check.
Reply
#5

How would that affect anything?

if(IsPlayerInAnyVehicle(playerid))
{
}
else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
Reply
#6

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.
Reply
#7

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
Reply
#8

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)