problem with pickable items

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: May 29th, 2022, 11:51 pm
hermestrismi wrote: May 29th, 2022, 9:04 pmI took it without adding something new to the community.
Well, you did inspire me to give it a try this morning, which I wouldn't have done otherwise. I didn't look at any LOTI code until now, but I think what I made is MUCH easier to use. All you ever need to do is add items to the item_list file, and everything else is automatic. It also doesn't continue to add more and more events to the scenario. It just adds to a small array. You need item_list.cfg and item_events.cfg in your utils folder, then you just put {DROP_ITEMS} in your main scenario file to use it. There is some refinement that could be done, but it works fine for now.item_events.cfgitem_list.cfg


I'm also posting it inside a campaign called Tester so you can try it out more easily. (Only the first scenario is set up for drops right now, and it's currently set at a 100% drop rate in item_events.cfg.) I hope someone does want to try it out: It might have a bug or two because I haven't tested it extensively. Let me know if you find a situation that doesn't work right.
hermestrismi wrote: May 29th, 2022, 9:04 pm LotI items system
Of course you can still use that one if you want. I won't be offended, but at least take a look at mine. You can see how I did, in fact, use [set_variables] to create an array of many variables all at once.
good morning. good job.
By coincidence, I had the same idea (I had a test scenario and I use the story .cfg to test every bit of anything)
you could take a look at utils/story.cfg where I put only one item with 100% rate (unfinished, yet) but it is the simplest way I can extract from loti items-utils
Attachments
story.cfg
(6.38 KiB) Downloaded 35 times
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

Lord-Knightmare wrote: May 30th, 2022, 5:26 am
Desperately, I have to use LotI items system
I feel ashamed to use it instead of creating my own. The one who created it have spent a lot of time to create it and then I come I took it without adding something new to the community.
TBH, just listing it as dependency would have suffice...maybe you just dont know how...
Let's see...

firstly there's the main cfg file
Note: I am only showing how to implement Loti's item system using the file of IC2 as an example

Code: Select all

#ifdef CAMPAIGN_DARK_MASTER
[binary_path]
    path=data/add-ons/Legend_of_the_Invincibles/
[/binary_path]

{~add-ons/Legend_of_the_Invincibles/utils}

[lua]
    code = << wesnoth.dofile("~add-ons/Legend_of_the_Invincibles/lua/main.lua") >>
[/lua]

#endif
and then in the scenario files, add the drop generator code

Code: Select all

{DROPS 5 7 (sword,sword,dagger,knife,mace,spear,bow,xbow) yes 3,4,5}
Lastly, crediting Dugi and the LotI team would have sufficed so there's really no need to be ashamed about anything. I believe they'd be happy that other UMC authors are utlising their code.
Thank you.
Indeed, you gave me another idea. Since the items system is not too weight , a dependency will not be necessary but the music file is very high (the campaign jumped from 16Mb to 40Mb because of the added music-playlist items key from BfW 1.2 and 1.0 and will be more perhaps), I think it will be a solution to add the music file as an optional dependency
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2340
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: problem with pickable items

Post by Lord-Knightmare »

16Mb to 40Mb
I think you really should be putting out the music files as a dependency addon since that's an 150% increase in size or so.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: May 29th, 2022, 11:51 pm
hermestrismi wrote: May 29th, 2022, 9:04 pmI took it without adding something new to the community.
Well, you did inspire me to give it a try this morning, which I wouldn't have done otherwise. I didn't look at any LOTI code until now, but I think what I made is MUCH easier to use. All you ever need to do is add items to the item_list file, and everything else is automatic. It also doesn't continue to add more and more events to the scenario. It just adds to a small array. You need item_list.cfg and item_events.cfg in your utils folder, then you just put {DROP_ITEMS} in your main scenario file to use it. There is some refinement that could be done, but it works fine for now.item_events.cfgitem_list.cfg


I'm also posting it inside a campaign called Tester so you can try it out more easily. (Only the first scenario is set up for drops right now, and it's currently set at a 100% drop rate in item_events.cfg.) I hope someone does want to try it out: It might have a bug or two because I haven't tested it extensively. Let me know if you find a situation that doesn't work right.
hermestrismi wrote: May 29th, 2022, 9:04 pm LotI items system
Of course you can still use that one if you want. I won't be offended, but at least take a look at mine. You can see how I did, in fact, use [set_variables] to create an array of many variables all at once.
I tested it and no bugs so far :eng: :eng: :eng:
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

