SA-MP Forums Archive
Carlock Help - 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: Carlock Help (/showthread.php?tid=435278)



Carlock Help - SkyWinder - 06.05.2013

Hi, I am trying to get this command to work. It works inside the car but outside the car it doesnt seem to work.

pawn Код:
CMD:carlock(playerid, params[])
{
    if(!isnull(params)) return SystemMsg(playerid, "Use /carlock");
//   if(!IsPlayerInAnyVehicle(playerid)) return SystemMsg(playerid, "You must be in your vehicle.");

    new playerstate = GetPlayerState(playerid);
    if(playerstate == PLAYER_STATE_DRIVER && playerstate != PLAYER_STATE_ONFOOT)
    {
       if(GetPlayerVehicleSeat(playerid) != 0) return SystemMsg(playerid, "You must be in the drivers seat to lock or unlock the vehicle.");
       new vid = GetPlayerVehicleID(playerid);
       new PlayerName[24];
       GetPlayerName(playerid, PlayerName, 24);
       if(!PlayerOwnsVehicle(PlayerName, vid)) return SystemMsg(playerid, "You can only lock your own vehicles.");
       if(CarLocked(vid))
       {
          new loc[25];
          format(loc, sizeof(loc), "/Vehicles/%i.ini", FileID[vid]);
          dini_IntSet(loc, "Locked", 0);
          SendClientMessage(playerid, COLOR_SKY, "You unlocked your vehicle.");
       }
       else
       {
          new loc[25];
          format(loc, sizeof(loc), "/Vehicles/%i.ini", FileID[vid]);
          dini_IntSet(loc, "Locked", 1);
          SendClientMessage(playerid, COLOR_SKY, "You locked your vehicle.");
       }
    }
    if(playerstate == PLAYER_STATE_ONFOOT)
    {
            new vid = GetPlayerVehicleID(playerid);
            new Float:pX,Float:pY,Float:pZ;
            GetPlayerPos(playerid,pX,pY,pZ);
            new Float:vX,Float:vY,Float:vZ;
            new Found=0;
            vid=0;
            while((vid<MAX_VEHICLES)&&(!Found))
            {
                vid++;
                GetVehiclePos(vid,vX,vY,vZ);
                new PlayerName[24];
                GetPlayerName(playerid, PlayerName, 24);
                if  ((floatabs(pX-vX)<4.0)&&(floatabs(pY-vY)<4.0)&&(floatabs(pZ-vZ)<4.0) && PlayerOwnsVehicle(PlayerName, vid))
                {

                   if(CarLocked(vid))
                   {
                      new loc[25];
                      format(loc, sizeof(loc), "/Vehicles/%i.ini", FileID[vid]);
                      dini_IntSet(loc, "Locked", 0);
                      SendClientMessage(playerid, COLOR_SKY, "You unlocked your vehicle.");
                   }
                   else
                   {
                      new loc[25];
                      format(loc, sizeof(loc), "/Vehicles/%i.ini", FileID[vid]);
                      dini_IntSet(loc, "Locked", 1);
                      SendClientMessage(playerid, COLOR_SKY, "You locked your vehicle.");
                   }
                } else return SystemMsg(playerid, "You can only lock your own car.");
    }       }
    return 1;
}



Re: Carlock Help - dominik523 - 06.05.2013

Here is code from one GM:
Код:
if(IsPlayerInRangeOfPoint(playerid, 3, vx, vy, vz))
	    {
	        idx = PlayerInfo[playerid][pVeh];
	        new engine, lights, alarm, doors, bonnet, boot, objective;
			GetVehicleParamsEx(idx, engine, lights, alarm, doors, bonnet, boot, objective);
			if(doors)
			{

			    SetVehicleParamsEx(idx, engine, lights, alarm, 0, bonnet, boot, objective);
			    PlayerInfo[playerid][vLocked] = 0;
			    format(string, sizeof(string), "* %s takes out their vehicle keys and unlocks it.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				GameTextForPlayer(playerid, "~g~Vehicle Unlocked", 3500, 3);
			}
			else
			{
			    SetVehicleParamsEx(idx, engine, lights, alarm, 1, bonnet, boot, objective);
			    PlayerInfo[playerid][vLocked] = 1;
			    format(string, sizeof(string), "* %s takes out their vehicle keys and locks it.", RPN(playerid));
				SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
				GameTextForPlayer(playerid, "~r~Vehicle Locked", 3500, 3);
			}
			lockdone = 1;
			return 1;
Just replace variables like vX, vY etc with yours