Jump to content
  • 0

Looping.


Yomigaeru

Question


  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   5
  • Joined:  12/25/11
  • Last Seen:  

hey ra.

 

I'm currently scripting a "draw npc".

 

the mechanics are, a player have to draw a number. rand(1,16) if that player draws number 1 no one in the server can pick number 1 again. Thus, when a player "draws" another number 1 if someone have already drawn that number, the script will loop until it finds another number that have not yet been chosen. 

 

here's my unfinished script since i don't know what to do with the loop:

 

 

prontera,153,138,3	script	Tournament Official	405,{

set .drawlats,rand(1,16);
if ( .drawlats == 1 && $@potm != 1 ) {
set $@potm,1;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You picked number 1!";
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 1st Combatant!",0;
end;

Hope someone knows what i'm talking about. I'm using 3ceam anyways so please don't use ra tags.

 

Thanks.

 



it worked somehow after whole day of scripting.

 

my only problem is how to remove 1 number if it's already chosen?

 

Example:

 

if number 1 is chosen, the rand will not read 1 again.

 

It's time consuming to get redirected again and again to get a number.

 

here's my current script

cell_game,155,140,3	script	Tournament Official	405,{
l_potm_start2:
set .potmdraw,rand(1,16);
//if ( $@potmsv1 == 1 || $@potmsv2 == 1 || $@potmsv3 == 1 ) goto l_potm_start;

mes "[Tournament Official]";
mes "You can now pick a number!";
menu "Pick a number",l_potm_start;

l_potm_start:
if ( $@potmsv1 == 1 && $@potmsv2 == 1 && $@potmsv3 == 1 && $@potmsv4 == 1 && $@potmsv5 == 1 && $@potmsv6 == 1 && $@potmsv7 == 1 && $@potmsv8 == 1 && $@potmsv9 == 1 && $@potmsv10 == 1 && $@potmsv11 == 1 && $@potmsv12 == 1 && $@potmsv13 == 1 && $@potmsv14 == 1 && $@potmsv15 == 1 && $@potmsv16 == 1 ) {
next;
mes "[Tournament Official]";
mes "All numbers were drawn. Better luck next time!";
close;
}
if ( .potmdraw == 1 && $@potmsv1 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #1!";
set $@potmsv1,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 1st combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 2 && $@potmsv2 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #2!";
set $@potmsv2,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 2nd combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 3 && $@potmsv3 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #3!";
set $@potmsv3,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 3rd combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 4 && $@potmsv4 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #4!";
set $@potmsv4,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 4th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 5 && $@potmsv5 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #5!";
set $@potmsv5,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 5th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 6 && $@potmsv6 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #6!";
set $@potmsv6,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 6th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 7 && $@potmsv7 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #7!";
set $@potmsv7,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 7th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 8 && $@potmsv8 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #8!";
set $@potmsv8,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 8th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 9 && $@potmsv9 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #9!";
set $@potmsv9,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 9th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 10 && $@potmsv10 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #10!";
set $@potmsv10,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 10th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 11 && $@potmsv11 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #11!";
set $@potmsv11,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 11th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 12 && $@potmsv12 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #12!";
set $@potmsv12,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 12th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 13 && $@potmsv13 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #13!";
set $@potmsv13,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 13th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 14 && $@potmsv14 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #14!";
set $@potmsv14,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 14th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 15 && $@potmsv15 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #15!";
set $@potmsv15,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 15th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 16 && $@potmsv16 != 1 ) {
next;
mes ".";
next;
mes ".";
mes "..";
next;
mes ".";
mes "..";
mes "...";
next;
mes "[Tournament Official]";
mes "Congratulations!";
mes "You have drawn #16!";
set $@potmsv16,1;
close2;
mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the 16th combatant in the POTM Tournament!",0;
//warp "poring_w02",99,85;
end;
}
if ( .potmdraw == 1 && $@potmsv1 == 1 || .potmdraw == 2 && $@potmsv2 == 1 || .potmdraw == 3 && $@potmsv3 == 1 || .potmdraw == 4 && $@potmsv4 == 1 || .potmdraw == 5 && $@potmsv5 == 1 || .potmdraw == 6 && $@potmsv6 == 1 || .potmdraw == 7 && $@potmsv7 == 1 || .potmdraw == 8 && $@potmsv8 == 1 || .potmdraw == 9 && $@potmsv9 == 1 || .potmdraw == 10 && $@potmsv10 == 1 || .potmdraw == 11 && $@potmsv11 == 1 || .potmdraw == 12 && $@potmsv12 == 1 || .potmdraw == 13 && $@potmsv13 == 1 || .potmdraw == 14 && $@potmsv14 == 1 || .potmdraw == 15 && $@potmsv15 == 1 || .potmdraw == 16 && $@potmsv16 == 1 ) {
next;
mes "[Tournament Official]";
mes "Please pick another number because that number is already taken!";
close2;
goto l_potm_start2;
end;
}
end;
}

//Server Reseter
cell_game,152,141,3	script	Server Reseter	888,{
set $@potmsv1,0;
set $@potmsv2,0;
set $@potmsv3,0;
set $@potmsv3,0;
set $@potmsv4,0;
set $@potmsv5,0;
set $@potmsv6,0;
set $@potmsv7,0;
set $@potmsv8,0;
set $@potmsv9,0;
set $@potmsv10,0;
set $@potmsv11,0;
set $@potmsv12,0;
set $@potmsv13,0;
set $@potmsv14,0;
set $@potmsv15,0;
set $@potmsv16,0;
end;
}

Help please?

Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2350
  • Joined:  10/28/11
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

if number 1 is chosen, the rand will not read 1 again.

It's time consuming to get redirected again and again to get a number.

I suggest to initialize an array which contains all numbers, make a rand of index instead of a rand of number then delete the index

 

Sample:

for ( set .@i, 1; .@i < 17; .@i++ )
	set .init_random_number[.@i-1], .@i;// initialize all number (1->16) in an array index (0->15)
set .total_number, 16;// total: 16 index
set .@random_number, rand( .total_number );// choose a random index in the array

Player get number in index 1.

deletearray .init_random_number[1], 1;// delete the number in index 1
set .total_number, .total_number -1;

 

 

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   5
  • Joined:  12/25/11
  • Last Seen:  

can you add that to my script?

 

im kinda not familiar with that kinds of scripts.

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

cell_game,155,140,3	script	Tournament Official	405,{

	if ( .total_number == 0) {
		mes "[Tournament Official]";
		mes "All numbers were drawn. Better luck next time!";
		close;
	}
	mes "[Tournament Official]";
	mes "You can now pick a number!";
	next;
	select( "Pick a number" );
	if ( .total_number == 0) {// another player pick the lastnumber
		mes "[Tournament Official]";
		mes "All numbers were drawn. Better luck next time!";
		close;
	}
	set .@index, rand( .total_number );
	set .@tmp, .random_number[.@index];
	set .number_draw[.size_draw], .@tmp;
	set .name_draw$[.size_draw], strcharinfo(0);
	set .size_draw, .size_draw +1;
	deletearray .random_number[.@index], 1;
	set .total_number, .total_number -1;
	mes ".";
	next;
	mes ".";
	mes "..";
	next;
	mes ".";
	mes "..";
	mes "...";
	next;
	mes "[Tournament Official]";
	mes "Congratulations!";
	mes "You have drawn #"+ .@tmp +"!";
	close2;
	mapannounce "cell_game","Tournament Official : "+strcharinfo(0)+" will be the "+ .@tmp + ( .@tmp == 1 ? "st" : .@tmp == 2 ? "nd" : "th" ) +" combatant in the POTM Tournament!",0;
	//warp "poring_w02",99,85;
	end;

OnInit:
	for ( set .@i, 1; .@i < 17; set .@i, .@i +1 )
		set .random_number[.@i-1], .@i;// initialize all number (1->16) in an array index (0->15)
	set .total_number, 16;// total: 16 index
	end;

OnWhisperGlobal:
	if ( getgmlevel() < 99 ) end;
	deletearray .random_number, .total_number;
	dispbottom "Number reseted";
	end;
}

Use whisper system to reset the value

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   5
  • Joined:  12/25/11
  • Last Seen:  

weird. I'm having this msg always even if i reset the variables.

 

 

post-1027-0-11895100-1373280417_thumb.jpg

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

It was a sample..

Replace by

OnWhisperGlobal:
	if ( getgmlevel() < 99 ) end;
	deletearray .random_number, .total_number;
	dispbottom "Number reseted";

OnInit:
	for ( set .@i, 1; .@i < 17; set .@i, .@i +1 )
		set .random_number[.@i-1], .@i;// initialize all number (1->16) in an array index (0->15)
	set .total_number, 16;// total: 16 index
	end;

to re-initialize the number

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  23
  • Topics Per Day:  0.01
  • Content Count:  89
  • Reputation:   5
  • Joined:  12/25/11
  • Last Seen:  

thanks. works fine now.

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