Jump to content
  • 0

Array based Quest with Blacklist


mawjustin

Question


  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   6
  • Joined:  09/26/14
  • Last Seen:  

Hi Guys,

 

How do we do this? How do we compare 2 list of arrays, remove those that matched, and the remaining arrays will be the one used for random summoning?

Here is an example code.

//======Name========================================
// Daily Monster Hunt
//======Version=====================================
// 1.2
//======Author(s)===================================
// Sandbox
//======Comments====================================
// This NPC allows your player to hunt a random amount
// of a random monster
// *randomception!*
// If the player successfully hunts the monster
// he'll receive a reward!
//======Credits=====================================
// KeyWorld, nanakiwurtz, NeoMind, Kido
// Thanks for helping me out guize!
// Modified by Luciar for Yonko
//================================================== 
 
prontera,132,168,3	script	Branch Hunt Challenge	78,{

mes .Npc_Name$;
	if(Hunter) {
	mes "You have killed ^880000"+HuntCount+"^000000/^0000FF"+Amt
 
+"^000000 "+getmonsterinfo(Hunt,0)+"s, keep it up!";
	close;
	}
	if(gettimetick(2) < HuntDelay) {
		mes "You can only do this quest once every 4 hours!";
		mes "You have "+(((HuntDelay) - (gettimetick(2)))/60)+" minutes left until the next quest.";
		close;
	}
mes "Hello "+strcharinfo(0)+", do you want to take on the Branch Hunting Challenge?","If you manage to kill them, you'll receive a reward!"," "+.RewAmt+" x ^880000"+DispLink(.Reward)+"^000000";
if (.c_RewAmt > 0) {
mes "and a bonus of up to "+.c_RewAmt+" ^880000"+DispLink(.c_Reward)+"^000000 for every challenge."; 
} else if (.z_RewAmt > 0) { 
mes "and a bonus of up to "+callfunc( "F_InsertComma",.z_RewAmt)+"z."; 
} else {
mes "for every challenge."; 
}
next;
mes .Npc_Name$;
mes "Do not forget to loot all the monster drops, they are part of the ^880000Dead Branch Quest^000000.";
if(select("Bring it on!:How about no?")==2) {
	next;
	mes .Npc_Name$;
	mes "Fine!";
	close;
}
 
next;
mes .Npc_Name$;
	Hunt = .Mob_List[rand(getarraysize(.Mob_List))];
	Amt = rand (50,100); //Amount of mob to hunt
	atcommand "@alootid -7201";
	atcommand "@alootid -7189";
	atcommand "@alootid -1019";
	atcommand "@alootid -7222";
	
	atcommand "@alootid +7201";
	atcommand "@alootid +7189";
	atcommand "@alootid +1019";
	atcommand "@alootid +7222";
	Hunter++;
 
mes "You have to hunt ^0000FF"+Amt+" "+getmonsterinfo(Hunt,0)+"^000000!";
next;
mes .Npc_Name$;
mes "Go go go!";
close2;
HuntDelay = gettimetick(2)+1; //every 1 sec.
end;

 
//----------Config----------
 
OnInit:
	.Npc_Name$ = "[^0000FF Daily Hunt ^000000]";
	setarray .Mob_List[0],1497,1495,1880,1400,1151,1010,1277,1269,1503; //Mobs to hunt
	.Reward = 12103; //Reward ID
	.RewAmt = 10; //Reward Amount
	.c_Reward = 50000; //Reward ID
	.c_RewAmt = 0; //Reward Amount
	.z_RewAmt = 1000000; //Zeny Reward
	end;

OnNPCKillEvent:
	sleep2 200;
	if(Hunter > 0) {
		if(killedrid == Hunt) {
			HuntCount++;
			dispbottom "You have killed "+HuntCount+"/"+Amt+" "+getmonsterinfo(Hunt,0)+"s, keep it up!";
			if (rand(1,100) > rand(1,100)) {
			getitem 7850,1;
			}
			if(HuntCount >= Amt) {
				dispbottom strnpcinfo(1)+": Congratulations! You did it!";
				dispbottom strnpcinfo(1)+": "+getitemname(.Reward)+" x "+.RewAmt+"!";
				getitem .Reward,.RewAmt;
				if (.c_RewAmt > 0) {
				getitem .c_Reward,rand(1,.c_RewAmt); // Edit to the reward that you would be giving
				dispbottom strnpcinfo(1)+": "+getitemname(.c_Reward)+" x "+.c_RewAmt+"!";
				} 
				if (.z_RewAmt > 0) {
				Zeny = Zeny + .z_RewAmt; // Edit to the zeny that you would be giving
				dispbottom strnpcinfo(1)+": "+callfunc( "F_InsertComma",.z_RewAmt)+"z!";
				} 

				Hunt = 0;
				Hunter = 0;
				HuntCount = 0;
				Amt = 0;
			}
		}
	}
end;
}

And this is the array of mobs.

setarray .Mob_List[0],1497,1495,1880,1400,1151,1010,1277,1269,1503; //Mobs to hunt

How do we put a blacklist into the set of arrays, without removing it from .Mob_List[0] ??

