[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
#2

Ahh indentation!
Reply
#3

so good.
Reply
#4

Edited
Reply
#5

i have a question,how does it work?
Reply
#6

Edited.
Reply
#7

This looks really unclear, and I don't see it being better than DCMD and SSCANF...
Reply
#8

Quote:
Originally Posted by Weirdosport
This looks really unclear, and I don't see it being better than DCMD and SSCANF...
OK...Here's easy use
pawn Code:
public OnGamemodeInit(){
 gcmd("testCommand","test","t");
 return true;
}
public OnPlayerCommandText(playerid,cmdtext[]){
 return true;
}
//Player() - return the playerid
//params(pos) - return param (split by whitespace)
Command(testCommand){
 if(!nullparam(1)) printf "player:%d,param:%s" ,Player(),params(1)
 else printf "player:%d",Player()
 return true;
}
Reply
#9

Update
Reply
#10

hm its not so difficult to use dcmd^^ Why should we use yours? Is it faster or something?
Reply
#11

Quote:
Originally Posted by @TheShadow@
hm its not so difficult to use dcmd^^ Why should we use yours? Is it faster or something?
As I know,dcmd use strcmp to loop server commands,this is the main reason that affects efficiency.
In gcmd,it will check only two integer values first,that is far more faster than strcmp.

And while using gcmd,it offers some functions(some are marcos) to suit ur work.
eg:
paramsame(ppos,str[]); --> to check if is complete same string or not
paramlist(param1,param2...,param10); --> to check if is same with params
If you look the example 2,you will get more information about gcmd.(I'll try to make example 2 clearer,my fault.)
gcmd also easy for making one command with different types.(gcmd("testCommand","a","b","c","d","e"))
Whats more,it does support create/destroy and disallow/allow player to use any command.

If you have more suggestions,please advice tehn to me.^^
Reply
#12

as i know dcmd uses sscanf also...
it's fuckn simple an you don't need to make this idiotic funcs... your gcmd some kind of useless... need to understand and also debug
dcmd+sscanf and 4 minutes for make the command at all
Reply
#13

Quote:
Originally Posted by [RD
Chez ]
as i know dcmd uses sscanf also...
it's fuckn simple an you don't need to make this idiotic funcs... your gcmd some kind of useless... need to understand and also debug
dcmd+sscanf and 4 minutes for make the command at all
Thx for ur advice,i've found gcmd0.1's is very usless and inconvenientt for such command "/test <playerid>",which I was inadvertent on designing gcmd.
I'll update this issue,as far as better than d+s^^
Reply
#14

updated.
Reply
#15

your code is awesome! i need two days to understand it =)
Good job, i'm wait for anozer update
Reply
#16

Quote:
Originally Posted by [RD
Chez ]
your code is awesome! i need two days to understand it =)
Good job, i'm wait for anozer update
Thx^^,
in my opion, some code still unclear,and something still usless.That's why still 0.x version.
Im looking fowrad to getting commentary ,for taking more convenient,efficient for users^^
Reply
#17

Updated.
Add some examples in first post,and upgrade gcmd from 0.2.1 to 0.2.2
Reply
#18

Updated.
Easy for transalting dcmd to gcmd now(see Reply #3).
And upgrade gcmd from 0.2.2 to 0.2.3
Reply
#19

Updated.
1.It now use less memory and less time
2.Highly support for translating dcmd to gcmd now.(Only 1 issue)
3.No user-operation changed.
4.Upgrade gcmd from 0.2.4 to 0.3.0.
Reply
#20

Excellent work ! So function allows one command to do just short and full version?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)