UID178554
帖子
精華
主題
積分16695
現金
積極性
威望
違規
熱心
推廣次數
閱讀權限30
註冊時間2009-7-26
在線時間 小時
最後登錄1970-1-1
TA的每日心情 | 慵懶 2013-7-11 12:09 AM |
---|
簽到天數: 118 天 連續簽到: 1 天 [LV.6]常住居民II
|
本帖最後由 Alopex 於 2011-9-6 07:50 PM 編輯
已測結束,感謝sinya,rgrg1234
atcommand.c
add:- #define MAX_CMD 100 //Default the limit of cmd.
- struct Command {
- char cmd_name[100]; //The length of name.
- int gm_lv;
- int char_lv;
- int cmd_para_num;
- struct script_code *cmd_script;
- };
- static struct Command *cmd_db[MAX_CMD];//To be a point.
- static int cmd_num = 0;
- void do_init_command(const char *filename);
- void do_init_command(const char *filename){
- FILE* fp;
- int line_num = 0,read_cmd_num = 0;
- char line[1024];
- if((fp = fopen(filename, "r")) == NULL )
- {
- ShowWarning("do_init_command: File "%s" does not exist.\n ",filename);
- return;
- }
- memset(cmd_db, 0, sizeof(cmd_db)); //Init cmd_db.
- while(fgets(line, sizeof(line), fp) && ++line_num)
- {
- int i;
- char *str[5], *p;
- struct Command *cmd;
- CREATE(cmd, struct Command, 1);
- memset(str, 0, sizeof(str));
-
- p = line;
- while(ISSPACE(*p))p++;//skip space.
- if(*p == '/' && *(p+1) == '/')
- continue; // skip "//"
- if(*p == '\0')
- continue; // The ending of line.
- for(i = 0 ; i < 5 ; i++)
- {
- str[i] = p;
- p = strchr(p, ',');
- if(p == NULL||i==4) break;
- *p = '\0'; // Exchange ',' for '\0';
- p++;
- }
- if(get_atcommandinfo_byname(str[0]) == NULL || str[0] == NULL)// check repeated cmd.
- {
- safestrncpy(cmd->cmd_name, str[0], sizeof(cmd->cmd_name));
- cmd->gm_lv = atoi(str[1]);
- cmd->char_lv = atoi(str[2]);
- cmd->cmd_para_num = atoi(str[3]);
- cmd->cmd_script = parse_script(str[4], filename ,line_num ,0);
- if(cmd->cmd_script)
- {
- cmd_db[read_cmd_num] = cmd;
- read_cmd_num++;
- //ShowStatus("Do_init_command: Loaded Command: %s , Number : %d. \n",cmd->cmd_name,read_cmd_num);
- }else
- aFree(cmd);
- }else
- aFree(cmd);
- }
- cmd_num = read_cmd_num;
- fclose(fp);
- ShowStatus("Do_init_command: Complete ! Total %lu defined in %s . \n",cmd_num,filename);
- return;
- }
複製代碼 Looking for:- info = get_atcommandinfo_byname(command);
複製代碼 add:- if(info == NULL){
- int cmd_id;
- struct Command *cmd_info;
- char* name = (char*)command;
- if( *name == atcommand_symbol || *name == charcommand_symbol ) name++;
- ARR_FIND( 0, cmd_num, cmd_id, strcmpi(cmd_db[cmd_id]->cmd_name, name) == 0 );//looking for name in cmd_db;
- cmd_info = ((cmd_id > cmd_num) ? NULL : cmd_db[cmd_id]);
-
- if(cmd_info == NULL || (type && ((*atcmd_msg == atcommand_symbol && pc_isGM(sd) < cmd_info->gm_lv) || (*atcmd_msg == charcommand_symbol && pc_isGM(sd) < cmd_info->char_lv))))
- {
- sprintf(output, msg_txt(153), command); // "%s is Unknown Command."
- clif_displaymessage(fd, output);
- return true;
- }
-
- {
- int i;
- char *str = params;
- char *split,para_data[100];
- struct map_session_data *target = (*atcmd_msg==atcommand_symbol) ? sd : ssd;
- script_cleararray_pc(target, "@cmd_para$" ,(void*)0);//clear @cmd_para$.
- for(i = 0 ; i < cmd_info->cmd_para_num && i < 128 ; i++)
- {
- split = strchr(str ,' ');
- if(split == NULL)//To avoid empty data.
- {
- script_setarray_pc(target,"@cmd_para$", i , (void*)str , (int*)0);
- break;
- }
- *split = '\0';
- safestrncpy(para_data, str, sizeof(para_data));
- script_setarray_pc(target,"@cmd_para$", i , (void*)para_data , (int*)0);
- str = ++split;
- }
- run_script(cmd_info->cmd_script,0,target->bl.id,0);
- }
- return true;
- }
複製代碼 map.c
looking for:add:- do_init_command("db/cmd_db.txt");
複製代碼 db底下建cmd_db.txt
內容:- //格式:
- //<玩家指令>,<@指令等級>,<#指令等級>,<參數數量>,{腳本}
- // @cmd_para$[]為參數,不超過127
- // 數字參數請使用atoi(@cmd_para$[])
- testcommand,10,20,1,{mes "看到訊息表示成功!"+@cmd_para$[0];close;}
複製代碼 |
評分
-
查看全部評分
|