SA-MP Forums Archive
/lock command is bugged. - 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: /lock command is bugged. (/showthread.php?tid=628847)



/lock command is bugged. - MyUndiesSmell - 15.02.2017

The /lock command only works when the OWNER of the vehicle is inside the vehicle. If they try to unlock the car outside of the car it will simply not work.

Link to the script - https://sampforum.blast.hk/showthread.php?tid=609992

Код:
CMD:lock(playerid, params[])
{
	static
	    id = -1;

	if (!IsPlayerInAnyVehicle(playerid) && (id = (House_Inside(playerid) == -1) ? (House_Nearest(playerid)) : (House_Inside(playerid))) != -1 && House_IsOwner(playerid, id))
	{
		if (!HouseData[id][houseLocked])
		{
			HouseData[id][houseLocked] = true;
			House_Save(id);

			ShowPlayerFooter(playerid, "You have ~r~locked~w~ your house!");
			PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
		}
		else
		{
			HouseData[id][houseLocked] = false;
			House_Save(id);

			ShowPlayerFooter(playerid, "You have ~g~unlocked~w~ your house!");
			PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
		}
	}
	else if (!IsPlayerInAnyVehicle(playerid) && (id = (Business_Inside(playerid) == -1) ? (Business_Nearest(playerid)) : (Business_Inside(playerid))) != -1)
	{
		if (Business_IsOwner(playerid, id))
		{
			if (!BusinessData[id][bizLocked])
			{
				BusinessData[id][bizLocked] = true;

				Business_Refresh(id);
				Business_Save(id);

				ShowPlayerFooter(playerid, "You have ~r~locked~w~ the business!");
				PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
			}
  			else
			{
				BusinessData[id][bizLocked] = false;

				Business_Refresh(id);
				Business_Save(id);

				ShowPlayerFooter(playerid, "You have ~g~unlocked~w~ the business!");
				PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
			}
		}
	}
	else if (!IsPlayerInAnyVehicle(playerid) && (id = (Entrance_Inside(playerid) == -1) ? (Entrance_Nearest(playerid)) : (Entrance_Inside(playerid))) != -1)
	{
		if (strlen(EntranceData[id][entrancePass]))
		{
			Dialog_Show(playerid, EntrancePass, DIALOG_STYLE_INPUT, "Entrance Pass", "Please enter the password for this entrance:", "Submit", "Cancel");
		}
	}
	else if ((id = Car_Nearest(playerid)) != -1)
	{
	    static
	        engine,
	        lights,
	        alarm,
	        doors,
	        bonnet,
	        boot,
	        objective;

	    GetVehicleParamsEx(CarData[id][carVehicle], engine, lights, alarm, doors, bonnet, boot, objective);

	    if (Car_IsOwner(playerid, id) || (PlayerData[playerid][pFaction] != -1 && CarData[id][carFaction] == GetFactionType(playerid)))
	    {
			if (!CarData[id][carLocked])
			{
				CarData[id][carLocked] = true;
				Car_Save(id);

				ShowPlayerFooter(playerid, "You have ~r~locked~w~ the vehicle!");
				PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);

				SetVehicleParamsEx(CarData[id][carVehicle], engine, lights, alarm, 1, bonnet, boot, objective);
			}
			else
			{
				CarData[id][carLocked] = false;
				Car_Save(id);

				ShowPlayerFooter(playerid, "You have ~g~unlocked~w~ the vehicle!");
				PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);

				SetVehicleParamsEx(CarData[id][carVehicle], engine, lights, alarm, 0, bonnet, boot, objective);
			}
		}
	}
	else SendErrorMessage(playerid, "You are not in range of anything you can lock.");
	return 1;
}



Re: /lock command is bugged. - MiiSha - 16.02.2017

Paste that " Car_Nearest(playerid) " thing here !


Re: /lock command is bugged. - MyUndiesSmell - 16.02.2017

Код:
Car_Nearest(playerid)
{
	static
	    Float:fX,
	    Float:fY,
	    Float:fZ;

	for (new i = 0; i != MAX_DYNAMIC_CARS; i ++) if (CarData[i][carExists]) {
		GetVehiclePos(CarData[i][carVehicle], fX, fY, fZ);

		if (IsPlayerInRangeOfPoint(playerid, 3.0, fX, fY, fZ)) {
		    return i;
		}
	}
	return -1;
}



Re: /lock command is bugged. - MyUndiesSmell - 16.02.2017

Anyone able to help me?


Re: /lock command is bugged. - Sew_Sumi - 16.02.2017

I always check if the vehicle is streamed in for the player before checking the distance... Just as a random thing.


Re: /lock command is bugged. - MyUndiesSmell - 16.02.2017

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
I always check if the vehicle is streamed in for the player before checking the distance... Just as a random thing.
So what would I need to add to the code?


Re: /lock command is bugged. - MyUndiesSmell - 16.02.2017

I tested the /lock again with my friend. It worked for him and when I tried it worked. But later after he got off. I restarted the server and tried again didn't work at all.


Re: /lock command is bugged. - Sew_Sumi - 16.02.2017

You'll probably want to test it more, as this is likely to be something else. Test with more players, try respawn the car, try using someone elses car, to see if it is going to pick up that you aren't actually near it.

You also should mind out having too much on that one command. House and Business, no worries... But you could make the vehicle lock work off another command to make it more defined.


Re: /lock command is bugged. - MyUndiesSmell - 16.02.2017

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
You'll probably want to test it more, as this is likely to be something else. Test with more players, try respawn the car, try using someone elses car, to see if it is going to pick up that you aren't actually near it.

You also should mind out having too much on that one command. House and Business, no worries... But you could make the vehicle lock work off another command to make it more defined.
I've already tried this. I had four of my friends get on and help me. The /lock command didn't work. Tried with empty server. Still didn't work. I restarted the server and it worked. Then when I tried again later it didn't work. It's like something is triggering it. I have no clue what's wrong. That's why I've came here for some help.


Re: /lock command is bugged. - Sew_Sumi - 16.02.2017

What's actually being given as a message when it's not working?

And how are you creating those vehicles?