SA-MP Forums Archive
veh locks - 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: veh locks (/showthread.php?tid=480545)



veh locks - iBots - 11.12.2013

i have made a lock system to lock the car and unlock but it only works if ur inside the vehicle and do /lock it locks the vehicle,and if u are inside the car and u do /unlock it works,but if ur near your car and do /lock or /unlock it sends the message i set but it doesnt lock or unlock
code:
pawn Код:
if(strcmp(cmd, "/lock", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetVehiclePos(PlayerInfo[playerid][CarLinkID], PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ]);
            if(IsPlayerInRangeOfPoint(playerid, 4, PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ]))
            {
                GetPlayerName(playerid, sendername, sizeof(sendername));
                if(PlayerInfo[playerid][pMask] == 1) format(string, sizeof(string), "* Stranger has locked their vehicle.");
                else format(string, sizeof(string), "* %s has locked their vehicle.", sendername);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                new engine, lights, alarm, doors, bonnet, boot, objective;
                GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, true, true, bonnet, boot, objective);
                PlayerInfo[playerid][HouseCarLock] = 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are too far away from your vehicle !");
                return 1;
            }
        }
        return 1;
    }
    if(strcmp(cmd, "/unlock", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetVehiclePos(PlayerInfo[playerid][CarLinkID], PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ]);
            if(IsPlayerInRangeOfPoint(playerid, 4, PlayerInfo[playerid][CarX], PlayerInfo[playerid][CarY], PlayerInfo[playerid][CarZ]))
            {
                if(gVehicleLock[playerid] != 1)
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You don't have a lock for this vehicle !");
                    return 1;
                }
                GetPlayerName(playerid, sendername, sizeof(sendername));
                PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                if(PlayerInfo[playerid][pMask] == 1) format(string, sizeof(string), "* Stranger has locked their vehicle.");
                else format(string, sizeof(string), "* %s has unlocked their vehicle.", sendername);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                new engine, lights, alarm, doors, bonnet, boot, objective;
                GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
                SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, false, false, bonnet, boot, objective);
                PlayerInfo[playerid][HouseCarLock] = 0;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   You are too far away from your vehicle !");
                return 1;
            }
        }
        return 1;
    }



Re: veh locks - iBots - 11.12.2013

Help?


Re: veh locks - iBots - 12.12.2013

any one?


Re: veh locks - Punches - 12.12.2013

I'm currently on my phone I'll give you the code when I get back home.


Re: veh locks - batonsa - 12.12.2013

That's because the script is bound to only lock/unlock the vehicle the player is currently inside of.

You should use the following code instead:

ON LOCK:
Код:
    GetVehicleParamsEx(PlayerInfo[playerid][CarLinkID], engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(PlayerInfo[playerid][CarLinkID], engine, lights, true, true, bonnet, boot, objective);
ON UNLOCK:
Код:
    GetVehicleParamsEx(PlayerInfo[playerid][CarLinkID], engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(PlayerInfo[playerid][CarLinkID], engine, lights, false, false, bonnet, boot, objective);



Re: veh locks - iBots - 13.12.2013

thanks batonsa,+rep for you