From fcf9c8c31bb28d6580fa647766a1d8192c435c89 Mon Sep 17 00:00:00 2001 From: shennetsind Date: Thu, 6 Sep 2012 20:37:07 +0000 Subject: 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 --- src/map/script.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/map/script.c') 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 , */ +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) **/ -- cgit v1.2.3-70-g09d2