[Tutorial] How to make a /engine and a /lock command.
#1

Okay this is my first tutorial about how to make simple and basic /engineon,and /lock command.

I know most of you know that how to make this but I am doing this for newbies around searching for the same topics.

Okay now:
Here is the whole script with good explanation.
PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/engine"cmdtexttrue10) == 0)//your command.
    
{
        new 
vehicleid GetPlayerVehicleID(playerid);//defining vehicleid is = to GetPlayerVehicleID.
        
new enginelightsalarmdoorsbonnetbootobjective;//these are the defines of the thing used in the command.
        
if(IsPlayerInAnyVehicle(playerid))//This will check that if a player is in the vehicle or not.
            
{
                if(
GetPlayerVehicleSeat(playerid) == 0//Now this will check that if a player is on the driving seat or not.
                
{
                    
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);//will check that what is the state of the engine.
                    
if(engine == 1)//will check that if the wngine in on or not.
                    
{
                        
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);//this will check that what is the state of engine.That is is on or off.We can use it for multiple things like doors,alarms etc.But In this case I am using this for the engine only.
                        
SetVehicleParamsEx(vehicleid,false,lights,alarm,doors,bonnet,boot,objective);//when we change the engine and replace it with false,this will turn the vehicle engine off.Same if we make if true,this will make the engine on.
                        
GameTextForPlayer(playerid,"Vehicle Engine Stopped!",2000,6);//for a text to appar on the screen for only 2 seconds.
                        
return 1;
                    }
                    else
                    
SetVehicleParamsEx(vehicleid,true,lights,alarm,doors,bonnet,boot,objective);//if vehicle engine is false it will change it to true.
                    
GameTextForPlayer(playerid,"Vehicle Engine Started!",2000,6);//for a text to appar on the screen for only 2 seconds.
                
}
                else 
SendClientMessage(playerid,-1,"Error: You are not at the driving seat!");//this is an error message,that if a player is not on the driving seat,this error message would appear.
                
return 1;
            }
            else
            
SendClientMessage(playerid,-1,"Error: You are not in a vehicle!");//this is the error message,that if a player is not in the car,the error message would apper.
    
}
    if (
strcmp("/lock"cmdtexttrue10) == 0)//your command.
    
{
        new 
enginelightsalarmdoorsbonnetbootobjective;
        new 
vehicleid GetPlayerVehicleID(playerid);//defining vehicleid is = to GetPlayerVehicleID.
        
if(IsPlayerInAnyVehicle(playerid))//Thsi will check that is a player In a vehcile or not.
            
{
                
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);//will check that what is the state of the vehicle lock.
                
if(doors == 1)//will check if the doors are already loocked it not.
                
{
                    
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
                      
SetVehicleParamsEx(vehicleid,engine,lights,alarm,false,bonnet,boot,objective);//same as the engine one.
                      
GameTextForPlayer(playerid,"Vehicle Unlocked!",2000,6);//for a text to appar on the screen for only 2 seconds.
                       
return 1;
                }
                else
                
SetVehicleParamsEx(vehicleid,engine,lights,alarm,true,bonnet,boot,objective);
                
GameTextForPlayer(playerid,"Vehicle Locked!",2000,6);//for a text to appar on the screen for only 2 seconds.
            
}
            else
            
SendClientMessage(playerid,-1,"Error: You are not in a vehicle!");//the error message.
    
}
    return 
0;

for any question just write a comment.
Reply
#2

I guess this is for RP servers , can you make it so it gives /unlock? I can't do it. Thanks in advance.
Reply
#3

Nice Work
Reply
#4

Quote:
Originally Posted by ThomasRiddle
Посмотреть сообщение
I guess this is for RP servers , can you make it so it gives /unlock? I can't do it. Thanks in advance.
There you go.
PHP код:
    if (strcmp("/unlock"cmdtexttrue10) == 0)//your command.
    
{
        new 
enginelightsalarmdoorsbonnetbootobjective;
        new 
vehicleid GetPlayerVehicleID(playerid);//defining vehicleid is = to GetPlayerVehicleID.
        
if(IsPlayerInAnyVehicle(playerid))//Thsi will check that is a player In a vehcile or not.
            
{
                
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);//will check that what is the state of the vehicle lock.
                
if(doors == 1)//will check if the doors are already loocked it not.
                
{
                    
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
                    
SetVehicleParamsEx(vehicleid,engine,lights,alarm,false,bonnet,boot,objective);//same as the engine one.
                    
GameTextForPlayer(playerid,"Vehicle Unlocked!",2000,6);//for a text to appar on the screen for only 2 seconds.
                    
return 1;
                }
            }
            else
            
SendClientMessage(playerid,-1,"Error: You are not in a vehicle!");//the error message.
    
}
    if (
strcmp("/lock"cmdtexttrue10) == 0)//your command.
    
{
        new 
enginelightsalarmdoorsbonnetbootobjective;
        new 
vehicleid GetPlayerVehicleID(playerid);//defining vehicleid is = to GetPlayerVehicleID.
        
if(IsPlayerInAnyVehicle(playerid))//Thsi will check that is a player In a vehcile or not.
            
{
                
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);//will check that what is the state of the vehicle lock.
                
if(doors == 0)//will check if the doors are already loocked it not.
                
{
                    
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
                    
SetVehicleParamsEx(vehicleid,engine,lights,alarm,true,bonnet,boot,objective);//same as the engine one.
                    
GameTextForPlayer(playerid,"Vehicle Unlocked!",2000,6);//for a text to appar on the screen for only 2 seconds.
                    
return 1;
                }
            }
            else
            
SendClientMessage(playerid,-1,"Error: You are not in a vehicle!");//the error message.
    

And thanks for nice comments.
Reply
#5

Ty. For it Talha
Reply
#6

You must explain well.
Reply
#7

I explained it to the best but thanks for the suggestion.I explained them in the script.
Reply
#8

Thanks. I needed it
Reply
#9

well i use createvehicle and vehicle respawns after 15 sec if i add this lock command should he stay in the position until i unlock him?
Reply
#10

No I think so.Explain your problem maybe.
Reply
#11

Can you please make that the car turn the engine on by pressingshift please ?
Reply
#12

I have a Question about this Script... When ive enter a parked car somewhere it automaticly starts when i entering it.... What is the problem then?
Reply
#13

You should make it so then the players can lock/unlock outside of a vehicle too.
Reply
#14

Can u make me /lock, /unlock and /engine in this format CMD:lock, CMD:unlock, CMD:engine
Reply
#15

Quote:
Originally Posted by TaLhA XIV
Посмотреть сообщение
if (strcmp("/engine", cmdtext, true, 10) == 0)//your command[/php]
Why 10 ?
Reply
#16

Quote:
Originally Posted by xXtremeXx
Посмотреть сообщение
Can u make me /lock, /unlock and /engine in this format CMD:lock, CMD:unlock, CMD:engine
/lock and /unlock could be made with /engine, just by changing a few things.

But this is what does the magic: https://sampwiki.blast.hk/wiki/SetVehicleParamsEx
Reply
#17

Quote:
Originally Posted by Dutheil
Посмотреть сообщение
Why 10 ?
I don't think he'll be replying to you.. he hasn't been online in almost 4 years xD
Reply
#18

That 4 year bump..lol.
Reply
#19

Nice!
Reply
#20

You should get Vehicle ID of the player after checking if he's in a vehicle or not.

EDIT: Never mind, You haven't been online for 4 years.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)