[URGENT HELP] /lock Command Problem
#1

Hi there,

First, I've got this command that I'm willing to compile with my script, so I understood some of the functions and variables there that I will change, but I really couldn't change one problem.

The command is locking the vehicle to everybody, and the owner have to type the command again to enter it.

So, What I want to do is to make the vehicle locks only to other players beside the owner [ownerid]

This is the Command :
Код:
CMD:pvlock(playerid, params[])
{
    new Float: x, Float: y, Float: z;
    if(PlayerInfo[playerid][pVehicleKeysFrom] != INVALID_PLAYER_ID)
	{
        new ownerid = PlayerInfo[playerid][pVehicleKeysFrom];
        if(IsPlayerConnected(ownerid))
		{
            new d = PlayerInfo[playerid][pVehicleKeys];
            if(PlayerVehicleInfo[ownerid][d][pvId] != INVALID_PLAYER_VEHICLE_ID) GetVehiclePos(PlayerVehicleInfo[ownerid][d][pvId], x, y, z);
            if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
			{
                if(PlayerVehicleInfo[ownerid][d][pvLock] > 0)
				{
                    if(PlayerVehicleInfo[ownerid][d][pvLocked] == 0)
					{
                        GameTextForPlayer(playerid,"~r~Vehicle Locked!",5000,6);
                        PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                        PlayerVehicleInfo[ownerid][d][pvLocked] = 1;
                        LockPlayerVehicle(ownerid, PlayerVehicleInfo[ownerid][d][pvId], PlayerVehicleInfo[ownerid][d][pvLock]);
                        return 1;
                    }
                    else
					{
                        GameTextForPlayer(playerid,"~g~Vehicle Unlocked!",5000,6);
                        PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                        PlayerVehicleInfo[ownerid][d][pvLocked] = 0;
                        UnLockPlayerVehicle(ownerid, PlayerVehicleInfo[ownerid][d][pvId], PlayerVehicleInfo[ownerid][d][pvLock]);
                        return 1;
                    }
                }
                else
				{
                    SendClientMessageEx(playerid, COLOR_GREY, " You don't have a lock system installed on this vehicle.");
                    return 1;
                }
            }
        }
    }
    for(new d = 0 ; d < MAX_PLAYERVEHICLES; d++)
    {
        if(PlayerVehicleInfo[playerid][d][pvId] != INVALID_PLAYER_VEHICLE_ID) GetVehiclePos(PlayerVehicleInfo[playerid][d][pvId], x, y, z);
        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
		{
            if(PlayerVehicleInfo[playerid][d][pvLock] > 0 && PlayerVehicleInfo[playerid][d][pvLocked] == 0)
			{
                GameTextForPlayer(playerid,"~r~Vehicle Locked!",5000,6);
                PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                PlayerVehicleInfo[playerid][d][pvLocked] = 1;
                LockPlayerVehicle(playerid, PlayerVehicleInfo[playerid][d][pvId], PlayerVehicleInfo[playerid][d][pvLock]);
                return 1;
            }
            else if(PlayerVehicleInfo[playerid][d][pvLock] > 0 && PlayerVehicleInfo[playerid][d][pvLocked] == 1)
			{
                GameTextForPlayer(playerid,"~g~Vehicle Unlocked!",5000,6);
                PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                PlayerVehicleInfo[playerid][d][pvLocked] = 0;
                UnLockPlayerVehicle(playerid, PlayerVehicleInfo[playerid][d][pvId], PlayerVehicleInfo[playerid][d][pvLock]);
                return 1;

            }
            SendClientMessageEx(playerid, COLOR_GREY, " You don't have a lock system installed on this vehicle.");
            return 1;
        }
    }
    SendClientMessageEx(playerid, COLOR_GREY, " You are not near any vehicle that you own.");
    return 1;
}
Can you please help me with that ?! I would be very thankful.
THANKS in advance.


P.S: This PvLock doesn't work unless you buy it from 24/7, that's what if(PlayerVehicleInfo[ownerid][d][pvLock] > 0) means ^^ .
Reply
#2

Use OnPlayerEnterVehicle/OnPlayerStateChange callback to check if player who is entering the vehicle is the vehicle owner, then unlock it.
Reply
#3

Oh yeah ..
Emm I think there is a better way ..
This is a command that I found in wiki.sa-mp.com, and I think it would be better if I could merge between them using the 'foreach' loop.

Код:
// Locks own car for all players, except the player who used the command.
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext,"/lock",true)) 
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFFFFFFAA,"You have to be inside a vehicle.");
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            if(i == playerid) continue;
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,0,1);
        }
        return 1;
    }
    return 0;
}

Emm.. What do you think is better, then if this is better, please help me get this into that command (/pvlock).
Thanks Agaiin !
Reply
#4

SOLVED.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)