Jump to content
  • 0
Sign in to follow this  
Anisotropic Defixation

Treasure chest randomization for SE castles

Question

While this was very simple for FE script, I'm scratching my head with this.

 

What I want is to basically make it always spawn the default chest (1324) plus a random one from the array, still based on investment.

 

 

Here's the default portion of the script (agit_main_se):

 

 

 

OnClock0001:	// Spawn Treasure Chests based on castle economy.	if (strnpcinfo(2) == "template") end;	if (!getcastledata(strnpcinfo(2),1)) end;	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";	if (getcastledata(strnpcinfo(2),4)) {		.@Economy = getcastledata(strnpcinfo(2),2);		setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));		if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;		setcastledata strnpcinfo(2),4,0;	}	if (getcastledata(strnpcinfo(2),5)) {		.@defence = getcastledata(strnpcinfo(2),3);		setcastledata strnpcinfo(2),3,.@defence+getcastledata(strnpcinfo(2),5);		if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;		setcastledata strnpcinfo(2),5,0;	}	.@Treasure = getcastledata(strnpcinfo(2),2)/5+4;	if (!.@Treasure) end;	freeloop(1);	if (compare(strnpcinfo(2),"arug")) {		if (strnpcinfo(2) == "arug_cas01") {			.@treasurebox = 1943;			setarray .@treasurex[0],251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258;			setarray .@treasurey[0],369,369,369,369,368,368,368,368,367,367,367,367,366,366,366,366,365,365,365,365,364,364,364,364;		}		else if (strnpcinfo(2) == "arug_cas02") {			.@treasurebox = 1944;			setarray .@treasurex[0],382,383,384,385,386,387,384,385,386,387,388,389,382,383,384,385,386,387,384,385,386,387,388,389;			setarray .@treasurey[0],231,231,231,231,231,231,230,230,230,230,230,230,225,225,225,225,225,225,224,224,224,224,224,224;		}		else { 	// Castles 3,4,5 are identical, except 4's treasure.			.@treasurebox = (strnpcinfo(2) == "arug_cas04")?1946:1945;			setarray .@treasurex[0],291,292,293,294,295,296,293,294,295,296,297,298,291,292,293,294,295,296,293,294,295,296,297,298;			setarray .@treasurey[0],276,276,276,276,276,276,274,274,274,274,274,274,272,272,272,272,272,272,269,269,269,269,269,269;		}	}	else {		if (strnpcinfo(2) == "schg_cas02") {			.@treasurebox = 1939;			setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;			setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;		}		else if (strnpcinfo(2) == "schg_cas03") {			.@treasurebox = 1940;			setarray .@treasurex[0],189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194;			setarray .@treasurey[0], 21, 21, 21, 21, 21, 21, 19, 19, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 15, 15, 15, 15, 15, 15;		}		else {	// Castles 1,4,5 are identical, except treasures.			if (strnpcinfo(2) == "schg_cas01") .@treasurebox = 1938;			else if (strnpcinfo(2) == "schg_cas04") .@treasurebox = 1941;			else .@treasurebox = 1942;			setarray .@treasurex[0],388,388,388,387,386,385,384,384,384,384,384,384,385,386,387,388,389,390,390,390,389,388,387,386;			setarray .@treasurey[0],388,389,390,390,390,390,389,388,387,386,385,384,384,384,384,384,384,384,385,386,386,386,386,386;		}	}	for(.@i = 0; .@i<4; ++.@i)		monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";	for(.@i = 4; .@i<24; ++.@i) {		if (.@Treasure < .@i+1) break;		monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";	}	freeloop(0);	end;OnTreasureDied:	end;}

 

 

 

 

Here's mine (differences are bold):

 

 

 

