Jump to content
  • 0

NPC Random Function Did Not Work


Dolphin86

Question


  • Group:  Members
  • Topic Count:  245
  • Topics Per Day:  0.06
  • Content Count:  687
  • Reputation:   15
  • Joined:  01/07/12
  • Last Seen:  

the plan was if the player bring item A and item B he will get normal item.

but if he bring item A and item C, there is 10% chance to get unique item.. but it did not work as plan, i cant even click on the npc..

-	script	Tall Grass	-1,{

OnInit:
	setarray .itemid[0], 40062,40063,40064,40065,40066;
	setarray .itemchance[0], 10,10,10,10,10;
	end;
	
	mes "=== Select Tools ===";
	next;
	switch(select("- Stone Blade:- Bone Blade:- Cancel")) {
	
	case 1:
		if (rentalcountitem(40024) == 1 && countitem(40044) == 1 ){
			getitem 40006, 1;
			getitem 40008, 1;
			end;
		}
		if (rentalcountitem(40024) == 1 && countitem(40067) == 1 ){
			getitem .temp_array[rand(0, getarraysize(.temp_array))], 1;
			getitem 40006, 1;
			end;
		}
		else
		mes "Stone Blade is needed.";
		close;
		
	case 2:
		if (rentalcountitem(40058) == 1 && countitem(40044) == 1 ){
			getitem 40006, 1;
			getitem 40008, 1;
			end;
		}
		else
		mes "Bone Blade is needed.";
		close;
	case 3:
		mes "Gathering Cancel";
		close;
	}
}
// Duplicates
//============================================================
neko_isle,75,122,6	duplicate(Tall Grass)	Tall Grass#new11	666
new_1-3,111,73,6	duplicate(Tall Grass)	Tall Grass#new12	666
new_1-3,115,71,6	duplicate(Tall Grass)	Tall Grass#new13	666
new_1-3,119,71,6	duplicate(Tall Grass)	Tall Grass#new14	666
new_1-3,123,71,6	duplicate(Tall Grass)	Tall Grass#new15	666
new_1-3,127,71,6	duplicate(Tall Grass)	Tall Grass#new16	666
new_1-3,131,72,6	duplicate(Tall Grass)	Tall Grass#new17	666

 

Edited by Dolphin86
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

  • Group:  Content Moderator
  • Topic Count:  55
  • Topics Per Day:  0.02
  • Content Count:  1675
  • Reputation:   697
  • Joined:  12/21/14
  • Last Seen:  

what are item A and B in the script ? I see there is multiple items checked, not only 2

OnInit should be at the end of the script, or else each time the player will lick on the npc OnInit would run, you can just remove the OnInit event and use .@var instead , it's better to stay away from events because you are duplicating the npc

there is no .temp_array defined in the script , I assume you wanted .itemid

