SA-MP Forums Archive
/lock and /unlock - 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: /lock and /unlock (/showthread.php?tid=551837)



/lock and /unlock - ATGOggy - 21.12.2014

This is a command that lock doors:
PHP код:
// /lock
    
if(strcmp(cmdtext"/lock"true20) == 0)
    {
        if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: You are not in any vehicle.");
        if(
GetPlayerState(playerid)==PLAYER_STATE_PASSENGER) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: Only drivers can lock car doors.");
        for(new 
i=0i<MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                if(
PlayerInfo[i][pAdmin]<5)
                {
                    
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i01);
                    
doorslocked[playerid]=1;
                }
            }
        }
        
SendClientMessage(playeridCOLOR_YELLOW"Doors locked.");
        return 
1;
    }
// /unlock
    
if(strcmp(cmdtext"/unlock"true20) == 0)
    {
        if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: You are not in any vehicle.");
        if(
GetPlayerState(playerid)==PLAYER_STATE_PASSENGER) return SendClientMessage(playeridCOLOR_ORANGE"ERROR: Only drivers can unlock car doors.");
        for(new 
i=0i<MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i))
            {
                
SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i00);
                
doorslocked[playerid]=0;
            }
        }
        
SendClientMessage(playeridCOLOR_YELLOW"Doors unlocked.");
        return 
1;
    } 
But, it's not working. All can enter the car if its doors are locked too.

Someone, please help me.

rep++;


Re: /lock and /unlock - Write - 21.12.2014

pawn Код:
if(strcmp(cmdtext, "/lock", true, 20) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You are not in any vehicle.");
        if(GetPlayerState(playerid)==PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Only drivers can lock car doors.");
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(PlayerInfo[i][pAdmin]<5)
                {
                    SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, 1, bonnet, boot, objective);
                    doorslocked[playerid]=1;
                }
            }
        }
        SendClientMessage(playerid, COLOR_YELLOW, "Doors locked.");
        return 1;
    }

// /unlock
    if(strcmp(cmdtext, "/unlock", true, 20) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You are not in any vehicle.");
        if(GetPlayerState(playerid)==PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Only drivers can unlock car doors.");
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                SetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, 0, bonnet, boot, objective);
                doorslocked[playerid]=0;
            }
        }
        SendClientMessage(playerid, COLOR_YELLOW, "Doors unlocked.");
        return 1;
    }



Re: /lock and /unlock - ATGOggy - 21.12.2014

Thank you
rep++;


Re: /lock and /unlock - ATGOggy - 21.12.2014

It is not working.
Someone please help.


Re: /lock and /unlock - Sew_Sumi - 21.12.2014

pawn Код:
doorslocked[playerid]=1;
One problem lies there... You're locking the playerid not the vehicle ID.

You need to review your code more... There's no doubt simple mistakes such as this.

Also go back to using SetVehicleParamsForPlayer, and doing all the user IDs,

Then


pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
        if(doorslocked[vehicleid]==1)
        {
        SetVehicleParamsForPlayer(vehicleid,forplayerid,0,1);
        }
}



Re: /lock and /unlock - ATGOggy - 21.12.2014

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
pawn Код:
doorslocked[playerid]=1;
One problem lies there... You're locking the playerid not the vehicle ID.

You need to review your code more... There's no doubt simple mistakes such as this.

Also go back to using SetVehicleParamsForPlayer, and doing all the user IDs,

Then


pawn Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
        if(lockstate[vehicleid]==1)
        {
        SetVehicleParamsForPlayer(vehicleid,forplayerid,0,1);
        }
}
I'm using that variable to only make the doors unlock after the player exit vehicle.
That variable has got nothing else to do with this.


Re: /lock and /unlock - Sew_Sumi - 21.12.2014

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
I'm using that variable to only make the doors unlock after the player exit vehicle.
That variable has got nothing else to do with this.
Even though that variable has nothing to do with this, the variable is redundant...

you'd be better off making that the vehicles lock state, and using that to make the script set the vehicles lock status correctly.

Using SetVehicleParamsEx is a decent way, but it has several other options to set, when really, all you want to do is lock the doors.

I'm unsure how the streaming situation goes now... All my scripts for locks still work as intended, yet I use SetVehicleParams. They also update in OnVehicleStreamIn.



Could this....

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
I'm using that variable to only make the doors unlock after the player exit vehicle.
Also have something to do with it?


You gotta debug your code, pasting a portion in only gets what you got... A dude who copies and pastes a "quick fix" that has issues in it, inherent from your original bugs, which, more than likely, have more bugs that attribute to this.


Post up your OnPlayerStateChange relevant to your locks...

Also use pastebin with a short expiry (30day or less)


Respuesta: /lock and /unlock - JuanStone - 22.12.2014

pawn Код:
new vehicle_loock[MAX_PLAYERS]; // Note: This variable must be in 0 when you spawn to a vehicle.

if(strcmp(cmdtext, "/lock", true, 20) == 0)
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You are not in any vehicle.");
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Only drivers can lock car doors.");
    if(vehicle_loock[GetPlayerVehicleID(playerid)] == 1) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Your vehicle is already locked.");
   
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pAdmin] <5)
            {
                if(i != playerid)
                {
                    SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i, 0, 1);
                    vehicle_loock[GetPlayerVehicleID(playerid)] = 1;
                }
            }
        }
    }
    SendClientMessage(playerid, COLOR_YELLOW, "Doors locked.");
    return 1;
}

if(strcmp(cmdtext, "/unlock", true, 20) == 0)
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: You are not in any vehicle.");
    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Only drivers can unlock car doors.");
    if(vehicle_loock[GetPlayerVehicleID(playerid)] == 0) return SendClientMessage(playerid, COLOR_ORANGE, "ERROR: Your vehicle is not blocked.");

    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(i != playerid)
            {
                SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i, 0, 0);
                vehicle_loock[GetPlayerVehicleID(playerid)] = 0;
            }
        }
    }
    SendClientMessage(playerid, COLOR_YELLOW, "Doors unlocked.");
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid) //When you exit the vehicle will automatically unlock.
{
    if(vehicle_loock[GetPlayerVehicleID(playerid)] == 1)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i, 0, 0);
        }
        vehicle_loock[GetPlayerVehicleID(playerid)] = 0;
    }
    return true;
}



Re: Respuesta: /lock and /unlock - Sew_Sumi - 22.12.2014

Quote:
Originally Posted by JuanStone
Посмотреть сообщение
pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid) //When you exit the vehicle will automatically unlock.
{
    if(vehicle_loock[GetPlayerVehicleID(playerid)] == 1)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid), i, 0, 0);
        }
        vehicle_loock[GetPlayerVehicleID(playerid)] = 0;
    }
    return true;
}
Don't just post up code.

He needs to give more info instead of blindly ++reping people who also paste up code...


Re: /lock and /unlock - ATGOggy - 02.01.2015

I found out my own ways. Thank your for your help.