OnClock0001:
 // Spawn Treasure Chests based on castle economy.
 if (strnpcinfo(2) == "template") end;
 if (!getcastledata(strnpcinfo(2),1)) end;
 killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";
 if (getcastledata(strnpcinfo(2),4)) {
   .@Economy = getcastledata(strnpcinfo(2),2);
   setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));
   if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;
   setcastledata strnpcinfo(2),4,0;
 }
 if (getcastledata(strnpcinfo(2),5)) {
   .@defence = getcastledata(strnpcinfo(2),3);
   setcastledata strnpcinfo(2),3,.@defence+getcastledata(strnpcinfo(2),5);
   if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;
   setcastledata strnpcinfo(2),5,0;
 }
 .@Treasure = getcastledata(strnpcinfo(2),2)/5+4;
 if (!.@Treasure) end;
 freeloop(1);
 if (compare(strnpcinfo(2),"arug")) {
   if (strnpcinfo(2) == "arug_cas01") {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258;
     setarray .@treasurey[0],369,369,369,369,368,368,368,368,367,367,367,367,366,366,366,366,365,365,365,365,364,364,364,364;
   }
   else if (strnpcinfo(2) == "arug_cas02") {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],382,383,384,385,386,387,384,385,386,387,388,389,382,383,384,385,386,387,384,385,386,387,388,389;
     setarray .@treasurey[0],231,231,231,231,231,231,230,230,230,230,230,230,225,225,225,225,225,225,224,224,224,224,224,224;
   }
   else {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],291,292,293,294,295,296,293,294,295,296,297,298,291,292,293,294,295,296,293,294,295,296,297,298;
     setarray .@treasurey[0],276,276,276,276,276,276,274,274,274,274,274,274,272,272,272,272,272,272,269,269,269,269,269,269;
   }
 }
 else {
   if (strnpcinfo(2) == "schg_cas02") {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;
     setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;
   }
   else if (strnpcinfo(2) == "schg_cas03") {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194;
     setarray .@treasurey[0], 21, 21, 21, 21, 21, 21, 19, 19, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 15, 15, 15, 15, 15, 15;
   }
   else {
     setarray .@rand[0],1938,1939,1940;
     set .@treasurebox,.@rand[getarraysize(.@rand)];

     setarray .@treasurex[0],388,388,388,387,386,385,384,384,384,384,384,384,385,386,387,388,389,390,390,390,389,388,387,386;
     setarray .@treasurey[0],388,389,390,390,390,390,389,388,387,386,385,384,384,384,384,384,384,384,385,386,386,386,386,386;
   }
 }
 for(.@i = 0; .@i<4; ++.@i) {
   monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";
   monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",.@treasurebox,1,strnpcinfo(0)+"::OnTreasureDied";
 }
 for(.@i = 4; .@i<24; ++.@i) {
   if (.@Treasure < .@i+1) break;
   monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";
   monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",.@treasurebox,1,strnpcinfo(0)+"::OnTreasureDied";
 }
 freeloop(0);
 end;

OnTreasureDied:
 end;
}

 

 

 

 

All this does is only spawn the default chest (1324) and nothing else, stuff from the array isn't pulled in.

 

 

Any help is appreciated!

Edited by Anisotropic Defixation

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

a) If all your random treasure ID arrays are same for each castle, you'd do a better job setting them once, instead of setting them in every if.

B) Are you fine with the fact that the chests will be spawned on each other?

c) Chests spawned are changing between 1934 for even numbered chests (0,2,4) and castle-specific chest for odd numbered(1,2,5), so I wouldn't change the .@treasurebox setting.

Try this one:

 

