viewing paste topic/7040- item_deny.c | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#include "../map/atcommand.h"
#include "../map/itemdb.h"
#include "../map/clif.h"
#include "../map/pc.h"
#include "../map/pet.h"
 
#include "../common/HPMi.h"
#include "../common/HPMDataCheck.h" // should always be the last file included! (if you don't make it last, it'll intentionally break compile time)
 
HPExport struct hplugin_info pinfo = {
    "at_item",  // Plugin name
    SERVER_TYPE_MAP,// Which server types this plugin works with?
    "0.1",          // Plugin version
    HPM_VERSION,    // HPM Version (don't change, macro is automatically updated)
};
 
int item_deny_id[999]; // deny up to 999 items,
int item_deny_lv[999]; // which means allow up to 999 entries in `item_deny` table
int item_deny_total = 0;
 
void load_item_deny(void) {
    if ( SQL->Query( map->mysql_handle, "select * from item_deny" ) == SQL_ERROR )
        Sql_ShowDebug( map->mysql_handle );
    else {
        int i = 0;
        char *data;
        while ( SQL->NextRow( map->mysql_handle ) == SQL_SUCCESS ) {
            if ( SQL->GetData( map->mysql_handle, 0, &data, NULL ) == SQL_SUCCESS )
                item_deny_id[i] = atoi(data);
            if ( SQL->GetData( map->mysql_handle, 1, &data, NULL ) == SQL_SUCCESS )
                item_deny_lv[i] = atoi(data);
            i++;
        }
        item_deny_total = i;
        SQL->FreeResult( map->mysql_handle );
    }
    return;
}
 
HPExport void server_online (void) {
    load_item_deny();
}
 
ACMD(reloaditemdeny) {
    int i;
    char aaa[255];
    load_item_deny();
    clif->message( fd, "Item Deny has been reloaded." );
    safesnprintf( aaa, 255, "Total -> %d", item_deny_total );
    clif->message( fd, aaa );
    for ( i = 0; i < item_deny_total; i++ ) {
        safesnprintf( aaa, 255, "Item ID %d : Deny lv %d", item_deny_id[i], item_deny_lv[i] );
        clif->message( fd, aaa );
    }
    return true;
}
 
ACMD(item) {
    char item_name[100];
    int number = 0, item_id, flag = 0, bound = 0;
    struct item item_tmp;
    struct item_data *item_data;
    int get_count, i;
    memset(item_name, '\0', sizeof(item_name));
    if (!strcmp(info->command,"itembound") && (!message || !*message || (
        sscanf(message, "\"%99[^\"]\" %d %d", item_name, &number, &bound) < 2 &&
        sscanf(message, "%99s %d %d", item_name, &number, &bound) < 2
    ))) {
        clif->message(fd, msg_txt(295)); // Please enter an item name or ID (usage: @itembound <item name/ID> <quantity> <bound_type>).
        return false;
    } else if (!message || !*message || (
        sscanf(message, "\"%99[^\"]\" %d", item_name, &number) < 1 &&
        sscanf(message, "%99s %d", item_name, &number) < 1
    )) {
        clif->message(fd, msg_txt(983)); // Please enter an item name or ID (usage: @item <item name/ID> <quantity>).
        return false;
    }
    if (number <= 0)
        number = 1;
    if ((item_data = itemdb->search_name(item_name)) == NULL &&
        (item_data = itemdb->exists(atoi(item_name))) == NULL
    ) {
        clif->message(fd, msg_txt(19)); // Invalid item ID or name.
        return false;
    }
    if (!strcmp(info->command,"itembound") ) {
        if( !(bound >= IBT_MIN && bound <= IBT_MAX) ) {
            clif->message(fd, msg_txt(298)); // Invalid bound type
            return false;
        }
        switch( (enum e_item_bound_type)bound ) {
            case IBT_CHARACTER:
            case IBT_ACCOUNT:
                break; /* no restrictions */
            case IBT_PARTY:
                if( !sd->status.party_id ) {
                    clif->message(fd, msg_txt(1498)); //You can't add a party bound item to a character without party!
                    return false;
                }
                break;
            case IBT_GUILD:
                if( !sd->status.guild_id ) {
                    clif->message(fd, msg_txt(1499)); //You can't add a guild bound item to a character without guild!
                    return false;
                }
                break;
        }
    }
    item_id = item_data->nameid;
 
    for ( i = 0; i < item_deny_total; i++ ) {
        if ( item_deny_id[i] == item_id ) {
            if ( pc_get_group_level(sd) < item_deny_lv[i] ) {
                 clif->message( fd, "You are restricted from creating this item." );
                 return false;
            }
        }
    }
 
    get_count = number;
    //Check if it's stackable.
    if (!itemdb->isstackable2(item_data)) {
        if( bound && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) {
            clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors.
            return false;
        }
        get_count = 1;
    }
    for (i = 0; i < number; i += get_count) {
        // if not pet egg
        if (!pet->create_egg(sd, item_id)) {
            memset(&item_tmp, 0, sizeof(item_tmp));
            item_tmp.nameid = item_id;
            item_tmp.identify = 1;
            item_tmp.bound = (unsigned char)bound;
            if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
                clif->additem(sd, 0, 0, flag);
        }
    }
    if (flag == 0)
        clif->message(fd, msg_txt(18)); // Item created.
    return true;
}
 
