[Tutorial] How to make a simple strcmp cmd!
#1

Hello guys, some guys get complaines to create simple commands like a /vr one when start scripting... So i will explain how to make a simple /vr cmd for example:


You need the basic cmd format:

Put this on public OnPlayerCommandText(playerid, cmdtext[]);

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/vr", true);
Now you will put the Function code... RepairVehicle(GetPlayerVehicleID(playerid));
pawn Code:
{
        RepairVehicle(GetPlayerVehicleID(playerid));
        SendClientMessage(playerid, 0xFF4444FF, "You Repaired Your Vehicle");
        return 1;
    }
    return 0;
}
Will look like this:

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/vr", true) == 0)
    {
        RepairVehicle(GetPlayerVehicleID(playerid));
        SendClientMessage(playerid, 0xFF4444FF, "You Repaired Your Vehicle");
        return 1;
    }
    return 0;
}
So, i will now explain the parts:

if(strcmp(cmdtext, "/vr", true) == 0) = Basic cmd format

{ =open the script
RepairVehicle(GetPlayerVehicleID(playerid)); = This make the cmd repair the vehicle(This is the command FUNCTION)
SendClientMessage(playerid, 0xFF4444FF, "You Repaired Your Vehicle"); = This send a message to player!
return 1; = Return the value
} = Close the script

I hope this is helpfull... If you think i need to change something only replay!
Reply
#2

Well, you shouldn't put commands inside OnFilterScriptInit. Its not realy explained well either. Eg, you could have said what strcmp does (in this case compares the command the player typed to "/vr"). I thought that might be better than just saying this is the basic format. Its good that your trying to help people, its just better if you make sure the code works before posting.
Reply
#3

Failed... A command will not work under OnFilterScriptInit lol.
Did you even check the wiki before making this tutorial?
If n00bs will copy this they will get all kinda errors
Reply
#4

ZCMD / Y_CMD is much faster then strcmp.
Reply
#5

Quote:
Originally Posted by alpha500delta
View Post
Failed... A command will not work under OnFilterScriptInit lol.
Did you even check the wiki before making this tutorial?
If n00bs will copy this they will get all kinda errors
Ups, i just done a mistake... If you see in up of tut it is OnPlayerCommandText (Thanks for reporting and will be changed) And i don't post tuturials of thinks i don't know make

P.S: Code compile and work well! Tested by me before posting... I just didn't copy past the cmd of my test but yes made it again... It is normal make some mistakes right?
Reply
#6

Actually the /vr failed a bit because it sets the vehicle's visual damage but not the smoke damage
Reply
#7

It repair the whole types of damage... Not only visual!
Reply
#8

Quote:
Originally Posted by alpha500delta
View Post
Actually the /vr failed a bit because it sets the vehicle's visual damage but not the smoke damage
RepairVehicle repairs visual damage along with the health.
Reply
#9

Quote:
Originally Posted by Not available
View Post
RepairVehicle repairs visual damage along with the health.
Yeah and i have done this coz in forums, haven't there mutch tuts of this!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)