Jump to content
  • 0

Monster Drops script getitem random not working


Yami

Question


  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

Hi there, I've been using this script in the past and just tried to use it again. But it seems some of the scripts are not working as they did before, mainly the getitem random amount is not working. It will only give a fixed amount even set at random.

Can someone check it out please?

 

Here's the script:
 

-	script	Monster_Drop	-1,{
OnNPCKillEvent:
//if(getgmlevel()>50) end;

// MVP DROP
if ( getmonsterinfo( killedrid, 22 ) ) {
set #daily_mvp,#daily_mvp + 1;
	for ( .@i = 0; .@i < getarraysize( .items ); .@i += 3 ) {
		if ( rand( 100 ) < .items[ .@i +  2 ] ) {
			getitem .items[ .@i ], .items[ .@i + 1 ];
			//announce strcharinfo(0)+" got "+getitemname( .items[ .@i ] )+" x"+.items[ .@i + 1 ]+" from "+getmonsterinfo(killedrid, 0)+"!!",bc_all,0xFFFFFF;
			}
		}
	}
// NORMAL MOB DROPS
else {
	for ( .@i = 0; .@i < getarraysize( .mobitem ); .@i += 3 ) {
		if ( rand( 100 ) < .mobitem[ .@i +  2 ] ) {
			getitem .mobitem[ .@i ], .mobitem[ .@i + 1 ];
			}
		}
	}
end;

OnInit:
// Random amount 6240,rand(1,3),1,
// MVP ITEMS	<item id>,<amount>,<chance>
setarray .items[0],673,5,10,
			675,1,1,
			7859,20,5;

// MOB ITEMS	<item id>,<amount>,<chance>
setarray .mobitem[0],7859,rand(1,10),5;
			//7859,5,1;
end;

} // END OF SCRIPT

 

Looking forward to getting the script work as intended again. Thank you!

Edited by Yami
Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  7
  • Reputation:   0
  • Joined:  01/04/15
  • Last Seen:  

Fixed script:

-	script	Monster_Drop	-1,{
OnNPCKillEvent:
//if(getgmlevel()>50) end;

// MVP DROP
if ( getmonsterinfo( killedrid, 22 ) ) {
set #daily_mvp,#daily_mvp + 1;
	for ( .@i = 0; .@i < getarraysize( .items ); .@i += 4 ) {
		if ( rand( 100 ) < .items[ .@i +  3 ] ) {
			.@quantity = rand(.items[.@i + 1], .items[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			getitem .items[.@i], .@quantity;
			//announce strcharinfo(0)+" got "+getitemname( .items[ .@i ] )+" x"+.@quantity+" from "+getmonsterinfo(killedrid, 0)+"!!",bc_all,0xFFFFFF;
        }
    }
}
// NORMAL MOB DROPS
else {
	for ( .@i = 0; .@i < getarraysize( .mobitem ); .@i += 4 ) {
		if ( rand( 100 ) < .mobitem[ .@i +  3 ] ) {
			.@quantity = rand(.mobitem[.@i + 1], .mobitem[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			getitem .mobitem[.@i], .@quantity; 
        }
    }
}
end;

OnInit:
// Random amount 6240,rand(1,3),1,
// MVP ITEMS	<item id>,<min_amount>,<max_amount>,<chance>
//setarray .items[0],673,5,10,675,1,1,7859,20,5;
setarray .items[0],
  673,5,5,10,
  675,1,1,1,
  7859,10,20,10;

// MOB ITEMS	<item id>,<min_amount>,<max_amount>,<chance>
//setarray .mobitem[0],7859,rand(1,10),5;
setarray .mobitem[0],
  7859,1,5,5;
end;

} // END OF SCRIPT

This way you should be able to add items to the arrays at the end without trouble. I don't have a setup to test right away but will post update if I find any issue.

Edited by jurelmetal
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  7
  • Reputation:   0
  • Joined:  01/04/15
  • Last Seen:  

You are executing the rand() at OnInit, so it only runs when the server starts.

You should store both min and max amounts in the array, and run the rand() inside the OnNPCKillEvent label with those stored values to get the effect you want:

At OnInit:

setarray .mobitem[0],7859,1,10,5; // sets 1 as the minimum amount and 10 as the max

At OnNPCKillEvent:

// ... your code ...
getitem .items[.@i], rand(.items[.@i + 1], .items[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)

Also remember to modify your loop so that it adds 4 instead of 3 to .@i on each iteration.

Edited by jurelmetal
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

34 minutes ago, jurelmetal said:

You are executing the rand() at OnInit, so it only runs when the server starts.

You should store both min and max amounts in the array, and run the rand() inside the OnNPCKillEvent label with those stored values to get the effect you want:

At OnInit:


setarray .mobitem[0],7859,1,10,5; // sets 1 as the minimum amount and 10 as the max

At OnNPCKillEvent:


// ... your code ...
getitem .items[.@i], rand(.items[.@i + 1], .items[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)

Also remember to modify your loop so that it adds 4 instead of 3 to .@i on each iteration.

Should I change my code into this @jurelmetal? What about when I add more Items? Or just have it on a fixed amount because I probably wont randomize the amount of all the items the I put as drops.

I'm not entirely sure, but the old script works back then, with all the rand(1,123) on the code, but now it's not working.

Edited by Yami
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  7
  • Reputation:   0
  • Joined:  01/04/15
  • Last Seen:  

To add more items just add more sets of 4 values in your array. (item ID, min qty, max qty, chance)

Certainly my suggestions assumes that you're going to randomize the quantity for all items in the array. If you don't want this, you can set both values to the same number for that item.

Hope that helps!

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

36 minutes ago, jurelmetal said:

To add more items just add more sets of 4 values in your array. (item ID, min qty, max qty, chance)

Certainly my suggestions assumes that you're going to randomize the quantity for all items in the array. If you don't want this, you can set both values to the same number for that item.

Hope that helps!

Aight, will try this as soon as I can. Thank you

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

@jurelmetal does this still follow the drop chance?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

@jurelmetal I'm getting this error on my Map server. Do you know why?

KaYAL2y.png

 

Here's my updated script:
 


-	script	Monster_Drop	-1,{
OnNPCKillEvent:
//if(getgmlevel()>50) end;

// MVP DROP
if ( getmonsterinfo( killedrid, 22 ) ) {
set #daily_mvp,#daily_mvp + 1;
	for ( .@i = 0; .@i < getarraysize( .items ); .@i += 3 ) {
		if ( rand( 100 ) < .items[ .@i +  2 ] ) {
			getitem .items[.@i], rand(.items[.@i + 1], .items[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			//announce strcharinfo(0)+" got "+getitemname( .items[ .@i ] )+" x"+.items[ .@i + 1 ]+" from "+getmonsterinfo(killedrid, 0)+"!!",bc_all,0xFFFFFF;
			}
		}
	}
// NORMAL MOB DROPS
else {
	for ( .@i = 0; .@i < getarraysize( .mobitem ); .@i += 3 ) {
		if ( rand( 100 ) < .mobitem[ .@i +  2 ] ) {
			getitem .mobitem[.@i], rand(.mobitem[.@i + 1], .mobitem[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			}
		}
	}
end;

OnInit:
// Random amount 6240,rand(1,3),1,
// MVP ITEMS	<item id>,<amount>,<chance>
//setarray .items[0],673,5,10,675,1,1,7859,20,5;
setarray .items[0],673,5,5,10,675,1,1,1,7859,10,20,10;

// MOB ITEMS	<item id>,<amount>,<chance>
//setarray .mobitem[0],7859,rand(1,10),5;
setarray .mobitem[0],7859,1,5,5; // sets 1 as the minimum amount and 10 as the max
end;

} // END OF SCRIPT

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

I think I know the issue, I did some testing myself. I believe it comes from the MVP drops line, since I added more items to the array, I think I get an error when it tries to trigger 2nd or 3rd item drop. I've only been getting the Bronze Coin (673,5,5,10).

Anyone know how I can add more items without getting any error? Please?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

Thank you @jurelmetal, will try this as soon as I can. 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  35
  • Topics Per Day:  0.01
  • Content Count:  111
  • Reputation:   2
  • Joined:  01/02/14
  • Last Seen:  

12 hours ago, jurelmetal said:

Fixed script:


-	script	Monster_Drop	-1,{
OnNPCKillEvent:
//if(getgmlevel()>50) end;

// MVP DROP
if ( getmonsterinfo( killedrid, 22 ) ) {
set #daily_mvp,#daily_mvp + 1;
	for ( .@i = 0; .@i < getarraysize( .items ); .@i += 4 ) {
		if ( rand( 100 ) < .items[ .@i +  3 ] ) {
			.@quantity = rand(.items[.@i + 1], .items[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			getitem .items[.@i], .@quantity;
			//announce strcharinfo(0)+" got "+getitemname( .items[ .@i ] )+" x"+.@quantity+" from "+getmonsterinfo(killedrid, 0)+"!!",bc_all,0xFFFFFF;
        }
    }
}
// NORMAL MOB DROPS
else {
	for ( .@i = 0; .@i < getarraysize( .mobitem ); .@i += 4 ) {
		if ( rand( 100 ) < .mobitem[ .@i +  3 ] ) {
			.@quantity = rand(.mobitem[.@i + 1], .mobitem[.@i + 2]); // Use the numbers as arguments to the call to rand(a, b)
			getitem .mobitem[.@i], .@quantity; 
        }
    }
}
end;

OnInit:
// Random amount 6240,rand(1,3),1,
// MVP ITEMS	<item id>,<min_amount>,<max_amount>,<chance>
//setarray .items[0],673,5,10,675,1,1,7859,20,5;
setarray .items[0],
  673,5,5,10,
  675,1,1,1,
  7859,10,20,10;

// MOB ITEMS	<item id>,<min_amount>,<max_amount>,<chance>
//setarray .mobitem[0],7859,rand(1,10),5;
setarray .mobitem[0],
  7859,1,5,5;
end;

} // END OF SCRIPT

This way you should be able to add items to the arrays at the end without trouble. I don't have a setup to test right away but will post update if I find any issue.

Script worked as intended! Thank you very much!

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...