SetVehicleParamsEx
#1

As seen in the video:

ww.youtube.com/watch?v=z75GCjRS9PI

I gotta use the command twice to open the hood, and twice to turn on lights and twice to open trunk.


Any idea why?

pawn Код:
CMD:car(playerid, params[])
{
    new Option[32];
    new vid = GetPlayerVehicleID(playerid);
    if(sscanf(params, "s[32]", Option)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /car [Engine/Lights/Hood/Trunk/Speedo]");
    new eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective;
    GetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
    {
        if(strcmp(Option, "engine", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && pData[playerid][TurnKey] == 0)
            {
               
                if(eengine == 0)
                {
                    new TextString[128];
                    format(TextString, sizeof TextString,"* %s turns the vehicle key, attempting to start the vehicle.",RemoveUnderLine(GetName(playerid)));
                    ProxDetector(30, playerid, TextString, COLOR_RPPURPLE);
                    pData[playerid][TurnKey] = 1;
                    pvCar[playerid][EngineTimer] = SetTimerEx("EngineOn", 3000, false, "i", playerid);
                }
                else
                {
                    SetVehicleParamsEx(vid,0,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                    new TextString[128];
                    format(TextString, sizeof TextString,"* %s turns the vehicle key, Turning the vehicle off.",RemoveUnderLine(GetName(playerid)));
                    ProxDetector(30, playerid, TextString, COLOR_RPPURPLE);
                }
            }
        }
        if(strcmp(Option, "lights", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(llights == 0)
                {

                    SetVehicleParamsEx(vid,eengine,1,aalarm,ddoors,bbonnet,bboot,oobjective);
                }
                else
                {

                    SetVehicleParamsEx(vid,eengine,0,aalarm,ddoors,bbonnet,bboot,oobjective);
                }
            }
        }
        if(strcmp(Option, "trunk", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(bboot == 0)
                {


                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,1,oobjective);
                }
                else
                {


                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,0,oobjective);
                }
            }
        }
        if(strcmp(Option, "hood", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(bbonnet == 0)
                {

                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,1,bboot,oobjective);
                }
                else
                {

                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,0,bboot,oobjective);
                }
            }
        }
    }
    return 1;
}
Reply
#2

i didnt check the code ..but i noticed that you have the same things there,try this:,if it doesnt work tell me and i will check it
pawn Код:
CMD:car(playerid, params[])
{
    new Option[32];
    new vid = GetPlayerVehicleID(playerid);
    if(sscanf(params, "s[32]", Option)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /car [Engine/Lights/Hood/Trunk/Speedo]");
    new eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective;
    GetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
    {
        if(strcmp(Option, "engine", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && pData[playerid][TurnKey] == 0)
            {
               
                if(eengine == 0)
                {
                    new TextString[128];
                    format(TextString, sizeof TextString,"* %s turns the vehicle key, attempting to start the vehicle.",RemoveUnderLine(GetName(playerid)));
                    ProxDetector(30, playerid, TextString, COLOR_RPPURPLE);
                    pData[playerid][TurnKey] = 1;
                    pvCar[playerid][EngineTimer] = SetTimerEx("EngineOn", 3000, false, "i", playerid);
                }
                else
                {
                    SetVehicleParamsEx(vid,0,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                    new TextString[128];
                    format(TextString, sizeof TextString,"* %s turns the vehicle key, Turning the vehicle off.",RemoveUnderLine(GetName(playerid)));
                    ProxDetector(30, playerid, TextString, COLOR_RPPURPLE);
                }
            }
        }
        if(strcmp(Option, "lights", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(llights == 0)
                {
                    SetVehicleParamsEx(vid,eengine,1,aalarm,ddoors,bbonnet,bboot,oobjective);
                }
                else
                {
                    SetVehicleParamsEx(vid,eengine,0,aalarm,ddoors,bbonnet,bboot,oobjective);
                }
            }
        }
        if(strcmp(Option, "trunk", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(bboot == 0)
                {

                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,1,oobjective);
                }
                else
                {

                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,0,oobjective);
                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,0,oobjective);
                }
            }
        }
        if(strcmp(Option, "hood", true) == 0)
        {
            if(IsPlayerInAnyVehicle(playerid) == 1 && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(bbonnet == 0)
                {
                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,1,bboot,oobjective);
                }
                else
                {
                    SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,0,bboot,oobjective);
                }
            }
        }
    }
    return 1;
}
Reply
#3

I added extra SetVehicleParamEx's to see if that would fix it, but it didn't.
Reply
#4

well well ^^

just use else if
instead of

