Jump to content
  • 0

Requesting a "special custom box"


ItsFree

Question


  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

Hi, Rathena community is there a way to "create" a custom box,. that only can be open if you have X item, and after opening the custom box the X item is consumed....

i know how to create a custom box, but is there a way to do that? is like.... i need  a "key" to open it and after open the box the "key" is consumed.

If need more info... i can try explain better ^^

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  120
  • Topics Per Day:  0.03
  • Content Count:  295
  • Reputation:   6
  • Joined:  12/02/11
  • Last Seen:  

Hi there all of the resources are in the /doc files

heres what i do for that 

create item type 11 and create script Inside the box item that calls a function

Quote

Item type 11 Usable with delayed consumption (intended for 'itemskill')
        Items using the 'itemskill' script command are consumed after
        selecting a target. Any other command will NOT consume the item.

31173,Box,Box,11,50,,70,,,,,0xFFFFFFFF,63,2,,,,,,{ callfunc "test"; },{},{}
31174,Key,Key,11,50,,70,,,,,0xFFFFFFFF,63,2,,,,,,{ },{},{}

.../doc/item_db

then create a function that checks the Key Item ID like this

Quote

function    script    test    {
if(countitem(<keyid>) >= 1) {
    delitem <boxid>,1; // Box ID
    delitem <keyid>,<amount>; // Key ID
    getitem <reward>,<amount> // Reward ID
    end;
} else {
    dispbottom "You need key to open it";
    end;
}
}

.../doc/script_commands

hope this will help you

Edited by hakuren
  • Like 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

Thx! i'll try it on a few hours (alredy on bed...) but yeah i guess i understand ^^ well first i gonna check it xD

 just on...

 

 getitem <reward>,<amount> // Reward ID

on "<reward>"  there i can put... "getrandgroupitem(IG_CustomBox),1;" right ¿? or....

Edited by ItsFree
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  1137
  • Reputation:   290
  • Joined:  04/29/13
  • Last Seen:  

501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ if(countitem(512)>0) { callfunc "CustomBox"; }},{},{}
function	script	CustomBox	{
	setarray .BoxItems[0],501,502,503;
	
	set .Random, getarraysize( .BoxItems );
	delitem 512,1;
	getitem .BoxItems[ rand( .Random ) ], 1;
	announce "["+strcharinfo(0)+"] has just obtained a ["+getitemname(.BoxItems[ .Random ])+"] from a Custom Box.",0;
	end;
}

 

Edited by Cyro
  • Like 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ if(countitem(512)>0) { callfunc "CustomBox"; }},{},{}
function	script	CustomBox	{
	setarray .BoxItems[0],501,502,503;
	
	set .Random, getarraysize( .BoxItems );
	delitem 512,1;
	getitem .BoxItems[ rand( .Random ) ], 1;
	announce "["+strcharinfo(0)+"] has just obtained a ["+getitemname(.BoxItems[ .Random ])+"] from a Custom Box.",0;
	end;
}

@Cyro

Nice... just a question is there no a way to set percent by items like the original "old blue box" ¿? i mean 1% to 501, 10% to 502, 50% to 503, etc.

Edited:

what did i do wrong ? i tried with "old red box" changing it... but no error on console and only unidentified ribbon gives me :/

also i can open it without consuming the item 512 :c

 

function	script	SpecialCustomBox	{
	setarray .BoxItems[0],7228,7229,7230,7231,7232,7333;
	
	set .Random, getarraysize( .BoxItems );
	delitem 512,1;
	getitem .BoxItems[ rand( .Random ) ], 1;
	announce "["+strcharinfo(0)+"] has just obtained a ["+getitemname(.BoxItems[ .Random ])+"] from a Special Custom Box.",0;
	end;
}

018235227d257b854cb56ee2d43c7c50.png

Edited by ItsFree
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

Check your import folder for duplicate of old red box. Also before you make the code run, be sure to reloaditemdb and reloadscript afterward in that order.

I will give you code later make it very easy to config, with instruction also. When I get home in maybe 2 hours. I will try put as much info as possible so you can learn how to do it also in the future, or maybe even improve it. Good luck.

Edit:

Note: This might not be working 100% because I had no time to test it, feel free to message me or reply to this topic for support. Hope this helps. And i've added as much information I could put to make it easily configurable, it might look ugly and dirty, but it should work, hopefully.

DB: 

501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ callfunc "CustomBox",501,512; },{},{}

Script:

