Jump to content
  • 0

Randomize item drop by unique type, quantity


Desryuu

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   0
  • Joined:  09/05/22
  • Last Seen:  

Hello community!

  I need your help with something...

But first, I want to explain how it is expected to work.

Expected Result: After killing x monster, add a chance to obtain randomly from 1 to 3 different items (not duplicating), of random x (from 1 to the max specified amount in the array) amounts. Everything is practically randomized.

Right now, it is throwing duplicate items and the random amount is not in line with the corresponding item.

 

//============================================================ 
//= Dropped Random Items by Monsters
//============================================================ 
-    script    Dropped    -1,{

OnInit:
    .rand_amt = 3;                                  // Amount of random items
    setarray .item_id[1], 501, 645, 533; // Possible items to receive (ID, amount)
    setarray .item_qty[1], 25, 5, 30;
    monster "jupe_ele",0,0,"--ja--",1004,1,"Dropped::OnDropping";
end;

OnDropping:
    getmapxy(@map$, @x, @y, BL_PC);
    do{
        .@loc = rand(1, getarraysize(.item_id) - 1);
        .@pos = rand(1, getarraysize(.item_qty) - 1);
        debugmes ("count: "+.@i);      
        makeitem .item_id[.@loc], .item_qty[.@pos],@map$, @x, @y;  
        .@count++;
        debugmes("Count: "+.@count);
    }while(.@count < rand(0,.rand_amt));
    monster "jupe_ele",0,0,"--ja--",1004,1,"Dropped::OnDropping";
end;

}

Hopefully you guys can help me!

Thanks in advance.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  10
  • Reputation:   2
  • Joined:  10/21/22
  • Last Seen:  

// -- This function was originally from Annieruru
function	script	F_ShuffleNumbers	{
	deletearray getarg(2);
	.@static = getarg(0);
	.@range = getarg(1) +1 - .@static;
	.@count = getarg(3, .@range);
	if (.@range <= 0 || .@count <= 0)
		return 0;
	if (.@count > .@range)
		.@count = .@range;
	for (.@i = 0; .@i < .@range; ++.@i)
		.@temparray[.@i] = .@i;
	for (.@i = 0; .@i < .@count; ++.@i) {
		.@rand = rand(.@range);
		set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
		.@temparray[.@rand] = .@temparray[--.@range];
	}
	return .@count;
}

-	script	Dropped	-1,{
OnInit:
	setarray .item_id, 501, 645, 533; // Possible items to receive (ID, amount)
	setarray .item_qty, 25, 5, 30;
	monster "jupe_ele",0,0,"--ja--",1004,1,strnpcinfo(0)+"::OnDropping";
	end;

OnDropping:
	getmapxy(@map$, @x, @y, BL_PC);
	.@t = rand(getarraysize(.item_id));
	callfunc "F_ShuffleNumbers", 0, .@t, .@id;
	callfunc "F_ShuffleNumbers", 0, .@t, .@qt;
	for ( .@i = 0; .@i < .@t; .@i++ )
		makeitem .item_id[.@id[.@i]], .item_qty[.@qt[.@i]], @map$, @x, @y;
	monster "jupe_ele",0,0,"--ja--",1004,1,strnpcinfo(0)+"::OnDropping";
	end;  
}

 

I was using annieruru's number shuffler function because it is reliable (at least for me)

Edited by RagEmp
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   0
  • Joined:  09/05/22
  • Last Seen:  

Hi @RagEmp

  Thank you so much for your help! The different items dropped in the array list are not duplicated, which is perfect, but, the amounts of each item are not relational based in the order the array, and the amount should be also random from (1 to 25 for 501 , 1 to 5 for 645 and 1 to 30 for 533).

 

image.png.d3ce616488f9058b63da8aac1e5795a0.png

Can you help me? ?

Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

// -- This function was originally from Annieruru
function	script	F_ShuffleNumbers	{
	deletearray getarg(2);
	.@static = getarg(0);
	.@range = getarg(1) +1 - .@static;
	.@count = getarg(3, .@range);
	if (.@range <= 0 || .@count <= 0)
		return 0;
	if (.@count > .@range)
		.@count = .@range;
	for (.@i = 0; .@i < .@range; ++.@i)
		.@temparray[.@i] = .@i;
	for (.@i = 0; .@i < .@count; ++.@i) {
		.@rand = rand(.@range);
		set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
		.@temparray[.@rand] = .@temparray[--.@range];
	}
	return .@count;
}

-	script	Dropped	-1,{
OnInit:
	setarray .item_id, 501, 645, 533; // Possible items to receive (ID, amount)
	setarray .item_qty, 25, 5, 30;
	.item_id_size = getarraysize(.item_id);
	end;

OnDropping:
	getmapxy(.@map$, .@x, .@y, BL_PC);
	.@t = rand(.item_id_size);
	callfunc "F_ShuffleNumbers", 0, .@t, .@id;
	for ( .@i = 0; .@i < .@t; .@i++ )
		makeitem .item_id[.@id[.@i]], rand(1, .item_qty[.@id[.@i]]), .@map$, .@x, .@y;
	end;  
}


jupe_ele,0,0	monster	Boss	1004,1,5000,0,"Dropped::OnDropping"

use the monster keep respawn, you can consider use the permanent monster spawn script instead.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  10
  • Reputation:   2
  • Joined:  10/21/22
  • Last Seen:  

1 hour ago, Desryuu said:

Can you help me? ?

@Emistry already fixed it for you.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   0
  • Joined:  09/05/22
  • Last Seen:  

Hey @Emistry! It works like a charm! Thanks a lot!

Thanks to you too @RagEmp

Just a final request: how can I condition/limit the number of different items drop in the list? If I include 3 possible different items, I would like to set it manually to 2 (1 to 2).

Thanks!!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  10
  • Reputation:   2
  • Joined:  10/21/22
  • Last Seen:  

4 minutes ago, Desryuu said:

Hey @Emistry! It works like a charm! Thanks a lot!

Thanks to you too @RagEmp

Just a final request: how can I condition/limit the number of different items drop in the list? If I include 3 possible different items, I would like to set it manually to 2 (1 to 2).

Thanks!!

 

Change these:

	.item_id_size = getarraysize(.item_id);

----------------------------------------------------------

	.@t = rand(.item_id_size);
	callfunc "F_ShuffleNumbers", 0, .@t, .@id;
	for ( .@i = 0; .@i < .@t; .@i++ )

To these:

	.item_id_size = 1; // To how ever much you want to put

----------------------------------------------------------

	//.@t = rand(.item_id_size);
	callfunc "F_ShuffleNumbers", 0, .@t, .@id;
	for ( .@i = 0; .@i < .item_id_size; .@i++ )

 

Link to comment
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...