[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
#2

https://sampforum.blast.hk/showthread.php?tid=356382
Please don't post the same tutorials again and again.
Reply
#3

Quote:
Originally Posted by Lexi'
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=356382
Please don't post the same tutorials again and again.
Sorry, but I didn't meant to. I wanted to make a fixing vehicle tutorial, which was I thinking of.
Reply
#4

Quote:
Originally Posted by JustinAn
Посмотреть сообщение
Sorry, but I didn't meant to. I wanted to make a fixing vehicle tutorial, which was I thinking of.
However good tutorial you explained good, but please next time think of something unique.
Reply
#5

Quote:
Originally Posted by Lexi'
Посмотреть сообщение
However good tutorial you explained good, but please next time think of something unique.
Thanks for the compliment, also I will try to think of something unique next time.
Thanks for the tip.
Reply
#6

Umg u nooooob u stolez mah dangd tut umg umg umg.


Joke.. Unique-ness is the key my friend.
Anyway nice tutorial for someone who wasn't wanting to add stocks (Idk why).
Reply
#7

This can be a command only for admin?
Reply
#8

Quote:
Originally Posted by Tyrexo
Посмотреть сообщение
This can be a command only for admin?
No, this command is for all players. You can add
PHP код:
if(!IsPlayerAdmin(playerid) return SendClientMessage(playerid, -1"You are not an Rcon Admin!")) 
and now is only for Rcon Admins.
Reply
#9

Nice tutorial
Reply
#10

Very nice tutorial..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)