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:

problem with pickable items

Post by hermestrismi »

well, one of my persistent problems is droppable items so I appreciate any help here.
i want to create an items where any dying can leave behind an item so create this code (for testing so rand=1, one item with simple name...)

Code: Select all

#define ITEM_GENERAL SIDE
    [event]
	    name=last breath
		first_time_only=no
		    [filter]
			    side={SIDE}
			[/filter]
			[set_variable]
			    name=chance_item
				rand=1
			[/set_variable]
			[if]
			    [variable]
				    name=chance_item
					equals=1
				[/variable]
				[then]
				    [store_unit]
					    [filter]
					    id=$unit.id
						[/filter]
						variable=item_loc
						kill=yes
					[/store_unit]
						[set_variables]
							mode=append
							name=item_new_loc
							[value]
								x,y=$item_loc.x,$item_loc.y
							[/value]
						[/set_variables]
		    [set_variable]
			    name=item_type
				rand=sword,sword
			[/set_variable]
			    [if]
				    [variable]
					    name=item_type
						equals=sword
					[/variable]
					    [then]
						    [set_variable]
							    name=sword_type
								rand=sword_1,sword_2
							[/set_variable]
			                 {Item_On_Ground sword}
						[/then]
				[/if]
				[/then]
			[/if]
	[/event]
	[event]
	    name=turn refresh
		{CLEAR_VARIABLE chance_item}
	[/event]
#enddef

#define CONDITION_SWORD
    [has_attack]
        name=sword
    [/has_attack]
#enddef

#define sword_1
    name=sword_of_1
	description="arcane melee attack"
	[object]
            name= _ "Holy Sword"
            image=items/flame-sword-bare.png
            duration=forever
			take_only_once=no
            description= _ "This sword grants you <i>arcane</i> melee attacks."
            [effect]
                apply_to=attack
                range=melee
                set_type=arcane
            [/effect]
        [/object]
#enddef
#define Item_On_Ground sword

    {PICKUPPABLE_ITEM "" $item_new_loc.x $item_new_loc.y (
        side=1
		{CONDITION_SWORD}
    ) items/flame-sword-bare.png
    _"The sword	grants you $sword_1.description|. Should $unit.name use it?"
    _"$sword_1.name|. Take it"
    _"$sword_1.name|. Leave it"
    _"$unit.name has no need for this item.  Let another unit take it." (
	{sword_1}
        [sound]
            name={SOUND_LIST:HOLY}
        [/sound]
)}
#enddef
the problem with that code is that the item is always dropped on the first item_loc whatever I tried (mode=append an replace for both store unit and set variables, adding variables for random id for the item, using store locations instead of store unit...).
can someone plz give me what is wrong?
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: problem with pickable items

Post by Ravana »

You write to item_new_loc as if it is array, but read from it as if it is single object.
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

Ravana wrote: May 27th, 2022, 4:17 pm You write to item_new_loc as if it is array, but read from it as if it is single object.
hmm possible. I think you have right,
any suggestion how fix it?
this is better but the problem didn't solved of course

Code: Select all

#define ITEM_GENERAL SIDE
    [event]
	    name=last breath
		first_time_only=no
		    [filter]
			    side={SIDE}
			[/filter]
				[set_variable]
					name=chance_item
					rand=1
				[/set_variable]
					[if]
						[variable]
							name=chance_item
							equals=1
						[/variable]
							[then]
								[store_unit]
									[filter]
										id=$unit.id
									[/filter]
									variable=item_loc
									kill=yes
								[/store_unit]
										[set_variables]
											mode=insert
											name=item_new_loc
												[value]
													x,y=$item_loc.x,$item_loc.y
													id=$unit.id
												[/value]
										[/set_variables]
									{FOREACH item_new_loc mm}
											[set_variable]
												name=item_type
												rand=sword,sword
											[/set_variable]
												[if]
													[variable]
														name=item_type
														equals=sword
													[/variable]
														[then]
															[set_variable]
																name=sword_type
																rand=sword_1,sword_2
															[/set_variable]
																[if]
																	[variable]
																		name=sword_type
																		equals=sword_1
																	[/variable]
																		[then]
    {PICKUPPABLE_ITEM ($item_new_loc.id) $item_new_loc.x $item_new_loc.y (
        side=1
		{CONDITION_SWORD}
    ) items/flame-sword-bare.png
    _"The sword	grants you arcane melee attack, Should $unit.name use it?"
    _"sword_of_1. Take it"
    _"sword_of_1. Leave it"
    _"$unit.name has no need for this item.  Let another unit take it." (
	{sword_1}
        [sound]
            name={SOUND_LIST:HOLY}
        [/sound]
)}
																		[/then]
																[/if]
									{CLEAR_VARIABLE item_loc,item_type}
														[/then]
											[/if]
									{NEXT mm}
							[/then]
					[/if]
	[/event]
	[event]
	    name=turn refresh
		{CLEAR_VARIABLE chance_item}
	[/event]
