[Tutorial] How to add commands in our samp script
#1

Hi!
In this post i'd like to help those who don't know about scripting or they are beginners and they do not know how to add commands and add any action in it, Well, It is very easy, Before that i'm going to introduce myself. I am a 15-16 years old programmer from Pakistan. I've studied PHP , Javascript from different sites, Because i really thought that coding language will also make scripting easy. Yes, that's true if you're alone and you have no teacher and i recommend you to learn Javascript , C or c++, Because you would have understood some commands and will get to know what coding is. So that'd make scripting easier, But if you don't know any coding language then don't worry because there's a teacher to help you out! . So Let's begin the tutorial.
Following is the example of adding command!
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/mycommand", cmdtext, true, 10) == 0)
	{
		// Do something here
		return 1;
	}
	return 0;
}
//Following command is used to show commands which you've added,
Код:
  if (strcmp(cmdtext,"/cmds") == 0)
    {
        SendClientMessage(playerid, 0xAA3333AA, "/kill , /get ");
		return 1;
    }
If you'll write /cmds then this will appear as:
Код:
/kill , /get

That was easy, wasn't it?
So let's go forward to add any action in the command
Let's make a command to give person a gun.
Note: You should write "else if" because this will make a single action.
Like:
Код:
else if (strcmp("/molo", cmdtext, true, 10) == 0)
{
        SendClientMessage(playerid, HexColorHere, "You have recieved some molotovs.");
		GivePlayerWeapon (playerid,18,15);
		return 1;
  	}
Well, Following command will just send a person message who writes that command
Код:
SendClientMessage(playerid, HexColorHere, "You have recieved some molotovs.");
And following command will give weapon only
Код:
GivePlayerWeapon (playerid,weaponid,ammount);
So, it is very easy to add command then other coding. isn't it?
Reply if you want more help then i'll help you out!
Reply
#2

Why not use ZCMD? strcmp is too old
Reply
#3



Sorry but any command based off in OnPlayerCommandText is a bit meh due to its slow speed. It's all fun and games for you to learn a bit about strcmp because that is very useful, but then make sure you learn about that function rather than just how to do commands with it. Cool that you are learning but, as OneDay said, switch to something else. :P
Reply
#4

I, when i started scripting (a few months ago), used from ZCMD after first weeks. Why? Because it is more easy. Like everyone said: just get a command processor. There are many like: ZCMD (most popular),YCMD,iZCMD,LIFECMD. Just try one of these.
Reply
#5

Strcmp is old and slow if you want to help even esude YCMD or ZCMD are the best includes of processing
Reply
#6

Quote:
Originally Posted by C4rtm4n
Посмотреть сообщение
Strcmp is old and slow if you want to help even esude YCMD or ZCMD are the best includes of processing
Hey, everyone you must correct this idea.

strcmp is the most fastest processor or native, and its not slow.
the problem on it is just the 'if' and 'else if' if you are gonna make a server with much commands then you should use a command processor, because of strcmp can't handle all of this.
else use strcmp.

How its work?

exemple:

strcmp is fastest than CallRemoteFunction (CMD Processor), when you use a single command when OnPlayerCommandText isn't too long, the command got called fast, because of CPU search on shorts lines and doesn't need more search, but if OnPlayerCommandText containing much commands, the cpu need to search for the target cmd bettwen all of those cmds, so CallRemoteFunction is better in this case.

EDIT: forgot to specifie that isn't a cmd processor, @GoldenLion more faster :<
Reply
#7

To everyone who is saying something like "strcmp is slow" or "strcmp is old" or anything like this above: strcmp is a function to compare strings not a command processor.
Reply
#8

Talk about a proper explanation @******.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
...
In GoldenLion's defense, what he meant (I think) is that strcmp has its uses, just like any other string function, and that it should be used properly for that purpose only. That is, not as a command processor, but simply to compare 2 strings, not 1 string with 100 other strings.

I agree with everything else though + I hope your comment puts an end to the "what's the fastest command processor" threads (probably not though, because people can't be bothered to use the search function...).
Reply
#10

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
In GoldenLion's defense, what he meant (I think) is that strcmp has its uses, just like any other string function, and that it should be used properly for that purpose only. That is, not as a command processor, but simply to compare 2 strings, not 1 string with 100 other strings.
Yes, but I also said that because some people for whatever reason refer to a command processor by saying strcmp and that just sounds wrong in my opinion because it's just a function to compare strings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)