you should use 1 chance variable if you want the player to have 10% chance to get one of the items in the array just use if(rand(100) <= 10){//get item whatever }

keep in mind that countitem() == 1 means the player must have only 1 , no more no less , if you want don't care how many the player have , just remove the "== 1"

the "else" has no use snice the script will end if the "if" was true

I suggest you use a UNIQUE NPC NAME as a main

if you click on the NPC and nothing happens you would get an error code in the Console , read it and you would know why nothing happens when you click it.

 

I am not sure how you want the npc but here is an optimize to the script

-	script	::TALL_GRASS_MAIN	-1,{
	setarray .@itemid[0], 40062,40063,40064,40065,40066;
	.@Chance = 10;
	
	mes "=== Select Tools ===";
	switch(select("- Stone Blade:- Bone Blade:- Cancel")) {
		clear;
		case 1:
			if (rentalcountitem(40024) == 1){
				if(countitem(40044) == 1){
					getitem 40006, 1;
					getitem 40008, 1;
					end;
				}
				if(countitem(40067) == 1){
					if(rand(100) <= .@Chance){
						getitem .@itemid[rand(getarraysize(.@itemid))], 1;
					}
					getitem 40006, 1;
					end;
				}
			}
			mes "Stone Blade is needed.";
			close;
		case 2:
			if (rentalcountitem(40058) == 1 && countitem(40044) == 1 ){
				getitem 40006, 1;
				getitem 40008, 1;
				end;
			}
			mes "Bone Blade is needed.";
			close;
		case 3:
			mes "Gathering Cancel";
			close;
	}
end;
}
// Duplicates
//============================================================
neko_isle,75,122,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new11	666
new_1-3,111,73,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new12	666
new_1-3,115,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new13	666
new_1-3,119,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new14	666
new_1-3,123,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new15	666
new_1-3,127,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new16	666
new_1-3,131,72,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new17	666

 

if that's not what you want , you might want to follow up with more details so people can help you with the script.

Edited by sader1992
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  245
  • Topics Per Day:  0.06
  • Content Count:  687
  • Reputation:   15
  • Joined:  01/07/12
  • Last Seen:  

@sader1992 sorry to interrupt, but what if i need another set of random item array with different random chance ? 

-	script	::TALL_GRASS_MAIN	-1,{
	setarray .@itemid[0], 40068,40069,40070,40071,40072; // random array set 1
	.@Chance = 5; // random array set 1
	
	mes "=== Select Tools ===";
	switch(select("- Stone Blade:- Bone Blade:- Cancel")) {
		clear;
		case 1:
			if (rentalcountitem(40024) == 1){ // 40024 (item A)
				if(countitem(40044) == 1){ // 40044 (item B)
					getitem 40006, 1;
					getitem 40008, 1;
					end;
				}
				if(countitem(40067) == 1){ // 40067 (item C)
					if(rand(100) <= .@Chance){ 
						getitem .@itemid[rand(getarraysize(.@itemid))], 1; // ( array random set 1 )
					}
					getitem 40008, 1;
					getitem 40006, 1;
					end;
					}
			}
			mes "Stone Blade is needed.";
			close;
		case 2:
			if (rentalcountitem(40058) == 1){ // 40058 (item D)
				if(countitem(40044) == 1){ // 40044 (item B)
					getitem 40006, 1;
					getitem 40008, 1;
					end;
				}
				if(countitem(40067) == 1){ // 40067 (item C)
					if(rand(100) <= .@Chance){
						getitem .@itemid[rand(getarraysize(.@itemid))], 1; // ( array random set 2 )
					}
					getitem 40008, 1;
					getitem 40006, 1;
					end;
					}
			}
		case 3:
			mes "Gathering Cancel";
			close;
	}
end;
}
// Duplicates
//============================================================
neko_isle,75,122,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new11	666
new_1-3,111,73,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new12	666
new_1-3,115,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new13	666
new_1-3,119,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new14	666
new_1-3,123,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new15	666
new_1-3,127,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new16	666
new_1-3,131,72,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new17	666

 

Edited by Dolphin86
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  226
  • Reputation:   83
  • Joined:  06/30/18
  • Last Seen:  

-	script	::TALL_GRASS_MAIN	FAKE_NPC,{
	mes "=== Select Tools ===";
	switch(select("- Stone Blade:- Bone Blade:- Cancel")) {
		clear;
		case 1:
			if (!rentalcountitem(40024)) {
                mes "Stone Blade is needed.";
                close;
            }
            
			if(!countitem(40044) && !countitem(40067)) end;
 
            if(countitem(40067)) {
				if(rand(1, 100) <= .drop_chances[0])
					getitem(.@stone_items[rand(getarraysize(.@stone_items))], 1);
			}

			getitem(40006, 1);
			getitem(40008, 1);
			end;
		case 2:
			if (!rentalcountitem(40058)) {
				mes "Stone Blade is needed.";
				close;
			}

			if(!countitem(40044) && !countitem(40067)) end;

			if(countitem(40067)) {
				if(rand(1, 100) <= .drop_chances[1]) 
					getitem(.@bone_items[rand(getarraysize(.@bone_items))], 1);
			}

			getitem(40008, 1);
			getitem(40006, 1);
			end;
		case 3:
			mes "Gathering Cancel";
			close;
	}

    OnInit:
        setarray(.stone_items[0], 40068, 40069, 40070, 40071, 40072);
        setarray(.bone_items[0], 40068, 40069, 40070, 40071, 40072);
        setarray(.drop_chances, 5, 10);
}

// Duplicates
//============================================================
neko_isle,75,122,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new11	666
new_1-3,111,73,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new12	666
new_1-3,115,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new13	666
new_1-3,119,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new14	666
new_1-3,123,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new15	666
new_1-3,127,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new16	666
new_1-3,131,72,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new17	666

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  245
  • Topics Per Day:  0.06
  • Content Count:  687
  • Reputation:   15
  • Joined:  01/07/12
  • Last Seen:  

4 minutes ago, Winterfox said:
-	script	::TALL_GRASS_MAIN	FAKE_NPC,{
	mes "=== Select Tools ===";
	switch(select("- Stone Blade:- Bone Blade:- Cancel")) {
		clear;
		case 1:
			if (!rentalcountitem(40024)) {
                mes "Stone Blade is needed.";
                close;
            }
            
			if(!countitem(40044) && !countitem(40067)) end;
 
            if(countitem(40067)) {
				if(rand(1, 100) <= .drop_chances[0])
					getitem(.@stone_items[rand(getarraysize(.@stone_items))], 1);
			}

			getitem(40006, 1);
			getitem(40008, 1);
			end;
		case 2:
			if (!rentalcountitem(40058)) {
				mes "Stone Blade is needed.";
				close;
			}

			if(!countitem(40044) && !countitem(40067)) end;

			if(countitem(40067)) {
				if(rand(1, 100) <= .drop_chances[1]) 
					getitem(.@bone_items[rand(getarraysize(.@bone_items))], 1);
			}

			getitem(40008, 1);
			getitem(40006, 1);
			end;
		case 3:
			mes "Gathering Cancel";
			close;
	}

    OnInit:
        setarray(.stone_items[0], 40068, 40069, 40070, 40071, 40072);
        setarray(.bone_items[0], 40068, 40069, 40070, 40071, 40072);
        setarray(.drop_chances, 5, 10);
}

// Duplicates
//============================================================
neko_isle,75,122,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new11	666
new_1-3,111,73,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new12	666
new_1-3,115,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new13	666
new_1-3,119,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new14	666
new_1-3,123,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new15	666
new_1-3,127,71,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new16	666
new_1-3,131,72,6	duplicate(TALL_GRASS_MAIN)	Tall Grass#new17	666

 

thanks

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