#enddef
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 »

You have several problems and a lot of extraneous sections in this code, but the biggest problem is the array called item_new_loc. It holds an X, Y, and the ID of the unit that died on that hex. (I think it would make more sense if it held an X, Y, and item type.) Every time an enemy unit dies, you loop through that whole array and "randomly" place an item in each location stored in it. Soon, you will have a mountain of items on every spot an enemy has ever died. That may be the problem you are describing. You don't need that FOREACH here at all.

Also, I had to fix the indentation before I could read your code. The deepest lines should have 8 indents, and you had 18. I am reposting part of your code here with standard indentation. You should use this style because more people will be willing to read it and help this way.

Code: Select all

#define ITEM_GENERAL SIDE
	[event]
		name=last breath
		first_time_only=no
		[filter]
			side={SIDE}
		[/filter]
		[set_variable]
			name=chance_item
			rand=1
		[/set_variable]
		[if]
			[variable]
				name=chance_item
				equals=1
			[/variable]
			[then]
				[store_unit]
					[filter]
						id=$unit.id
					[/filter]
					variable=item_loc
					kill=yes
				[/store_unit]
				[set_variables]
					mode=insert
					name=item_new_loc
					[value]
						x,y=$item_loc.x,$item_loc.y
						id=$unit.id
					[/value]
				[/set_variables]
				[set_variable]
					name=item_type
					rand=sword,sword
				[/set_variable]
				[if]
...
You should look up the [switch] tag. It is made for a situation like yours, and it could remove a couple more indent levels.
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: May 28th, 2022, 7:05 am You have several problems and a lot of extraneous sections in this code, but the biggest problem is the array called item_new_loc. It holds an X, Y, and the ID of the unit that died on that hex. (I think it would make more sense if it held an X, Y, and item type.) Every time an enemy unit dies, you loop through that whole array and "randomly" place an item in each location stored in it. Soon, you will have a mountain of items on every spot an enemy has ever died. That may be the problem you are describing. You don't need that FOREACH here at all.

Also, I had to fix the indentation before I could read your code. The deepest lines should have 8 indents, and you had 18. I am reposting part of your code here with standard indentation. You should use this style because more people will be willing to read it and help this way.

Code: Select all

#define ITEM_GENERAL SIDE
	[event]
		name=last breath
		first_time_only=no
		[filter]
			side={SIDE}
		[/filter]
		[set_variable]
			name=chance_item
			rand=1
		[/set_variable]
		[if]
			[variable]
				name=chance_item
				equals=1
			[/variable]
			[then]
				[store_unit]
					[filter]
						id=$unit.id
					[/filter]
					variable=item_loc
					kill=yes
				[/store_unit]
				[set_variables]
					mode=insert
					name=item_new_loc
					[value]
						x,y=$item_loc.x,$item_loc.y
						id=$unit.id
					[/value]
				[/set_variables]
				[set_variable]
					name=item_type
					rand=sword,sword
				[/set_variable]
				[if]
