[Include] [INC]gcmd v0.4.1(2009/07/18)
#1

[gcmd]
Description:
gcmd is a command system:
Own its individual command syntax
Support mutli-named command(gcmd("command1","typeme_a","typeme_b","typ eme_c"))
Support "dcmd" syntax
Support individual teleport command
It also similar with dcmd,so you can easily know how to use gcmd.
Version:0.4.1

Start to use gcmd
Firstly,you should DO:
pawn Code:
//First add include <gcs_gcmd> on the top of script.
#include <gcs_gcmd>
//then add gcmd_struction() when install
public OnGameModeInit(){
 gcmd_struction();//struction
 return true;
}
//or
public OnFilterScriptInit(){
 gcmd_struction();
 return true;
}
//And then add gcmd_process() in OnPlayerCommandText(playerid,cmdtext[])
public OnPlayerCommandText(playerid,cmdtext[]){
 gcmd_tele_insert();//struction for tele system
 gcmd_process();//process for main system
 return false;
}
Now,struct finished.

1 command = 1 teleportion
gcmd individual teleport command.
pawn Code:
public OnPlayerCommandText(playerid,cmdtext[]){
 gcmd_tele_insert();//struction
 //gcmd_tele(command[],Float:x,Float:y,Float:z,Float:angel,Interior,ignoreVec,remindText[]);
 /**
 ignoreVec = true --> teleport player without vehicle
 ignoreVec = false --> teleport player within vehicle(if has)
 */

 gcmd_tele("helloworld",1836.75,-1837.99,26.04,180.0,0,true,"Hellow,world!");//type "/helloworld" you will be teleported
 return false;
}
It is easy and fast.

Translate dcmd to gcmd easily
You can easily translate dcmd to gcmd without function alomost any code edit now^^
Note:
It has less effeicent than using gcmd function.
Is time to translate dcmd&sscanf to gcmd^^.
pawn Code:
//Firstly,change dcmd to gcmd_create
//eg:
public OnPlayerCommandText(playerid,cmdtext[]){
 dcmd(kill,4,cmdtext);
 return false;
}
//edited to:
public OnGameModeInit(){// OR OnFilterScriptInit()
 gcmd_create("kill","kill");
 return true;
}
//Secondly,change dcmd_functioname(playerid,params[]) to gcmd(functionname)
//eg:
dcmd_kill(playerid,params[])
//edited to:
gcmd(kill)
Now start to compiler,will get no error and works find!

