Jump to content
  • 0

Error on callfunction random box [ null ]


Question

Posted

Can anyone make this script work >.< thank yooou!! 

function    script    specialbox {
    setarray .i1[0],909,910; // Common Items
    set .i1rand,rand(0,1); // Randomize Common Items; just change max amount if you add items
    setarray .i2[0],911,912; // Rare Items
    set .i2rand,rand(0,1); // Randomize Rare Items; just change max amount if you add items
    setarray .i3[0],2199,1599; // Super Rare Items
    set .i3rand,rand(0,1); //Randomize Super Rare Items; just change max amount if you add items
    set .chance, rand(100);

        // Super Rare Item 1%
        if (.chance == 1){
        getitem .i[.i3rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i[.i3rand])+"] from the Special Box.",0;
        end;
        } 

        // Rare Item 10%
        else if (.chance <= 2 && .chance >= 11){
        getitem .i[.i2rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i[.i2rand])+"] from the Special Box.",0;
        end;
        } 

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

help.png

help2.png

3 answers to this question

Recommended Posts

  • 0
Posted
function	script	specialbox	{
	.@chance = rand(100);
	if (.@chance == 1) {
		// Super Rare Item 1%
		.@item_id = F_Rand(2199,1599);
	}
	else if (.@chance <= 2 && .@chance >= 11) { 
		// Rare Items
		.@item_id = F_Rand(911,912);
	}
	else {
		// Common Items
		.@item_id = F_Rand(909,910);
	}
	announce "["+strcharinfo(0)+"] won a ["+getitemname(.@item_id)+"] from the Special Box.",0;
	return;
}

a simpler and more appropriate approach.

you shouldn't create/declare a npc variable  within a function ....

  1. because it shared the value with everyone ..
  2. when you declare anything inside the function, it keep repeating the unnecessary process when other player access it again
  • 0
Posted (edited)

Hello, basically you are not calling ".i3" and ".i2" in the correct way, the script tries to do the search but cannot find anything. you don't have any array called just ".i"

current code:

10 hours ago, Noire said:

        // Super Rare Item 1%
        if (.chance == 1){
        getitem .i[.i3rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i[.i3rand])+"] from the Special Box.",0;
        end;
        } 

        // Rare Item 10%
        else if (.chance <= 2 && .chance >= 11){
        getitem .i[.i2rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i[.i2rand])+"] from the Special Box.",0;
        end;
        } 

correction:

10 hours ago, Noire said:

// Super Rare Item 1%
        if (.chance == 1){
        getitem .i3[.i3rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i3[.i3rand])+"] from the Special Box.",0;
        end;
        } 

        // Rare Item 10%
        else if (.chance >= 2 && .chance <= 11){
        getitem .i2[.i2rand],1;
        announce "["+strcharinfo(0)+"] won a ["+getitemname(.i2[.i2rand])+"] from the Special Box.",0;
        end;}

Another detail that I noticed were the addresses of "else if (.chance <= 2 && .chance >= 11)" basically said if it was equal to or less than 2 and greater than or equal to 11 it would go out, as well as this in the correction it should work good. hope to help you ^^

Edited by xSoul
  • 0
Posted
3 hours ago, xSoul said:

Hello, basically you are not calling ".i3" and ".i2" in the correct way, the script tries to do the search but cannot find anything. you don't have any array called just ".i"

current code:

correction:

Another detail that I noticed were the addresses of "else if (.chance <= 2 && .chance >= 11)" basically said if it was equal to or less than 2 and greater than or equal to 11 it would go out, as well as this in the correction it should work good. hope to help you ^^

thanks you!! big heeeeelp >.< 

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