Help using enums
#1

I've saw how the enum was used in other ways, so i tried this:
pawn Код:
enum enum_vParams
{
    vBonnet,
    vObjective,
    vAlarm,
    vDoors,
    vEngine,
    vBoot,
    vLights
};

stock SetVehParams(vehicleid, param, status)
{
    new
        VehParams[7];

    GetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);

    switch(enum_vParams:param)
    {
        case vBonnet: VehParams[0] = status;
        case vObjective: VehParams[1] = status;
        case vAlarm: VehParams[2] = status;
        case vDoors: VehParams[3] = status;
        case vEngine: VehParams[4] = status;
        case vBoot: VehParams[5] = status;
        case vLights: VehParams[6] = status;
    }
    return SetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);
}
Compiles fine, but doesn't seem to work. Any help will be appreciated


EDIT:
If you want to use this code, I tweaked it a little:
pawn Код:
enum enum_vParams
{
    Engine,
    Lights,
    Alarm,
    Doors,
    Bonnet,
    Boot,
    Objective
};

stock SetVehParams(vehicleid, params, status)
{
    new
        VehParams[7];

    GetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);

    VehParams[enum_vParams:params] = status ? (1):(0);
    return SetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);
}
Usage:
pawn Код:
SetVehParams(GetPlayerVehicleID(playerid), Engine, VEHICLE_PARAMS_ON);
Turns the engine on.
Reply
#2

Shouldn't you use

pawn Код:
switch(enum_vParams[param])
Instead of

pawn Код:
switch(enum_vParams:param)
? Not 100% sure, just an idea.
Reply
#3

You use enums like this.

pawn Код:
enum Stuff
{
    Thing1,
    Thing2,
    Thing3
};

new Items[Stuff];

//Then you can do something like...
Items[Thing2] = 1337;
At least that's how I've always used them.
Reply
#4

try this code. no enum needed.

pawn Код:
stock SetVehParams(vehicleid, param, bool:status)
{
    if(param < 0 || param > 6)return -1;
    new vp[7];
    GetVehicleParamsEx(vehicleid, vp[0], vp[1], vp[2], vp[3], vp[4], vp[5], vp[6]);
    vp[param] = status;
    return SetVehicleParamsEx(vehicleid, vp[0], vp[1], vp[2], vp[3], vp[4], vp[5], vp[6]);
}
didn't test, but i guess it work fine.
Reply
#5

Well this fixed it:
pawn Код:
stock SetVehParams(vehicleid, param, status)
{
    new
        VehParams[7];

    GetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);

    switch(enum_vParams:param)
    {
        case vBonnet: VehParams[0] = status ? (1):(0);
        case vObjective: VehParams[1] = status ? (1):(0);
        case vAlarm: VehParams[2] = status ? (1):(0);
        case vDoors: VehParams[3] = status ? (1):(0);
        case vEngine: VehParams[4] = status ? (1):(0);
        case vBoot: VehParams[5] = status ? (1):(0);
        case vLights: VehParams[6] = status ? (1):(0);
    }
    return SetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);
}
Thanks for the feedback tho!


EDIT:
If you want to use this code, I tweaked it a little:

pawn Код:
enum enum_vParams
{
    Engine,
    Lights,
    Alarm,
    Doors,
    Bonnet,
    Boot,
    Objective
};

stock SetVehParams(vehicleid, params, status)
{
    new
        VehParams[7];

    GetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);

    VehParams[enum_vParams:params] = status ? (1):(0);
    return SetVehicleParamsEx(vehicleid, VehParams[0], VehParams[1], VehParams[2], VehParams[3], VehParams[4], VehParams[5], VehParams[6]);
}
Usage:
pawn Код:
SetVehParams(GetPlayerVehicleID(playerid), Engine, VEHICLE_PARAMS_ON);
Turns the engine on.
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)