Problems with 2 commands!
#1

To make this fast:

I've created a lock command, which allows a player to lock his vehicle and prevent other players to get in it until the player has unlocked it! Unfortunately, players still can get in:

pawn Код:
COMMAND:lock(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][VIPlevel] >= 2)
    {
        if(VehicleLocked[playerid] == 1) return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle is already locked!");
        if(IsPlayerInAnyVehicle(playerid))
        {
            VehicleLocked[playerid] = 1;
            new name[MAX_PLAYER_NAME], string[ 128 ], string2[ 128 ];
            GetPlayerName(playerid, name, sizeof(name));
            format(string, sizeof(string), "|| Administrator %s has locked his vehicle! ||", name);
            format(string2, sizeof(string2), "|| You have successfully locked your vehicle! ||");
            SendClientMessageToAll(COLOR_LIGHTBLUE, string);
            SendClientMessage(playerid, TEAM_GROVE_COLOR, string2);

        }
        else return SendClientMessage(playerid, COLOR_RED, "You need to be in a vehicle to lock it!");
    }
    else return SendClientMessage(playerid, COLOR_RED, "You need to be an level 2 admin or level 2 VIP to use this command!");
    return 1;
}
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
                        //=========================[LOCKING]============================================
            VehicleLocked[playerid] = 0;
            if(VehicleLocked[playerid] == 1)
            {
                //new name[MAX_PLAYER_NAME];
                //GetPlayerName(playerid, name, sizeof(name));
                if(playerid != playerid) return SendClientMessage(playerid, COLOR_RED, "This vehicle has been locked!");
                RemovePlayerFromVehicle(playerid);
            }
               
        return 1;
    }
My second command is the jailcommand, which works fine! But only when the player should get unjailed, he spawns somewhere in the sky! He should get spawned normally:

pawn Код:
CMD:jail(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            new targetid, minutes;
            if(sscanf(params, "ui", targetid, minutes)) return SendClientMessage(playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>");
            if(minutes <= 0 || minutes > 60) return SendClientMessage(playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!");
            //if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You can't jail yourself!");
            //if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_RED, "You can't jail higher level admins!");
            if(!IsPlayerConnected(targetid))
                return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");
            else
            {
                new str[128];
                format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", Name(playerid), Name(targetid), minutes);
                SendClientMessageToAll(COLOR_LIGHTBLUE,str);
                JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false);
                SetPlayerPos(targetid, 264.4176, 77.8930, 1001.0391);
                SetPlayerInterior(targetid, 6);
                inJail[targetid] = true;
                GameTextForPlayer(targetid, "~p~JAILED", 10000, 6);
                PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
            }
        }
        else return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!");
        return 1;
    }
pawn Код:
forward Unjail(playerid);
public Unjail(playerid)
{
    SpawnPlayer(playerid);
    SetPlayerInterior(playerid, 0);
    inJail[playerid] = false;
    KillTimer(JailTimer[playerid]);
    GameTextForPlayer(playerid, "~g~Unjailed", 5000, 6);
    PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
}
Reply
#2

I commented the VehicleLocked[playerid] = 0; line. Your setting the locked vehicle to 0, once they try to enter it, so therefore, unlocking it.

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
    {
                        //=========================[LOCKING]============================================
            VehicleLocked[playerid] = 0; // Remove this!
            if(VehicleLocked[playerid] == 1)
            {
                //new name[MAX_PLAYER_NAME];
                //GetPlayerName(playerid, name, sizeof(name));
                if(playerid != playerid) return SendClientMessage(playerid, COLOR_RED, "This vehicle has been locked!");
                RemovePlayerFromVehicle(playerid);
            }
               
        return 1;
    }
Reply
#3

I think this line
JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false);
should be changed to
JailTimer[targetid] = SetTimerEx("Unjail", minutes*60*1000, false,"d",targetid);
Reply
#4

JAIL CMD:

Top of script:
pawn Код:
new LastPos[2];
pawn Код:
CMD:jail(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            new targetid, minutes;
            if(sscanf(params, "ui", targetid, minutes)) return SendClientMessage(playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>");
            if(minutes <= 0 || minutes > 60) return SendClientMessage(playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!");
            //if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You can't jail yourself!");
            //if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_RED, "You can't jail higher level admins!");
            if(!IsPlayerConnected(targetid))
                return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");
            else
            {
                new str[128];
                format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", Name(playerid), Name(targetid), minutes);
                new Float: pX, Float: pY, Float: pZ;
                GetPlayerPos(playerid, pX, pY, pZ);
                LastPos[0] = pX;
                LastPos[1] = pY;
                LastPos[2] = pZ;
                SendClientMessageToAll(COLOR_LIGHTBLUE,str);
                JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false);
                SetPlayerPos(targetid, 264.4176, 77.8930, 1001.0391);
                SetPlayerInterior(targetid, 6);
                inJail[targetid] = true;
                GameTextForPlayer(targetid, "~p~JAILED", 10000, 6);
                PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
            }
        }
        else return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!");
        return 1;
    }
