Jump to content
  • 0

Why some time [Error]: buildin_getitem: Nonexistant item 0 requested.


GubA

Question


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  24
  • Reputation:   0
  • Joined:  06/16/14
  • Last Seen:  

prontera,155,177,5	script	random	615,{
function Getcostume;
    if( countitem( .rare_ticket ) ) {
        mes "Rare Ticket";
        .@r = .rate_chance_rare; // chance
        .@ticket = .rare_ticket ;
    }
    else if( countitem( .normal_ticket ) ) {
        mes "Normal Ticket";
        .@r = .rate_chance_normal; // chance
        .@ticket = .normal_ticket;
    }
    else {
        mes "random";
        close;
    }

    if( select( "go", "no" ) -1 ) close;
    delitem .@ticket, 1;
    if( .@r > rand( 1, 1000 ) ) { // chance 50% for rare ticket
        mes "random";
        getitem Getcostume( "rare" ), 1;
        close;
    }
    else {
        mes "random";
        getitem Getcostume( "normal" ), 1;
        close;
    }
    
OnInit:
    .normal_ticket = 501;
    .rare_ticket = 502;
    .rate_chance_rare = 500; // chance to get a rare costume with rare ticket
    .rate_chance_normal = 100; // chance to get a rare costume with normal ticket
    
// rare costume ID
// size array must be < 128
// use the synthaxe .rare_IDX for adding news array
// ------------------------------------------------
    setarray .rare_ID0,5909;
    setarray .rare_ID1,5912;
    setarray .rare_ID2,5914;
    setarray .rare_ID3,5915;
    setarray .rare_ID4,5977;
    setarray .rare_ID5,5979;
    setarray .rare_ID6,5980;
    setarray .rare_ID7,15280;
    setarray .rare_ID8,15841;
    setarray .rare_ID9,15843;
    setarray .rare_ID10,15858;
	
// normal costume ID
// size array must be < 128
// use the synthaxe .normal_IDX for adding news array
// ------------------------------------------------
    setarray .normal_ID0,50001;
	setarray .normal_ID1,50001;
    setarray .normal_ID2,50001;
    setarray .normal_ID3,50001;
    setarray .normal_ID4,50001;
    setarray .normal_ID5,50001;
    setarray .normal_ID6,50001;
    setarray .normal_ID7,50001;
// Don't touch
// -----------
    callsub L_size, "rare";
    callsub L_size, "normal";
    end;
L_size:
    while( getd( "."+ getarg(0) +"_ID"+ .@i +"[0]" ) ) {
        setd ".size_"+ getarg(0) +""+ .@i, getarraysize( getd( "."+ getarg(0) +"_ID"+ .@i ) );
        setd ".size_tot_"+ getarg(0), getd( ".size_tot_"+ getarg(0) ) + getarraysize( getd( "."+ getarg(0) +"_ID"+ .@i ) );
        .@i++;
    }
    return;

function Getcostume {
    .@r = rand( 1, getd( ".size_tot_"+ getarg(0) ) );
    .@i = -1;
    while( .@r > .@tmp ) .@tmp = .@tmp + getd( ".size_"+ getarg(0) + .@i++ );
    .@in = .@r - ( .@tmp - getd( ".size_"+ getarg(0) + .@i ) ) -1;
    return getd( "."+ getarg(0) +"_ID"+ .@i +"[ "+ .@in +" ]" );
}
}

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  162
  • Topics Per Day:  0.05
  • Content Count:  1546
  • Reputation:   192
  • Joined:  07/23/14
  • Last Seen:  

2 hours ago, GubA said:
prontera,155,177,5	script	random	615,{
function Getcostume;
    if( countitem( .rare_ticket ) ) {
        mes "Rare Ticket";
        .@r = .rate_chance_rare; // chance
        .@ticket = .rare_ticket ;
    }
    else if( countitem( .normal_ticket ) ) {
        mes "Normal Ticket";
        .@r = .rate_chance_normal; // chance
        .@ticket = .normal_ticket;
    }
    else {
        mes "random";
        close;
    }

    if( select( "go", "no" ) -1 ) close;
    delitem .@ticket, 1;
    if( .@r > rand( 1, 1000 ) ) { // chance 50% for rare ticket
        mes "random";
        getitem Getcostume( "rare" ), 1;
        close;
    }
    else {
        mes "random";
        getitem Getcostume( "normal" ), 1;
        close;
    }
    
OnInit:
    .normal_ticket = 501;
    .rare_ticket = 502;
    .rate_chance_rare = 500; // chance to get a rare costume with rare ticket
    .rate_chance_normal = 100; // chance to get a rare costume with normal ticket
    
// rare costume ID
// size array must be < 128
// use the synthaxe .rare_IDX for adding news array
// ------------------------------------------------
    setarray .rare_ID0,5909;
    setarray .rare_ID1,5912;
    setarray .rare_ID2,5914;
    setarray .rare_ID3,5915;
    setarray .rare_ID4,5977;
    setarray .rare_ID5,5979;
    setarray .rare_ID6,5980;
    setarray .rare_ID7,15280;
    setarray .rare_ID8,15841;
    setarray .rare_ID9,15843;
    setarray .rare_ID10,15858;
	
// normal costume ID
// size array must be < 128
// use the synthaxe .normal_IDX for adding news array
// ------------------------------------------------
    setarray .normal_ID0,50001;
	setarray .normal_ID1,50001;
    setarray .normal_ID2,50001;
    setarray .normal_ID3,50001;
    setarray .normal_ID4,50001;
    setarray .normal_ID5,50001;
    setarray .normal_ID6,50001;
    setarray .normal_ID7,50001;
// Don't touch
// -----------
    callsub L_size, "rare";
    callsub L_size, "normal";
    end;
L_size:
    while( getd( "."+ getarg(0) +"_ID"+ .@i +"[0]" ) ) {
        setd ".size_"+ getarg(0) +""+ .@i, getarraysize( getd( "."+ getarg(0) +"_ID"+ .@i ) );
        setd ".size_tot_"+ getarg(0), getd( ".size_tot_"+ getarg(0) ) + getarraysize( getd( "."+ getarg(0) +"_ID"+ .@i ) );
        .@i++;
    }
    return;

function Getcostume {
    .@r = rand( 1, getd( ".size_tot_"+ getarg(0) ) );
    .@i = -1;
    while( .@r > .@tmp ) .@tmp = .@tmp + getd( ".size_"+ getarg(0) + .@i++ );
    .@in = .@r - ( .@tmp - getd( ".size_"+ getarg(0) + .@i ) ) -1;
    return getd( "."+ getarg(0) +"_ID"+ .@i +"[ "+ .@in +" ]" );
}
}

 

