Difference between revisions of "DroppableItem"

From The Battle for Wesnoth Wiki
 
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Droppable Item ==
+
This page is for code fragments for dropping items.
  
X=the starting X-location for the object
+
== Droppable on Death ==
  
Y=the starting Y-location for the object
+
This section is for macros that drop an item due to the death of unit.
  
XVAR=the variable to store the item's current X-location in
+
=== Dropping a picked up item ===
  
YVAR=the variable to store the item's current Y-location in
+
This macro comes in two parts with space for [effect] code between them. Using this macro creates an item at a point on the map specified by X and Y, keeps track of it (when the unit carrying it dies) via two variable (which the user names!!) and provides an image for the map.
  
NAME=the name of the object
+
Note that if you want any unit to be able to pick up the item you can ignore the ADDITIONAL_FILTERS part.
 
+
==== Part One ====
IMAGE=the image of the object
+
  #define DROPPABLE_ITEM X Y XVAR YVAR NAME IMAGE ADDITIONAL_FILTERS
 
+
[label]
  #define DROPPABLE_ITEM X Y XVAR YVAR NAME IMAGE
+
x={X}
 +
y={Y}
 +
text="{NAME}"
 +
[/label]
 
  [event]
 
  [event]
 
  name=prestart
 
  name=prestart
 
 
  {VARIABLE {XVAR} {X}}
 
  {VARIABLE {XVAR} {X}}
 
  {VARIABLE {YVAR} {Y}}
 
  {VARIABLE {YVAR} {Y}}
 
+
 
  [item]
 
  [item]
 
  x=${XVAR}
 
  x=${XVAR}
Line 25: Line 27:
 
  image={IMAGE}
 
  image={IMAGE}
 
  [/item]
 
  [/item]
 
+
 +
[event]
 +
name=die
 +
first_time_only=no
 +
[store_unit]
 +
[filter]
 +
x=$x1
 +
y=$y1
 +
[/filter]
 +
variable=itemstore
 +
[/store_unit]
 +
[if]
 +
[variable]
 +
name=itemstore.variables.{XVAR}
 +
equals=on
 +
[/variable]
 +
[then]
 +
{VARIABLE_OP {XVAR} to_variable x1}
 +
{VARIABLE_OP {YVAR} to_variable y1}
 +
[item]
 +
x=$x1
 +
y=$y1
 +
image={IMAGE}
 +
[/item]
 +
[/then]
 +
[/if]
 +
[/event]
 +
 
  [event]
 
  [event]
 
  name=moveto
 
  name=moveto
Line 32: Line 61:
 
  x=${XVAR}
 
  x=${XVAR}
 
  y=${YVAR}
 
  y=${YVAR}
 +
{ADDITIONAL_FILTERS}
 
  [/filter]
 
  [/filter]
 
[event]
 
name=die
 
first_time_only=no
 
[store_unit]
 
[filter]
 
x=$x1
 
y=$y1
 
[/filter]
 
variable=itemstore
 
[/store_unit]
 
[if]
 
[variable]
 
name=itemstore.variables.{XVAR}
 
equals=on
 
[/variable]
 
[then]
 
{VARIABLE_OP {XVAR} to_variable x1}
 
{VARIABLE_OP {YVAR} to_variable y1}
 
[item]
 
x=$x1
 
y=$y1
 
image={IMAGE}
 
[/item]
 
[/then]
 
[/if]
 
[/event]
 
 
 
 
 
 
  [removeitem]
 
  [removeitem]
Line 72: Line 75:
 
  [/filter]
 
  [/filter]
 
  [/store_unit]
 
  [/store_unit]
  {VARIABLE itemstore.variables.{XVAR} on}
+
{VARIABLE itemstore.variables.{XVAR} on}
 
  [unstore_unit]
 
  [unstore_unit]
 
  variable=itemstore
 
  variable=itemstore
 
  [/unstore_unit]
 
  [/unstore_unit]
 
 
 
 
  {VARIABLE {XVAR} 0}
+
  [unit_overlay]
  {VARIABLE {YVAR} 0}
+
x=${XVAR}
 +
  y=${YVAR}
 +
image={IMAGE}
 +
[/unit_overlay]
 
 
 
 
 
  [object]
 
  [object]
Line 84: Line 90:
 
  image={IMAGE}
 
  image={IMAGE}
 
  duration=forever
 
  duration=forever
 +
cannot_use_message="-cannot use message-"
 
  [filter]
 
  [filter]
 
  x=${XVAR}
 
  x=${XVAR}
Line 89: Line 96:
 
  [/filter]
 
  [/filter]
 
  #enddef
 
  #enddef
 
#All this should be between the DROPPABLE_ITEM macro and /DROPPABLE_ITEM
 
