Jump to content
  • 0
Yonko

R> Specific Global Item drop

Question

Hi,

I would like to request a simple script like this. When monster is killed there's a percentage to
 drop 1 random item on list(custom list) which bypass their natural drop items see the scenario below(percentage of drop can be configured from 0.01%~1%)  on a specific map.

Poring in prt_fild01 drops 1 item on the list together of the its natural item drop(jellopy,  empty bottle, unripe apple. sticky mucus, knife[3], apple & poring card) when killed.

Thanks

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0
Posted (edited)

maybe something like :
(I have not tested)

-	script	RandomItem	-1,{
OnNPCKillEvent:
	if (rand(99) > 9) end; // 10% chance of success
	set [email protected]$,strcharinfo(3);
	switch(killedrid){
		case 1002:     // IF PORING
				if ([email protected]$ == "prt_fild01") 
					getitem 4005,1; // Santa poring card
				else if ([email protected]$ == "prt_fild02") 
					getitem 2236,1; // Santa poring hat
				break; 
	}
	end;
}

or alternatively

-	script	RandomItem	-1,{
OnNPCKillEvent:
	if (rand(99) > 9 || strnpcinfo(3) != "prt_fild01") end; // 10% chance of success, only works on prt_fild01

	.setarray [email protected],4005,2236;  		// Item array
	set [email protected],rand(1,getarraysize([email protected]);
	getitem [email protected][[email protected]],1; 
	end;
}



Note: This will add a item drop but not bypass any drops. Eg. if you add poring card on the custom list, you may drop 2 poring card at the sam time.

For bypass itemdrop you may have to use *addmonsterdrop but this has no conditional. It means the any monster will drop that item, doesnt matter map or anything...

Edited by buraquera

Share this post


Link to post
Share on other sites
  • 0
11 hours ago, buraquera said:

maybe something like :
(I have not tested)

-	script	RandomItem	-1,{
OnNPCKillEvent:
	if (rand(99) > 9) end; // 10% chance of success
	set [email protected]$,strcharinfo(3);
	switch(killedrid){
		case 1002:     // IF PORING
				if ([email protected]$ == "prt_fild01") 
					getitem 4005,1; // Santa poring card
				else if ([email protected]$ == "prt_fild02") 
					getitem 2236,1; // Santa poring hat
				break; 
	}
	end;
}

or alternatively

-	script	RandomItem	-1,{
OnNPCKillEvent:
	if (rand(99) > 9 || strnpcinfo(3) != "prt_fild01") end; // 10% chance of success, only works on prt_fild01

	.setarray [email protected],4005,2236;  		// Item array
	set [email protected],rand(1,getarraysize([email protected]);
	getitem [email protected][[email protected]],1; 
	end;
}



Note: This will add a item drop but not bypass any drops. Eg. if you add poring card on the custom list, you may drop 2 poring card at the sam time.

For bypass itemdrop you may have to use *addmonsterdrop but this has no conditional. It means the any monster will drop that item, doesnt matter map or anything...

thanks for the alternatively one how will i add another maps incase I want is multiple maps?

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
17 hours ago, Yonko said:

thanks for the alternatively one how will i add another maps incase I want is multiple maps?


 

-	script	RandomItem	-1,{
function CheckConditions;
OnNPCKillEvent:
	if (!CheckConditions(strcharinfo(0))) end; 

	.setarray [email protected],4005,2236;  		// Item array
	set [email protected],rand(1,getarraysize([email protected]);
	getitem [email protected][[email protected]],1; 
	end;

	function	CheckConditions	{
		set [email protected],10;													// Chance in percentage
		setarray [email protected]$,"prt_fild01","gef_fild02","moc_fild10";			// Maps
		for ([email protected] = 0;[email protected] < getarraysize([email protected]$); [email protected]++){					
			if (getarg(0) == [email protected]$[[email protected]]){					
				if (rand(99) < [email protected])
					return 1;
				else
					return 0;
			}
		}	
		return 0;
	}
}

 

Edited by buraquera

Share this post


Link to post
Share on other sites
  • 0
6 hours ago, buraquera said:


 

-	script	RandomItem	-1,{
function CheckConditions;
OnNPCKillEvent:
	if (!CheckConditions(strcharinfo(0))) end; 

	.setarray [email protected],4005,2236;  		// Item array
	set [email protected],rand(1,getarraysize([email protected]);
	getitem [email protected][[email protected]],1; 
	end;

	function	CheckConditions	{
		set [email protected],10;													// Chance in percentage
		setarray [email protected]$,"prt_fild01","gef_fild02","moc_fild10";			// Maps
		for ([email protected] = 0;[email protected] < getarraysize([email protected]$); [email protected]++){					
			if (getarg(0) == [email protected]$[[email protected]]){					
				if (rand(99) < [email protected])
					return 1;
				else
					return 0;
			}
		}	
		return 0;
	}
}

 

thank you so much. Last modification is it possible for 0.01~0.99% chances instead of 1%~100% chances?

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
11 hours ago, Yonko said:

thank you so much. Last modification is it possible for 0.01~0.99% chances instead of 1%~100% chances?

if (rand(99) < [email protected])

to:

set [email protected], 99; // For 0.99%
or
set [email protected],1;  // For 0.01%

and rand must be:

if (rand(9999) < [email protected])

Edited by buraquera

Share this post


Link to post
Share on other sites
  • 0

getitem will give the item directly to your inventory, if you want the monster to drop an item "on top" of their natural drops then you can do like below

 

// 1. Go to your src/map/script.cpp
// 2. Add below code before "case BL_PC:	//Get Character Position"
// case BL_MOB:
//	if (script_hasdata(st,6)) 
//		bl = map_id2bl(script_getnum(st,6));
//	break;
// 3. Recompile your server
// 4. Add below script

-	script	CustomDrop	FAKE_NPC,{
	OnNPCKillEvent:
		for ([email protected] = 0; [email protected] < .size; [email protected] += 4) {
			if (killedrid == .data[[email protected]]) {
				if (rand(10000) < .data[[email protected] + 3]) {
					getmapxy [email protected]$, [email protected], [email protected], BL_MOB, killedgid;
					[email protected] = .data[[email protected] + 2];
					while ([email protected]) {
						makeitem .data[[email protected] + 1], 1, [email protected]$, [email protected], [email protected];
						[email protected];
					}
				}
			}
		}
		end;
		
	OnInit:
		// <mob_id>, <item_id>, <item_amount>, <chance>
		// Chance ========================
		// 10000 	= 100%
		// 1000		= 10%
		// 100		= 1%
		// 99		= 0.99%
		// 50		= 0.50%
		// 1		= 0.01%
		// ===============================
		setarray .data[0], 
			1002, 607, 2, 10000, // poring will drop 2 ygg berries on the floor with 100% chance
			1002, 608, 3, 10000; // poring will drop 3 ygg seeds on the floor with 100% chance
		
		.size = getarraysize(.data);
		end;
}

 

Untitled.png

Share this post


Link to post
Share on other sites
  • 0
2 hours ago, Patskie said:

getitem will give the item directly to your inventory, if you want the monster to drop an item "on top" of their natural drops then you can do like below

 

// 1. Go to your src/map/script.cpp
// 2. Add below code before "case BL_PC:	//Get Character Position"
// case BL_MOB:
//	if (script_hasdata(st,6)) 
//		bl = map_id2bl(script_getnum(st,6));
//	break;
// 3. Recompile your server
// 4. Add below script

-	script	CustomDrop	FAKE_NPC,{
	OnNPCKillEvent:
		for ([email protected] = 0; [email protected] < .size; [email protected] += 4) {
			if (killedrid == .data[[email protected]]) {
				if (rand(10000) < .data[[email protected] + 3]) {
					getmapxy [email protected]$, [email protected], [email protected], BL_MOB, killedgid;
					[email protected] = .data[[email protected] + 2];
					while ([email protected]) {
						makeitem .data[[email protected] + 1], 1, [email protected]$, [email protected], [email protected];
						[email protected];
					}
				}
			}
		}
		end;
		
	OnInit:
		// <mob_id>, <item_id>, <item_amount>, <chance>
		// Chance ========================
		// 10000 	= 100%
		// 1000		= 10%
		// 100		= 1%
		// 99		= 0.99%
		// 50		= 0.50%
		// 1		= 0.01%
		// ===============================
		setarray .data[0], 
			1002, 607, 2, 10000, // poring will drop 2 ygg berries on the floor with 100% chance
			1002, 608, 3, 10000; // poring will drop 3 ygg seeds on the floor with 100% chance
		
		.size = getarraysize(.data);
		end;
}

 

Untitled.png

Quote
// case BL_MOB:
//	if (script_hasdata(st,6)) 
//		bl = map_id2bl(script_getnum(st,6));
//	break;

Really usefull! Tks for that. Why this is not commited??

Any chance of both mine or your script be laggy?? 

Share this post


Link to post
Share on other sites
  • 0
1 hour ago, buraquera said:

Really usefull! Tks for that. Why this is not commited??

Any chance of both mine or your script be laggy?? 

There should be no issues if you are using latest rAthena (C++ version)

Share this post


Link to post
Share on other sites
  • 0

There is getunitdata to retrieve x y for monster. Sample untested :






-	script	CustomDrop	FAKE_NPC,{
function add_drop;

OnNPCKillEvent:
	if (!playerattached())
		end;
	[email protected]_id = killedrid;
	[email protected] = getd(".size_" + [email protected]_id);
	if ([email protected] < 1)
		end;
	getunitdata killedgid, [email protected];
	[email protected] = [email protected][UMOB_X];
	[email protected] = [email protected][UMOB_Y];
	[email protected]$ = strcharinfo(3);

	for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
		[email protected] = getd(".chance_" + [email protected]_id + "[" + [email protected] + "]");
		if (rand(10000) < [email protected]) {
			[email protected] = getd(".item_id_" + [email protected]_id + "[" + [email protected] + "]");
			[email protected] = getd(".item_amount_" + [email protected]_id + "[" + [email protected] + "]");
			while ([email protected] > 0) {
				makeitem [email protected], 1, [email protected]$, [email protected], [email protected];
				[email protected];
			}
		}
	}
	end;
	
OnInit:
	// <mob_id>, <item_id>, <item_amount>, <chance>
	// Chance ========================
	// 10000 	= 100%
	// 1000		= 10%
	// 100		= 1%
	// 99		= 0.99%
	// 50		= 0.50%
	// 1		= 0.01%
	// ===============================
	add_drop( 1002, 607, 2, 10000 );	// poring will drop 2 ygg berries on the floor with 100% chance
	add_drop( 1002, 608, 3, 10000 ); // poring will drop 3 ygg seeds on the floor with 100% chance
	end;

function add_drop {
	[email protected]_count = getargcount();
	if ([email protected]_count % 4)
		return;

	for ([email protected] = 0; [email protected] < [email protected]_count; [email protected] += 4) {
		[email protected]_id = getarg([email protected]);
		[email protected] = getd(".size_" + [email protected]_id);
		setd ".item_id_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+1);	// <item_id>
		setd ".item_amount_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+2);	// <item_amount>
		setd ".chance_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+3);	// <chance>
		setd ".size_" + [email protected]_id, [email protected] + 1;
	}
	return;
}
}

 

  • MVP 1

Share this post


Link to post
Share on other sites
  • 0
On 7/31/2020 at 10:08 PM, Capuche said:

There is getunitdata to retrieve x y for monster. Sample untested :






-	script	CustomDrop	FAKE_NPC,{
function add_drop;

OnNPCKillEvent:
	if (!playerattached())
		end;
	[email protected]_id = killedrid;
	[email protected] = getd(".size_" + [email protected]_id);
	if ([email protected] < 1)
		end;
	getunitdata killedgid, [email protected];
	[email protected] = [email protected][UMOB_X];
	[email protected] = [email protected][UMOB_Y];
	[email protected]$ = strcharinfo(3);

	for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
		[email protected] = getd(".chance_" + [email protected]_id + "[" + [email protected] + "]");
		if (rand(10000) < [email protected]) {
			[email protected] = getd(".item_id_" + [email protected]_id + "[" + [email protected] + "]");
			[email protected] = getd(".item_amount_" + [email protected]_id + "[" + [email protected] + "]");
			while ([email protected] > 0) {
				makeitem [email protected], 1, [email protected]$, [email protected], [email protected];
				[email protected];
			}
		}
	}
	end;
	
OnInit:
	// <mob_id>, <item_id>, <item_amount>, <chance>
	// Chance ========================
	// 10000 	= 100%
	// 1000		= 10%
	// 100		= 1%
	// 99		= 0.99%
	// 50		= 0.50%
	// 1		= 0.01%
	// ===============================
	add_drop( 1002, 607, 2, 10000 );	// poring will drop 2 ygg berries on the floor with 100% chance
	add_drop( 1002, 608, 3, 10000 ); // poring will drop 3 ygg seeds on the floor with 100% chance
	end;

function add_drop {
	[email protected]_count = getargcount();
	if ([email protected]_count % 4)
		return;

	for ([email protected] = 0; [email protected] < [email protected]_count; [email protected] += 4) {
		[email protected]_id = getarg([email protected]);
		[email protected] = getd(".size_" + [email protected]_id);
		setd ".item_id_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+1);	// <item_id>
		setd ".item_amount_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+2);	// <item_amount>
		setd ".chance_" + [email protected]_id + "[" + [email protected] + "]", getarg([email protected]+3);	// <chance>
		setd ".size_" + [email protected]_id, [email protected] + 1;
	}
	return;
}
}

 

@Capuche Yeah right i always remember setunitdata and getunitdata for their main attributes only and tend to forget the UMOB_X and UMOB_Y constants as part of it 😛

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.