Making a command to lock/unlock the owners car in a radius.
#1

Hey all,

I'm trying to make a command that will allow the user to lock/unlock their vehicle within a small radius of the car they own but i'm having trouble getting the radius to work, the player can lock/unlock their vehicle when they are sat inside it, but not outside, here's the code I have right now:

Код:
command(lock, playerid, params[])
{
	new Float:cX, Float:cY, Float:cZ;
	new vehicleid = GetPlayerVehicleID(playerid);
	GetVehiclePos(vehicleid, cX, cY, cZ);
	new string[128];
	new engine,lights,alarm,doors,bonnet,boot,objective;
	GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
	if(IsPlayerInRangeOfPoint(playerid, 4, cX, cY, cZ))
    {
        if(doors == 1)
        {
            doors = 1;
            SetVehicleParamsEx(vehicleid,engine,lights,alarm,VEHICLE_PARAMS_OFF,bonnet,boot,objective);
            format(string, sizeof(string), "{9d21ad}* %s unlocks the vehicle.", GetName(playerid));
            NearByMessage(playerid, NICESKY, string);
            return 1;
        }
        else
        {
            doors = 0;
	        SetVehicleParamsEx(vehicleid,engine,lights,alarm,VEHICLE_PARAMS_ON,bonnet,boot,objective);
	        format(string, sizeof(string), "{9d21ad}* %s locks the vehicle.", GetName(playerid));
	        NearByMessage(playerid, NICESKY, string);
	        return 1;
        }
    }
	else if(!IsPlayerInRangeOfPoint(playerid, 4, cX, cY, cZ))
		{
		    SendClientMessage(playerid, WHITE, "You are not near a vehicle!");
		    return 1;
		}
	return doors;
}
Any help with this would be greatly appreciated!
Reply
#2

You need to finish your command with returning 1 if I'm right.
Код:
return doors -> return 1;
EDIT:
Also, function GetPlayerVehicleID only work if player is in any vehicle. That's why your command is working only when the player is in the car. You need to create a vehicle when the player joins the server and then save vehicleid to your variable. For example:
pawn Код:
enum pInfo
{
     pVehModel,
     pVehicle
};
new PlayerData[MAX_PLAYERS][pInfo];
// under on player connect
if(PlayerData[playerid][pVehModel])
     pVehicle = CreateVehicle(...);

// and in your command
GetVehiclePos(PlayeData[playerid][pVeh], x, y, z);
If(IsPlayerInRangeOfPoint(playerid, 4, x, y, z))
...
Reply
#3

Quote:
Originally Posted by dominik523
Посмотреть сообщение
You need to finish your command with returning 1 if I'm right.
Код:
return doors -> return 1;
This doesn't make much difference, I still have the same problem as I was having before.
Reply
#4

Quote:
Originally Posted by dominik523
Посмотреть сообщение
EDIT:
Also, function GetPlayerVehicleID only work if player is in any vehicle. That's why your command is working only when the player is in the car. You need to create a vehicle when the player joins the server and then save vehicleid to your variable. For example:
pawn Код:
enum pInfo
{
     pVehModel,
     pVehicle
};
new PlayerData[MAX_PLAYERS][pInfo];
// under on player connect
if(PlayerData[playerid][pVehModel])
     pVehicle = CreateVehicle(...);

// and in your command
GetVehiclePos(PlayeData[playerid][pVeh], x, y, z);
If(IsPlayerInRangeOfPoint(playerid, 4, x, y, z))
...
This worked, thanks for the help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)