function	script	CustomBox	{
	//start of settings
	//amount and chances
	.@req_amt = 1; //change to how many items is needed to open
	.@good_chance = 10; //10 = 10%
	.@best_chance = 1; //1 = 1%
	.@announce = 1; //change to 0 if you want to turn off or 1 to turn on announce
	
	//arrays
	setarray .@rew_basic,501,502,503,504,505; //your reward items id [basic]
	setarray .@rew_good,501,502,503,504,505; //your reward items id [good]
	setarray .@rew_best,501,502,503,504,505; //your reward items id [best]
	setarray .@rew_amt_basic,1,2,3,4,5; //your reward amount [basic]
	setarray .@rew_amt_good,1,2,3,4,5; //your reward amount [good]
	setarray .@rew_amt_best,1,2,3,4,5; //your reward amount [best
	/* Note #1: This can still be simplified into a more compact snippet, but for sake of basicness, i will not make it into that */
	/* Note #2: Make sure your amount and rewards match, if you have 5 items in the reward category, make sure you have 5 amounts in your amount category too */
	
	//size of arrays
	.@basic_size = getarraysize(.@rew_basic) - 1;
	.@good_size = getarraysize(.@rew_good) - 1;
	.@best_size = getarraysize(.@rew_best) - 1;
	/* Note: Why we do this is because we want subtract one value from the output of getarraysize, because our array index starts at 0 (we did not specify it to start at 1)*/
	
	//end of settings
	if(getarg(1) < 1){ //if required amount is less than 1, warning will pop up and consumed item will be returned
		message strcharinfo(0),"You require [ "+getitemname(getarg(1))+" ] x"+.@req_amt+" to open this item.";
		getitem 501,1;
		end;
	}
	.@rand = rand(0,100); //randomize chance to get rewards above
	delitem getarg(1),.@req_amt; //required item is deleted before giving out rewards
	if(.@rand <= .@best_chance){ //this produces the "best" items
		.@item = rand(0,.@best_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_best[.@item],.@rew_amt_best[.@item];
		end;
	}
	if(.@rand <= .@good_chance){ //since we already catch anything that is either 1 or 0 above, no need to add check for <= 1
		.@item = rand(0,.@good_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_good[.@item],.@rew_amt_good[.@item];
		end;
	}
	//they get basic reward
	.@item = rand(0,.@basic_size); //item is randomly chosen from the list
	if(.@announce) //if announce is active or 1, will announce
		announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
	getitem .@rew_basic[.@item],.@rew_amt_basic[.@item];
	end;
}

 

Edited by Aisha
adding script
  • Like 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

Looks like is working. not error and anything just editing like i want, for now 2 questions... so... if i wanna create more "boxes" with this script stucture, i just have to rename...

1.-

function	script	CustomBox

to something differente like dunno... 'DarkBox', 'LightBox' etc... right ¿?

2.- if i want to add more "chances" i just have to create them ¿? i mean...

 

	.@good_chance = 10; //10 = 10%
	.@best_chance = 1; //1 = 1%
	setarray .@rew_good,501,502,503,504,505; //your reward items id [good]
	setarray .@rew_best,501,502,503,504,505; //your reward items id [best]

here i guess understand but here....
 

	.@rand = rand(0,100); //randomize chance to get rewards above
	delitem getarg(1),.@req_amt; //required item is deleted before giving out rewards
	if(.@rand <= .@best_chance){ //this produces the "best" items
		.@item = rand(0,.@best_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_best[.@item],.@rew_amt_best[.@item];
		end;
	}
	if(.@rand <= .@good_chance){ //since we already catch anything that is either 1 or 0 above, no need to add check for <= 1
		.@item = rand(0,.@good_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_good[.@item],.@rew_amt_good[.@item];
		end;

is just change those ".@best_chance" and ".@rew_best" , ".@rew_amt_best" to the new ¿?

also... how fix the "null" ><

null.png

Edited by ItsFree
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

Try removing the - 1 from the getarraysize section.

Also, to make more, yes you'd have to just copy what I've made above, just make sure to make them distinguishable and unique.

And to your last question, that is correct, just change those variables to the one you created. Also, another good thing is that these are temporary variables so everytime they finish executing, they are free'd so you won't be using memory as much as when you're using permanent ones, but that is just trivial, but is key if you want to save memory.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

Thx, last 2 questions: 

1.- 
Is there a way to the "box" item not consume if i dont have the "key" item ¿? i mean if i've the key is consume and work without problems, but i dont dont have the "key" also consume and yeah dont give anything but the "box consume..." that i want is that dont let to consume the box if i dont have the "key"

2.- 

so i just change this
 

//size of arrays
	.@basic_size = getarraysize(.@rew_basic) - 1;
	.@good_size = getarraysize(.@rew_good) - 1;
	.@best_size = getarraysize(.@rew_best) - 1;

to this
 

//size of arrays
	.@basic_size = getarraysize(.@rew_basic);
	.@good_size = getarraysize(.@rew_good);
	.@best_size = getarraysize(.@rew_best);

i mean "remove the - 1" ¿?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

I'm not sure you can stop the item from being consumed. You can try this one instead.

501,Red_Potion,Red Potion,11,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ if(countitem(512) > 0){ callfunc "CustomBox",501,512; } end; },{},{}

Let me know if it still consumes upon use even without a key. If it does not, good, then check if when you have a key and you consume it, does the item(box) go away.

As for your second question, that is correct, try to use that format and try to see if you can still get the "null" result.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

sorry for delay to answer... yeah solved about the "null" but still consuming :c
 

12189,Red_Box_,Old Red Box,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ if(countitem(512) > 0) {callfunc "CustomBox",501,512;} end; },{},{}

using that

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

Then there really isn't any other way to fix it (not that I know of).

The item is given back though if you use it without a key, so it should be okay?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

well if the item is get back i mean the box, if i use without a key would be fine, but at this moment just consume :c

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

Can you check the console for errors? It should give back the item when consuming without the proper key.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

no error on console after using it :/

also the CustomBox Script:

 

function	script	CustomBox	{
	//start of settings
	//amount and chances
	.@req_amt = 1; //change to how many items is needed to open
	.@good_chance = 10; //10 = 10%
	.@best_chance = 1; //1 = 1%
	.@announce = 0; //change to 0 if you want to turn off or 1 to turn on announce
	
	//arrays
	setarray .@rew_basic,4853,4854,4855,4856,4857,4858; //your reward items id [basic]
	setarray .@rew_good,4853,4854,4855,4856,4857,4858; //your reward items id [good]
	setarray .@rew_best,4853,4854,4855,4856,4857,4858; //your reward items id [best]
	setarray .@rew_amt_basic,1,1,1,1,1,1; //your reward amount [basic]
	setarray .@rew_amt_good,2,2,2,2,2,2; //your reward amount [good]
	setarray .@rew_amt_best,3,3,3,3,3,3; //your reward amount [best
	/* Note #1: This can still be simplified into a more compact snippet, but for sake of basicness, i will not make it into that */
	/* Note #2: Make sure your amount and rewards match, if you have 5 items in the reward category, make sure you have 5 amounts in your amount category too */
	
	//size of arrays
	.@basic_size = getarraysize(.@rew_basic);
	.@good_size = getarraysize(.@rew_good);
	.@best_size = getarraysize(.@rew_best);
	/* Note: Why we do this is because we want subtract one value from the output of getarraysize, because our array index starts at 0 (we did not specify it to start at 1)*/
	
	//end of settings
	if(getarg(1) < 1){ //if required amount is less than 1, warning will pop up and consumed item will be returned
		message strcharinfo(0),"You require [ "+getitemname(getarg(1))+" ] x"+.@req_amt+" to open this item.";
		getitem 501,1;
		end;
	}
	.@rand = rand(0,100); //randomize chance to get rewards above
	delitem getarg(1),.@req_amt; //required item is deleted before giving out rewards
	if(.@rand <= .@best_chance){ //this produces the "best" items
		.@item = rand(0,.@best_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_best[.@item],.@rew_amt_best[.@item];
		end;
	}
	if(.@rand <= .@good_chance){ //since we already catch anything that is either 1 or 0 above, no need to add check for <= 1
		.@item = rand(0,.@good_size); //item is randomly chosen from the list
		if(.@announce) //if announce is active or 1, will announce
			announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
		getitem .@rew_good[.@item],.@rew_amt_good[.@item];
		end;
	}
	//they get basic reward
	.@item = rand(0,.@basic_size); //item is randomly chosen from the list
	if(.@announce) //if announce is active or 1, will announce
		announce "Congratulations! "+strcharinfo(0)+" has won "+getitemname(.@item)+" from opening a [ "+getitemname(getarg(0))+" ] !!",0;
	getitem .@rew_basic[.@item],.@rew_amt_basic[.@item];
	end;
}

 

Edited by ItsFree
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  27
  • Reputation:   2
  • Joined:  06/27/17
  • Last Seen:  

Well, I have to figure out what's causing the issue, because looking at it, I don't really see why it would fail this check.

	if(getarg(1) < 1){ //if required amount is less than 1, warning will pop up and consumed item will be returned
		message strcharinfo(0),"You require [ "+getitemname(getarg(1))+" ] x"+.@req_amt+" to open this item.";
		getitem 501,1;
		end;
	}

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  121
  • Reputation:   7
  • Joined:  04/11/15
  • Last Seen:  

Thx gonna try it and check if everything fine then posting c:

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