# description="-the description-"
 
# cannot_use_message="-cannot use message-"
 
# [effect]
 
# blahblahblah=somethingorother
 
# [/effect]
 
  
  #define /DROPPABLE_ITEM
+
==== Effect goes here ====
 +
 
 +
Of course the code for the macro above will do nothing without an [effect] attatched to the item (via the [object] tag in the above macro) other than cart an image around. To add an effect, make an [effect] tag as below (or look at [[EffectWML]]:
 +
 +
#All this should be between the usage of the DROPPABLE_ITEM macro and its /DROPPABLE_ITEM
 +
#
 +
# This is not the only thing you can do but for an item that increases movementspeed by 10(!) do:
 +
[effect]
 +
    apply_to=movement
 +
    increase=10
 +
[/effect]
 +
 +
==== Part 2 ====
 +
Once you have done all of the above, call the closing macro to close all the tags and clear the variables.
 +
 
 +
  #define /DROPPABLE_ITEM XVAR YVAR
 
  [/object]
 
  [/object]
 +
 +
{VARIABLE {XVAR} 0}
 +
{VARIABLE {YVAR} 0}
 
  [/event]
 
  [/event]
 
  [/event]
 
  [/event]
 
  #enddef
 
  #enddef
 
  
 
== See Also ==
 
== See Also ==
  
 
* [[UsefulWMLFragments]]
 
* [[UsefulWMLFragments]]
 +
* [[ReferenceWML]]
  
 +
[[Category: UsefulWMLFragments]]

Latest revision as of 04:59, 23 January 2021

This page is for code fragments for dropping items.

Droppable on Death

This section is for macros that drop an item due to the death of unit.

Dropping a picked up item

This macro comes in two parts with space for [effect] code between them. Using this macro creates an item at a point on the map specified by X and Y, keeps track of it (when the unit carrying it dies) via two variable (which the user names!!) and provides an image for the map.

Note that if you want any unit to be able to pick up the item you can ignore the ADDITIONAL_FILTERS part.

Part One

#define DROPPABLE_ITEM X Y XVAR YVAR NAME IMAGE ADDITIONAL_FILTERS
[label]
x={X}
y={Y}
text="{NAME}"
[/label]
[event]
name=prestart
	{VARIABLE {XVAR} {X}}
	{VARIABLE {YVAR} {Y}}

	[item]
	x=${XVAR}
	y=${YVAR}
	image={IMAGE}
	[/item]
		
	[event]
	name=die
	first_time_only=no
	[store_unit]
	[filter]
	x=$x1
	y=$y1
	[/filter]
	variable=itemstore
	[/store_unit]
	[if]
	[variable]
	name=itemstore.variables.{XVAR}
	equals=on
	[/variable]
		[then]
		{VARIABLE_OP {XVAR} to_variable x1}
		{VARIABLE_OP {YVAR} to_variable y1}
		[item]
		x=$x1
		y=$y1
		image={IMAGE}
		[/item]
		[/then]
	[/if]
	[/event]

	[event]
	name=moveto
	first_time_only=no
		[filter]
		x=${XVAR}
		y=${YVAR}
		{ADDITIONAL_FILTERS}
		[/filter]
		
		[removeitem]
		x=${XVAR}
		y=${YVAR}
		[/removeitem]
		[store_unit]
		variable=itemstore
		[filter]
		x=${XVAR}
		y=${YVAR}
		[/filter]
		[/store_unit]
		{VARIABLE itemstore.variables.{XVAR} on}
		[unstore_unit]
		variable=itemstore
		[/unstore_unit]
		
		[unit_overlay]
		x=${XVAR}
		y=${YVAR}
		image={IMAGE}
		[/unit_overlay]
		
		[object]
		name={NAME}
		image={IMAGE}
		duration=forever
		cannot_use_message="-cannot use message-"
			[filter]
			x=${XVAR}
			y=${YVAR}
			[/filter]
#enddef

Effect goes here

Of course the code for the macro above will do nothing without an [effect] attatched to the item (via the [object] tag in the above macro) other than cart an image around. To add an effect, make an [effect] tag as below (or look at EffectWML:

#All this should be between the usage of the DROPPABLE_ITEM macro and its /DROPPABLE_ITEM
#		
# This is not the only thing you can do but for an item that increases movementspeed by 10(!) do:
[effect]
    apply_to=movement
    increase=10
[/effect]

Part 2

Once you have done all of the above, call the closing macro to close all the tags and clear the variables.

#define /DROPPABLE_ITEM XVAR YVAR
		[/object]
		
	{VARIABLE {XVAR} 0}
	{VARIABLE {YVAR} 0}
	[/event]
[/event]
#enddef

See Also

This page was last edited on 23 January 2021, at 04:59.