Difference between revisions of "DroppableItem"

From The Battle for Wesnoth Wiki
(MAJOR CHANGE! Changed structure of page completely. Added comments and instructions to help newbies. Added sections. Kept links but it should all make sense now.)
(Dropping Loot)
Line 125: Line 125:
 
   
 
   
 
  #Re writing... come back later.
 
  #Re writing... come back later.
 +
 +
== Removing an object ==
 +
(1.10) This macro is designed to remove an object of a certain name (of course, just a bit of editing, and you can remove an object following different criteria) from the unit matching the filter. It clashes with AMLA, so if you are using it, better use strict_amla=yes for all advancements that might happen to the unit you are removing the object from.
 +
 +
#define REMOVE_OBJECT FILTER NAME
 +
#First, the unit is stored, it searches in modifications for objects with names
 +
#like that, and deletes them. Then the unit is advanced to apply the changes,
 +
#and then it gets the HP, movement, attack_left and exp of the original unit.
 +
[store_unit]
 +
[filter]
 +
{FILTER}
 +
[/filter]
 +
variable=gifted
 +
kill=no
 +
[/store_unit]  #Stores the unit
 +
{FOREACH gifted.modifications.object i}
 +
[if]
 +
[variable]
 +
name=gifted.modifications.object[$i].name
 +
equals={NAME}
 +
[/variable]
 +
[then]
 +
{CLEAR_VARIABLE gifted.modifications.object[$i]}
 +
[/then]
 +
[else]
 +
    [set_variable
 +
      name=i
 +
      add=1
 +
    [/set_variable]
 +
[/else]
 +
[/if]
 +
    [/do]
 +
[/while]
 +
{CLEAR_VARIABLE i}
 +
[unstore_unit]
 +
        variable=gifted
 +
find_vacant=no
 +
[/unstore_unit]
 +
{ADVANCE_UNIT x,y=$x1,$y1 $gifted.type}
 +
[store_unit]
 +
[filter]
 +
x,y=$x1,$y1
 +
[/filter]
 +
variable=gifted2
 +
kill=no
 +
[/store_unit]
 +
{VARIABLE gifted2.hitpoints $gifted.hitpoints}
 +
{VARIABLE gifted2.level $gifted.level}
 +
{VARIABLE gifted2.moves $gifted.moves}
 +
{VARIABLE gifted2.attacks_left $gifted.attacks_left}
 +
[unstore_unit]
 +
        variable=gifted2
 +
find_vacant=no
 +
[/unstore_unit]
 +
{CLEAR_VARIABLE gifted}
 +
{CLEAR_VARIABLE gifted2}
 +
#enddef
  
 
== See Also ==
 
== See Also ==

Revision as of 18:23, 26 March 2012

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

Dropping Loot

This macro makes it so that when a unit matching a filter dies, it will drop an item (eg gold!)

#Re writing... come back later.

Removing an object

(1.10) This macro is designed to remove an object of a certain name (of course, just a bit of editing, and you can remove an object following different criteria) from the unit matching the filter. It clashes with AMLA, so if you are using it, better use strict_amla=yes for all advancements that might happen to the unit you are removing the object from.

#define REMOVE_OBJECT FILTER NAME
#First, the unit is stored, it searches in modifications for objects with names
#like that, and deletes them. Then the unit is advanced to apply the changes,
#and then it gets the HP, movement, attack_left and exp of the original unit.
[store_unit]
	[filter]
		 {FILTER}
	[/filter]
	variable=gifted
	kill=no
[/store_unit]   #Stores the unit
{FOREACH gifted.modifications.object i}
	[if]
		[variable]
			name=gifted.modifications.object[$i].name
			equals={NAME}
		[/variable]
		[then]
			{CLEAR_VARIABLE gifted.modifications.object[$i]}
		[/then]
		[else]
		    [set_variable
		       name=i
		       add=1
		    [/set_variable]
		[/else]
	[/if]
   [/do]
[/while]
{CLEAR_VARIABLE i}
[unstore_unit]
        variable=gifted
	find_vacant=no
[/unstore_unit]
{ADVANCE_UNIT x,y=$x1,$y1 $gifted.type}
[store_unit]
	[filter]
		x,y=$x1,$y1
	[/filter]
	variable=gifted2
	kill=no
[/store_unit]
{VARIABLE gifted2.hitpoints $gifted.hitpoints}
{VARIABLE gifted2.level $gifted.level}
{VARIABLE gifted2.moves $gifted.moves}
{VARIABLE gifted2.attacks_left $gifted.attacks_left}
[unstore_unit]
       variable=gifted2
	find_vacant=no
[/unstore_unit]
{CLEAR_VARIABLE gifted}
{CLEAR_VARIABLE gifted2}
#enddef

See Also