Now I understand that this would be a lot easier if we just remove the mob in the .Mob_List[0] , but I would like to understand how do we do this.

So instead of directly calling this line:

	Hunt = .Mob_List[rand(getarraysize(.Mob_List))];
	Amt = rand (50,100); //Amount of mob to hunt

It would have to check first if there is something in the blacklist, and then summon the monster.

setarray .Mob_BlackList[0],1031,1002; //Mobs to exclude from array

What I'm trying to accomplish here is an array-based list of monsters, and blacklisted monsters.

Supposing A = .Mob_List[0]
and B =  .Mob_BlackList[0]

It must compare first the list of A, and B, then remove the same ID on both. And then whatever's left will be the one randomized.

I tried doing this using for loop, but my coding is rusty. I'm sorry.

I hope you can help me guys.

EDIT:

Found a quick workaround, I used if statement to check if it is in .Mob_BlackList[0], but the script will be too long if there's many blackist.

 

Edited by mawjustin
found a quick workaround.
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 1

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3122
  • Reputation:   1614
  • Joined:  03/26/12
  • Last Seen:  

On 1/18/2021 at 8:56 AM, botka4aet said:

Loop for everyone in array one

- if it's in array two or three - skip

- else add to array three

After this random from array three

That is a complete waste of system resources.

 

On 1/18/2021 at 9:04 AM, mawjustin said:

if/else/goto would be the best option?? 

No. Use the script command 'compare'.

*compare("<string>","<substring>")

This command returns 1 or 0 when the substring is in the main string (1) or not (0).
This command is not case sensitive.

Examples:
	//dothis; will be executed ('Bloody Murderer' contains 'Blood').
	if (compare("Bloody Murderer","Blood"))
		dothis;

	//dothat; will not be executed ('Blood butterfly' does not contain 'Bloody').
	if (compare("Blood Butterfly","Bloody"))
		dothat;

So for your script you would do something like:

if(compare(.Mob_BlackList, .Mob_List)){
	debugmes "Mob is in blacklist.";
} else {
	debugmes "Mob is NOT blacklist.";
}	

Iterate through your array elements however you wish. See Disguise NPC in our repo for further usage example https://github.com/rathena/rathena/blob/master/npc/custom/events/disguise.txt#L208

Link to comment
Share on other sites

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3122
  • Reputation:   1614
  • Joined:  03/26/12
  • Last Seen:  

I could understand why you would want to do that if the array was being built dynamically based on varying factors - but your arrays are both defined within the script itself. The simplest way of removing them from the array is.. removing them from the array.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   6
  • Joined:  09/26/14
  • Last Seen:  

13 hours ago, Akkarin said:

I could understand why you would want to do that if the array was being built dynamically based on varying factors - but your arrays are both defined within the script itself. The simplest way of removing them from the array is.. removing them from the array.

I'm planning to use the script in other NPC, as of now the only way I know to solve this if via if and goto; but it wont be logical if there is a long list of loop that i need to do. so i'm hoping an array vs array sorting will do ?

Example: Random Option NPC

Array 1 : List all the Possible random option from 1 - 193

Array 2 : List all the random option to be ignored.

Array 3 : Avoid random option repetition in an item, all 1-5 random option must be different from each other, so array 3 will capture all the current random option of the item, and will remove this from the list in Array 1, thus making in an array vs array.

This is the result that i'm hoping to achieve, as of now i did this using if and goto; but it will be soooo long if i keep on doing this in this way.

Edited by mawjustin
added details
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  5
  • Topics Per Day:  0.00
  • Content Count:  211
  • Reputation:   17
  • Joined:  12/23/11
  • Last Seen:  

Loop for everyone in array one

- if it's in array two or three - skip

- else add to array three

After this random from array three

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   6
  • Joined:  09/26/14
  • Last Seen:  

5 minutes ago, botka4aet said:

Loop for everyone in array one

- if it's in array two or three - skip

- else add to array three

After this random from array three

if/else/goto would be the best option?? 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   6
  • Joined:  09/26/14
  • Last Seen:  

2 hours ago, Akkarin said:

That is a complete waste of system resources.

 

No. Use the script command 'compare'.


*compare("<string>","<substring>")

This command returns 1 or 0 when the substring is in the main string (1) or not (0).
This command is not case sensitive.

Examples:
	//dothis; will be executed ('Bloody Murderer' contains 'Blood').
	if (compare("Bloody Murderer","Blood"))
		dothis;

	//dothat; will not be executed ('Blood butterfly' does not contain 'Bloody').
	if (compare("Blood Butterfly","Bloody"))
		dothat;

So for your script you would do something like:


if(compare(.Mob_BlackList, .Mob_List)){
	debugmes "Mob is in blacklist.";
} else {
	debugmes "Mob is NOT blacklist.";
}	

Iterate through your array elements however you wish. See Disguise NPC in our repo for further usage example https://github.com/rathena/rathena/blob/master/npc/custom/events/disguise.txt#L208

this is exactly what i'm looking for.. thank you.. i should've read rathena docs more.

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