SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 10/11/2018, 07:56 AM   #1
BigGreen
Big Clucker
 
Join Date: Feb 2015
Posts: 86
Reputation: 8
Default [Help] /lock wont work right

Hello i need help to fix this problem i've come across in my server whenever i type /lock outside of my car it doesn't unlock or lock but when i enter the car and i type /lock the vehicle locks and unlocks while inside i've been trying to fix this myself but i seem to not have any luck

Code:
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);

			SendClientMessage(playerid, COLOR_WHITE, "You have locked your house.");
			PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
		}
		else
		{
			HouseData[id][houseLocked] = false;
			House_Save(id);

			SendClientMessage(playerid, COLOR_WHITE, "You have unlocked 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);

				SendClientMessage(playerid, COLOR_WHITE, "You have locked your business.");
				PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
			}
  			else
			{
				BusinessData[id][bizLocked] = false;

				Business_Refresh(id);
				Business_Save(id);

				SendClientMessage(playerid, COLOR_WHITE, "You have unlocked your 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(IsPlayerInAnyVehicle(playerid))
	    {
			if (!CarData[id][carLocked])
			{
				CarData[id][carLocked] = true;
				Car_Save(id);

			    SendClientMessage(playerid, COLOR_GREY, "Your Vehicle is now locked.");
				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);

				SendClientMessage(playerid, COLOR_GREY, "Your vehicle is now unlocked.");
				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;
}
__________________
BigGreen is offline   Reply With Quote
Old 10/11/2018, 10:00 AM   #2
khRamin78
Huge Clucker
 
khRamin78's Avatar
 
Join Date: Jun 2015
Location: IRI/LA
Posts: 321
Reputation: 30
Default Re: [Help] /lock wont work right

becuse you are checking if(IsPlayerInAnyVehicle(playerid))

and it will return false if player isnt in vehicle and its out side of vehicle

just do this

PHP Code:
CMD:lock(playeridparams[])
{
    static
        
id = -1;

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

            
SendClientMessage(playeridCOLOR_WHITE"You have locked your house.");
            
PlayerPlaySound(playerid11450.00.00.0);
        }
        else
        {
            
HouseData[id][houseLocked] = false;
            
House_Save(id);

            
SendClientMessage(playeridCOLOR_WHITE"You have unlocked your house");
            
PlayerPlaySound(playerid11450.00.00.0);
        }
    }
    else if (!
IsPlayerInAnyVehicle(playerid) && (id = (Business_Inside(playerid) == -1) ? (Business_Nearest(playerid)) : (Business_Inside(playerid))) != -1)
    {
        if (
Business_IsOwner(playeridid))
        {
            if (!
BusinessData[id][bizLocked])
            {
                
BusinessData[id][bizLocked] = true;

                
Business_Refresh(id);
                
Business_Save(id);

                
SendClientMessage(playeridCOLOR_WHITE"You have locked your business.");
                
PlayerPlaySound(playerid11450.00.00.0);
            }
              else
            {
                
BusinessData[id][bizLocked] = false;

                
Business_Refresh(id);
                
Business_Save(id);

                
SendClientMessage(playeridCOLOR_WHITE"You have unlocked your business");
                
PlayerPlaySound(playerid11450.00.00.0);
            }
        }
    }
    else if (!
IsPlayerInAnyVehicle(playerid) && (id = (Entrance_Inside(playerid) == -1) ? (Entrance_Nearest(playerid)) : (Entrance_Inside(playerid))) != -1)
    {
        if (
strlen(EntranceData[id][entrancePass]))
        {
            
Dialog_Show(playeridEntrancePassDIALOG_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], enginelightsalarmdoorsbonnetbootobjective);

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

                
SendClientMessage(playeridCOLOR_GREY"Your Vehicle is now locked.");
                
PlayerPlaySound(playerid11450.00.00.0);

                
SetVehicleParamsEx(CarData[id][carVehicle], enginelightsalarm1bonnetbootobjective);
            }
            else
            {
                
CarData[id][carLocked] = false;
                
Car_Save(id);

                
SendClientMessage(playeridCOLOR_GREY"Your vehicle is now unlocked.");
                
PlayerPlaySound(playerid11450.00.00.0);

                
SetVehicleParamsEx(CarData[id][carVehicle], enginelightsalarm0bonnetbootobjective);
            }
              }
    }
    else 
SendErrorMessage(playerid"You are not in range of anything you can lock.");
    return 
1;

khRamin78 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comanda /v lock , lock2 Not work/nu functioneaza MAXYMUSS Scripting Help 8 24/01/2015 10:43 AM
/lock Command dont work.. Geniuss Scripting Help 8 01/06/2012 06:14 PM
Lock Command Doesnt Work? Nuke547 Scripting Help 1 29/01/2012 05:50 AM
Vehicle Lock doesn't work pantelimonfl Help Archive 5 08/01/2011 01:55 PM
Why the command /lock dont work? _ERO_ Help Archive 1 03/01/2010 06:56 PM


All times are GMT. The time now is 10:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.