Jump to content
  • 0

R> Specific Global Item drop


Question

Posted

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

13 answers to this question

Recommended Posts

  • 1
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) < .@chance)

to:

set .@chance, 99; // For 0.99%
or
set .@chance,1;  // For 0.01%

and rand must be:

if (rand(9999) < .@chance)

Edited by buraquera
  • 0
Posted (edited)

maybe something like :
(I have not tested)

-	script	RandomItem	-1,{
OnNPCKillEvent:
	if (rand(99) > 9) end; // 10% chance of success
	set .@map$,strcharinfo(3);
	switch(killedrid){
		case 1002:     // IF PORING
				if (.@map$ == "prt_fild01") 
					getitem 4005,1; // Santa poring card
				else if (.@map$ == "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 .@Items,4005,2236;  		// Item array
	set .@rand,rand(1,getarraysize(.@items);
	getitem .@Items[.@rand],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
  • 0
Posted
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 .@map$,strcharinfo(3);
	switch(killedrid){
		case 1002:     // IF PORING
				if (.@map$ == "prt_fild01") 
					getitem 4005,1; // Santa poring card
				else if (.@map$ == "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 .@Items,4005,2236;  		// Item array
	set .@rand,rand(1,getarraysize(.@items);
	getitem .@Items[.@rand],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?

  • 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 .@Items,4005,2236;  		// Item array
	set .@rand,rand(1,getarraysize(.@items);
	getitem .@Items[.@rand],1; 
	end;

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

 

Edited by buraquera
  • 0
Posted
6 hours ago, buraquera said:


 


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

	.setarray .@Items,4005,2236;  		// Item array
	set .@rand,rand(1,getarraysize(.@items);
	getitem .@Items[.@rand],1; 
	end;

	function	CheckConditions	{
		set .@chance,10;													// Chance in percentage
		setarray .@maps$,"prt_fild01","gef_fild02","moc_fild10";			// Maps
		for (.@i = 0;.@i < getarraysize(.@maps$); .@i++){					
			if (getarg(0) == .@maps$[.@i]){					
				if (rand(99) < .@chance)
					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?

  • 0
Posted

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 (.@i = 0; .@i < .size; .@i += 4) {
			if (killedrid == .data[.@i]) {
				if (rand(10000) < .data[.@i + 3]) {
					getmapxy .@map$, .@x, .@y, BL_MOB, killedgid;
					.@amt = .data[.@i + 2];
					while (.@amt) {
						makeitem .data[.@i + 1], 1, .@map$, .@x, .@y;
						.@amt--;
					}
				}
			}
		}
		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

  • 0
Posted
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 (.@i = 0; .@i < .size; .@i += 4) {
			if (killedrid == .data[.@i]) {
				if (rand(10000) < .data[.@i + 3]) {
					getmapxy .@map$, .@x, .@y, BL_MOB, killedgid;
					.@amt = .data[.@i + 2];
					while (.@amt) {
						makeitem .data[.@i + 1], 1, .@map$, .@x, .@y;
						.@amt--;
					}
				}
			}
		}
		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?? 

  • 0
Posted
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)

  • 0
Posted

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






-	script	CustomDrop	FAKE_NPC,{
function add_drop;

OnNPCKillEvent:
	if (!playerattached())
		end;
	.@mob_id = killedrid;
	.@size = getd(".size_" + .@mob_id);
	if (.@size < 1)
		end;
	getunitdata killedgid, .@v;
	.@x = .@v[UMOB_X];
	.@y = .@v[UMOB_Y];
	.@map$ = strcharinfo(3);

	for (.@i = 0; .@i < .@size; .@i++) {
		.@chance = getd(".chance_" + .@mob_id + "[" + .@i + "]");
		if (rand(10000) < .@chance) {
			.@id = getd(".item_id_" + .@mob_id + "[" + .@i + "]");
			.@amt = getd(".item_amount_" + .@mob_id + "[" + .@i + "]");
			while (.@amt > 0) {
				makeitem .@id, 1, .@map$, .@x, .@y;
				.@amt--;
			}
		}
	}
	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 {
	.@arg_count = getargcount();
	if (.@arg_count % 4)
		return;

	for (.@i = 0; .@i < .@arg_count; .@i += 4) {
		.@mob_id = getarg(.@i);
		.@size = getd(".size_" + .@mob_id);
		setd ".item_id_" + .@mob_id + "[" + .@size + "]", getarg(.@i+1);	// <item_id>
		setd ".item_amount_" + .@mob_id + "[" + .@size + "]", getarg(.@i+2);	// <item_amount>
		setd ".chance_" + .@mob_id + "[" + .@size + "]", getarg(.@i+3);	// <chance>
		setd ".size_" + .@mob_id, .@size + 1;
	}
	return;
}
}

 

  • MVP 1
  • 0
Posted
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;
	.@mob_id = killedrid;
	.@size = getd(".size_" + .@mob_id);
	if (.@size < 1)
		end;
	getunitdata killedgid, .@v;
	.@x = .@v[UMOB_X];
	.@y = .@v[UMOB_Y];
	.@map$ = strcharinfo(3);

	for (.@i = 0; .@i < .@size; .@i++) {
		.@chance = getd(".chance_" + .@mob_id + "[" + .@i + "]");
		if (rand(10000) < .@chance) {
			.@id = getd(".item_id_" + .@mob_id + "[" + .@i + "]");
			.@amt = getd(".item_amount_" + .@mob_id + "[" + .@i + "]");
			while (.@amt > 0) {
				makeitem .@id, 1, .@map$, .@x, .@y;
				.@amt--;
			}
		}
	}
	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 {
	.@arg_count = getargcount();
	if (.@arg_count % 4)
		return;

	for (.@i = 0; .@i < .@arg_count; .@i += 4) {
		.@mob_id = getarg(.@i);
		.@size = getd(".size_" + .@mob_id);
		setd ".item_id_" + .@mob_id + "[" + .@size + "]", getarg(.@i+1);	// <item_id>
		setd ".item_amount_" + .@mob_id + "[" + .@size + "]", getarg(.@i+2);	// <item_amount>
		setd ".chance_" + .@mob_id + "[" + .@size + "]", getarg(.@i+3);	// <chance>
		setd ".size_" + .@mob_id, .@size + 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 ?

  • 0
Posted
On 7/31/2020 at 9:08 AM, Capuche said:

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







-	script	CustomDrop	FAKE_NPC,{
function add_drop;

OnNPCKillEvent:
	if (!playerattached())
		end;
	.@mob_id = killedrid;
	.@size = getd(".size_" + .@mob_id);
	if (.@size < 1)
		end;
	getunitdata killedgid, .@v;
	.@x = .@v[UMOB_X];
	.@y = .@v[UMOB_Y];
	.@map$ = strcharinfo(3);

	for (.@i = 0; .@i < .@size; .@i++) {
		.@chance = getd(".chance_" + .@mob_id + "[" + .@i + "]");
		if (rand(10000) < .@chance) {
			.@id = getd(".item_id_" + .@mob_id + "[" + .@i + "]");
			.@amt = getd(".item_amount_" + .@mob_id + "[" + .@i + "]");
			while (.@amt > 0) {
				makeitem .@id, 1, .@map$, .@x, .@y;
				.@amt--;
			}
		}
	}
	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 {
	.@arg_count = getargcount();
	if (.@arg_count % 4)
		return;

	for (.@i = 0; .@i < .@arg_count; .@i += 4) {
		.@mob_id = getarg(.@i);
		.@size = getd(".size_" + .@mob_id);
		setd ".item_id_" + .@mob_id + "[" + .@size + "]", getarg(.@i+1);	// <item_id>
		setd ".item_amount_" + .@mob_id + "[" + .@size + "]", getarg(.@i+2);	// <item_amount>
		setd ".chance_" + .@mob_id + "[" + .@size + "]", getarg(.@i+3);	// <chance>
		setd ".size_" + .@mob_id, .@size + 1;
	}
	return;
}
}

 

Possible to add a setarrays map cuz i want something a specific maps? Thank you!

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...