SA-MP Forums Archive
How to make when player press 2, to start the car engine ? - 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)
+--- Thread: How to make when player press 2, to start the car engine ? (/showthread.php?tid=485438)



How to make when player press 2, to start the car engine ? - barts - 04.01.2014

When press 2 to process the CMD:engine


Re: How to make when player press 2, to start the car engine ? - iOxide - 04.01.2014

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new engine, lights, alarm, doors, bonnet, boot, objective;
    new vehicleid = GetPlayerVehicleID(playerid);
    if (GetPlayerVehicleSeat(playerid) == 0)
    {
        if (newkeys & EXAMPLE_KEY) //Change your key here
        {
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
            SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle's engine is now turned [ON].");
        }

    }
    return 1;
}



Re: How to make when player press 2, to start the car engine ? - Stefand - 04.01.2014

Only possible with keys from this list:

https://sampwiki.blast.hk/wiki/Keys

pawn Код:
IsKeyJustDown(key, newkeys, oldkeys)
{
    if((newkeys & key) && !(oldkeys & key))  return 1;
    return 0;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(IsKeyJustDown(KEY_FIRE, newkeys, oldkeys))
    {
        return cmd_engine(playerid,param);
    }
    return 1;
}



Re: How to make when player press 2, to start the car engine ? - barts - 04.01.2014

error 017: undefined symbol "param" i used your code,@Stefand


Re: How to make when player press 2, to start the car engine ? - Konstantinos - 04.01.2014

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if ((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
    {
        cmd_engine(playerid, "");
    }
    return 1;
}



Re: How to make when player press 2, to start the car engine ? - Yashas - 04.01.2014

(iOxide)You can't use his code directly.He just gave an idea and you were supposed to change the key.(Stefand Code)He assumes that you have a command engine already.And change the param to ""(I think so).You were supposed to fix youself because you know about your command better than us.If you still haven't done your code use this code...

A little change to I oxide's code, replace the existing callback in your script with this one.This code will turn off the engine if it was on and turn on if it was off.
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (GetPlayerVehicleSeat(playerid) == 0)
    {
        if (newkeys & KEY_SUBMISSION) 
        {
               return cmd_engine(playerid,"");
        }

    }
    return 1;
}
And paste this anywhere in the script.
Код:
CMD:engine(playerid,params[])
{
            new engine, lights, alarm, doors, bonnet, boot, objective;
            new vehicleid = GetPlayerVehicleID(playerid);
if(IsPlayerInAnyVehicle(i))
{
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, !engine, lights, alarm, doors, bonnet, boot, objective);
            SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle's engine is now turned [ON].");
}
else
{
        //Send a message telling he is not in a vehicle to manipulate an engine
}
return 1;
}