20.08.2012, 21:46
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.
for any question just write a comment.
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(playerid, cmdtext[])
{
if (strcmp("/engine", cmdtext, true, 10) == 0)//your command.
{
new vehicleid = GetPlayerVehicleID(playerid);//defining vehicleid is = to GetPlayerVehicleID.
new engine, lights, alarm, doors, bonnet, boot, objective;//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", cmdtext, true, 10) == 0)//your command.
{
new engine, lights, alarm, doors, bonnet, boot, objective;
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;
}