[Tutorial] How to create a vehicle fix command - For Admins
#1

Hello everyone today i will be presenting you with a NOOB friendly tutorial, in this tutorial i will teach you how to create a /afix command for admins only, this is based around my admin variable which is pAdmin, please change it to the variable that your script uses! Without further adue, lets start the tutorial step by step!

First of all we are going to need a include, the include is ZCMD which is a command processor, a link can be found here: https://sampforum.blast.hk/showthread.php?tid=91354 .

To add this include into your script, we will put it into /yourserver/pawno/includes, then we will also use this code which goes underneath your:
pawn Код:
#include <a_samp>
#include <ZCMD> //Like so!
Now that we have our command processor into the script we are going to setup a basic command like this:

pawn Код:
CMD:afix(playerid, params[])
{
        //The code for our command goes here.
    return 1;
}
Inside this command above the ( return 1; ) we are going to put this:
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4)
    {
    //Rest of the script goes here
    }
         else return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
This piece of code ensures us that the player is a admin, otherwise it will tell them that they have to be a level 5 admin.

Inside the 2 curly brackets ( {} ) we are going to place the main code which will fix the visual and engine damage to the car.


This code is:

pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
    RepairVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle has been successfully repaired!");
Ok, let me break that down for you, the
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
this will ensure that the player is in a vehicle, otherwise it will tell them that they have to be in a vehicle.

The next piece of code is:
pawn Код:
RepairVehicle(GetPlayerVehicleID(playerid));
this repairs the visual and engine damage of the vehicle.

Finally we will send the player a message tell them that there vehicle has been fixed
pawn Код:
SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle has been successfully repaired!");
So overall your whole command should look like this:

pawn Код:
CMD:afix(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");
    RepairVehicle(GetPlayerVehicleID(playerid));
    SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle has been successfully repaired!");
    }
    else return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
    return 1;
}

//COPIERS NEVER LEARN!

Thanks for taking your time to read this, hope i helped! -Connor



P.S. This is my first tutorial, tell me whether or not i explained everything well enough, also i know that a similar script is available on the wiki, i just wanted to teach how you would do it when hecking of the player is a admin! thank -.-
Reply
#2

Quote:
Originally Posted by NewerthRoleplay
Посмотреть сообщение
[COLOR="Blue"]
Inside this command above the ( return 1; ) we are going to put this:
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4) return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
    {
    //Rest of the script goes here
    }
This piece of code ensures us that the player is a admin, otherwise it will tell them that they have to be a level 5 admin.

Inside the 2 curly brackets ( {} ) we are going to place the main code which will fix the visual and engine damage to the car.

Well, you should change that up a little bit...

return will stop the current function, also...


pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4) return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
{
    //Rest of the script goes here
}
You should remove the return there or, at least remove the brackets.
Reply
#3

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Well, you should change that up a little bit...

return will stop the current function, also...


pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4) return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
{
    //Rest of the script goes here
}
You should remove the return there or, at least remove the brackets.
So am i right in thinking that instead of return'ing it instead i should use 'else'??

Thanks for the feedback ^.^
Reply
#4

pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4) //Here we check if the player's admin level is greater than or equal to 4
{
    //Rest of the script goes here
}
else return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!"); //If it's not, we'll escape the function while sending them a message
You could do that...or this

pawn Код:
if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
If their level is less than 4, we aren't going to continue
Reply
#5

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
pawn Код:
if(PlayerInfo[playerid][pAdmin] >= 4) //Here we check if the player's admin level is greater than or equal to 4
{
    //Rest of the script goes here
}
else return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!"); //If it's not, we'll escape the function while sending them a message
You could do that...or this

pawn Код:
if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
If their level is less than 4, we aren't going to continue
Ok thanks alot Antonio, do you think its good for a first tutorial, like is there anything i could improve on?
Reply
#6

sorry but I dont see why a tutorial on such a basic thing would be helpfull:/
Reply
#7

It's helpful for beginners.
Good Job.
Reply
#8

first off i think you have done a decent job,
but I would not compact the code so much,

noobies will have a better time understanding the same code but written

pawn Код:
CMD:afix(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 4) //check admin level
    {
        if(!IsPlayerInAnyVehicle(playerid)) //check if they are NOT in a vehicle
        {
            return SendClientMessage(playerid, 0xFFFFFFFF, "You are not in a vehicle!");  
        }
        //they are in a vehicle so repaire and send a message
        RepairVehicle(GetPlayerVehicleID(playerid));
        SendClientMessage(playerid, 0xFFFFFFFF, "Your vehicle has been successfully repaired!");
    }
    else    //they are not an admin so send message saying so
    {
        return SendClientMessage, 0xFFFFFFFF, " **You must be a level 4 admin to use that!");
    }
    return 1;  //also i see no point in a return here when it will never be reached.
}
but line for line like you showed is good.
and comments in the code normally help for the COPIERS lol

all in all good job 7/10
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)