Pickup 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.
Post Reply
hermestrismi
Posts: 32
Joined: February 6th, 2016, 11:28 pm

Pickup items

Post by hermestrismi »

Hi everyone,
I returned to wesnoth after a year and I am trying to improve one of my old campaign but I forget many thgs about wml so I need help (knowing i m still using 1.12 because 1.14 is hard to open in my pc)
the idea briefly is:
1. when a unit dies, there is a chance that it drops an item (weapon, portion, clues, ...).
2. every dropped item isn't unique (it can be found again by another unit that can use it too),
3. the following wml use only two possibilities for make the test easy,
problem:
since I used only

Code: Select all

                [set_variable]
                    name=item_unknown_x
                    value=$x1
                [/set_variable]
                [set_variable]
                    name=item_unknown_y
                    value=$y1
                [/set_variable]
so, the item can be found only with the last killed unit which means one usuful item per turn.
the whole code I wrote is:

Code: Select all

#define ITEM_EVENT
    [event]
        name=die
        first_time_only=no
        [filter]
            [not]
			    side=1
			[/not]
        [/filter]
                [set_variable]
                    name=item_unknown_x
                    value=$x1
                [/set_variable]
                [set_variable]
                    name=item_unknown_y
                    value=$y1
                [/set_variable]
			
                [set_variable]			
                    name=random_drop
                    rand=1,2
                [/set_variable]
                    [if]
                       [variable]
                           name=random_drop
                           equals=1
                        [/variable]
                            [then]
                                [fire_event]
                                     name=add_axe
                                [/fire_event]
                            [/then]
                    [/if]

                    [if]
                        [variable]
                            name=random_drop
                            equals=2
                        [/variable]
                            [then]
                                [fire_event]
                                    name=add_staff
                                [/fire_event]
                            [/then]
                    [/if]
				
    [/event]

    [event]
        name=add_axe
        first_time_only=no
            [item]
                x=$item_unknown_x
			    y=$item_unknown_y
                image=items/axe.png
	        [/item]
    [/event]

    [event]
        name=add_staff
        first_time_only=no
            [item]
                x=$item_unknown_x
			    y=$item_unknown_y
                image=items/staff.png
	        [/item]
            [set_variable]			
                name=random_staff
                rand=1,2
            [/set_variable]
    [if]
        [variable]
            name=random_staff
            equals=1
        [/variable]
        [then]
    {PICKUPPABLE_ITEM "staff of hp" race=human items/staff.png
  "This staff grants the wearer +10 max hp!"
  ([object]
             name= _ "staff of HP"
             image=items/staff.png
             description=_"This staff grants the wearer +10 max hp!"
    
             [effect]
                 apply_to=hitpoints
                 increase_total=10
             [/effect]
         [/object])}
        [/then]
    [/if]
    [if]
        [variable]
            name=random_staff
            equals=2
        [/variable]
        [then]
    {PICKUPPABLE_ITEM "staff of Power" race=human items/staff.png
 "This staff grants the wearer +2 melee attacks!"
 ([object]
             name= _ "staff of Power"
             image=items/staff.png
             description=_"This staff grants the wearer +2 melee attacks!"
    
                       [effect]
                           apply_to=attack
                           [filter]
                           range=melee
                           [/filter]
                           increase_attacks=2
                       [/effect]
         [/object])}
        [/then]
    [/if]
    [/event]
#enddef

