SA-MP Forums Archive
[Tutorial] How to make a /engine and a /lock command. - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make a /engine and a /lock command. (/showthread.php?tid=370677)



How to make a /engine and a /lock command. - TaLhA XIV - 20.08.2012

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.


Re: How to make a /engine and a /lock command. - ThomasRiddle - 21.08.2012

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


Re: How to make a /engine and a /lock command. - Team_PRO - 22.08.2012

Nice Work


Re: How to make a /engine and a /lock command. - TaLhA XIV - 22.08.2012

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.


Re: How to make a /engine and a /lock command. - DeadLy™ - 22.08.2012

Ty. For it Talha


Re: How to make a /engine and a /lock command. - Lordzy - 22.08.2012

You must explain well.


Re: How to make a /engine and a /lock command. - TaLhA XIV - 22.08.2012

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


Re: How to make a /engine and a /lock command. - MoDee - 24.08.2012

Thanks. I needed it


Re: How to make a /engine and a /lock command. - Beljulji - 18.09.2012

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?


Re: How to make a /engine and a /lock command. - TaLhA XIV - 18.09.2012

No I think so.Explain your problem maybe.


Re: How to make a /engine and a /lock command. - Private200 - 19.11.2012

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


Re: How to make a /engine and a /lock command. - goviscrap - 27.11.2012

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?


Re: How to make a /engine and a /lock command. - iGetty - 01.12.2012

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


Re: How to make a /engine and a /lock command. - xXtremeXx - 28.06.2016

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


Re: How to make a /engine and a /lock command. - Dutheil - 28.06.2016

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


Re: How to make a /engine and a /lock command. - SickAttack - 28.06.2016

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


Re: How to make a /engine and a /lock command. - EiresJason - 28.06.2016

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


Re: How to make a /engine and a /lock command. - Quinncell - 28.06.2016

That 4 year bump..lol.


Respuesta: How to make a /engine and a /lock command. - REMAK3 - 28.06.2016

Nice!


Re: How to make a /engine and a /lock command. - DarkSkull - 02.07.2016

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.