Jump to content
kokoboko

Hi how to make a random chest ?

Recommended Posts

I am looking to make a chest for equipments when i use that chest i get a single item from the items put inside the chest, it would be much appreciated if someone could tell me at which file i could find functions for this 

Share this post


Link to post
Share on other sites

Please be a bit more clear on what you want to do.
Do you want to create a chest that will randomly give the player an item?
Or do you want a chest to store items and randomly pop them out once the player uses it?

 

For the last option you will have to store this data somewhere - database table or text files.


"Beware of bugs in the above code; I have only proved it correct, not tried it."

- Donald E. Knuth

Share this post


Link to post
Share on other sites
5 hours ago, Mdrst said:

Please be a bit more clear on what you want to do.
Do you want to create a chest that will randomly give the player an item?
Or do you want a chest to store items and randomly pop them out once the player uses it?

 

For the last option you will have to store this data somewhere - database table or text files.

I want to make a random uns85 weapon chest

Share this post


Link to post
Share on other sites
12 hours ago, Mdrst said:

Please be a bit more clear on what you want to do.
Do you want to create a chest that will randomly give the player an item?
Or do you want a chest to store items and randomly pop them out once the player uses it?

 

For the last option you will have to store this data somewhere - database table or text files.

By items i mean the items i put from files lile all of the uns85 weapon but i get only one random

Share this post


Link to post
Share on other sites
2 hours ago, kokoboko said:

By items i mean the items i put from files lile all of the uns85 weapon but i get only one random

You just need to edit your ItemEffect.lua for the created chest in the iteminfo.txt . First you need to specify what conditions you want that one item will be chosen from. Either it classed based or totally random. This code are an example from Chaos chest.

 

function ItemUse_FightingBox( role , Item )
	local Item_CanGet = GetChaFreeBagGridNum ( role )
	 if Item_CanGet < 2 then
		SystemNotice(role ,"You need at least 2 empty inventory slots to open the Chaos Chest")
		UseItemFailed ( role )
		return
	end
	GiveItem ( role , 0 , 2610  , 1 , 4 )
	local rad = math.random ( 1, 4 )
	if rad ==1 then
	GiveItem ( role , 0 , 1124  , 1 , 15 )	
	end
	
	if rad ==2 then
	GiveItem ( role , 0 , 1125  , 1 , 15 )	
	end
	
	if rad ==3 then
	GiveItem ( role , 0 , 1126  , 1 , 15 )	
	end
	
	if rad ==4 then
	GiveItem ( role , 0 , 1127  , 1 , 15 )	
	end
end

Based on the code, it used a math.random outcome to decide which item to be given. Since it have 4 item, the probability is 1/4 for each item and the outcome of the math.random is specified with each item after the result. If its classed based and want to give 1 item only, you need to specified the class check and called for the math.random for each class.

  • Thanks 1

Share this post


Link to post
Share on other sites
On 6/15/2023 at 8:39 AM, Mdrst said:
On 6/15/2023 at 11:58 PM, kyleflow said:

You just need to edit your ItemEffect.lua for the created chest in the iteminfo.txt . First you need to specify what conditions you want that one item will be chosen from. Either it classed based or totally random. This code are an example from Chaos chest.

 



function ItemUse_FightingBox( role , Item )
	local Item_CanGet = GetChaFreeBagGridNum ( role )
	 if Item_CanGet < 2 then
		SystemNotice(role ,"You need at least 2 empty inventory slots to open the Chaos Chest")
		UseItemFailed ( role )
		return
	end
	GiveItem ( role , 0 , 2610  , 1 , 4 )
	local rad = math.random ( 1, 4 )
	if rad ==1 then
	GiveItem ( role , 0 , 1124  , 1 , 15 )	
	end
	
	if rad ==2 then
	GiveItem ( role , 0 , 1125  , 1 , 15 )	
	end
	
	if rad ==3 then
	GiveItem ( role , 0 , 1126  , 1 , 15 )	
	end
	
	if rad ==4 then
	GiveItem ( role , 0 , 1127  , 1 , 15 )	
	end
end

Based on the code, it used a math.random outcome to decide which item to be given. Since it have 4 item, the probability is 1/4 for each item and the outcome of the math.random is specified with each item after the result. If its classed based and want to give 1 item only, you need to specified the class check and called for the math.random for each class.

Ty man I've made it

 

  • Haha 1

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
Reply to this topic...

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


×
×
  • Create New...