[Tutorial] Fix Vehicle (ZCMD)
#1

Fix Vehicle

Credits:
Zeex - ZCMD creator.




Hello guys, today I will be showing you how to make a /repair command to fix your vehicle.

First, your going to want to define the include 'ZCMD', a fast command processor and 'a_samp' include, which gets to access functions like SendClientMessage, SendClientMessageToAll, SetWeather, SetWorldTime, SetTimer, SetTimerEx, all those functions that are in 'a_samp' include.


pawn Код:
#include <a_samp>
#include <zcmd>
Okay, now let's start with the commands.

I will put the code here, then I will explain after the code.

pawn Код:
CMD:repair(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "You are not in a vehicle!");
    if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, -1, "You are not in the driver seat!");
    RepairVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid, -1, "Your vehicle has been sucessfully repaired!");
    PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
    return 1;
}
Now, you will see this code, this code starts off the command, like the name of the command.
pawn Код:
CMD:repair(playerid, params[])


After that, which is inside the code.
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "You are not in a vehicle!");
    if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, -1, "You are not in the driver seat!");
    RepairVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid, -1, "Your vehicle has been sucessfully repaired!");
    PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
    return 1;



Basically, this code means that if the player isn't in a vehicle, it will send a message to the player saying that they are not in a vehicle.

Also, the '!' behind the function, 'IsPlayerInAnyVehicle(playerid)), stands for if the player isn't in a vehicle, if you don't put a '!' it will stand for if the player is in a vehicle, and then you just type in the functions, repair the vehicle, send a message they repaired it.
The -1 is a color, -1 is white. You can change it to another color that you like.
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "You are not in a vehicle!");


This code here basically means that if the player is in the passenger seat or any other seat other than the driver seat, it will send them a message saying that they are not in the driver seat and it won't repair the vehicle.
The -1 is a color, -1 is white. You can change it to another color that you like.
pawn Код:
if(GetPlayerState(playerid) != 2) return SendClientMessage(playerid, -1, "You are not in the driver seat!");


Now, this code basically means that it will repair the player's vehicle that the player is in, and it won't repair any other vehicles that they aren't in.
pawn Код:
RepairVehicle(GetPlayerVehicleID(playerid));

This code means that it will send the player a message saying that their vehicle has been sucessfully repaired.
The -1 is a color, -1 is white. You can change it to another color that you like.


pawn Код:
SendClientMessage(playerid, -1, "Your vehicle has been sucessfully repaired!");


This code, plays a sound.
The number '1133' is the sound id.
You can find other sounds at this link, and change it to a different sound you like.
The current sound I have is a SOUND_BUY_CAR_MOD.
After you will see, '0.0, 0.0, 0.0' that is the coordinates where it will play the sound, if you set all the coordinates all to 0, it will just play the sound.
pawn Код:
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
And that's it guys, my simple /repair your vehicle tutorial.

Downloads and pastebin:
Solidfiles .pwn
Solidfiles .amx
Pastebin
Reply


Messages In This Thread
Fix Vehicle (ZCMD) - by JustinAn - 03.07.2012, 19:20
Re: Fix Vehicle (ZCMD) - by Glint - 03.07.2012, 19:22
Re: Fix Vehicle (ZCMD) - by JustinAn - 03.07.2012, 19:26
Re: Fix Vehicle (ZCMD) - by Glint - 03.07.2012, 19:31
Re: Fix Vehicle (ZCMD) - by JustinAn - 03.07.2012, 19:34
Re: Fix Vehicle (ZCMD) - by LukeStephens - 04.07.2012, 08:07
Respuesta: Fix Vehicle (ZCMD) - by Tyrexo - 03.05.2013, 18:16
Re: Respuesta: Fix Vehicle (ZCMD) - by Areax - 03.05.2013, 21:49
Re: Fix Vehicle (ZCMD) - by qazwsx - 24.07.2013, 11:31
Re: Fix Vehicle (ZCMD) - by qazwsx - 24.07.2013, 13:53

Forum Jump:


Users browsing this thread: 1 Guest(s)