[Snippet]Efficient command
#1

Код:
//edit:1
if(strcmp("/bla",cmdtext) == 0)
A bit slower than
Код:
//edit:2
if(!strcmp("/bla",cmdtext))
A bit slower than
Код:
edit:3
if(!strcmp("bla",cmdtext[1]))
And time analysis&code
pawn Код:
#include <a_samp>

main(){}

public OnGameModeInit(){
  OnPlayerCommandText(0,"/test");
  return true;
}

public OnPlayerCommandText(playerid,cmdtext[]){
  for(new j;j<10;j++){
  new
    t1,t2,t3,t4,t5;
  t1 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(!strcmp("test",cmdtext[1])){}
  }
  t2 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(strcmp("test",cmdtext[1]) == 0){}
  }
  t3 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(!strcmp("/test",cmdtext)){}
  }
  t4 = GetTickCount();
  for(new i; i < 10000000;i++){
    if(strcmp("/test",cmdtext) == 0){}
  }
  t5 = GetTickCount();
  printf("-%d-%d-%d-%d-",t2-t1,t3-t2,t4-t3,t5-t4);
  }
  return true;
}
Код:
[10:22:59] -1266-1406-1313-1453-
[10:23:05] -1265-1407-1296-1454-
[10:23:10] -1265-1406-1313-1453-
[10:23:16] -1266-1406-1297-1453-
[10:23:21] -1281-1406-1297-1438-
[10:23:26] -1265-1422-1297-1453-
[10:23:32] -1266-1406-1313-1437-
[10:23:37] -1281-1407-1297-1453-
[10:23:43] -1281-1406-1297-1453-
[10:23:48] -1266-1406-1313-1437-
As we can see, edit:3 is faster than anyother edition.
Would anyone use edit:3 to make command in the future?
Reply
#2

a command like teleport or text ill show u both

Teleport:
----------
Код:
if( !strcmp(cmdtext,"/Drift1",true ))
	{
		SetPlayerPos(playerid, -274.9351,1535.3416,75.3594);
		SendClientMessage(playerid,COLOR_GREEN, "Welcome To drift1");
		return 1;
Text:
-------------
Код:
{
	if (strcmp("/text", cmdtext, true, 10) == 0)
	{
		SendClientMessage(playerid,0xAA3333A,"Text");
		return 1;
u can add as many as u want aslong as u use }{ and on send message to just add SendClientMessage( est under to give a new line on that command
Reply
#3

Quote:
Originally Posted by [DD
FlameOFDeath ]
a command like teleport or text ill show u both

Teleport:
----------
Код:
if( !strcmp(cmdtext,"/Drift1",true ))
	{
		SetPlayerPos(playerid, -274.9351,1535.3416,75.3594);
		SendClientMessage(playerid,COLOR_GREEN, "Welcome To drift1");
		return 1;
Text:
-------------
Код:
{
	if (strcmp("/text", cmdtext, true, 10) == 0)
	{
		SendClientMessage(playerid,0xAA3333A,"Text");
		return 1;
u can add as many as u want aslong as u use }{ and on send message to just add SendClientMessage( est under to give a new line on that command
O.o something here I think.
Reply
#4

where O.o quite simple i learnd sa-mpscripting for these bits and adding stuff onto the server like cars objects quite simple just got a streamer problem i think lol
Reply
#5

Quote:
Originally Posted by [DD
FlameOFDeath ]
where O.o quite simple i learnd sa-mpscripting for these bits and adding stuff onto the server like cars objects quite simple just got a streamer problem i think lol
Hmm, I don't make sense : O
This is a [Snippet] topic, not a [Help] topic

And wrong's here
Код:
if(strcmp("/text",cmdtext,true,10) == 0)
How does this work? I dunno
Reply
#6

Quote:

Hmm, I don't make sense : O
This is a [Snippet] topic, not a [Help] topic

And wrong's here
Код:
if(strcmp("/text",cmdtext,true,10) == 0)
How does this work? I dunno
WOOPs sorry
Reply
#7

Quote:
Originally Posted by [DD
FlameOFDeath ]
Quote:

Hmm, I don't make sense : O
This is a [Snippet] topic, not a [Help] topic

And wrong's here
Код:
if(strcmp("/text",cmdtext,true,10) == 0)
How does this work? I dunno
WOOPs sorry
Never mind.
But what is your opinion to this snippet?
Reply
#8

Quote:
Originally Posted by yezizhu
Код:
//edit:1
if(strcmp("/bla",cmdtext) == 0)
A bit slower than
Код:
//edit:2
if(!strcmp("/bla",cmdtext))
A bit slower than
Код:
edit:3
if(!strcmp("bla",cmdtext[1]))
Does anyone can use edit:3 to make command?
I think
Код:
if(!strcmp("bla",cmdtext[1]))
will be faster as
Код:
if(!strcmp("/bla",cmdtext))
but I don't think
Код:
if(!strcmp("/bla",cmdtext))
is faster then
Код:
if(strcmp("/bla",cmdtext) == 0)
Reply
#9

Quote:
Originally Posted by °ғαιιοцт°
Quote:
Originally Posted by yezizhu
Код:
//edit:1
if(strcmp("/bla",cmdtext) == 0)
A bit slower than
Код:
//edit:2
if(!strcmp("/bla",cmdtext))
A bit slower than
Код:
edit:3
if(!strcmp("bla",cmdtext[1]))
Does anyone can use edit:3 to make command?
I think
Код:
if(!strcmp("bla",cmdtext[1]))
will be faster as
Код:
if(!strcmp("/bla",cmdtext))
but I don't think
Код:
if(!strcmp("/bla",cmdtext))
is faster then
Код:
if(strcmp("/bla",cmdtext) == 0)
Ya, I will add time analysis later.
Reply
#10

how can you do that??
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)