Engine command not working
#1

pawn Код:
command(engine, playerid, params[])
{
    new engine,lights,alarm,doors,bonnet,boot,objective;
    new vehicle, seat;
    vehicle = GetPlayerVehicleID(playerid);
    seat = GetPlayerVehicleSeat(playerid);
    GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
    if(seat == 0) {
        if(engine == 0) {
            if(GetPlayerVehicleID(playerid) == Player[playerid][CarLinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car2LinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car3LinkID])
            {
                SetVehicleParamsEx(vehicle,1,lights,alarm,doors,bonnet,boot,objective);
            } else {
                SendClientMessage(playerid, WHITE, "You don't have the keys to this vehicle.");
            }
        }
        if(engine == 1) {
            if(GetPlayerVehicleID(playerid) == Player[playerid][CarLinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car2LinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car3LinkID])
            {
                SetVehicleParamsEx(vehicle,0,lights,alarm,doors,bonnet,boot,objective);
            } else {
                SendClientMessage(playerid, WHITE, "You don't have the keys to this vehicle.");
            }
        }
    } else {
        SendClientMessage(playerid, WHITE, "You must be in the driver's seat to start the engine.");
    }
    return 1;
}
Here's my /lock command, I based it off of that:
pawn Код:
command(lock, playerid, params[])
{
    new engine,lights,alarm,doors,bonnet,boot,objective;
    new vehslot;
    if(sscanf(params, "d", vehslot))
    {
        SendClientMessage(playerid, WHITE, "SYNTAX: /lock [1-3]");
    }
    else
    {
        switch(vehslot)
        {
            case 1:
            {
                if(Player[playerid][PlayerCarModel] > 0)
                {
                    if(IsPlayerInRangeOfVehicle(playerid, Player[playerid][CarLinkID], 10))
                    {
                        if(Player[playerid][CarLinkID] > 0)
                        {
                            GetVehicleParamsEx(Player[playerid][CarLinkID],engine,lights,alarm,doors,bonnet,boot,objective);
                            if(doors == 0)
                            {
                                SendClientMessage(playerid, WHITE, "You have locked your vehicle.");
                                SetVehicleParamsEx(Player[playerid][CarLinkID],engine,lights,alarm,1,bonnet,boot,objective);
                                return 1;
                            }
                            else
                            {
                                SetVehicleParamsEx(Player[playerid][CarLinkID],engine,lights,alarm,0,bonnet,boot,objective);
                                SendClientMessage(playerid, WHITE, "You have un-locked your vehicle.");
                                return 1;
                            }
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid, WHITE, "You're too far away.");
                    }
                }
            }
            case 2:
            {
                if(Player[playerid][PlayerCarModel2] > 0)
                {
                    if(IsPlayerInRangeOfVehicle(playerid, Player[playerid][Car2LinkID], 10))
                    {
                        if(Player[playerid][Car2LinkID] > 0)
                        {
                            GetVehicleParamsEx(Player[playerid][Car2LinkID],engine,lights,alarm,doors,bonnet,boot,objective);
                            if(doors == 0)
                            {
                                SendClientMessage(playerid, WHITE, "You have locked your vehicle.");
                                SetVehicleParamsEx(Player[playerid][Car2LinkID],engine,lights,alarm,1,bonnet,boot,objective);
                                return 1;
                            }
                            else
                            {
                                SetVehicleParamsEx(Player[playerid][Car2LinkID],engine,lights,alarm,0,bonnet,boot,objective);
                                SendClientMessage(playerid, WHITE, "You have un-locked your vehicle.");
                                return 1;
                            }
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid, WHITE, "You're too far away.");
                    }
                }
            }
            case 3:
            {
                if(Player[playerid][PlayerCarModel3] > 0)
                {
                    if(IsPlayerInRangeOfVehicle(playerid, Player[playerid][Car3LinkID], 10))
                    {
                        if(Player[playerid][Car3LinkID] > 0)
                        {
                            GetVehicleParamsEx(Player[playerid][Car3LinkID],engine,lights,alarm,doors,bonnet,boot,objective);
                            if(doors == 0)
                            {
                                SendClientMessage(playerid, WHITE, "You have locked your vehicle.");
                                SetVehicleParamsEx(Player[playerid][Car3LinkID],engine,lights,alarm,1,bonnet,boot,objective);
                                return 1;
                            }
                            else
                            {
                                SetVehicleParamsEx(Player[playerid][Car3LinkID],engine,lights,alarm,0,bonnet,boot,objective);
                                SendClientMessage(playerid, WHITE, "You have un-locked your vehicle.");
                                return 1;
                            }
                        }
                    }
                    else
                    {
                        SendClientMessage(playerid, WHITE, "You're too far away.");
                    }
                }
            }
        }
    }
    return 1;
}
Now, I type /lock 1 and it unlocks it, /lock 1 and it locks it again.
But, I type /engine outside of the car and it says "You must be in the driver's seat to start the engine.", so I get in and type it and nothing happens. Help please?
Reply
#2

Well, switch doesn't counts from 1. But basically from 0
Like this:
pawn Код:
info = Me, You, Them;
switch(info)
{
case 0:Me // 0
case 1:You //
case 2:Them
}
You're starting from 1. You should start from 0. Instead 1, 2, 3, it'd had to be: 0,1,2
Reply
#3

No, the switch doesn't always start from 0, it starts from whatever I start it from. And the lock command functions fine, it's my other command that doesn't (/engine).
Reply
#4

Bump, I need help on this.
Reply
#5

Bump, I need help with this.
Reply
#6

Change
pawn Код:
if(seat == 0)
to
pawn Код:
if(seat == 1)
Reply
#7

No, you are wrong.
Reply
#8

try this:
pawn Код:
command(engine, playerid, params[])
    {
        new engine,lights,alarm,doors,bonnet,boot,objective;
        new vehicle = GetPlayerVehicleID(playerid);
        GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, WHITE, "You must be in the driver's seat to start the engine.");
        if(engine == 0)
        {
            if(GetPlayerVehicleID(playerid) == Player[playerid][CarLinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car2LinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car3LinkID])
            {
                SetVehicleParamsEx(vehicle,1,lights,alarm,doors,bonnet,boot,objective);
            } else {
                SendClientMessage(playerid, WHITE, "You don't have the keys to this vehicle.");
            }
        }
        else if(engine == 1)
        {
            if(GetPlayerVehicleID(playerid) == Player[playerid][CarLinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car2LinkID] || GetPlayerVehicleID(playerid) == Player[playerid][Car3LinkID])
            {
                SetVehicleParamsEx(vehicle,0,lights,alarm,doors,bonnet,boot,objective);
            } else {
                SendClientMessage(playerid, WHITE, "You don't have the keys to this vehicle.");
            }
        }
        return 1;
}
Reply
#9

Nope, that doesn't work.
Reply
#10

Bump.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)