if(strcm....
if(strcm...
and so on

do

if(strcm...
else if(str....

and at the end

else Sendcl..... Invalid option

see, i used this to test it and it works.
You setup the control structure for the options in an invalid way


the code:
pawn Код:
YCMD:car(playerid, params[], help)
{
    new Option[32];//isn't that too much? 6 would do the trick :) well, it's your code
    new vid = GetPlayerVehicleID(playerid);
    if(sscanf(params, "s[32]", Option)) return SendClientMessage(playerid, -1, "Usage: /car [Engine/Lights/Hood/Trunk/Speedo]");
    new eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective;
    GetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
    if(strcmp(Option, "engine", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {

            if(eengine != VEHICLE_PARAMS_ON)
            {
                new TextString[128];
                SetVehicleParamsEx(vid,VEHICLE_PARAMS_ON,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                format(TextString, sizeof TextString,"* %s turns the vehicle key, attempting to start the vehicle.","b");
                SendClientMessage(playerid,-1,TextString);
            }
            else
            {
                SetVehicleParamsEx(vid,VEHICLE_PARAMS_OFF,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                new TextString[128];
                format(TextString, sizeof TextString,"* %s turns the vehicle key, Turning the vehicle off.","b");
                SendClientMessage(playerid,-1,TextString);
            }
        }
    }
    else if(strcmp(Option, "lights", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(llights != VEHICLE_PARAMS_ON)
            {

                SetVehicleParamsEx(vid,eengine,VEHICLE_PARAMS_ON,aalarm,ddoors,bbonnet,bboot,oobjective);
            }
            else
            {

                SetVehicleParamsEx(vid,eengine,VEHICLE_PARAMS_OFF,aalarm,ddoors,bbonnet,bboot,oobjective);
            }
        }
    }
    else if(strcmp(Option, "trunk", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(bboot != VEHICLE_PARAMS_ON)
            {


                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,VEHICLE_PARAMS_ON,oobjective);
            }
            else
            {


                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,VEHICLE_PARAMS_OFF,oobjective);
            }
        }
    }
    else if(strcmp(Option, "hood", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(bbonnet != VEHICLE_PARAMS_ON)
            {

                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,VEHICLE_PARAMS_ON,bboot,oobjective);
            }
            else
            {

                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,VEHICLE_PARAMS_OFF,bboot,oobjective);
            }
        }
    }
    else SendClientMessage(playerid,-1,"INVALID Option");
    return 1;
}
(it's basically your code, just slightly modifyed the parts with these player vars and functions i didn't have ofc.)
Reply
#5

Quote:
Originally Posted by CutX
Посмотреть сообщение
well well ^^

just use else if
instead of

if(strcm....
if(strcm...
and so on

do

if(strcm...
else if(str....

and at the end

else Sendcl..... Invalid option

see, i used this to test it and it works.
You setup the control structure for the options in an invalid way


the code:
pawn Код:
YCMD:car(playerid, params[], help)
{
    new Option[32];//isn't that too much? 6 would do the trick :) well, it's your code
    new vid = GetPlayerVehicleID(playerid);
    if(sscanf(params, "s[32]", Option)) return SendClientMessage(playerid, -1, "Usage: /car [Engine/Lights/Hood/Trunk/Speedo]");
    new eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective;
    GetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
    if(strcmp(Option, "engine", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {

            if(eengine != VEHICLE_PARAMS_ON)
            {
                new TextString[128];
                SetVehicleParamsEx(vid,VEHICLE_PARAMS_ON,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                format(TextString, sizeof TextString,"* %s turns the vehicle key, attempting to start the vehicle.","b");
                SendClientMessage(playerid,-1,TextString);
            }
            else
            {
                SetVehicleParamsEx(vid,VEHICLE_PARAMS_OFF,llights,aalarm,ddoors,bbonnet,bboot,oobjective);
                new TextString[128];
                format(TextString, sizeof TextString,"* %s turns the vehicle key, Turning the vehicle off.","b");
                SendClientMessage(playerid,-1,TextString);
            }
        }
    }
    else if(strcmp(Option, "lights", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(llights != VEHICLE_PARAMS_ON)
            {

                SetVehicleParamsEx(vid,eengine,VEHICLE_PARAMS_ON,aalarm,ddoors,bbonnet,bboot,oobjective);
            }
            else
            {

                SetVehicleParamsEx(vid,eengine,VEHICLE_PARAMS_OFF,aalarm,ddoors,bbonnet,bboot,oobjective);
            }
        }
    }
    else if(strcmp(Option, "trunk", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(bboot != VEHICLE_PARAMS_ON)
            {


                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,VEHICLE_PARAMS_ON,oobjective);
            }
            else
            {


                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,bbonnet,VEHICLE_PARAMS_OFF,oobjective);
            }
        }
    }
    else if(strcmp(Option, "hood", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            if(bbonnet != VEHICLE_PARAMS_ON)
            {

                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,VEHICLE_PARAMS_ON,bboot,oobjective);
            }
            else
            {

                SetVehicleParamsEx(vid,eengine,llights,aalarm,ddoors,VEHICLE_PARAMS_OFF,bboot,oobjective);
            }
        }
    }
    else SendClientMessage(playerid,-1,"INVALID Option");
    return 1;
}
(it's basically your code, just slightly modifyed the parts with these player vars and functions i didn't have ofc.)
Worked well, Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)