Jump to content
  • 0

About 'array' and 'randomize'.


Psyche

Question


  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  123
  • Reputation:   6
  • Joined:  03/12/13
  • Last Seen:  

Hi community.

I'm newbie and want to learn about array things. What the difference between . @ and $ or anything that scripter's usually used. I saw some used bracket [ ] too.

For my curious, I made a test script but I think I fail to code / the result is not as expected.

 

Heres the script. The purpose is give 4 equipment (Armor, Shield, Garments, and Shoes) to player with random refine +0 ~ +7 and random enchanted stone/orb.

function	script	Test	{
	setarray .Ref[0],0,1,2,3,4,5,6,7;
	setarray .Orb[0],4700,4701,4702;
	setarray .Armors[0],2301,2303,2305;
	setarray .Shields[0],2101,2103;
	setarray .Garments[0],2512,2501,2503,2505;
	setarray .Shoes[0],2416,2401,2403,2405,2411;
	
	set .Rand1, rand( getarraysize(.Ref) );
	set .Rand2, rand( getarraysize(.Orb) );
	
	set .RandA, rand( getarraysize(.Armors) );
	set .RandB, rand( getarraysize(.Shields) );
	set .RandC, rand( getarraysize(.Garments) );
	set .RandD, rand( getarraysize(.Shoes) );
	
	getitembound2 .Armors[.RandA], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Shields[.RandB], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Garments[.RandC], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Shoes[.RandD], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;

	end;
}

But that script give random armors, shield, garments, and shoes only. The Refine and Orb don't randomize. So the example result was :
First open +1 Cotton Shirt [STR +2] | +1 Muffler [STR +2] | +1 Guard [STR+2] | +1 Shoes [STR+2]
Second open : +3 Cotton Shirt [INT +1] | +3 Manteau [INT +1] | +3 Buckler [INT+1] | +3 Shoes [INT +1]

Get same refine and enchant. But the equipments are randomized. The expected result should be randomize everything. Please help me.

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  927
  • Reputation:   169
  • Joined:  04/05/13
  • Last Seen:  

.@  mean this variable will deleted after you finish with that npcs.

$ mean 'server variable'

For more info please look at doc > script_commands

 

For the randomize you should do 

set .Rand1, rand( getarraysize(.Ref) );

Again because it's located above 4 getitembound.

 

The simple way is.

Getitem > rand > Getitem> rand and so on.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  123
  • Reputation:   6
  • Joined:  03/12/13
  • Last Seen:  

3 hours ago, Start_ said:

.@  mean this variable will deleted after you finish with that npcs.

$ mean 'server variable'

For more info please look at doc > script_commands

 

For the randomize you should do 


set .Rand1, rand( getarraysize(.Ref) );

Again because it's located above 4 getitembound.

 

The simple way is.

Getitem > rand > Getitem> rand and so on.

 

Thankyou for your reply.

But if I do that again, it will be too many lines in total.

And i believe there was a way to simplify my script but sadly i don't know how.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  50
  • Topics Per Day:  0.01
  • Content Count:  1702
  • Reputation:   238
  • Joined:  09/05/12
  • Last Seen:  

Because you are caching the random indexed value in a variable and used them in all getitembound2 command. 

Remove

set .Rand1, rand( getarraysize(.Ref) );
set .Rand2, rand( getarraysize(.Orb) );

And change

getitembound2 .Armors[.RandA], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
getitembound2 .Shields[.RandB], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
getitembound2 .Garments[.RandC], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
getitembound2 .Shoes[.RandD], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;

to

getitembound2 .Armors[.RandA], 1, 1, .Ref[rand( getarraysize(.Ref) )], 0, 0, 0, 0, .Orb[rand( getarraysize(.Orb) )], 1;
getitembound2 .Shields[.RandB], 1, 1, .Ref[rand( getarraysize(.Ref) )], 0, 0, 0, 0, .Orb[rand( getarraysize(.Orb) )], 1;
getitembound2 .Garments[.RandC], 1, 1, .Ref[rand( getarraysize(.Ref) )], 0, 0, 0, 0, .Orb[rand( getarraysize(.Orb) )], 1;
getitembound2 .Shoes[.RandD], 1, 1, .Ref[rand( getarraysize(.Ref) )], 0, 0, 0, 0, .Orb[rand( getarraysize(.Orb) )], 1;

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

On 9/20/2020 at 8:33 PM, Psyche said:

Heres the script. The purpose is give 4 equipment (Armor, Shield, Garments, and Shoes) to player with random refine +0 ~ +7 and random enchanted stone/orb.


function	script	Test	{
	setarray .Ref[0],0,1,2,3,4,5,6,7;
	setarray .Orb[0],4700,4701,4702;
	setarray .Armors[0],2301,2303,2305;
	setarray .Shields[0],2101,2103;
	setarray .Garments[0],2512,2501,2503,2505;
	setarray .Shoes[0],2416,2401,2403,2405,2411;
	
	set .Rand1, rand( getarraysize(.Ref) );
	set .Rand2, rand( getarraysize(.Orb) );
	
	set .RandA, rand( getarraysize(.Armors) );
	set .RandB, rand( getarraysize(.Shields) );
	set .RandC, rand( getarraysize(.Garments) );
	set .RandD, rand( getarraysize(.Shoes) );
	
	getitembound2 .Armors[.RandA], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Shields[.RandB], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Garments[.RandC], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;
	getitembound2 .Shoes[.RandD], 1, 1, .Ref[.Rand1], 0, 0, 0, 0, .Orb[.Rand2], 1;

	end;
}

 

prontera,155,185,5	script	jhfkjsdf	1_F_MARIA,{
	getitembound2 F_Rand(2301,2303,2305), 1,1, rand(0,7), 0, 0,0,0, callsub(L_orbs), BOUND_ACCOUNT;
	getitembound2 F_Rand(2101,2103), 1,1, rand(0,7), 0, 0,0,0, callsub(L_orbs), BOUND_ACCOUNT;
	getitembound2 F_Rand(2512,2501,2503,2505), 1,1, rand(0,7), 0, 0,0,0, callsub(L_orbs), BOUND_ACCOUNT;
	getitembound2 F_Rand(2416,2401,2403,2405,2411), 1,1, rand(0,7), 0, 0,0,0, callsub(L_orbs), BOUND_ACCOUNT;
	end;
L_orbs:
	return F_Rand(4700,4701,4702);
}

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  32
  • Topics Per Day:  0.01
  • Content Count:  123
  • Reputation:   6
  • Joined:  03/12/13
  • Last Seen:  

BIG THANKS to @Patskie and @AnnieRuru . Both of you are my scripter idol. I'm so glad you replied to my thread.

and I also thank to @Start_ 

I'm starting to understand 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...