Use gcmd individual syntax:
If you feel something strange,don't worry,you will get it.
[/PAWN]
Create kill command
add gcmd_create("Command_Kill","kill","k"); in OnGameModeInit();
Then:
pawn Code:
gcmd(Command_Kill){
 SetPlayerHealth(player(),0);
 return true;
}
Create kick command
add gcmd_create("Command_Kick","kick","kickoff"); in OnGameModeInit();
Then:
pawn Code:
gcmd(Command_Kick){
 if(param("u"){//chexk if is playerid with connection
  new
   tmpstr[128];
  if(paramn(2)){//check no.2 param if is null
   format(tmpstr,sizeof tmpstr,"[Server]%d has been kicked by %d(reason:unknown).",parami(1),player());
  }else{
    format(tmpstr,sizeof tmpstr,"[Server]%d has been kicked by %d(reason:%s).",parami(1),player(),params(2));
  }
  kick(parami(1));
  SendClientMessageToAll(0xFF8080FF,tmpstr);
 }else{
  SendClientMessage(player(),0xFF8080FF,"[Server]Unconnect/exist playerid");
 }
 return true;
}
Create ban command
add gcmd_create("Command_Ban","ban","b"); in OnGameModeInit();
Then:
pawn Code:
gcmd(Command_Ban){
 if(param("u"){//chexk if is playerid with connection
  new
   tmpstr[128];
  if(paramn(2)){//check no.2 param if is null
   format(tmpstr,sizeof tmpstr,"[Server]%d has been banned by %d(reason:unknown).",parami(1),player());
  }else{
    format(tmpstr,sizeof tmpstr,"[Server]%d has been banned by %d(reason:%s).",parami(1),player(),params(2));
  }
  kick(parami(1));
  SendClientMessageToAll(0xFF8080FF,tmpstr);
 }else{
  SendClientMessage(player(),0xFF8080FF,"[Server]Unconnect/exist playerid");
 }
 return true;
}
Now,is time for some complex command.
Here's the explainsion:
cheatCommand:
text:
/cheat,/c
usage:
active cheat code,or active admin command
type "/cheat code health human(or god) 0" will change ur health
type "/cheat code armour human(or god) 0" will change ur armour
type "/cheat code gun minigun(or unkown) 0" will give u weapon
type "/cheat code admin active 911" will active adminCommand
adminCommand:
text:
/admin,/a
usage:
ban/unban/create/destroy cheatCommand
type "/admin 911 key 0" will destroy cheatCommand
type "/admin 911 key 1" will create cheatCommand
type "/admin 911 key 255" will ban cheatCommand for all
type "/admin 911 key 256" will unban cheatCommand for all
Add
pawn Code:
gcmd_create("cheatCommand","cheat","c");
gcmd_create("adminCommand","admin","a");
gcmd_create("killCommand","kill","k");
gcmd_setPlayerAbleUse(INVALID_PLAYER_ID,"adminCommand",false);//INVALID_PLAYER_ID means 0-199
in OnGameModeInit();
Then:
pawn Code:
#define send(%1) \
 SendClientMessage(player(),0xFFFFFFAA,(%1))

gcmd(cheatCommand){
 if(param("sssf","code","","")){//check if is same string, and no.2,no.3 params if are string,and no.4 param if is floatric
  if(paramsame(2,"health")){//no.2 param if is "health"
   if(paramsame(3,"human")){//no.3 param if is "human"
    SetPlayerHealth(player(),90);
    send("Im human");
   }else if(paramsame(3,"god")){//no.3 param if is "god"
    SetPlayerHealth(player(),99999);
    send("Im god...");
   }
  }else if(paramsame(2,"armour")){//no.2 param if is "armour"
     if(paramsame(3,"human")){//no.3 param if is "human"
        SetPlayerArmour(player(),90);
    send("I have armour");
     }else if(paramsame(3,"human")){//no.3 param if is "god"
        SetPlayerArmour(player(),99999);
        send("AI's here...");
     }
    }else if(paramsame(2,"gun")){//no.2 param if is "gun"
   if(paramsame(3,"minigun"))//no.3 param if is "minigun"
    GivePlayerWeapon(player(),38,9997);
     if(paramsame(3,"unknown"))//no.3 param if is "unknown"
    GivePlayerWeapon(player(),37,9997);
   }
   send("cheat code active");
  }else if(param("ssi","admin","active")){//if is same string + no.3 param if is a numberic
    if(paramsame(3,"911")){//no.3 param if is "911"
     new
      tmpstr[128],
      retstr[10][128];
      gcmd_getCommand("adminCommand",retstr);//create command
      format(tmpstr,sizeof tmpstr,"security code correct,you can now use %s %s %s %s %s %s %s %s %s now",retstr[0],retstr[1],retstr[2],retstr[3],retstr[4],retstr[5],retstr[6],retstr[7],retstr[8],retstr[9]);
      send(tmpstr);
      gcmd_setPlayerAbleUse(player(),"adminCommand",true);
    }else{
     send("security code error");
      }
    }
  return true;
}
 
gcmd(adminCommand){
 if(paramn(1)){
  send("please input security code");
  return true;
 }
 if(param("isi","911","key")){//check if is same string,and no.3 param if is numberic
  if(paramsame(3,"0")){//if no.3 param is 0
   gcmd_delete("cheatCommand");
   send("[Admin]Destroy cheatCommand");
  }else if(paramsame(3,"1")){//if no.3 param is 1
   gcmd_create("cheatCommand","cheat","c");
   send("[Admin]Create cheatCommand");
  }else if(paramsame(3,"255")){//if no.3 param is 255
   if(gcmd_setPlayerAbleUse(parami(3),"cheatCommand",false)){
   send("[Admin]No one can use cheat command now");
   //because "parami(3)" is 255(INVALID_PLAYER_ID),so no one can use this command now
   }else{
    send("[Admin]cheat command not exist");
   }
  }else if(paramsame(3,"256")){//if no.3 param is 256
   if(gcmd_setPlayerAbleUse(INVALID_PLAYER_ID,"cheatCommand",true)){
   send("[Admin]Everyone can use cheat command now");
   //INVALID_PLAYER_ID means ban this command for anyone
   }else{
    send("[Admin]cheat command doesnt exist");
   }
  }
 }
 return true;
}
Time analysing:
loop 1000 times
gcmd main : 10329 10328 10359 10359 10360
gcmd tele : 3547 3563 3594 3562 3578
dcmd : 4766 4734 4719 4750 4750
test code.
pawn Code:
#define TEST_TYPE   (1)//-- 1=gcmd_main,2=gcmd_tele,3=dcmd


#include <a_samp>

#if (TEST_TYPE == 1 || TEST_TYPE == 2)
#include <gcs/gcs_gcmd>
#endif
main(){
    #if TEST_TYPE == 1
        print "Time test:gcmd_main"
    #elseif TEST_TYPE == 2
        print "Time test:gcmd_tele"
    #elseif TEST_TYPE == 3
        print "Time test:dcmd   "
    #else
        #error "Please set TEST_TYPE"
    #endif
}


#if TEST_TYPE == 3
#define dcmd(%1,%2,%3)      if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
#endif

public OnGameModeInit(){
    #if (TEST_TYPE == 1 || TEST_TYPE == 2)
    gcmd_struction();
    #endif
   
    #if TEST_TYPE == 1
    for(new i;i<1000;i++){
        gcmd_create("tele001","t-tele001");
        gcmd_create("test2","t-test");
        gcmd_create("complexcommand");
        gcmd_create("itypecomplexcommand","t_itypecomplexcommand");
        gcmd_create("testcommand","t-testcommand");
        gcmd_create("tele001","t-tele001");
        gcmd_create("test2","t-test");
        gcmd_create("complexcommand");
        gcmd_create("itypecomplexcommand","t_itypecomplexcommand");
        gcmd_create("testcommand","t-testcommand");
    }// = 10K commands
    #endif
   
    timetest_struction();
    SetTimer("timetest_start",1500,false);
}

forward timetest_start();

timetest_struction(){
    OnPlayerCommandText(0,"/");
}

public timetest_start(){
    print "start"
    for(new t;t<5;t++){
    new
        tick1,tick2;
    tick1 = GetTickCount();
    for(new i;i<1000;i++){
        OnPlayerCommandText(0,"/01 23 45 67 89 01 23 45 67 89");///itypecomplexcommand2
    }
    tick2 = GetTickCount();
    printf("tick:%d",tick2-tick1);
    }
    print "end"
}


#if TEST_TYPE == 3
dcmd_tele001(playerid,params[]){
    return true;
}
dcmd_test2(playerid,params[]){
    return true;
}
dcmd_complexcommand(playerid,params[]){
    return true;
}
dcmd_itypecomplexcommand(playerid,params[]){
    return true;
}
dcmd_testcommand(playerid,params[]){
    return true;
}
#endif

public OnPlayerCommandText(playerid,cmdtext[]){
    #if TEST_TYPE == 1
    gcmd_process();
    #endif
   
    #if TEST_TYPE == 2
    gcmd_tele_insert();
    for(new i;i<1000;i++){
        gcmd_tele("tele001",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("test2",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("complexcommand",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("itypecomplexcommand",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("testcommand",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("tele001",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("test2",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("complexcommand",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("itypecomplexcommand",125,320,5,random(360),0,true,"Welcome to tele001");
        gcmd_tele("testcommand",125,320,5,random(360),0,true,"Welcome to tele001");
    }// = 10K commands
    #endif
   
    #if TEST_TYPE == 3
    for(new i;i<1000;i++){
        dcmd(tele001,7,cmdtext);
        dcmd(test2,5,cmdtext);
        dcmd(complexcommand,14,cmdtext);
        dcmd(itypecomplexcommand,19,cmdtext);
        dcmd(testcommand,11,cmdtext);
        dcmd(tele001,7,cmdtext);
        dcmd(test2,5,cmdtext);
        dcmd(complexcommand,14,cmdtext);
        dcmd(itypecomplexcommand,19,cmdtext);
        dcmd(testcommand,11,cmdtext);
    }// = 10K commands
    #endif
   
    return false;
}
Download:
gcmd v0.4:
gcs_gcmd.inc
example:
example.pwn

Bug(s):
1.Thouth it can easily translate dcmd to gcmd(see reply#3),
it should replace all "return value;" to "return;" in the command function,
or you will get warnning 209.
In all,it does't matter
-

Other credits:
Nero_3D - 10 ----- SortArray
Y_less ----- sscanf

If you connot understand how to use gcmd,or any bug you find,
please contact us[mail,pmsg,or post].I'll try my best to help you (English my bad)

r:GCS Team
Reply


Messages In This Thread
[INC]gcmd v0.4.1(2009/07/18) - by yezizhu - 10.05.2009, 08:55
Re: [INC]gcmd v0.1 (really easy,and for speed) - by Lewwy - 10.05.2009, 09:04
Re: [INC]gcmd v0.1 (really easy,and for speed) - by shindo - 10.05.2009, 09:48
Re: [INC]gcmd v0.1 (really easy,and for speed) - by yezizhu - 10.05.2009, 09:50
Re: [INC]gcmd v0.1 (really easy,and for speed) - by shindo - 10.05.2009, 09:53
Re: [INC]gcmd v0.1 (really easy,and for speed) - by yezizhu - 10.05.2009, 10:08
Re: [INC]gcmd v0.1 (really easy,and for speed) - by Weirdosport - 10.05.2009, 14:20
Re: [INC]gcmd v0.1 (really easy,and for speed) - by yezizhu - 10.05.2009, 14:44
Re: [INC]gcmd v0.1 (Update) - by yezizhu - 11.05.2009, 10:41
Re: [INC]gcmd v0.1 (Update) - by @TheShadow@ - 11.05.2009, 12:18
Re: [INC]gcmd v0.1 (Update) - by yezizhu - 11.05.2009, 16:19
Re: [INC]gcmd v0.1 (Update) - by G_ROW_Chez - 13.05.2009, 10:37
Re: [INC]gcmd v0.1 (Updating) - by yezizhu - 13.05.2009, 13:09
Re: [INC]gcmd v0.2 - by yezizhu - 29.05.2009, 08:24
Re: [INC]gcmd v0.2 - by G_ROW_Chez - 30.05.2009, 11:09
Re: [INC]gcmd v0.2 - by yezizhu - 30.05.2009, 14:44
Re: [INC]gcmd v0.2 - by yezizhu - 06.06.2009, 06:51
Re: [INC]gcmd v0.2 - by yezizhu - 06.06.2009, 13:08
Re: [INC]gcmd v0.2 - by yezizhu - 07.06.2009, 14:42
Re: [INC]gcmd v0.3 - by mysan - 07.06.2009, 19:13
Re: [INC]gcmd v0.3 - by yezizhu - 08.06.2009, 13:07
Re: [INC]gcmd v0.3 - by yezizhu - 08.06.2009, 13:08
Re: [INC]gcmd v0.4.1(2009/07/18) - by yezizhu - 18.07.2009, 14:58

Forum Jump:


Users browsing this thread: 4 Guest(s)