//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;
}
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;
}
//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)
gcmd(Command_Kill){
SetPlayerHealth(player(),0);
return true;
}
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;
}
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;
}
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
#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;
}
#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;
}
Originally Posted by Weirdosport
This looks really unclear, and I don't see it being better than DCMD and SSCANF...
|
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;
}
Originally Posted by @TheShadow@
hm its not so difficult to use dcmd^^ Why should we use yours? Is it faster or something?
|
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 |
Originally Posted by [RD
Chez ]
your code is awesome! i need two days to understand it =) Good job, i'm wait for anozer update |