#define PICKUPPABLE_ITEM NAME CAN_TAKE_FILTER_WML IMAGE DESCRIPTION OBJECT_WML

    [item]
        x,y=$item_unknown_x,$item_unknown_y
        image={IMAGE}
    [/item]

    [event]
        name=moveto
        first_time_only=yes

        [filter]
            x,y=$item_unknown_x,$item_unknown_y
        [/filter]

        [if]
            [have_unit]
                x,y=$item_unknown_x,$item_unknown_y
                {CAN_TAKE_FILTER_WML}
            [/have_unit]

            [variable]
                name=item_{NAME}_picked_up
                not_equals=yes
            [/variable]

            [then]
                [message]
                    speaker=narrator
                    message=_"$unit.name finds a {NAME}. ({DESCRIPTION}) Should he pick it up?"
                    image={IMAGE}

                    [option]
                        message=_"Take the {NAME}"

                        [command]
                            {OBJECT_WML}

                            [remove_item]
                                x,y=$item_unknown_x,$item_unknown_y
                                image={IMAGE}
                            [/remove_item]

                            [set_variable]
                                name=item_{NAME}_picked_up
                                value=yes
                            [/set_variable]
                        [/command]
                    [/option]

                    [option]
                        message=_"Leave the {NAME}"

                        [command]
                            [allow_undo]
                            [/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]

            [else]
                [if]
                    [variable]
                        name=item_{NAME}_picked_up
                        not_equals=yes
                    [/variable]

                    [then]
                        [message]
                            speaker=narrator
                            message=_"$unit.name finds a {NAME}. But only {CAN_TAKE_FILTER_WML} can take it!"
                            image={IMAGE}
                            side_for=$side_number
                        [/message]
                    [/then]
                [/if]

                [allow_undo]
                [/allow_undo]
            [/else]
        [/if]
    [/event]

#enddef
Last edited by Pentarctagon on September 7th, 2021, 8:18 pm, edited 1 time in total.
Reason: add [code]
Author of The Dark Master (bfw 1.12-1.14), CoCreator of The Dark Hordes (bfw 1.12-1.14)
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Try setting delayed_variable_substitution=no in the moveto events.
And use [primary_attack] in [fire_event] to pass weapon.x, weapon.y information to the add_axe, add_staff events.
hermestrismi
Posts: 32
Joined: February 6th, 2016, 11:28 pm

Re: Pickup items

Post by hermestrismi »

vghetto wrote: September 8th, 2021, 1:32 am Try setting delayed_variable_substitution=no in the moveto events.
And use [primary_attack] in [fire_event] to pass weapon.x, weapon.y information to the add_axe, add_staff events.
Thank you
I tried both solution but they didnt work :(
Author of The Dark Master (bfw 1.12-1.14), CoCreator of The Dark Hordes (bfw 1.12-1.14)
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Unless you show what you have so far, I won't be able to help you much.
delayed_variable_substitution=no was supposed to take care of using the same variables for all dropped items.

Dropping items on death isn't something new, you should be able to find ample examples on how it is done.
I think Dead_Water has one, there might be others within the mainline campaigns.

For a fairly easy and straight forward approach, I recommend looking at how it is done in Den of Thieves. Look for "Killing a captain" in the file mission_events.cfg.
Mabuse
Posts: 2157
Joined: November 6th, 2007, 1:38 pm

Re: Pickup items

Post by Mabuse »

basically dropping items isnt as trivial as it may seem. you cant just put a moveto event into another event (with non predefined x,y).

because: nested events will not work, so BASIC EVENTS work only for predefined items that can be found on the map at start.

the best approach for dropping items at whatever occasion is to store the LOCATIONS where the items were dropped into a variable, and then check with moveto events and fire specific events.

i will post a template here, i tried to explain it a bit, but you have to chew yourself through the routine anyways.
it requires a bit preparation with macros to keep everything slim

credit go out to BOB THE MIGHTY for the store-locations thingy, this is the best solution imo

EDITED: i tried to give the example macros more intuitive names ;)

#this is a MACRO that defines the MOVETO_EVENT, it is on top of the code since the MACRO needs to be defined first
----------------------------------------------------------------------------------------------------------------------

#define ITEM_PICK NAME
[event]
name=moveto
first_time_only=no
[filter]
------------CAN TAKE FILTER----------
[filter_location]
find_in={NAME}_xy
[/filter_location]
[/filter]

[fire_event]
name={NAME}
[primary_unit]
x,y=$x1,$y1
[/primary_unit]
[/fire_event]

[/event]
#enddef


# here you can define as many items as you want, just Type in Items name, and it uses the macro bove.
# "ITEM1" is the name of the Item