OnClock0001:    // Spawn Treasure Chests based on castle economy.    if (strnpcinfo(2) == "template") end;    if (!getcastledata(strnpcinfo(2),1)) end;    killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";    if (getcastledata(strnpcinfo(2),4)) {        .@Economy = getcastledata(strnpcinfo(2),2);        setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));        if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;        setcastledata strnpcinfo(2),4,0;    }    if (getcastledata(strnpcinfo(2),5)) {        .@defence = getcastledata(strnpcinfo(2),3);        setcastledata strnpcinfo(2),3,.@defence+getcastledata(strnpcinfo(2),5);        if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;        setcastledata strnpcinfo(2),5,0;    }    .@Treasure = getcastledata(strnpcinfo(2),2)/5+4;    if (!.@Treasure) end;    freeloop(1);    if (compare(strnpcinfo(2),"arug")) {        if (strnpcinfo(2) == "arug_cas01") {            .@treasurebox = 1943;            setarray .@treasurex[0],251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258;            setarray .@treasurey[0],369,369,369,369,368,368,368,368,367,367,367,367,366,366,366,366,365,365,365,365,364,364,364,364;        }        else if (strnpcinfo(2) == "arug_cas02") {            .@treasurebox = 1944;            setarray .@treasurex[0],382,383,384,385,386,387,384,385,386,387,388,389,382,383,384,385,386,387,384,385,386,387,388,389;            setarray .@treasurey[0],231,231,231,231,231,231,230,230,230,230,230,230,225,225,225,225,225,225,224,224,224,224,224,224;        }        else {     // Castles 3,4,5 are identical, except 4's treasure.            .@treasurebox = (strnpcinfo(2) == "arug_cas04")?1946:1945;            setarray .@treasurex[0],291,292,293,294,295,296,293,294,295,296,297,298,291,292,293,294,295,296,293,294,295,296,297,298;            setarray .@treasurey[0],276,276,276,276,276,276,274,274,274,274,274,274,272,272,272,272,272,272,269,269,269,269,269,269;        }    }    else {        if (strnpcinfo(2) == "schg_cas02") {            .@treasurebox = 1939;            setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;            setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;        }        else if (strnpcinfo(2) == "schg_cas03") {            .@treasurebox = 1940;            setarray .@treasurex[0],189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194;            setarray .@treasurey[0], 21, 21, 21, 21, 21, 21, 19, 19, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 15, 15, 15, 15, 15, 15;        }        else {    // Castles 1,4,5 are identical, except treasures.            if (strnpcinfo(2) == "schg_cas01") .@treasurebox = 1938;            else if (strnpcinfo(2) == "schg_cas04") .@treasurebox = 1941;            else .@treasurebox = 1942;            setarray .@treasurex[0],388,388,388,387,386,385,384,384,384,384,384,384,385,386,387,388,389,390,390,390,389,388,387,386;            setarray .@treasurey[0],388,389,390,390,390,390,389,388,387,386,385,384,384,384,384,384,384,384,385,386,386,386,386,386;        }    }	setarray .@rand[0],1938,1939,1940; //array of custom treasure chests;    for(.@i = 0; .@i<4; ++.@i)        monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";        monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",.@rand[rand(getarraysize(.@rand))],1,strnpcinfo(0)+"::OnTreasureDied"; //we get random chest number from array, here it will randomize via rand, with current array the ID is equal to .@rand[rand(3)]    for(.@i = 4; .@i<24; ++.@i) {        if (.@Treasure < .@i+1) break;        monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";        monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",.@rand[rand(getarraysize(.@rand))],1,strnpcinfo(0)+"::OnTreasureDied";    }    freeloop(0);    end;OnTreasureDied:    end;}
Edited by Garr

Share this post


Link to post
Share on other sites
  • 0

Thanks!
 
a: Probably, but I want to keep them arranged.
 
b: Nah, which is why I set up arrays for every castle.
 
c: So I guess your script will spawn the default chest, castle specific chest plus those from the random array, and changing castle specific chest to default will only double the spawn rate of those. I don't really want default castle specific chests spawning. Maybe it would be better to simply make 4 chest random arrays for the castles so they aren't spawned on top of each other and change the spawn script to only pull from the array?

 

Isn't there a way to make my original idea work?

Edited by Anisotropic Defixation

Share this post


Link to post
Share on other sites
  • 0

Oh, I missed that somehow. Ofc it's simple. Just change both

(.@i%2)?.@treasurebox:1324

to just

1324

in the code I gave above. And then you can delete the .@treasurebox setting inside ifs, or if you like it that much replace it with .@rand() setting.

Edited by Garr

Share this post


Link to post
Share on other sites
  • 0

Getting pretty confused here, I guess I didn't explain myself properly.

 

What I want to do is to basically change the default castle specific chest (from the original script) to be a random one from the array, while keeping the default 1324 chest spawn function intact, which is what I tried to accomplish

 

So, from:

 

 

 else {		if (strnpcinfo(2) == "schg_cas02") {			.@treasurebox = 1939;			setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;			setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;		}

 

to:

 

 

else {        if (strnpcinfo(2) == "schg_cas02") {            setarray .@rand[0],1938,1939,1940;            set .@treasurebox,.@rand[getarraysize(.@rand)];            setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;            setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;        }

 

and to make this set. work:

 

 

monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",.@treasurebox,1,strnpcinfo(0)+"::OnTreasureDied";

 

below the default 1324 chest spawn function.
 

 

Share this post


Link to post
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.   Restore formatting

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.