Start engine pressing an button
#1

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.
Reply
#2

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;
}
Reply
#3

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.
Reply
#4

Thank you both.

I'm go test, thanks alot!
Reply
#5

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        }
Reply
#6

pawn Code:
EngineStatus[vid]
Reply
#7

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

Quote:

EngineStatus -> EngineStatus[vid]

and

in the beginning

PHP Code:
new EngineStatus[MAX_VEHICLES]; 
Reply
#9

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.
Reply
#10

Ok, that works!
Thanks.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)