Jump to content
  • 0

[solved] Simple Fishing rand


jamesandrew

Question


  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.07
  • Content Count:  58
  • Reputation:   3
  • Joined:  06/21/23
  • Last Seen:  

I'm making a simple fishing script.
The rules are:
-  Must equip a fishing rod (2764)
- 5 seconds cast time
- Get one reward per cast
- Rewards rate are: Red Herb 40%; Yellow Herb 30%; White Herb 20%, Blue Herb 10%, Yggdrasil Berry 0.01%
 

prt_fild00,278,237,0	script	Fishing School	10065,{
set .@Rod,2764; //Fishing rod
if (isequipped(.@Rod)){
	specialeffect EF_BUBBLE,"Fishing School";
	soundeffect "_attack_axe.wav",0;
	dispbottom "[Fishing] Casting...";
	set .@fcast,5;
	progressbar "ffffff",.@fcast;
	if (rand(1,10) <= 4) ||(rand(1,10) <= 3) || (rand(1,10) <= 2) || (rand(1,10) <= 1){
		setarray .@Catch[0],507,508,509,510;// Red 40%, Yellow 30%, White 20%, Blue Herb 10%
		set .@CatchRand,.@Catch[rand(getarraysize(.@Catch))];
		getitem .@CatchRand,1;
		specialeffect2 610;
		soundeffectall "see_otter_damage.wav",0,strcharinfo(3);
		dispbottom("[Fishing] You got "+ getitemname(.@CatchRand) +".");
		}
	else {
		dispbottom "[Fishing] Nothing was caught...";
		specialeffect2 611;
		end;}
			if (rand(1,100) == 1){
				setarray .@Rare[0],607; //Yggdrasil Berry 0.01%
				set .@RareCatch, .@Rare[rand(getarraysize(.@Rare))];
				getitem .@RareCatch,1;
				dispbottom("[Fishing] Congratulations you got "+ getitemname(.@RareCatch) +".");
				specialeffect2 68;
				end;}
			else {
				end;}
	}
else {
	dispbottom "[Fishing] You need a Fishing Rod.";
	end;
	}
}

are these rands correct?

Edited by jamesandrew
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 1

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

On 9/6/2023 at 8:12 PM, jamesandrew said:

I'm making a simple fishing script.
The rules are:
-  Must equip a fishing rod (2764)
- 5 seconds cast time
- Get one reward per cast
- Rewards rate are: Red Herb 40%; Yellow Herb 30%; White Herb 20%, Blue Herb 10%, Yggdrasil Berry 0.01%
 

prt_fild00,278,237,0	script	Fishing School	10065,{
set .@Rod,2764; //Fishing rod
if (isequipped(.@Rod)){
	specialeffect EF_BUBBLE,"Fishing School";
	soundeffect "_attack_axe.wav",0;
	dispbottom "[Fishing] Casting...";
	set .@fcast,5;
	progressbar "ffffff",.@fcast;
	if (rand(1,10) <= 4) ||(rand(1,10) <= 3) || (rand(1,10) <= 2) || (rand(1,10) <= 1){
		setarray .@Catch[0],507,508,509,510;// Red 40%, Yellow 30%, White 20%, Blue Herb 10%
		set .@CatchRand,.@Catch[rand(getarraysize(.@Catch))];
		getitem .@CatchRand,1;
		specialeffect2 610;
		soundeffectall "see_otter_damage.wav",0,strcharinfo(3);
		dispbottom("[Fishing] You got "+ getitemname(.@CatchRand) +".");
		}
	else {
		dispbottom "[Fishing] Nothing was caught...";
		specialeffect2 611;
		end;}
			if (rand(1,100) == 1){
				setarray .@Rare[0],607; //Yggdrasil Berry 0.01%
				set .@RareCatch, .@Rare[rand(getarraysize(.@Rare))];
				getitem .@RareCatch,1;
				dispbottom("[Fishing] Congratulations you got "+ getitemname(.@RareCatch) +".");
				specialeffect2 68;
				end;}
			else {
				end;}
	}
else {
	dispbottom "[Fishing] You need a Fishing Rod.";
	end;
	}
}