...
You should look up the [switch] tag. It is made for a situation like yours, and it could remove a couple more indent levels.
thank you but this didn't solve the problem (when a unit dies , the item left only at the first place). this is the ONLY problem i had. I used [foreach] to replace [switch] because it didn't solve the problem.
the id of the died unit is used because every unit have a random id so I use this id as an id for the item (so that every item will have a random id and will be picked and dropped many times without problem)
thank for the intendent .
the item_new_loc is used also because using only the item_loc from [store_unit] made the item to be dropped only in one x,y (whatever the mode append, replace, ... it is the same) so item_new_loc will be necessary to give me a new x, y and a new random id for each item.
the problem so is why all items take only the x and y of the first died unit and not a new x and y every time a unit dies.
Soon, you will have a mountain of items on every spot an enemy has ever died
nope, because the loop have a condition

Code: Select all

[set_variable]
			name=chance_item
			rand=1
		[/set_variable]
I made it rand=1 for testing purpose while it can be only 10% (rand=0,0..,1) so that the loop is limited, let's say only one item for each 20 died unit
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 see I didn't explain what I meant very well. You don't have a simple problem that can be changed by using a different tag in one or two places. You need some large changes here. First, you should not be using any kind of loop in this event. You should take out the FOREACH lines, and not replace them with anything. If it were written correctly, your loop would put a new item on MANY hexes if the condition was met. I didn't miss that line. But, as Ravana told you, you are using new_item_loc as a single variable when it is actually an array. You are also not substituting the loop variable "mm" for it either, which is why all the items all land on the same hex right now. (I did say there were several problems.)

But, when I said there were problems with your code, I didn't necessarily mean with what it does at the moment. I meant with how it is written. For example:
You use [store_unit] to make a copy of the unit variable, but then you only use the new variable in one line. You don't need to make a copy of $unit in the first place, but if you do want one, this is the faster and cleaner way to do it:

Code: Select all

[set_variable]
	name=item_loc
	to_variable=unit
[/set_variable]
Another example:
PICKUPPABLE_ITEM will probably not work correctly if multiple items using the same image are dropped on the same hex. Also, you should not use it because it will create two new events for every single item, causing code bloat and slowdown. You should write your own moveto event that checks for any of the dropped items all at once. That's why I suggested putting the item type in the array. (You could use a [foreach] loop for that, although there are faster ways to do it.) I guess using the dead unit's ID as well is not a bad idea though.

Another problem:
You have a lot of nested [if] statements. They are not too bad right now, but when you get a dozen different items, they will be a nightmare to read or modify. I suggested [switch] to fix that. You should use something like this instead of your ifs:

Code: Select all

[set_variable]
	name=item_type
	rand=1..10  # for 10 possible items
[/set_variable]
[switch]
	variable=item_type
	[case]
		value=1
		[set_variable]
			name=item_type
			value=sword_1
		[/set_variable]
		# You could set variables for the image, description, and so on here as well.
	[/case]
	[case]
		value=2
		#set item_type to sword_2
	[/case]
	[case]
		value=3
		#set item_type to wand_1
	[/case]
	# etc....
[/switch]
(This is pretty straightforward, but it is not what I would do, myself. I think I would have an array of containers storing all the information for each possible item, and the item_type random number would just be an index of that array making this [switch] statement unnecessary.)
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: May 29th, 2022, 2:52 am I see I didn't explain what I meant very well. You don't have a simple problem that can be changed by using a different tag in one or two places. You need some large changes here. First, you should not be using any kind of loop in this event. You should take out the FOREACH lines, and not replace them with anything. If it were written correctly, your loop would put a new item on MANY hexes if the condition was met. I didn't miss that line. But, as Ravana told you, you are using new_item_loc as a single variable when it is actually an array. You are also not substituting the loop variable "mm" for it either, which is why all the items all land on the same hex right now. (I did say there were several problems.)

But, when I said there were problems with your code, I didn't necessarily mean with what it does at the moment. I meant with how it is written. For example:
You use [store_unit] to make a copy of the unit variable, but then you only use the new variable in one line. You don't need to make a copy of $unit in the first place, but if you do want one, this is the faster and cleaner way to do it:

Code: Select all

[set_variable]
	name=item_loc
	to_variable=unit
