SA-MP Forums Archive
Start engine pressing an button - 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: Start engine pressing an button (/showthread.php?tid=274136)



Start engine pressing an button - Malakay - 04.08.2011

Hello guys (again),

In my Roleplay Gamemode I want put like, Rigth Ctrl for start engine, is that possible?
My Engine var is EngineStatus.

Can help me with that?
Thanks.


AW: Start engine pressing an button - Drebin - 04.08.2011

pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & EnterTheKeyYouWantHere && IsPlayerInAnyVehicle(playerid))
    {
        new EngineStatus, lights, alarm, doors, bonnet, boot, objective;
        new vid = GetPlayerVehicleID(playerid);      
        GetVehicleParamsEx(vid,EngineStatus,lights,alarm,doors,bonnet,boot,objective);
        if(vid != INVALID_VEHICLE_ID && EngineStatus== 0)
        {
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective); //engine started
        }
        else if(vid != INVALID_VEHICLE_ID && EngineStatus== 1)
        {
            SetVehicleParamsEx(vid, VEHICLE_PARAMS_OFF, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot, objective); //engine stopped
        }
    }
    return 1;
}



Re: Start engine pressing an button - AndreT - 04.08.2011

To the previous code: it would be useful to check if the key isn't just being held down, otherwise it will keep toggling the engine on and off.
pawn Code:
if(newkeys & KEY_ACTION && !(newkeys & KEY_ACTION))
I took KEY_ACTION as an example.


Re: Start engine pressing an button - Malakay - 04.08.2011

Thank you both.

I'm go test, thanks alot!


Re: Start engine pressing an button - Malakay - 04.08.2011

Well i'm getting some errors.

Code:
(16675) : error 035: argument type mismatch (argument 2)
(16676) : error 033: array must be indexed (variable "EngineStatus")
(16680) : error 033: array must be indexed (variable "EngineStatus")
pawn Code:
166669 - public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
166670           {
166671           if(newkeys & KEY_ACTION && !(newkeys & KEY_ACTION))
166672           {
166673           new lights, alarm, doors, bonnet, boot, objective;
166674           new vid = GetPlayerVehicleID(playerid);
166675           GetVehicleParamsEx(vid,EngineStatus,lights,alarm,doors,bonnet,boot,objective);
166676           if(vid != INVALID_VEHICLE_ID && EngineStatus== 0)
166677          {
166678           SetVehicleParamsEx(vid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);     //engine      started
166680        }
166681        else if(vid != INVALID_VEHICLE_ID && EngineStatus== 1)
166682        {
166683            SetVehicleParamsEx(vid, VEHICLE_PARAMS_OFF, VEHICLE_PARAMS_OFF, alarm, doors, bonnet, boot,      166684 objective); //engine stopped
166685        }
166686        }
166687        return 1;
166688        }



Re: Start engine pressing an button - MadeMan - 04.08.2011

pawn Code:
EngineStatus[vid]



Re: Start engine pressing an button - Malakay - 04.08.2011

Quote:
Originally Posted by MadeMan
View Post
pawn Code:
EngineStatus[vid]
Can you tell me where I put this? ... sorry.


Re: Start engine pressing an button - LZLo - 04.08.2011

Quote:

EngineStatus -> EngineStatus[vid]

and

in the beginning

PHP Code:
new EngineStatus[MAX_VEHICLES]; 



Re: Start engine pressing an button - Malakay - 04.08.2011

Quote:
Originally Posted by LZLo
View Post
PHP Code:
EngineStatus -> EngineStatus[vid
and

in the beginning

PHP Code:
new EngineStatus[MAX_VEHICLES]; 
Thanks, I will try.

Only I don't have the First, the second I have.

Thanks.


Re: Start engine pressing an button - Malakay - 04.08.2011

Ok, that works!
Thanks.