diff options
author | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-09-06 20:37:07 +0000 |
---|---|---|
committer | shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-09-06 20:37:07 +0000 |
commit | fcf9c8c31bb28d6580fa647766a1d8192c435c89 (patch) | |
tree | e6e760cb1e2f3c06e120c1f9750477b51270b63b /src/map | |
parent | ea06cf32502c3c7b2a5eefa4421c85f7a3315ee3 (diff) | |
download | hercules-fcf9c8c31bb28d6580fa647766a1d8192c435c89.tar.gz hercules-fcf9c8c31bb28d6580fa647766a1d8192c435c89.tar.bz2 hercules-fcf9c8c31bb28d6580fa647766a1d8192c435c89.tar.xz hercules-fcf9c8c31bb28d6580fa647766a1d8192c435c89.zip |
Added new script command 'getrandgroupitem' as a fix for bugreport:5529, db developers will follow up with the replacements shortly.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16752 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/script.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c index 4e30268d8..51c795a7c 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -16916,6 +16916,49 @@ BUILDIN_FUNC(checkre) return 0; } +/* getrandgroupitem <group_id>,<quantity> */ +BUILDIN_FUNC(getrandgroupitem) { + TBL_PC* sd; + int i, get_count = 0, flag, nameid, group = script_getnum(st, 2), qty = script_getnum(st,3); + struct item item_tmp; + + if( !( sd = script_rid2sd(st) ) ) + return 0; + + if( qty <= 0 ) { + ShowError("getrandgroupitem: qty is <= 0!\n"); + return 1; + } + if( (nameid = itemdb_searchrandomid(group)) == UNKNOWN_ITEM_ID ) { + return 1;/* itemdb_searchrandomid will already scream a error */ + } + + memset(&item_tmp,0,sizeof(item_tmp)); + + item_tmp.nameid = nameid; + item_tmp.identify = itemdb_isidentified(nameid); + + //Check if it's stackable. + if (!itemdb_isstackable(nameid)) + get_count = 1; + else + get_count = qty; + + for (i = 0; i < qty; i += get_count) { + // if not pet egg + if (!pet_create_egg(sd, nameid)) { + if ((flag = pc_additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT))) { + clif_additem(sd, 0, 0, flag); + if( pc_candrop(sd,&item_tmp) ) + map_addflooritem(&item_tmp,get_count,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0); + } + } + } + + return 0; +} + + // declarations that were supposed to be exported from npc_chat.c #ifdef PCRE_SUPPORT BUILDIN_FUNC(defpattern); @@ -17353,6 +17396,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(is_function,"s"), BUILDIN_DEF(get_revision,""), BUILDIN_DEF(freeloop,"i"), + BUILDIN_DEF(getrandgroupitem, "ii"), /** * @commands (script based) **/ |