I think in these list. you need to double check all the items that has been added, one or two might not be in the database that's why its saying non-existent error message.

    setarray .rare_ID0,5909;
    setarray .rare_ID1,5912;
    setarray .rare_ID2,5914;
    setarray .rare_ID3,5915;
    setarray .rare_ID4,5977;
    setarray .rare_ID5,5979;
    setarray .rare_ID6,5980;
    setarray .rare_ID7,15280;
    setarray .rare_ID8,15841;
    setarray .rare_ID9,15843;
    setarray .rare_ID10,15858;

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  24
  • Reputation:   0
  • Joined:  06/16/14
  • Last Seen:  

8 minutes ago, Radian said:

I think in these list. you need to double check all the items that has been added, one or two might not be in the database that's why its saying non-existent error message.

    setarray .rare_ID0,5909;
    setarray .rare_ID1,5912;
    setarray .rare_ID2,5914;
    setarray .rare_ID3,5915;
    setarray .rare_ID4,5977;
    setarray .rare_ID5,5979;
    setarray .rare_ID6,5980;
    setarray .rare_ID7,15280;
    setarray .rare_ID8,15841;
    setarray .rare_ID9,15843;
    setarray .rare_ID10,15858;

 

all item have in db i has check

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  162
  • Topics Per Day:  0.05
  • Content Count:  1546
  • Reputation:   192
  • Joined:  07/23/14
  • Last Seen:  

On 12/27/2022 at 10:16 PM, GubA said:

all item have in db i has check

check also for the normal costume part.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  659
  • Reputation:   664
  • Joined:  11/12/12
  • Last Seen:  

This script is... way more complicated than it has to be. The rand function is misused in two different places, which I'm guessing is the main problem you're having. First thing first:

.@r > rand( 1, 1000 )

^ that's a big no-no. Randomized numbers for chances are always from [0-999], not [1-1000]. You then use rand(1000); or rand(0, 999), but the former is preferred for various reasons. Also, normally you put the rand first for clarity's sake, but that one is preference:

if (rand(1000) < .@r)

Declaring functions at the beginning is fine, but it's also unecessary and not used that much anymore. Use callsub instead, though... using local scope functions for this script is overkill.

rAthena scripts prefer the no-space syntax for function arguments, but that one is up to you.

As for the main problem you're having, that is because .@in is returning negative values because of rand( 1, getd( ".size_tot_"+ getarg(0) ) ) has invalid bounds and... well, because this is overly complicated so it's not really worth spending time deciphering what it does. I suggest a simpler approach:

prontera,155,177,5	script	random	615,{
	if (countitem(.rare_ticket)) {
		mes "Rare Ticket";
		.@r = .rate_chance_rare; // chance
		.@ticket = .rare_ticket;
	}
	else if (countitem(.normal_ticket)) {
		mes "Normal Ticket";
		.@r = .rate_chance_normal; // chance
		.@ticket = .normal_ticket;
	}
	else {
		mes "random";
		close;
	}
	
	switch(select("Go.:No.:")) {
		case 2:
			close;
	}
	
	delitem .@ticket, 1;
	
	if (rand(1000) < .@r) {
		mes "random";
		getitem .rare[rand(.rare_size)], 1;
		close;
	}
	else {
		mes "random";
		getitem .normal[rand(.normal_size)], 1;
		close;
	}
	
	end;
OnInit:
	.normal_ticket = 501;
	.rare_ticket = 502;
	.rate_chance_rare = 500; // chance to get a rare costume with rare ticket (500 = 50%)
	.rate_chance_normal = 100; // chance to get a rare costume with normal ticket (100 = 10%)
	
	// rare items
	setarray .rare,5909,5912,5914,5915,5977,5979,5980,15280,15841,15843,15858;
	.rare_size = getarraysize(.rare);
	
	// normal items
	setarray .normal,50001;
	.normal_size = getarraysize(.normal);
	end;
}

 

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