Lord-Knightmare wrote: May 30th, 2022, 5:57 am
16Mb to 40Mb
I think you really should be putting out the music files as a dependency addon since that's an 150% increase in size or so.
this will be my next step on TDM Project (lighting the campaign and reviewing any unnecessary variables and so on)
User avatar
winkr7
Posts: 53
Joined: May 16th, 2019, 2:09 pm

Re: problem with pickable items

Post by winkr7 »

beetlenaut wrote: May 29th, 2022, 11:51 pm
hermestrismi wrote: May 29th, 2022, 9:04 pmI took it without adding something new to the community.
Well, you did inspire me to give it a try this morning, which I wouldn't have done otherwise. I didn't look at any LOTI code until now, but I think what I made is MUCH easier to use. All you ever need to do is add items to the item_list file, and everything else is automatic. It also doesn't continue to add more and more events to the scenario. It just adds to a small array. You need item_list.cfg and item_events.cfg in your utils folder, then you just put {DROP_ITEMS} in your main scenario file to use it. There is some refinement that could be done, but it works fine for now.item_events.cfgitem_list.cfg


I'm also posting it inside a campaign called Tester so you can try it out more easily. (Only the first scenario is set up for drops right now, and it's currently set at a 100% drop rate in item_events.cfg.) I hope someone does want to try it out: It might have a bug or two because I haven't tested it extensively. Let me know if you find a situation that doesn't work right.
hermestrismi wrote: May 29th, 2022, 9:04 pm LotI items system
Of course you can still use that one if you want. I won't be offended, but at least take a look at mine. You can see how I did, in fact, use [set_variables] to create an array of many variables all at once.
Hello beetlenaut;

I looked at Tester and I notice that line 128 of item_events.cfg you want chance_to_drop not chance_dropped. This is in variable cleanup.

yours
winkr7
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: problem with pickable items

Post by beetlenaut »

Thanks. I knew there was probably something wrong with it. At least it's not a bad bug and is easily fixed.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: September 23rd, 2022, 2:04 pm Thanks. I knew there was probably something wrong with it. At least it's not a bad bug and is easily fixed.
I did some improvements for the code to make the units take only weapons that fits with their original attacks
Notes:
1. not all units can take anything but all units can drops. However, I made some macros filters to any one who want to make any unit drops only what it uses as weapon
2. the chance of dropping and the side that drops both set manually for every scenario by {ITEM_DROPS DROPPER_SIDES PERCENT_CHANCE} however it can be changed easily by the original macro
3. when a unit takes a weapon or others, it will be easy to notice by adding an overlay. The overlay can be changed to existing icons by the developer
4. variable

Code: Select all

[variable]
		name=items_sys
		equals=yes
		[/variable]
must set to yes at every scenario or via events or conditions. It had been made to control all the items system easily
5. I tried to create a table that show to the player all units with all their items but my computer crashed and now I don't know even how to start. Any ideas?
Attachments
item_list.cfg
(6.54 KiB) Downloaded 27 times
item_events.cfg
(8.35 KiB) Downloaded 22 times
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: problem with pickable items

Post by beetlenaut »

I'm glad you are getting use out of my code! Thanks for mentioning it. Adding an overlay is a good improvement.
hermestrismi wrote: February 27th, 2023, 3:12 pm 5. I tried to create a table that show to the player all units with all their items
You will have to use Lua. With Lua, you can make a dialog showing any information you want including that table. I don't know if you have used Lua before, but you've coded a lot of things, so it shouldn't be too hard for you to learn. You will probably want to use wesnoth.show_dialog() eventually, but I recommend starting with wesnoth.show_popup_dialog() since it's much easier to use. Look here for those functions.

