Alopex 發表於 2010-2-18 11:39:23

[command]自定義指令系統

恩......
技術沒芭樂高

所以沒有參數可以用XD


用法跟芭樂的cmd一樣



atcommand.h

新增:


struct command {
    char command;//指令長度
    struct script_code *script;
};

void read_command();//讀取資料函數



atcommand.c

新增:


static struct command* command_array;


找到bool is_atcommand函數,裡面的
int lv = 0;

下增加

int i = 0;






if( !message || !*message )
return false;



增加:

sscanf(message,"%99s",command);
while(i<100 && command_array[++i]){
if(strcmpi(command_array->command,command)==0)
{
run_script(command_array->script,0,sd->bl.id,0);
return true;
}
}




隨處增加:



void read_command()
{
FILE* fp;
int i=0;
char line;
if ((fp = fopen("command.txt", "r")) == NULL) {
ShowWarning("系統讀取:沒有發現command.txt檔案\n");
return;
}
memset(command_array, 0, sizeof(command_array));
while(i++<100 && fgets(line, sizeof(line), fp)){
char *str,*p;
struct command* command;
CREATE(command, struct command, 1);
memset(str, 0, sizeof(str));
p = line;
if(line == '/' && line == '/')continue; //檢查註解狀態
                while( ISSPACE(*p) )++p; // 檢測開頭是否為空
if( *p == '\0' )continue; // 檢測是否為結尾
                str = p;
                p = strchr(p,',');
                *p = '\0';
                p++;
                str = p;
                safestrncpy(command->command, str, sizeof(command->command));
                command->script = parse_script(str,"command.txt",i,0);
                if(command->script)
                              command_array = command;
else
    aFree(command)
      }
      return;
}



mob.c
static int mob_readdb(void)內



int fi;


下面增加

read_command();



結束

哆啦ˇ 發表於 2010-2-18 11:43:36

囧 ..

雨過天晴 發表於 2010-2-18 14:02:13

樓上的未達十字噢..
-/- 提醒一下
感謝分享 雖然我不會..

ㄚ聯 發表於 2010-7-17 23:59:17

來瞧瞧....正想學習有關源碼的東西

Alopex 發表於 2010-9-13 16:50:40

歡迎提供意見.........
頁: [1]
查看完整版本: [command]自定義指令系統