Vehicle Lock Stream
#1

Hello Everyone,

I am working on a Vehicle System. I coded this command to lock the car if Vehicle[vehid][vLocked] is equal to 0. And unlocks it if the Vehicle[vehid][vLocked] is on 1. Here is the part of the command needed.

pawn Код:
COMMAND:vehicle(playerid, params[])
{
    new cmd[30], string[128];
    if (sscanf(params, "s ", cmd) != 0)
    {
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /vehicle <purchase | park | sell | lock>");
    }
    if (strcmp("lock", cmd, true, 8) == 0)
    {
        new vehicleid = GetClosestVehicle(playerid);
        if(IsPlayerInRangeOfVehicle(playerid, vehicleid, 20.0))
        {
            if(isVehicleOwner(vehicleid, playerid))
            {
                new lock;
                lock = Vehicle[vehicleid][vLocked];
                if(lock == 0)
                {
                    if(Vehicle[vehicleid][vLocked] != 1)
                    {
                        for(new j=0; j < MAX_PLAYERS; j++)
                        {
                            SetVehicleParamsForPlayer(vehicleid,j,0,1);
                        }
                        Vehicle[vehicleid][vLocked] = 1;
                        printf("[SAVE1] Vehicle Locked = %d",Vehicle[vehicleid][vLocked]);
                        format(query, sizeof(query), "UPDATE `Vehicle` SET `locked` = '%d' WHERE `id` = '%d'",Vehicle[vehicleid][vLocked],vehicleid);
                        db_free_result(db_query(database,query));
                        SendClientMessage(playerid, COLOR_YELLOW,"<!> You have successfully locked your Car.");
                    }
                }
                else
                {
                    if(Vehicle[vehicleid][vLocked] != 0)
                    {
                        for(new j=0; j < MAX_PLAYERS; j++)
                        {
                            SetVehicleParamsForPlayer(vehicleid,j,0,0);
                        }
                        Vehicle[vehicleid][vLocked] = 0;
                        printf("[SAVE1] Vehicle Locked = %d",Vehicle[vehicleid][vLocked]);
                        format(query, sizeof(query), "UPDATE `Vehicle` SET `locked` = '%d' WHERE `id` = '%d'",Vehicle[vehicleid][vLocked],vehicleid);
                        db_free_result(db_query(database,query));
                        SendClientMessage(playerid, COLOR_YELLOW,"<!> You have successfully unlocked your Car.");
                    }
                }
            }
            else return SendClientMessage(playerid, COLOR_RED,"<!> You dont have the authorised keys.");
        }
        else return SendClientMessage(playerid, COLOR_RED,"<!> There is no vehicle in range to unlock.");
    }
        return true;
}

Everything is fine. But the only problem i face is: Whenever i join the game , go near my owned vehicle and Press F. I find it locked if Vehicle[vehicleid][vLocked] = 1, Thats amazing works nice for Player-Vehicle Stream!

But when i use this command in front of it the first time. It locks the vehicle again! Even though it should unlock it.


It happens only the first time when you login. It locks the vehicle which is already locked but it should unlock. And when we enter the command again, it works fine after that. It locks the vehicle if the var is 0 and unlocks if the var is 1.


Any suggestions? Please help. Thanks for reading

- Ballu Miaa
Reply
#2

You need to update the vehicle params for player when vehicle streams in

pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    SetVehicleParamsForPlayer(vehicleid,forplayerid,0,Vehicle[vehicleid][vLocked]);
    return 1;
}
Reply
#3

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
You need to update the vehicle params for player when vehicle streams in

pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    SetVehicleParamsForPlayer(vehicleid,forplayerid,0,Vehicle[vehicleid][vLocked]);
    return 1;
}
I have already updated the vehicle params for the playerid. But still it first locks the vehicle when using the command.
(At the same time: Car is locked but it gets locked again when using the command just after logging in)
Reply
#4

Quote:
Originally Posted by Ballu Miaa
Посмотреть сообщение
I have already updated the vehicle params for the playerid.
When vehicle was streamed in for the player?
Reply
#5

Yes!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)