#define ITEM_PREPARATION
{ITEM_PICK (ITEM1)}
{ITEM_PICK (ITEM2)}
{ITEM_PICK (ITEM3)}
{ITEM_PICK (ITEM4)}
....
#enddef

# this is a standardized item-event macro, it helps reducing code that you would have to write otherwise all the time again
# it will trigger all nessesary codes and remove the item graphic and delete as well the stored location

#define ITEM_EVENT NAME MESSAGE CONDITION INGAMENAME EFFECT CODE
[event]
name={NAME}
first_time_only=no
[filter]
----CAN TAKE FILTER----
[/filter]
{CODE}
[message]
image="PATH/{NAME}.png"~SCALE(200,200)
speaker=narrator
message= _ "<span color='#e0d89e' weight='bold' size='larger'> You have found an Item!
You have found <span color='#14c8fa' weight='ultrabold'>{MESSAGE}</span></span>"
[option]
message= _ "<span color='#e0d89e' weight='bold'>I'll leave it for another player</span>"
image="PATH/REJECT.png"
[command]
[/command]
[/option]
[option]
[show_if]
{CONDITION}
[/show_if]
message= _ "<span color='#e0d89e' weight='bold'>Pick up {INGAMENAME}</span>"
image="PATH/{NAME}.png"
[command]
[remove_item]
x=$unit.x
y=$unit.y
image="PATH/{NAME}.png"
[/remove_item]
{EFFECT}
[store_locations]
variable={NAME}_xy
find_in={NAME}_xy
[not]
x,y=$x1,$y1
[/not]
[/store_locations]
[/command]
[/option]
[/message]
[/event]
#enddef


# this is actually the REAL ITEM Event (for ITEM1), example: staff that grant +2 damage
# for defining more items use this template

{ITEM_EVENT (ITEM1) (a Staff.
It's owners melee and ranged damage is increased by +2.
Will be used immediatly.) () (Staff and use it) (
[object]
silent=yes
[effect]
apply_to=attack
increase_damage=2
[/effect]
[/object])
()
}


# this is the actual DROP Macro, call it when an item is dropped. "ITEM1" is the name of the Item
# if there is more then one item, then you have to add a "selection" code that defines which item is dropped at which condition
#for this example only one type of items is dropped
# the macro places an image on the map and stores the location of the item into a variable with the items name

#define ITEM_DROP X Y
[store_locations]
x={X}
y={Y}
variable=ITEM1_xy
[or]
find_in=ITEM1_xy
[/or]
[/store_locations]
[item]
x={X}
y={Y}
image="PATH/ITEM1.png"
[/item]
#enddef



#These are the events in-game
----------------------------------------------------


# define all items at game start
[event]
name=start
{ITEM_PREPARATION}
[/event]


# call drop-item macro if PLAYER kills a unit
[event]
name=die
first_time_only=no
[filter_second]
----PLAYER----
[/filter_second]

{ITEM_DROP $unit.x $unit.y} # drop an item on killed units coordinates
[event]
The best bet is your own, good Taste.
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Den of Thieves is by bob the mighty and jb ;)
Yes, the find_in with store_location is brilliant.
Mabuse
Posts: 2157
Joined: November 6th, 2007, 1:38 pm

Re: Pickup items

Post by Mabuse »

vghetto wrote: September 10th, 2021, 7:48 pm Den of Thieves is by bob the mighty and jb ;)
Yes, the find_in with store_location is brilliant.
yeah, its really, really cool and useful.
bob and jb are wml wizards :)
The best bet is your own, good Taste.
hermestrismi
Posts: 32
Joined: February 6th, 2016, 11:28 pm

Re: Pickup items

Post by hermestrismi »

thanks all of you
I tried the both way and I mixed them. I tried again and again.
this is my code now

Code: Select all


#define PICKUP_ITEM NAME CAN_TAKE_FILTER_WML IMAGE DESCRIPTION OBJECT_WML

    [event]
        name=moveto
        first_time_only=no
    [filter]
        [filter_location]
            find_in=item_dropped_xy
        [/filter_location]
    [/filter]

        [if]
            [have_unit]
    [filter]
	    side=1
        {CAN_TAKE_FILTER_WML}
        [filter_location]
            find_in=item_dropped_xy
        [/filter_location]
    [/filter]
            [/have_unit]
            [then]
                [message]
                    speaker=narrator
                    message=_"$unit.name finds a {NAME}. ({DESCRIPTION}) Should he pick it up?"
                    image={IMAGE}

                    [option]
                        message=_"Take the {NAME}"

                        [command]
                            {OBJECT_WML}

                            [remove_item]
    [filter]
        [filter_location]
            find_in=item_dropped_xy
        [/filter_location]
    [/filter]
                                image={IMAGE}
                            [/remove_item]

                        [/command]
                    [/option]

                    [option]
                        message=_"Leave the {NAME}"

                        [command]
                            [allow_undo]
                            [/allow_undo]
                        [/command]
                    [/option]
                [/message]
            [/then]

            [else]
        [if]
            [have_unit]
    [filter]
	    side=1
        [filter_location]
            find_in=item_dropped_xy
        [/filter_location]
	[not]
                {CAN_TAKE_FILTER_WML}
	[/not]
    [/filter]
            [/have_unit]
            [then]
                        [message]
                            speaker=narrator
                            message=_"$unit.name finds a {NAME}. But only {CAN_TAKE_FILTER_WML} can take it!"
                            image={IMAGE}
                            side_for=$side_number
                        [/message]

                [allow_undo]
                [/allow_undo]
            [/then]
        [/if]

            [/else]
        [/if]
    [/event]
#enddef
#define ITEM_EVENT
	[event]
		name=die
		first_time_only=no
		[filter]
		[not]
			side=1
        [/not]
		[/filter]
		
[set_variable]
name=random_item
rand=0,1,1,1,2,2,2
[/set_variable]

				[store_locations]
					x,y=$x1,$y1
					variable=item_dropped_xy
				[/store_locations]
		[if]
		
		[variable]
		name=random_item
		equals=1
		[/variable]

			[then]
                [item]
			    x,y=$x1,$y1
                image=items/axe.png
	            [/item]
		
[set_variable]
name=random_axe
rand=1,1,1,2,2,2
[/set_variable]
		[if]
		[variable]
		name=random_axe
		equals=1
		[/variable]

			[then]
		    {PICKUP_ITEM axe_of_hp race=human items/axe.png
    "This axe grants the wearer +10 max hp!" (
    [object]
    name= _ "axe of HP"
    image=items/axe.png
    description= _ "This axe grants the wearer +10 max hp!"
    
    [effect]
    apply_to=hitpoints
    increase_total=10
    [/effect]
    [/object]
    )}
			[/then]
		[/if]
		
			
		[if]
		[variable]
		name=random_axe
		equals=2
		[/variable]
		
			[then]
		{PICKUP_ITEM axe_of_power race=human items/axe.png
    "This axe grants the wearer +2 melee attacks!" (
    [object]
    name= _ "axe of power"
    image=items/axe.png
    description= _ "This axe grants the wearer +2 melee attacks!"
    
                       [effect]
                           apply_to=attack
                           [filter]
                           range=melee
                           [/filter]
                           increase_attacks=2
                       [/effect]
    [/object]
    )}
			[/then]
		[/if]
		
		
			[/then]
		[/if]
		
		
		[if]
		[variable]
		name=random_item
		equals=2
		[/variable]
		
			[then]
                                [item]
			                        x,y=$x1,$y1
                                    image=items/staff.png
	                            [/item]
			[/then]
		[/if]
	[/event]
	
#enddef
it work partially. I mean sometimes I have only images and sometimes the message appears many times.
I think I have to clear some variables and to upgrade the code somehow to eliminate any loops. any ideas?
Author of The Dark Master (bfw 1.12-1.14), CoCreator of The Dark Hordes (bfw 1.12-1.14)
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

With the store_location + find approach, you'll need to have a separate store location variable and moveto for each item type.
So it should be something like axe_dropped_xy and staff_dropped_xy

The [remove_item][filter]... in the moveto event looks wrong.

The [store_locations] in the die event is overwriting the older dropped items locations, you'll need to append it to the list instead.
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Here is a better template to use.
I based this on Den of Thieves...
You'll have to fill in the [message] stuff and give the actual [object] and the rest.

Code: Select all

    [event]
        name=die
        first_time_only=no
        [filter]
            [not]
                side=1
            [/not]
        [/filter]
        {RANDOM axe,staff}
        [if]
            {VARIABLE_CONDITIONAL random equals axe}
            [then]
                {PLACE_IMAGE items/axe.png $x1 $y1}
                [store_locations]
                    x,y=$x1,$y1
                    variable=item_axe_xy
                    [or]
                        find_in=item_axe_xy
                    [/or]
                [/store_locations]
            [/then]
        [/if]
        [if]
            {VARIABLE_CONDITIONAL random equals staff}
            [then]
                {PLACE_IMAGE items/staff.png $x1 $y1}
                [store_locations]
                    x,y=$x1,$y1
                    variable=item_staff_xy
                    [or]
                        find_in=item_staff_xy
                    [/or]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE random}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                find_in=item_axe_xy
            [/filter_location]
        [/filter]

        {VARIABLE pick_up_item no}

        # Put your [message] and [object] code here
        # Randomly set the axe type here and give the corresponding object accordingly.
        # only use $x1,$y1 here. don't worry about the find_in
        # If the unit takes the item then set pick_up_item to yes like so  {VARIABLE pick_up_item yes}

        [if]
            {VARIABLE_CONDITIONAL pick_up_item boolean_equals yes}
            [then]
                {REMOVE_ITEM $x1 $y1 items/axe.png}
                [store_locations]
                    variable=item_axe_xy
                    find_in=item_axe_xy
                    [not]
                        x,y=$x1,$y1
                    [/not]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE pick_up_item}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                find_in=item_staff_xy
            [/filter_location]
        [/filter]

        {VARIABLE pick_up_item no}

        # Put your [message] and [object] code here
        # Randomly set the staff type here and give the corresponding object accordingly.
        # only use $x1,$y1 here. don't worry about the find_in
        # If the unit takes the item then set pick_up_item to yes like so  {VARIABLE pick_up_item yes}

        [if]
            {VARIABLE_CONDITIONAL pick_up_item boolean_equals yes}
            [then]
                {REMOVE_ITEM $x1 $y1 items/staff.png}
                [store_locations]
                    variable=item_staff_xy
                    find_in=item_staff_xy
                    [not]
                        x,y=$x1,$y1
                    [/not]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE pick_up_item}
    [/event]
Edit: don't mess with the die event. Your code would only be in the moveto where I have the comments.
It is in the moveto that the random types of axes or staffs are set. The die event should only register the location and put the image on the screen.
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Here's the modified PICKUP_ITEM macro. It's based on mainline PICKUPPABLE_ITEM macro.
This is what is supposed to go in the moveto event just like how you had above.

Code: Select all

#define PICKUP_ITEM ID CAN_TAKE_FILTER_WML IMAGE TEXT TAKE_IT_STRING LEAVE_IT_STRING CANNOT_TAKE_TEXT OBJECT_WML
    # ! {PICKUP_ITEM ring_of_hp race=human items/ring-red.png
    # !     _"$unit.name finds a pretty ring. Should he pick it up?"
    # !     _"ring of HP^Take it"
    # !     _"ring of HP^Leave it"
    # !     _"$unit.name finds a pretty ring. But only a human can take it!" (
    # !     [object]
    # !         name= _ "Ring of HP"
    # !         image=items/ring-red.png
    # !         description= _ "This ring grants the wearer +10 max hp!"
    # !
    # !         [effect]
    # !             apply_to=hitpoints
    # !             increase_total=10
    # !         [/effect]
    # !     [/object]
    # ! )}

    [if]
        [have_unit]
            x,y=$x1,$y1
            {CAN_TAKE_FILTER_WML}
        [/have_unit]
        [then]
            [message]
                speaker=narrator
                message={TEXT}
                image={IMAGE}
                [option]
                    label={TAKE_IT_STRING}
                    [command]
                       {OBJECT_WML}
                       {VARIABLE pick_up_item yes}
                    [/command]
                [/option]
                [option]
                    label={LEAVE_IT_STRING}
                    [command]
                        [allow_undo]
                        [/allow_undo]
                    [/command]
                [/option]
            [/message]
        [/then]
        [else]
            [message]
                speaker=narrator
                message={CANNOT_TAKE_TEXT}
                image={IMAGE}
            [/message]
            [allow_undo]
            [/allow_undo]
        [/else]
    [/if]
#enddef
If you want to reduce the chance of an item being dropped on death, then just add none to the list in the die event.
{RANDOM axe,staff,none,none}
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

Ugh, I ended up writing it anyway so might as well post it for you.
Here is the part that goes into the moveto for the axe. This uses the PICKUP_ITEM defined above.

Code: Select all

       [set_variable]
            name=random_axe
            rand=1,2
        [/set_variable]
        [if]
            [variable]
                name=random_axe
                equals=1
            [/variable]
            [then]
                {PICKUP_ITEM axe_of_hp race=human items/axe.png
                _"$unit.name finds a pretty axe. Should he pick it up?"
                _"Axe of HP^Take it"
                _"Axe of HP^Leave it"
                _"$unit.name finds a pretty axe. But only a human can take it!" (
                    [object]
                        name= _ "Axe of HP"
                        image=items/axe.png
                        description= _ "This axe grants the wearer +10 max hp!"

                        [effect]
                            apply_to=hitpoints
                            increase_total=10
                        [/effect]
                    [/object]
                )}
            [/then]
        [/if]
        [if]
            [variable]
                name=random_axe
                equals=2
            [/variable]
            [then]
                {PICKUP_ITEM axe_of_power race=human items/axe.png
                _"$unit.name finds a pretty axe. Should he pick it up?"
                _"Axe of power^Take it"
                _"Axe of power^Leave it"
                _"$unit.name finds a pretty axe. But only a human can take it!" (
                    [object]
                        name= _ "Axe of Power"
                        image=items/axe.png
                        description= _ "This axe grants the wearer +2 melee attacks!"

                        [effect]
                            apply_to=attack
                            [filter]
                                range=melee
                            [/filter]
                            increase_attacks=2
                        [/effect]
                    [/object]
                )}
            [/then]
        [/if]
        {CLEAR_VARIABLE random_axe}
hermestrismi
Posts: 32
Joined: February 6th, 2016, 11:28 pm

Re: Pickup items

Post by hermestrismi »

Thank you everyone
this is the final template

Code: Select all


#define ITEM_EVENT
   [event]
        name=die
        first_time_only=no
        [filter]
            [not]
                side=1
            [/not]
        [/filter]
        {RANDOM axe,staff}
        [if]
            {VARIABLE_CONDITIONAL random equals axe}
            [then]
                {PLACE_IMAGE items/axe.png $x1 $y1}
                [store_locations]
                    x,y=$x1,$y1
                    variable=item_axe_xy
                    [or]
                        find_in=item_axe_xy
                    [/or]
                [/store_locations]
            [/then]
        [/if]
        [if]
            {VARIABLE_CONDITIONAL random equals staff}
            [then]
                {PLACE_IMAGE items/staff.png $x1 $y1}
                [store_locations]
                    x,y=$x1,$y1
                    variable=item_staff_xy
                    [or]
                        find_in=item_staff_xy
                    [/or]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE random}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                find_in=item_axe_xy
            [/filter_location]
        [/filter]
        [if]
        {VARIABLE pick_up_item no}
		[then]
		    [set_variable]
			name=rand_axe
			rand=1,2
			[/set_variable]
			    [switch]
				variable=rand_axe
				    [case]
					value=1
					    {PICKUP_ITEM AOH1
						"Axe of HP."
						race=human
						items/axe.png
						"This axe grants the wearer +5 max hp!" (
    [object]
    name= _ "Axe of HP"
    image=items/axe.png
    description= _ "This axe grants the wearer +5 max hp!!"
    
        [effect]
        apply_to=hitpoints
        increase_total=10
        [/effect]
    [/object]
    )}
					[/case]
				    [case]
					value=2
					{PICKUP_ITEM AOH2
						"Axe of HP."
						race=human
						items/axe.png
						"This axe grants the wearer +10 max hp!" (
    [object]
    name= _ "Axe of HP"
    image=items/axe.png
    description= _ "This axe grants the wearer +10 max hp!!"
    
        [effect]
        apply_to=hitpoints
        increase_total=10
        [/effect]
    [/object]
    )}
					[/case] 
				[/switch]
		[/then]
		[/if]


        [if]
            {VARIABLE_CONDITIONAL pick_up_item boolean_equals yes}
            [then]
                [remove_item]
					x,y=$x1,$y1
                    image=items/axe.png
                [/remove_item]
                [store_locations]
                    variable=item_axe_xy
                    find_in=item_axe_xy
                    [not]
                        x,y=$x1,$y1
                    [/not]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE pick_up_item}
    [/event]

    [event]
        name=moveto
        first_time_only=no
        [filter]
            side=1
            [filter_location]
                find_in=item_staff_xy
            [/filter_location]
        [/filter]

        {VARIABLE pick_up_item no}

        # Put your [message] and [object] code here
        # Randomly set the staff type here and give the corresponding object accordingly.
        # only use $x1,$y1 here. don't worry about the find_in
        # If the unit takes the item then set pick_up_item to yes like so  {VARIABLE pick_up_item yes}

        [if]
            {VARIABLE_CONDITIONAL pick_up_item boolean_equals yes}
            [then]
                [remove_item]
					x,y=$x1,$y1
                    image=items/staff.png
                [/remove_item]
                [store_locations]
                    variable=item_staff_xy
                    find_in=item_staff_xy
                    [not]
                        x,y=$x1,$y1
                    [/not]
                [/store_locations]
            [/then]
        [/if]
        {CLEAR_VARIABLE pick_up_item}
    [/event]
#enddef

#define PICKUP_ITEM ID NAME CAN_TAKE_FILTER_WML IMAGE DESCRIPTION OBJECT_WML
    [if]
        [have_unit]
            x,y=$x1,$y1
            {CAN_TAKE_FILTER_WML}
        [/have_unit]
        [then]
            [message]
                speaker=narrator
                message=_"$unit.name finds a {NAME}. ({DESCRIPTION}) Should he pick it up?"
                image={IMAGE}
                [option]
                     message=_"Take the {NAME}"
                    [command]
                       {OBJECT_WML}
                       {VARIABLE pick_up_item yes}
                    [/command]
                [/option]
                [option]
                     message=_"Leave the {NAME}"
                    [command]
                        [allow_undo]
                        [/allow_undo]
                    [/command]
                [/option]
            [/message]
        [/then]
        [else]
            [message]
                            speaker=narrator
                            message=_"$unit.name finds a {NAME}. But only {CAN_TAKE_FILTER_WML} can take it!"
                            image={IMAGE}
                            side_for=$side_number
            [/message]
            [allow_undo]
            [/allow_undo]
        [/else]
    [/if]
#enddef
If I finish the campaign, I will write a special thanks for you two (Vghetto and Mabuse)
Author of The Dark Master (bfw 1.12-1.14), CoCreator of The Dark Hordes (bfw 1.12-1.14)
vghetto
Posts: 503
Joined: November 2nd, 2019, 5:12 pm

Re: Pickup items

Post by vghetto »

This wasn't a conditional. remove the [if] [then] and the closing [/then] [/if]. Keep {VARIABLE pick_up_item no}

Code: Select all

        [if]
        {VARIABLE pick_up_item no}
		[then]
Just to let you know, there is a tiny bug in my code. Since the random_axe gets reassigned on each move to, moving onto the item and not picking up will give a different axe type. You'll have to figure out a way of keeping track of what it should settle into.
Post Reply