ACMD(item2) {
    struct item item_tmp;
    struct item_data *item_data;
    char item_name[100];
    int item_id, number = 0, bound = 0;
    int identify = 0, refine = 0, attr = 0;
    int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    
    memset(item_name, '\0', sizeof(item_name));
    
    if (!strcmp(info->command,"itembound2") && (!message || !*message || (
        sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 &&
        sscanf(message, "%99s %d %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4, &bound) < 10 ))) {
        clif->message(fd, msg_txt(296)); // Please enter all parameters (usage: @itembound2 <item name/ID> <quantity>
        clif->message(fd, msg_txt(297)); //   <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4> <bound_type>).
        return false;
    } else if ( !message || !*message || (
                                  sscanf(message, "\"%99[^\"]\" %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9 &&
                                  sscanf(message, "%99s %d %d %d %d %d %d %d %d", item_name, &number, &identify, &refine, &attr, &c1, &c2, &c3, &c4) < 9
                                  )) {
        clif->message(fd, msg_txt(984)); // Please enter all parameters (usage: @item2 <item name/ID> <quantity>
        clif->message(fd, msg_txt(985)); //   <identify_flag> <refine> <attribute> <card1> <card2> <card3> <card4>).
        return false;
    }
    
    if (number <= 0)
        number = 1;
 
    if( !strcmp(info->command,"itembound2") && !(bound >= IBT_MIN && bound <= IBT_MAX) ) {
        clif->message(fd, msg_txt(298)); // Invalid bound type
        return false;
    }
 
    item_id = 0;
    if ((item_data = itemdb->search_name(item_name)) != NULL ||
        (item_data = itemdb->exists(atoi(item_name))) != NULL)
        item_id = item_data->nameid;
    
    if (item_id > 500) {
        int flag = 0;
        int loop, get_count, i;
        loop = 1;
        get_count = number;
        if( !strcmp(info->command,"itembound2") )
            bound = 1;
        if( !itemdb->isstackable2(item_data) ) {
            if( bound && (item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) ) {
                clif->message(fd, msg_txt(498)); // Cannot create bounded pet eggs or pet armors.
                return false;
            }
            loop = number;
            get_count = 1;
            if (item_data->type == IT_PETEGG) {
                identify = 1;
                refine = 0;
            }
            if (item_data->type == IT_PETARMOR)
                refine = 0;
            if (refine > MAX_REFINE)
                refine = MAX_REFINE;
        } else {
            identify = 1;
            refine = attr = 0;
        }
        for ( i = 0; i < item_deny_total; i++ ) {
            if ( item_deny_id[i] == item_id ) {
                if ( pc_get_group_level(sd) < item_deny_lv[i] ) {
                     clif->message( fd, "You are restricted from creating this item." );
                     return false;
                }
            }
        }
        for (i = 0; i < loop; i++) {
            memset(&item_tmp, 0, sizeof(item_tmp));
            item_tmp.nameid = item_id;
            item_tmp.identify = identify;
            item_tmp.refine = refine;
            item_tmp.attribute = attr;
            item_tmp.bound = (unsigned char)bound;
            item_tmp.card[0] = c1;
            item_tmp.card[1] = c2;
            item_tmp.card[2] = c3;
            item_tmp.card[3] = c4;
            
            if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_COMMAND)))
                clif->additem(sd, 0, 0, flag);
        }
        
        if (flag == 0)
            clif->message(fd, msg_txt(18)); // Item created.
    } else {
        clif->message(fd, msg_txt(19)); // Invalid item ID or name.
        return false;
    }
    
    return true;
}
 
ACMD(produce) {
    char item_name[100], atcmd_output[255];
    int item_id, attribute = 0, star = 0, i = 0;
    struct item_data *item_data;
    struct item tmp_item;
    
    memset(atcmd_output, '\0', sizeof(atcmd_output));
    memset(item_name, '\0', sizeof(item_name));
    
    if (!message || !*message || (
                                  sscanf(message, "\"%99[^\"]\" %d %d", item_name, &attribute, &star) < 1 &&
                                  sscanf(message, "%99s %d %d", item_name, &attribute, &star) < 1
                                  )) {
        clif->message(fd, msg_txt(1007)); // Please enter at least one item name/ID (usage: @produce <equip name/ID> <element> <# of very's>).
        return false;
    }
    
    if ( (item_data = itemdb->search_name(item_name)) == NULL &&
        (item_data = itemdb->exists(atoi(item_name))) == NULL ) {
        clif->message(fd, msg_txt(170)); //This item is not an equipment.
        return false;
    }
    
    item_id = item_data->nameid;
 
    for ( i = 0; i < item_deny_total; i++ ) {
        if ( item_deny_id[i] == item_id ) {
            if ( pc_get_group_level(sd) < item_deny_lv[i] ) {
                 clif->message( fd, "You are restricted from creating this item." );
                 return false;
            }
        }
    }
 
    if (itemdb->isequip2(item_data)) {
        int flag = 0;
        if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
            attribute = ATTRIBUTE_NORMAL;
        if (star < MIN_STAR || star > MAX_STAR)
            star = 0;
        memset(&tmp_item, 0, sizeof tmp_item);
        tmp_item.nameid = item_id;
        tmp_item.amount = 1;
        tmp_item.identify = 1;
        tmp_item.card[0] = CARD0_FORGE;
        tmp_item.card[1] = item_data->type==IT_WEAPON?
        ((star*5) << 8) + attribute:0;
        tmp_item.card[2] = sd->status.char_id & 0xFFFF;
        tmp_item.card[3] = sd->status.char_id >> 16;
        clif->produce_effect(sd, 0, item_id);
        clif->misceffect(&sd->bl, 3);
        
        if ((flag = pc->additem(sd, &tmp_item, 1, LOG_TYPE_COMMAND)))
            clif->additem(sd, 0, 0, flag);
    } else {
        safesnprintf(atcmd_output, 255, msg_txt(169), item_id, item_data->name); // The item (%d: '%s') is not equipable.
        clif->message(fd, atcmd_output);
        return false;
    }
    
    return true;
}
 
HPExport void plugin_init (void) {
    atcommand = GET_SYMBOL("atcommand");
    clif = GET_SYMBOL("clif");
    map = GET_SYMBOL("map");
    itemdb = GET_SYMBOL("itemdb");
    strlib = GET_SYMBOL("strlib");
    pet = GET_SYMBOL("pet");
    pc = GET_SYMBOL("pc");
    SQL = GET_SYMBOL("SQL");
 
    addAtcommand("item",item);
    addAtcommand("item2",item2);
    addAtcommand("produce",produce);
    addAtcommand("reloaditemdeny",reloaditemdeny);
}
Viewed 1346 times, submitted by AnnieRuru.