(A language note: You shouldn't use articles in the item names. For example, just use "Astral Blade" instead of "The Astral Blade." Only use an article if you put the name in a sentence.)
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: February 28th, 2023, 12:08 am I'm glad you are getting use out of my code! Thanks for mentioning it. Adding an overlay is a good improvement.
hermestrismi wrote: February 27th, 2023, 3:12 pm 5. I tried to create a table that show to the player all units with all their items
You will have to use Lua. With Lua, you can make a dialog showing any information you want including that table. I don't know if you have used Lua before, but you've coded a lot of things, so it shouldn't be too hard for you to learn. You will probably want to use wesnoth.show_dialog() eventually, but I recommend starting with wesnoth.show_popup_dialog() since it's much easier to use. Look here for those functions.

(A language note: You shouldn't use articles in the item names. For example, just use "Astral Blade" instead of "The Astral Blade." Only use an article if you put the name in a sentence.)
I made a good time with Lua but still I have too much to learn but an idea just crossed my mind and I wanted to try something with WML but since I don't know when the second crash will be, I worked very fast and I even imported a test addon to the server where many useful macros can be used.
but, still I am in a loop and a mind-blowing one and I am sure I missed something and I hope you point me up
so, to add a menu items that make the player have the ability to track the 'pikker' units, I began with:
step one
adding this macro outside the items system:

Code: Select all

#define INIT_OPTION_LIST
	[value]
		[option]
			label=_"name=$unit_to_list_2.name|
object=$unit_to_list_2.object|
sort=$unit_to_list_2.sort|
image=$unit_to_list_2.$($image)|
unit_image=$unit_to_list_2.unit_image|
type=$unit_to_list_2.type|"
		[/option]
	[/value]
#enddef 
Step two: I add two variables to collect informations just after the unit take an item and just before the instert tag that add the effect:

Code: Select all

									[store_unit]
										[filter]
										id=$unit.id
										[/filter]
										variable=unit_to_list_1
										kill=no
									[/store_unit]

									[set_variables]
										name=unit_to_list_2
										mode=append
										[value]
											id=$unit_to_list_1.id|
											name=$unit_to_list_1.name|
											object=$item_list[$this_item.index].name
											sort=$item_list[$this_item.index].sort
											image=$item_list[$this_item.index].image
											unit_image=$unit_to_list_1.image|
											type=$unit_to_list_1.type|
										[/value]
									[/set_variables]
									{CLEAR_VARIABLE unit_to_list_1}
		[set_variables]
			name=option_list
			mode=append  
			# not sure if I should replace the mode [i]append[/i] seems logic to me
			{INIT_OPTION_LIST}
		[/set_variables]
# I know about the images problems but this is for later may be
Step three: collect the information THAN create an [option] message for each unit. This turned to be difficult and I m sure the problem is that I missed something (no live/dead units checking for now. it is also another step for later)
# I want separated options to list units as I may add another for other options

Code: Select all

[set_variable]
			name=item_list_check_of_steps
			value=1
		[/set_variable]
	[set_menu_item]
		id=configure_items
		description=_ "Geared units"
		[command]
# step1 begin
			[message]
				speaker=narrator
				image="wesnoth-icon.png"
				message="list by unit names"
				
				[option]
				label=_"list by unit names"
					[command]
						{VARIABLE done no}
						[while]
							[variable]
								name=done
								equals=no
							[/variable]
							[do]
# step2 begin
								[set_variable]
									name=item_list_check_of_steps
									add=10
								[/set_variable]
								[set_variables]
									name=add_message
									mode=replace
										[value]
											speaker=narrator
											image="wesnoth-icon.png"
											message= _ "Here all the units"
											[option]
												image="$unit_to_list_2.unit_image|"
																label=_"name=$unit_to_list_2.name|
object=$unit_to_list_2.object|
sort=$unit_to_list_2.sort|
image=$unit_to_list_2.$($image)|
type=$unit_to_list_2.type|"
												[command]
												[/command]
											[/option]
											[option]
												label=_ "Back"
												[command]
													{VARIABLE done yes}
												[/command]
											[/option]
										[/value]
								[/set_variables]
								[insert_tag]
									name=message
									variable=add_message
								[/insert_tag]
								[/do]
						[/while]
						{CLEAR_VARIABLE add_message,done}
					[/command]
					[/option]
					[option]
						label=_ "Back"
						[command]
						[/command]
					[/option]
			[/message]
		[/command]
	[/set_menu_item]
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

PS: really sorry for the intend
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

I forget also to mention the problem. The problem is that always only one message appear about the first unit who took the item but no other unit appear. I suspect it is a problem of mode (for both variables) but I tried many combinations including the append mode
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: problem with pickable items

Post by beetlenaut »

I didn't think of listing units as fake menu options. That's an unusual idea that should actually work, but this is not the way to do it. You are trying to display a [message] that has [option] elements, and the options are messages that have other options. I'm sure the game is just ignoring most of that because it has no defined way to display it.

What you could do is build one list of options. Display ONE message, and insert all the options with [insert_tag]. It would look something like this:

Code: Select all

[set_variables]
    name=options_list
    mode=append   # I don't need this line, but I am planning to make this block work in a loop, so I need to make sure it won't cause a problem.
    [value]
        image="units/elves-wood/fighter.png"
        label="Elvish Fighter:"
        description="Bob, Astral Sword, Iron Shield"
    [/value]
[/set_variables]

[set_variables]
    name=options_list
    mode=append  # This is the correct mode.
    [value]
        image="units/elves-wood/archer.png"
        label="Elvish Archer:"
        description="Alice, Crystal Bow, Astral Sword"
    [/value]
[/set_variables]

[message]
    speaker=narrator
    message="Unit List"
    [insert_tag]
        name=option
        variable=options_list
    [/insert_tag]
[/message]
You will see here that I started with a very basic structure to make sure it works. There are no loops and a minimum number of variables. I know there are no bugs because I already found and corrected them. If I was going to continue working on this, I would add complexity a little at a time, testing at each step. It doesn't look like you are doing that. It looks like you are trying to code a hundred lines all at once so that there are dozens of problems that are very hard to find.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: March 1st, 2023, 10:25 pm I didn't think of listing units as fake menu options. That's an unusual idea that should actually work, but this is not the way to do it. You are trying to display a [message] that has [option] elements, and the options are messages that have other options. I'm sure the game is just ignoring most of that because it has no defined way to display it.

What you could do is build one list of options. Display ONE message, and insert all the options with [insert_tag]. It would look something like this:

Code: Select all

[set_variables]
    name=options_list
    mode=append   # I don't need this line, but I am planning to make this block work in a loop, so I need to make sure it won't cause a problem.
    [value]
        image="units/elves-wood/fighter.png"
        label="Elvish Fighter:"
        description="Bob, Astral Sword, Iron Shield"
    [/value]
[/set_variables]

[set_variables]
    name=options_list
    mode=append  # This is the correct mode.
    [value]
        image="units/elves-wood/archer.png"
        label="Elvish Archer:"
        description="Alice, Crystal Bow, Astral Sword"
    [/value]
[/set_variables]

[message]
    speaker=narrator
    message="Unit List"
    [insert_tag]
        name=option
        variable=options_list
    [/insert_tag]
[/message]
You will see here that I started with a very basic structure to make sure it works. There are no loops and a minimum number of variables. I know there are no bugs because I already found and corrected them. If I was going to continue working on this, I would add complexity a little at a time, testing at each step. It doesn't look like you are doing that. It looks like you are trying to code a hundred lines all at once so that there are dozens of problems that are very hard to find.
Thank you. I see my fault now and clearly it was methodic. I began from the end of the cycle (how the message will be displaying then the information are from where...)
My second fault was the misunderstanding of how insert tag work. It seemed like a variables to me while it is more like a copy past.
Thank you again.your expertise is very helpful.
By the way, I uploaded a test campaign to the system that feature many events like items and spawning animals. If you have time and you looked to it, I will surely appreciate your opinion about its structure and build (99% wml with very little wfl but no lua. In fact, I m sure that I have to learn lua coding but I don't know where I had a start or if there is a diy like campaign that show basic things especially tabels)
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

beetlenaut wrote: March 1st, 2023, 10:25 pm I didn't think of listing units as fake menu options. That's an unusual idea that should actually work, but this is not the way to do it. You are trying to display a [message] that has [option] elements, and the options are messages that have other options. I'm sure the game is just ignoring most of that because it has no defined way to display it.

What you could do is build one list of options. Display ONE message, and insert all the options with [insert_tag]. It would look something like this:

Code: Select all

[set_variables]
    name=options_list
    mode=append   # I don't need this line, but I am planning to make this block work in a loop, so I need to make sure it won't cause a problem.
    [value]
        image="units/elves-wood/fighter.png"
        label="Elvish Fighter:"
        description="Bob, Astral Sword, Iron Shield"
    [/value]
[/set_variables]

[set_variables]
    name=options_list
    mode=append  # This is the correct mode.
    [value]
        image="units/elves-wood/archer.png"
        label="Elvish Archer:"
        description="Alice, Crystal Bow, Astral Sword"
    [/value]
[/set_variables]

[message]
    speaker=narrator
    message="Unit List"
    [insert_tag]
        name=option
        variable=options_list
    [/insert_tag]
[/message]
You will see here that I started with a very basic structure to make sure it works. There are no loops and a minimum number of variables. I know there are no bugs because I already found and corrected them. If I was going to continue working on this, I would add complexity a little at a time, testing at each step. It doesn't look like you are doing that. It looks like you are trying to code a hundred lines all at once so that there are dozens of problems that are very hard to find.
By the way, I will try to make a filter that join all items of a single unit into one option. Do you think filtering by comparing key into variables (like a database program 🤔😳) is possible?
Post Reply