pawn Код:
forward Unjail(playerid);
public Unjail(playerid)
{
    SetPlayerPos(playerid, LastPos[0], LastPos[1], LastPos[2]);
    SetPlayerInterior(playerid, 0);
    inJail[playerid] = false;
    KillTimer(JailTimer[playerid]);
    GameTextForPlayer(playerid, "~g~Unjailed", 5000, 6);
    PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
}
Reply
#5

Add bool:cLocked to your player info enum.

We add it to the enum instead of just creating a new cLocked[MAX_PLAYERS] as that's just creating a brand new array...
We can just use the array we've already created.

pawn Код:
COMMAND:lock(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2 || PlayerInfo[playerid][VIPlevel] >= 2)
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new cID = GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective,string[20];
            GetVehicleParamsEx(cID,engine,lights,alarm,doors,bonnet,boot,objective);
            if(PlayerInfo[playerid][cLocked])
            {
                PlayerInfo[playerid][cLocked] = true;
                SetVehicleParamsEx(cID,engine,lights,alarm,1,bonnet,boot,objective);
                format(string, sizeof(string), "Vehicle locked.");
            }
            else
            {
                PlayerInfo[playerid][cLocked] = false;
                SetVehicleParamsEx(cID,engine,lights,alarm,0,bonnet,boot,objective);
                format(string, sizeof(string), "Vehicle unlocked.");
            }
            SendClientMessage(playerid, TEAM_GROVE_COLOR, string);
        }
        else return SendClientMessage(playerid, COLOR_RED, "You need to be in a vehicle to lock it!");
    }
    else return SendClientMessage(playerid, COLOR_RED, "You need to be an level 2 admin or level 2 VIP to use this command!");
    return 1;
}


For the jail command...

pawn Код:
new Float:PreJailPos[MAX_PLAYERS][6];

CMD:jail(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
        new targetid, minutes;
        if(sscanf(params, "ui", targetid, minutes)) return SendClientMessage(playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>");
        if(minutes <= 0 || minutes > 60) return SendClientMessage(playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!");
        //if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You can't jail yourself!");
        //if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_RED, "You can't jail higher level admins!");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected!");
        new str[128];
        format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", Name(playerid), Name(targetid), minutes);
        SendClientMessageToAll(COLOR_LIGHTBLUE,str);
        JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false);
        //---
        GetPlayerPos(targetid, PreJailPos[targetid][0], PreJailPos[targetid][1], PreJailPos[targetid][2]);
        GetPlayerFacingAngle(targetid, PreJailPos[targetid][3]);
        PreJailPos[targetid][4] = GetPlayerInterior(targetid);
        PreJailPos[targetid][5] = GetPlayerVirtualWorld(targetid);
        //---
        SetPlayerPos(targetid, 264.4176, 77.8930, 1001.0391);
        SetPlayerInterior(targetid, 6);
        inJail[targetid] = true;
        GameTextForPlayer(targetid, "~p~JAILED", 10000, 6);
        PlayerPlaySound(targetid,1057,0.0,0.0,0.0);
    }
    else return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!");
    return 1;
}
forward Unjail(playerid);
public Unjail(playerid)
{
    SetPlayerInterior(playerid, 0);
    inJail[playerid] = false;
    KillTimer(JailTimer[playerid]);
    GameTextForPlayer(playerid, "~g~Unjailed", 5000, 6);
    PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
    //---
    SetPlayerVirtualWorld(playerid, PreJailPos[playerid][5]);
    SetPlayerInterior(playerid, PreJailPos[playerid][4])
    SetPlayerPos(playerid, PreJailPos[playerid][0], PreJailPos[playerid][1], PreJailPos[playerid][2]);
    SetPlayerFacingAngle(playerid, PreJailPos[playerid][3]);
    //---
}
As you can see, we created a new array to store our players pre-jail position. Then we restore that position when they're free.
Reply
#6

I'm always getting the message "Vehicle unlocked." when I'm using "/lock" now!
Reply
#7

my bad change

if(PlayerInfo[playerid][cLocked])

to

if(!PlayerInfo[playerid][cLocked])
Reply
#8

Hmm, the messages are alright now, but when I lock my car and wanna enter it, I can't! The permission should be for the player who locked this car, only other players can't enter it, I myself should be able to!

EDIT:

Oh, and I'm also getting a tag-mismatch warning at these two lines:

pawn Код:
SetPlayerVirtualWorld(playerid, PreJailPos[playerid][5]);
    SetPlayerInterior(playerid, PreJailPos[playerid][4]);
The functions gotta be used in another way, I just forgot how, lol!
Reply
#9

probably variable PreJailPos is float, as i see in other posts, could you post all code? i am maybe wrong, hard to understand without seeing those things.
Reply
#10

pawn Код:
SetPlayerVirtualWorld(playerid, PreJail[playerid][0]);
SetPlayerInterior(playerid, PreJail[playerid][1]);
add

pawn Код:
new PreJail[MAX_PLAYERS][2] //under the other PreJail define then change the getplayerVW and int to this one
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)