SA-MP Forums Archive
Cars don't lock when you do /lock - 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: Cars don't lock when you do /lock (/showthread.php?tid=379159)



Cars don't lock when you do /lock - Luke_James - 20.09.2012

When you do /lock, it says the vehicle is locked but you can still get in it..

pawn Код:
command(lock, playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "You must be in a vehicle to use this command!");

    new
        VehicleID = GetPlayerVehicleID(playerid);
       
    if(OwnedCar(VehicleID) != 0)
    {
        if(strmatch(Vehicles[OwnedCar(VehicleID)][VehicleOwner], pName(playerid)))
        {
            Vehicles[OwnedCar(VehicleID)][vLocked] = 1;
           
            SendClientMessage(playerid, -1, "You've successfully locked your vehicle!");
           
            SaveOwnedCar(OwnedCar(VehicleID));
            return 1;
        }
        else return SendClientMessage(playerid, RED, "This vehicle does not belong to you!");
    }
    else return SendClientMessage(playerid, RED, "This is not a private vehicle!");
}



Re: Cars don't lock when you do /lock - mamorunl - 20.09.2012

You are forgetting to set them locked with SetVehicleParams


Re: Cars don't lock when you do /lock - Luke_James - 20.09.2012

pawn Код:
command(lock, playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "You must be in a vehicle to use this command!");

    new
        VehicleID = GetPlayerVehicleID(playerid);
       
    if(OwnedCar(VehicleID) != 0)
    {
        if(strmatch(Vehicles[OwnedCar(VehicleID)][VehicleOwner], pName(playerid)))
        {
            Vehicles[OwnedCar(VehicleID)][vLocked] = 1;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
            SendClientMessage(playerid, -1, "You've successfully locked your vehicle!");
            SaveOwnedCar(OwnedCar(VehicleID));
            return 1;
        }
        else return SendClientMessage(playerid, RED, "This vehicle does not belong to you!");
    }
    else return SendClientMessage(playerid, RED, "This is not a private vehicle!");
}
Like this?

EDIT: On compiling it says gives the following errors;
Quote:

error 017: undefined symbol "vehicleid"
error 017: undefined symbol "vehicleid"




Re: Cars don't lock when you do /lock - Riddy - 20.09.2012

You see, PAWN is case sensitive, so work it out yourself, of course you'd notice whats wrong if you use common sense..


Re: Cars don't lock when you do /lock - Luke_James - 21.09.2012

Actually, "vehicleid" is used elsewhere in my script, and it's lowercase.


Re: Cars don't lock when you do /lock - M3mPHi$_S3 - 21.09.2012

you should add this at the top of your script !!!!
pawn Код:
new vehicleid [ MAX_PLAYERS ];
pawn Код:
new vehicleid [ MAX_PLAYERS ];

command:(lock, playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "You must be in a vehicle to use this command!");

    new
        VehicleID = GetPlayerVehicleID(playerid);
       
    if(OwnedCar(VehicleID) != 0)
    {
        if(strmatch(Vehicles[OwnedCar(VehicleID)][VehicleOwner], pName(playerid)))
        {
            Vehicles[OwnedCar(VehicleID)][vLocked] = 1;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
            SendClientMessage(playerid, -1, "You've successfully locked your vehicle!");
            SaveOwnedCar(OwnedCar(VehicleID));
            return 1;
        }
        else return SendClientMessage(playerid, RED, "This vehicle does not belong to you!");
    }
    else return SendClientMessage(playerid, RED, "This is not a private vehicle!");
}
TRy now with this !!!


Re: Cars don't lock when you do /lock - mamorunl - 21.09.2012

Quote:
Originally Posted by мυ∂υℓ_вacнα
Посмотреть сообщение
you should add this at the top of your script !!!!
pawn Код:
new vehicleid [ MAX_PLAYERS ];
pawn Код:
new vehicleid [ MAX_PLAYERS ];

command:(lock, playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "You must be in a vehicle to use this command!");

    new
        VehicleID = GetPlayerVehicleID(playerid);
       
    if(OwnedCar(VehicleID) != 0)
    {
        if(strmatch(Vehicles[OwnedCar(VehicleID)][VehicleOwner], pName(playerid)))
        {
            Vehicles[OwnedCar(VehicleID)][vLocked] = 1;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, engine, lights, alarm, 0, bonnet, boot, objective);
            SendClientMessage(playerid, -1, "You've successfully locked your vehicle!");
            SaveOwnedCar(OwnedCar(VehicleID));
            return 1;
        }
        else return SendClientMessage(playerid, RED, "This vehicle does not belong to you!");
    }
    else return SendClientMessage(playerid, RED, "This is not a private vehicle!");
}
TRy now with this !!!
Oh my god,, so much fail. Don't ever try to fix your code like the way above, it will never work.

Luke: use the force! Seriously though, every variable is used differently. If you still can't tell global variables from local variables, then please refresh your coding course (also, PAWN is case sensitive as being told, that shouldve been enough of a hint).


Re: Cars don't lock when you do /lock - TaLhA XIV - 21.09.2012

You have a spelling mistake.


Re: Cars don't lock when you do /lock - clarencecuzz - 21.09.2012

pawn Код:
command(lock, playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, RED, "You must be in a vehicle to use this command!");
    new VehicleID = GetPlayerVehicleID(playerid);
    if(OwnedCar(VehicleID) != 0)
    {
        if(strmatch(Vehicles[OwnedCar(VehicleID)][VehicleOwner], pName(playerid)))
        {
            Vehicles[OwnedCar(VehicleID)][vLocked] = 1;
            GetVehicleParamsEx(VehicleID, engine, lights, alarm, doors, bonnet, boot, objective);
            if(doors == 0) return SendClientMessage(playerid, RED, "This Vehicle Is Already Locked.");
            SetVehicleParamsEx(VehicleID, engine, lights, alarm, 0, bonnet, boot, objective);
            SendClientMessage(playerid, -1, "You've successfully locked your vehicle!");
            SaveOwnedCar(OwnedCar(VehicleID));
        }
        else return SendClientMessage(playerid, RED, "This vehicle does not belong to you!");
    }
    else return SendClientMessage(playerid, RED, "This is not a private vehicle!");
    return 1;
}



Re: Cars don't lock when you do /lock - Luke_James - 21.09.2012

C:\Users\owner\Desktop\SCRP\Server Files\gamemodes\0.3.1.pwn(5592) : error 017: undefined symbol "engine"
C:\Users\owner\Desktop\SCRP\Server Files\gamemodes\0.3.1.pwn(5593) : error 017: undefined symbol "doors"
C:\Users\owner\Desktop\SCRP\Server Files\gamemodes\0.3.1.pwn(5594) : error 017: undefined symbol "engine"

Again, this is used in the script in other things