[/set_variable]
Another example:
PICKUPPABLE_ITEM will probably not work correctly if multiple items using the same image are dropped on the same hex. Also, you should not use it because it will create two new events for every single item, causing code bloat and slowdown. You should write your own moveto event that checks for any of the dropped items all at once. That's why I suggested putting the item type in the array. (You could use a [foreach] loop for that, although there are faster ways to do it.) I guess using the dead unit's ID as well is not a bad idea though.

Another problem:
You have a lot of nested [if] statements. They are not too bad right now, but when you get a dozen different items, they will be a nightmare to read or modify. I suggested [switch] to fix that. You should use something like this instead of your ifs:

Code: Select all

[set_variable]
	name=item_type
	rand=1..10  # for 10 possible items
[/set_variable]
[switch]
	variable=item_type
	[case]
		value=1
		[set_variable]
			name=item_type
			value=sword_1
		[/set_variable]
		# You could set variables for the image, description, and so on here as well.
	[/case]
	[case]
		value=2
		#set item_type to sword_2
	[/case]
	[case]
		value=3
		#set item_type to wand_1
	[/case]
	# etc....
[/switch]
(This is pretty straightforward, but it is not what I would do, myself. I think I would have an array of containers storing all the information for each possible item, and the item_type random number would just be an index of that array making this [switch] statement unnecessary.)
Thank you. your explanation now gave me an idea about my fault.
I used to recognise items as they are objects by themselves which is completely wrong.
so now, instead of focusing on the images, I need to focus on how extract x and Y and how to keep them intact while new X and Y added.
do you think think that [store_locations] and [fire_event] (with an id and a delayed_variable_sub is worthy to try?
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 »

well, one of my persistent problems is droppable items so I appreciate any help here.
i want to create an items where any dying can leave behind an item so create this code (for testing so rand=1, one item with simple name...)
It seems like you're trying to make your own LOTI item/equipment API. Wouldn't it be more simpler in just adding the main thing as an dependency API and let the LOTI code handle the droppable item, equip and un-equip?

I think you can check LOTI's sister addons to see how the implementation is done.
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 »

Lord-Knightmare wrote: May 29th, 2022, 1:34 pm
well, one of my persistent problems is droppable items so I appreciate any help here.
i want to create an items where any dying can leave behind an item so create this code (for testing so rand=1, one item with simple name...)
It seems like you're trying to make your own LOTI item/equipment API. Wouldn't it be more simpler in just adding the main thing as an dependency API and let the LOTI code handle the droppable item, equip and un-equip?

I think you can check LOTI's sister addons to see how the implementation is done.
I had the idea but I wanted a more simpler system with other fonctions.
also, the LOTI system is hard coded for me to manipulate
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

my new try didn't work either and I became more confused
so, if someone can explain more, let's forget about items and say that I need just a message to display whatever a unit stand where another died (it is just for learning about my faults)

Code: Select all

#define ITEM_GENERAL SIDE
    [event]
	    name=die
		first_time_only=no
		    [filter]
			    side={SIDE}
			[/filter]
			[set_variable]
				name=item_loc
				to_variable=unit
			[/set_variable]
				[fire_event]
					name=draw an item
				[/fire_event]
	[/event]

	[event]
		name=draw an item
		first_time_only=no
		id=$item_loc.id
		delayed_variable_substitution=yes

        [item]
             x,y=$item_loc.x,$item_loc.y
             image=items/flame-sword-bare.png
        [/item]
						[set_variables]
							name=good[$item_loc.length]
							mode=append
							[value]
								x=$item_loc.x
								y=$item_loc.y
							[/value]
						[/set_variables]
			   			 [set_variable]
				    			name=item_new_loc_x
							value=$good.x
						[/set_variable]
						[set_variable]
				   			 name=item_new_loc_y
							value=$good.y
						[/set_variable]
		{PICKUPP_ITEM}
	[/event]
#enddef
#define PICKUPP_ITEM
    [event]
        name=moveto
        first_time_only=no
	delayed_variable_substitution=yes

        [filter]
		side=1
           	x,y=$item_new_loc_x,$item_new_loc_y
        [/filter]
                [message]
                    speaker=narrator
                    message= _ "description"
		[/message]
	[/event]
#enddef
now step by step
step one is to capture the x,y of the died unit

Code: Select all

    [event]
	    name=die
		first_time_only=no
		    [filter]
			    side={SIDE}
			[/filter]
			[set_variable]
				name=item_loc
				to_variable=unit
			[/set_variable]
				[fire_event]
					name=draw an item
				[/fire_event]
	[/event]
I think nothing wrong here. And fire_event is a way to make the follow action possibly removed and delayed
Step two

Code: Select all

	[event]
		name=draw an item
		first_time_only=no
		id=$item_loc.id
		delayed_variable_substitution=yes

        [item]
             x,y=$item_loc.x,$item_loc.y
             image=items/flame-sword-bare.png
        [/item]
						[set_variables]
							name=good[$item_loc.length]
							mode=append
							[value]
								x=$item_loc.x
								y=$item_loc.y
							[/value]
						[/set_variables]
			   			 [set_variable]
				    			name=item_new_loc_x
							value=$good.x
						[/set_variable]
						[set_variable]
				   			 name=item_new_loc_y
							value=$good.y
						[/set_variable]
		{PICKUPP_ITEM}
now, I need to collect the x,y of the died unit (by an array) then transform them to the x,y of the action/message. I think there is a wrong move somewhere here or at least I have a misunderstanding of the functionality of [set_variables]
either way, all what I need is a way to create a new variable name to contain the new x,y or at least to add the x,y to the old ones instead of deleting them .
third step

Code: Select all

    [event]
        name=moveto
        first_time_only=no
	delayed_variable_substitution=yes

        [filter]
		side=1
           	x,y=$item_new_loc_x,$item_new_loc_y
        [/filter]
                [message]
                    speaker=narrator
                    message= _ "description"
		[/message]
	[/event]
now, when a unit is moved to a stored x,y, the message display
and I think there is also another wrong
I know my questions are somehow dumb but I tried to follow every step but still I didn't get it
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 »

hermestrismi wrote: May 29th, 2022, 6:35 pm I need just a message to display whatever a unit stand where another died (it is just for learning about my faults)
This is a good idea. I still program step-by-step like this because then I can make sure each piece works before I add more complexity.

Apparently, when Ravana and I mentioned problems with your arrays, you were not clear on what we meant. You should have said so, and we would have directed you to the where on the wiki you could read about them. The wiki is very important, and you will probably never stop referencing it.

Since you used [set_variables] on it, good is an array. When you access it, you need to specify an array element. There is no good.x. Instead, there can be a good[0].x, a good[1].x, a good[2].x, and so on. To use any of those variables, you would need to specify the element in brackets. good.length tells you how many elements there are. Since the element numbers start at zero, the number of the last element is the length minus one. However, in [set_variables], you need to provide the name of the array, not any specific element (according to the wiki). You should have used just name=good there. I don't know what you were expecting from the length of a unit variable. Another thing: delayed_variable_substitution is not relevant in any of these events, and "yes" is the default for that anyway (according to the wiki).

You should also be using :inspect all the time to see what value your variables have. If you had done that, you would have seen that your array hadn't been created, and of course good.x and good.y didn't exist.
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: May 29th, 2022, 8:07 pm
hermestrismi wrote: May 29th, 2022, 6:35 pm I need just a message to display whatever a unit stand where another died (it is just for learning about my faults)
This is a good idea. I still program step-by-step like this because then I can make sure each piece works before I add more complexity.

Apparently, when Ravana and I mentioned problems with your arrays, you were not clear on what we meant. You should have said so, and we would have directed you to the where on the wiki you could read about them. The wiki is very important, and you will probably never stop referencing it.

Since you used [set_variables] on it, good is an array. When you access it, you need to specify an array element. There is no good.x. Instead, there can be a good[0].x, a good[1].x, a good[2].x, and so on. To use any of those variables, you would need to specify the element in brackets. good.length tells you how many elements there are. Since the element numbers start at zero, the number of the last element is the length minus one. However, in [set_variables], you need to provide the name of the array, not any specific element (according to the wiki). You should have used just name=good there. I don't know what you were expecting from the length of a unit variable. Another thing: delayed_variable_substitution is not relevant in any of these events, and "yes" is the default for that anyway (according to the wiki).

You should also be using :inspect all the time to see what value your variables have. If you had done that, you would have seen that your array hadn't been created, and of course good.x and good.y didn't exist.
thank you very much. your explanations are helpful.
I read the wiki just now. It's very clear.
yes, I used the inspect: command a lot and this why I am confused and I recognise that there is something wrong (and this is why I tried desperately to extract the good.x and good.y all the time and by adding other variables and adding [store_unit] and even [store_locations] and other failed methods). and you have right, I failed to extract the information from the array (one failed method is (length) as a way to create a new variable everytime (I thought that [set_variables] mean creating many variables all at once)
User avatar
hermestrismi
Posts: 612
Joined: February 6th, 2016, 11:28 pm
Location: Tunisia
Contact:

Re: problem with pickable items

Post by hermestrismi »

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.
this is the reason why I dropped the idea earlier but I m stuck at the corner.

Code: Select all

#define DROPS 
    [event]
        name=die
        first_time_only=no
        [filter]
            side=1,2
        [/filter]
        {VARIABLE_OP did_drop rand (1,1)}
        [if]
            [variable]
                name=did_drop
                less_than_equal_to=1
            [/variable]
            [then]
                [set_variable]
                    name=item_unknown_x
                    value=$x1
                [/set_variable]
                [set_variable]
                    name=item_unknown_y
                    value=$y1
                [/set_variable]
                {GENERATE_ITEM}
                [set_variables]
                    name=items
                    mode=append
                    [value]
                        x=$item_unknown_x
                        y=$item_unknown_y
                        type=$item_type
                    [/value]
                [/set_variables]
                {PLACE_ITEM_EVENT $x1 $y1}
                [item]
                    halo=halo/misc/leadership-flare-1.png:20,halo/misc/leadership-flare-2.png:20,halo/misc/leadership-flare-3.png:20,halo/misc/leadership-flare-4.png:20,halo/misc/leadership-flare-4.png:20,halo/misc/leadership-flare-6.png:20,halo/misc/leadership-flare-7.png:20,halo/misc/leadership-flare-8.png:20,halo/misc/leadership-flare-9.png:20,halo/misc/leadership-flare-10.png:20,halo/misc/leadership-flare-11.png:20,halo/misc/leadership-flare-12.png:20,halo/misc/leadership-flare-13.png:20,misc/blank-hex.png:1000
                    x,y=$item_unknown_x,$item_unknown_y
                    image=items/flame-sword-bare.png
                [/item]
            [/then]
        [/if]
        {CLEAR_VARIABLE did_drop}
    [/event]
#enddef

#define GENERATE_ITEM
    {VARIABLE_OP item_kind rand (sword)}
    [switch]
        variable=item_kind
        [case]
            value=sword
            {VARIABLE_OP item_sort rand (sword)}
            [switch]
                variable=item_sort
                [case]
                    value=armour
                    {VARIABLE_OP item_type rand (sword_1)}
                [/case]
            [/switch]
        [/case]
    [/switch]
    {CLEAR_VARIABLE item_kind}
#enddef

#define PLACE_ITEM_EVENT X Y
    [set_variables]
        name=item_event
        mode=replace
        [literal]
            name=moveto
            first_time_only=no	
            [filter]
                x,y={X},{Y}
                side=1
            [/filter]
            [fire_event]
                name=item_pick
                [primary_unit]
                    x,y=$x1,$y1
                [/primary_unit]
            [/fire_event]
        [/literal]
    [/set_variables]
    {VARIABLE item_event.id "ie{X}|{Y}"}
    {VARIABLE item_event.filter.x {X}}
    {VARIABLE item_event.filter.y {Y}}
    [insert_tag]
        name=event
        variable=item_event
    [/insert_tag]
    {CLEAR_VARIABLE item_event}
#enddef 
note:
I feel happy, too because I was close and I get the same method as its :eng:
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 »

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.cfg
(5.56 KiB) Downloaded 33 times
item_list.cfg
(2.92 KiB) Downloaded 30 times

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.
Attachments
Tester.zip
(494.74 KiB) Downloaded 34 times
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
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 »

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.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Post Reply