Jump to content
  • 0

buildin_getitem: NonExistant item 0 requested


Question

Posted (edited)
Quote

 

function    script    specialbox    {

    setarray .i1[0],7539,7621; // Common Items
    set .i1rand,rand(0,2); // Randomize Common Items; just change max amount if you add items
    setarray .i2[0],14003,13607,12922,12912; // Rare Items
    set .i2rand,rand(0,3); // Randomize Rare Items; just change max amount if you add items
    setarray .i3[0],19568,31120,31121; // Super Rare Items
    set .i3rand,rand(0,2); //Randomize Super Rare Items; just change max amount if you add items
    set .chance, rand(50);

        // Super Rare Item 3%
        if (.chance < 10){
        getitem .i3[.i3rand],1;
        announce "["+strcharinfo(0)+"] got a ["+getitemname(.i3[.i3rand])+"] from the Lucky Egg.",0;
        end;
        } 

        // Rare Item 15%
        else if (.chance < 15){
        getitem .i2[.i2rand],1;
        announce "["+strcharinfo(0)+"] got a ["+getitemname(.i2[.i2rand])+"] from the Lucky Egg.",0;
        end;
        } 

        // Common Items
        else {
        getitem .i1[.i1rand],1;
        end; 
        }
}

 

Hi rAthena!

Can I pls ask a little help with this script.

I'm getting a "buildin_getitem: NonExistant item 0 requested"

Thanks in advanced!

Edited by Musika6988

6 answers to this question

Recommended Posts

  • 0
Posted
1 hour ago, Musika6988 said:

Hi rAthena!

Can I pls ask a little help with this script.

I'm getting a "buildin_getitem: NonExistant item 0 requested"

Thanks in advanced!

Here is the problem:

Spoiler

	setarray .i1[0],7539,7621; // Common Items
	set .i1rand,rand(0,2); // Randomize Common Items; just change max amount if you add items

 

The array '.i1' size is '2', and the '.i1rand' randomize values from '0' to '2' instead of '0' to '1'... so when you trying to give the common items prize, when '.i1rand' get value the random value '2', the array '.i1[2]' has empty values because the array has declared values until 'i1[1]'.

You can do this to fix:

Spoiler

set .i1rand,rand(0,1); // Randomize Common Items; just change max amount if you add items

 

Or this:

Spoiler

	setarray .i1[0],7539,7621; // Common Items
	set .i1rand,rand(getarraysize(.i1)); // Randomize Common Items; Don't need to change if you add more items. :)
	setarray .i2[0],14003,13607,12922,12912; // Rare Items
	set .i2rand,rand(getarraysize(.i2)); // Randomize Rare Items; Don't need to change if you add more items. :)
	setarray .i3[0],19568,31120,31121; // Super Rare Items
	set .i3rand,rand(getarraysize(.i3)); //Randomize Super Rare Items; Don't need to change if you add more items. :)
	set .chance, rand(50);

 

 

  • Love 1
  • 0
Posted
15 hours ago, Cretino said:

Here is the problem:

  Hide contents


	setarray .i1[0],7539,7621; // Common Items
	set .i1rand,rand(0,2); // Randomize Common Items; just change max amount if you add items

 

The array '.i1' size is '2', and the '.i1rand' randomize values from '0' to '2' instead of '0' to '1'... so when you trying to give the common items prize, when '.i1rand' get value the random value '2', the array '.i1[2]' has empty values because the array has declared values until 'i1[1]'.

You can do this to fix:

  Reveal hidden contents


set .i1rand,rand(0,1); // Randomize Common Items; just change max amount if you add items

 

Or this:

  Reveal hidden contents


	setarray .i1[0],7539,7621; // Common Items
	set .i1rand,rand(getarraysize(.i1)); // Randomize Common Items; Don't need to change if you add more items. :)
	setarray .i2[0],14003,13607,12922,12912; // Rare Items
	set .i2rand,rand(getarraysize(.i2)); // Randomize Rare Items; Don't need to change if you add more items. :)
	setarray .i3[0],19568,31120,31121; // Super Rare Items
	set .i3rand,rand(getarraysize(.i3)); //Randomize Super Rare Items; Don't need to change if you add more items. :)
	set .chance, rand(50);

 

 

Kindly correct me if I'm wrong, so, what I understand is that if setarray .i1[0],7539,7621; (Has 2 items), then my set .i1rand,rand should be set .i1rand,rand(0,1); but if the items on setarray .i1[0] are 3 items, then my set .i1rand,rand should be set .i1rand,rand(0,2);? or it should always stay as 1?

Thanks so much by the way for the educational reply. ?

  • 0
Posted
13 minutes ago, Musika6988 said:

if the items on setarray .i1[0] are 3 items, then my set .i1rand,rand should be set .i1rand,rand(0,2);

Yes, but I think is better you use the second solution I showed to you, you'll never change the rand always you add new items.

  • Love 1
  • 0
Posted
15 hours ago, Cretino said:

Yes, but I think is better you use the second solution I showed to you, you'll never change the rand always you add new items.

Actually that's what I ended up using instead. Worked like a charm. Thanks so much!

By the way, If I may add. What if I wanted it to be like,

The setarray .i1[0] automatically gives all items on it's list, then the only part where it uses chance % is with setarray .i2[0] and setarray .i3[0]? Is that even possible?

  • 0
Posted
On 5/4/2020 at 6:49 AM, Musika6988 said:

Actually that's what I ended up using instead. Worked like a charm. Thanks so much!

By the way, If I may add. What if I wanted it to be like,

The setarray .i1[0] automatically gives all items on it's list, then the only part where it uses chance % is with setarray .i2[0] and setarray .i3[0]? Is that even possible?

up

  • 0
Posted

Change 

set .i1rand,rand(getarraysize(.i1));

to

set .i1rand,getarraysize(.i1);

Change 

// Common Items
else {
	getitem .i1[.i1rand],1;
	end; 
}

to

// Common Items
else {
	while (.@i < .i1rand) {
		getitem .i1[.@i],1;
		.@i++;
	}
	end; 
}

 

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