problem with pickable items
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.
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
problem with pickable items
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...)
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?
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
can someone plz give me what is wrong?
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
Re: problem with pickable items
You write to item_new_loc as if it is array, but read from it as if it is single object.
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
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
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: problem with pickable items
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.
You should look up the [switch] tag. It is made for a situation like yours, and it could remove a couple more indent levels.
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]
...
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
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.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.You should look up the [switch] tag. It is made for a situation like yours, and it could remove a couple more indent levels.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] ...
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.
nope, because the loop have a conditionSoon, you will have a mountain of items on every spot an enemy has ever died
Code: Select all
[set_variable]
name=chance_item
rand=1
[/set_variable]
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: problem with pickable items
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:
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:
(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.)
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]
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]
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
Thank you. your explanation now gave me an idea about my fault.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:Another example:Code: Select all
[set_variable] name=item_loc to_variable=unit [/set_variable]
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:(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.)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]
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?
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- Lord-Knightmare
- Discord Moderator
- Posts: 2360
- 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
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?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...)
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
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
I had the idea but I wanted a more simpler system with other fonctions.Lord-Knightmare wrote: ↑May 29th, 2022, 1:34 pmIt 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?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...)
I think you can check LOTI's sister addons to see how the implementation is done.
also, the LOTI system is hard coded for me to manipulate
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
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)
now step by step
step one is to capture the x,y of the died unit
I think nothing wrong here. And fire_event is a way to make the follow action possibly removed and delayed
Step two
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
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
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
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]
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}
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]
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
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: problem with pickable items
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.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)
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
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
thank you very much. your explanations are helpful.beetlenaut wrote: ↑May 29th, 2022, 8:07 pmThis 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.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)
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 nogood.x
. Instead, there can be agood[0].x
, agood[1].x
, agood[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 justname=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 coursegood.x
andgood.y
didn't exist.
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)The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- hermestrismi
- Posts: 626
- Joined: February 6th, 2016, 11:28 pm
- Location: Tunisia
- Contact:
Re: problem with pickable items
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.
note:
I feel happy, too because I was close and I get the same method as its
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
I feel happy, too because I was close and I get the same method as its
The Dark Master, The Dark Hordes (Unofficial version), Return of the Legion , Eternal Kingdom, An Elvish Scout,Unrest in Elfland , Hidden War ...
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
The Dark Master Project, Arabic tra. maintainer
"But he loves you" G. Carlin
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: problem with pickable items
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 needhermestrismi wrote: ↑May 29th, 2022, 9:04 pmI took it without adding something new to the community.
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.
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.
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
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
- Lord-Knightmare
- Discord Moderator
- Posts: 2360
- 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
TBH, just listing it as dependency would have suffice...maybe you just dont know how...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.
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
Code: Select all
{DROPS 5 7 (sword,sword,dagger,knife,mace,spear,bow,xbow) yes 3,4,5}
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium