SA-MP Forums Archive
Problem assigning secondary-key to engine ignition. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem assigning secondary-key to engine ignition. (/showthread.php?tid=245524)



Problem assigning secondary-key to engine ignition. - shitbird - 31.03.2011

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?


Re: Problem assigning secondary-key to engine ignition. - Vince - 31.03.2011

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.


Re: Problem assigning secondary-key to engine ignition. - shitbird - 31.03.2011

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;
}



Re: Problem assigning secondary-key to engine ignition. - Vince - 31.03.2011

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


Re: Problem assigning secondary-key to engine ignition. - shitbird - 31.03.2011

Damn, Son. I owe you.

Works perfect. Thanks.