OK論壇

 找回密碼
 註冊
查看: 1828|回復: 0

[分享] giveitem

[複製鏈接]
  • TA的每日心情
    開心
    2011-6-25 01:53 PM
  • 簽到天數: 10 天

    連續簽到: 0 天

    [LV.3]偶爾看看II

    發表於 2011-6-13 00:02:59 | 顯示全部樓層 |閱讀模式
    1. void atcommand_giveitem_sub(struct map_session_data *sd,struct item_data *item_data,int number)
    2. {
    3. int loop = 1,i,get_count,flag;
    4. struct item item_tmp;

    5. if(sd && item_data){
    6. if (!itemdb_isstackable2(item_data))
    7. { //如果不可叠加
    8. loop = number; //循环次数等于物品数量
    9. get_count = 1; //每次给与物品等于1
    10. }
    11. for (i = 0; i < loop; i++) { //分配物品
    12. memset(&item_tmp, 0, sizeof(item_tmp));
    13. item_tmp.nameid = item_data->nameid;
    14. item_tmp.identify = 1;
    15. if ((flag = pc_additem(sd, &item_tmp, get_count)))
    16. clif_additem(sd, 0, 0, flag);
    17. }
    18. }
    19. return;
    20. }
    21. ACMD_FUNC(giveitem)
    22. {
    23. char item_name[100];
    24. int number = 0, item_id;
    25. char flag[100];
    26. struct item_data *item_data;
    27. struct map_session_data *pl_sd;
    28. struct s_mapiterator* iter;

    29. nullpo_retr(-1, sd);

    30. memset(item_name, '\0', sizeof(item_name));

    31. if (!message || !*message || (
    32. sscanf(message, ""%99[^"]" %d "%99[^"]"", item_name, &number,flag) < 3 &&
    33. sscanf(message, "%99s %d %99s", item_name, &number,flag) < 3
    34. )) {
    35. clif_displaymessage(fd, "&#35831;&#36755;入物品Id,&#25968;量,&#23545;象 例:@Giveitem 501 100 MAP)");
    36. return -1;
    37. }

    38. if(number < 1)
    39. number = 1; //&#35774;置最小&#25968;量&#20026;1

    40. if ((item_data = itemdb_searchname(item_name)) == NULL &&
    41. (item_data = itemdb_exists(atoi(item_name))) == NULL)
    42. {
    43. clif_displaymessage(fd, msg_txt(19)); // 未找到相&#24212;名&#31216;或Id的物品
    44. return -1;
    45. }

    46. if (!itemdb_isstackable2(item_data))
    47. number = 1; //如果不可&#21472;加,&#25968;量&#20026;1,否&#21017;保持默&#35748;

    48. item_id = item_data->nameid;

    49. if(strcmp(flag,"MAP")==0)//如果是&#24403;前地&#22270;
    50. {
    51. iter = mapit_getallusers(); //取得Map&#20869;所有玩家
    52. while( (pl_sd = (TBL_PC*)mapit_next(iter)) != NULL ) {
    53. if (sd->status.account_id != pl_sd->status.account_id && pc_isGM(sd) >= pc_isGM(pl_sd) && pl_sd->bl.m == sd->bl.m)
    54. {//&#26465;件判&#26029;:目&#26631;Aid != 自身Aid 且 自身Gm等&#32423;大于&#23545;方 且 &#23545;方与自己在同一地&#22270;

    55. if ( pl_sd->vender_id || pl_sd->chatID )
    56. continue;
    57. else if (pc_isdead(pl_sd))
    58. continue;
    59. else
    60. atcommand_giveitem_sub(pl_sd,item_data,number);
    61. }
    62. }
    63. mapit_free(iter); //&#37322;放
    64. } else if(strcmp(flag,"ALL")==0) {//全服&#21457;放
    65. iter = mapit_getallusers(); //取得Map&#20869;所有玩家
    66. while( (pl_sd = (TBL_PC*)mapit_next(iter)) != NULL ) {
    67. if (sd->status.account_id != pl_sd->status.account_id && pc_isGM(sd) >= pc_isGM(pl_sd))
    68. {//&#26465;件判&#26029;:目&#26631;Aid != 自身Aid 且 自身Gm等&#32423;大于&#23545;方
    69. if ( pl_sd->vender_id || pl_sd->chatID ) //在挂店或者聊天室&#20869;
    70. continue;
    71. else if (pc_isdead(pl_sd)) //死亡
    72. continue;
    73. else
    74. atcommand_giveitem_sub(pl_sd,item_data,number); //&#21457;放物品
    75. }
    76. }
    77. mapit_free(iter); //&#37322;放
    78. } else if((pl_sd=map_nick2sd(flag)) && (pl_sd=map_charid2sd(atoi(flag)))){
    79. if(pl_sd != sd)
    80. atcommand_giveitem_sub(pl_sd,item_data,number); //&#21457;放物品
    81. } else
    82. return -1;
    83. return 0;
    84. }
    複製代碼


    1. @giveitem 501 100 MAP
    複製代碼
    回復

    使用道具 舉報

    您需要登錄後才可以回帖 登錄 | 註冊

    本版積分規則

    Archiver|手機版|小黑屋|OK討論區

    GMT+8, 2024-5-7 02:32 AM , Processed in 0.052321 second(s), 19 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回復 返回頂部 返回列表