are these rands correct?

Your pick code throws 4 dice with 10 eyes and checks if at least one fits, and then picks an item randomly.
Which means your script decides if it should give loot or not (Which contradicts your 4. Rule) but in case it drops an item, it gives every item an equal chance to be dropped.

Except Yggrasil Berry, which gets a 1% chance to be dropped regardless of if there was already a drop, which also contradicts your 4. Rule.
Here is what I would do to change your script to make it fit your given rules:
 

prt_fild00,278,237,0	script	Fishing School	10065,{
	if (!isequipped(.rod)) {
		dispbottom("[Fishing] You need a Fishing Rod.");
		end;
	}

	specialeffect(EF_BUBBLE, "Fishing School");
	soundeffect("_attack_axe.wav", 0);
	dispbottom("[Fishing] Casting...");
	progressbar("ffffff", .cast_delay);

	.@pick = rand(1, .catch_weight_sum);
	for(.@i = 0; .@i < getarraysize(.catches); .@i += 2) {
		.@pick -= .catches[.@i + 1];
		if(.@pick <= 0) {
			.@catch = .catches[.@i];
			break;
		}
	}

	getitem(.@catch, 1);
	specialeffect2(610);
	soundeffectall("see_otter_damage.wav", 0, strcharinfo(3));
	dispbottom("[Fishing] You got "+ getitemname(.@catch) + ".");
	end;

    OnInit:
		.rod = 2764;
		.cast_delay = 5;
		
		// Red Herb 40%; Yellow Herb 30%; White Herb 20%, Blue Herb 10%, Yggdrasil Berry 0.01%
		setarray(.catches, 507, 4000, 508, 3000, 509, 2000, 510, 1000, 607, 1);

		for(.@i = 0; .@i < getarraysize(.catches); .@i += 2)
			.catch_weight_sum = .catches[.@i + 1];
}

 

Edited by Winterfox
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  22
  • Topics Per Day:  0.07
  • Content Count:  58
  • Reputation:   3
  • Joined:  06/21/23
  • Last Seen:  

19 hours ago, Winterfox said:

Your pick code throws 4 dice with 10 eyes and checks if at least one fits, and then picks an item randomly.
Which means your script decides if it should give loot or not (Which contradicts your 4. Rule) but in case it drops an item, it gives every item an equal chance to be dropped.

Except Yggrasil Berry, which gets a 1% chance to be dropped regardless of if there was already a drop, which also contradicts your 4. Rule.
Here is what I would do to change your script to make it fit your given rules:
 

prt_fild00,278,237,0	script	Fishing School	10065,{
	if (!isequipped(.rod)) {
		dispbottom("[Fishing] You need a Fishing Rod.");
		end;
	}

	specialeffect(EF_BUBBLE, "Fishing School");
	soundeffect("_attack_axe.wav", 0);
	dispbottom("[Fishing] Casting...");
	progressbar("ffffff", .cast_delay);

	.@pick = rand(1, .catch_weight_sum);
	for(.@i = 0; .@i < getarraysize(.catches); .@i += 2) {
		.@pick -= .catches[.@i + 1];
		if(.@pick <= 0) {
			.@catch = .catches[.@i];
			break;
		}
	}

	getitem(.@catch, 1);
	specialeffect2(610);
	soundeffectall("see_otter_damage.wav", 0, strcharinfo(3));
	dispbottom("[Fishing] You got "+ getitemname(.@catch) + ".");
	end;

    OnInit:
		.rod = 2764;
		.cast_delay = 5;
		
		// Red Herb 40%; Yellow Herb 30%; White Herb 20%, Blue Herb 10%, Yggdrasil Berry 0.01%
		setarray(.catches, 507, 4000, 508, 3000, 509, 2000, 510, 1000, 607, 1);

		for(.@i = 0; .@i < getarraysize(.catches); .@i += 2)
			.catch_weight_sum = .catches[.@i + 1];
}

 

Awesome, thanks for the explanation and the script as well.

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