Problem assigning secondary-key to engine ignition.
#1

Hey there.

I've been messing about with SA:MP servers recently, and I've stumbled upon this problem.

I'm trying to assign the secondary key (2), to turn the engine up and running. The 'starting' part works fine, but when I'm trying to make it shut down, it just starts it -again-

This is what I've got so far:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        new vid = GetPlayerVehicleID(playerid);

        if(vid != INVALID_VEHICLE_ID)
        {
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_ON, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
            GameTextForPlayer(playerid, "~w~Engine: ~g~Started", 3000, 3);
            PlayerPlaySound(playerid, 1053, 0.0, 0.0, 10.0);
        }
        else if (engine == 1)
        {
            GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_OFF, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
            GameTextForPlayer(playerid, "~w~Engine: ~r~Stopped", 3000, 3);
            PlayerPlaySound(playerid, 1046, 0.0, 0.0, 10.0);
        }
    }
    return 1;
}
Anyone interested in helping me?
Reply
#2

pawn Код:
if(vid != INVALID_VEHICLE_ID && engine == 0)
And move the GetVehicleParamsEx function just before you start the if-statement (so just after your variable declarations), and remove that function from both blocks of code.
Reply
#3

Thanks for your fast reply, however it still doesn't work. It does the same.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_SUBMISSION && IsPlayerInAnyVehicle(playerid))
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        new vid = GetPlayerVehicleID(playerid);
       
        GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);

        if(vid != INVALID_VEHICLE_ID)
        {
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_ON, VEHICLE_PARAMS_ON, alarm, doors, bonnet, boot, objective);
            GameTextForPlayer(playerid, "~w~Engine: ~g~Started", 3000, 3);
            PlayerPlaySound(playerid, 1053, 0.0, 0.0, 10.0);
        }
       
        else if(vid != INVALID_VEHICLE_ID && engine == 1)
        {
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_OFF, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective);
            GameTextForPlayer(playerid, "~w~Engine: ~r~Stopped", 3000, 3);
            PlayerPlaySound(playerid, 1053, 0.0, 0.0, 10.0);
        }
    }
    return 1;
}
Reply
#4

Read my previous post again. Especially that line of code I provided.
Reply
#5

Damn, Son. I owe you.

Works perfect. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)