Weapon Special: Redemption

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
Garen Voh
Posts: 69
Joined: July 29th, 2007, 2:19 am
Location: Wherever I Am
Contact:

Weapon Special: Redemption

Post by Garen Voh »

First, this was a friend of mine's idea, who implemented it on an older version. So I don't get credit for this...

I'm trying to figure out how to create a weapon special like plague for a campaign of mine, called "redemption." A unit with this special could, in theory, kill an undead and revive them to a human (or whatever) on the side of the unit that killed it.

Seems to me this should be fairly straightforward, but I'm having problems figuring out how to just write the code. The "plague" special doesn't seem to have any code I can look at for reference.

I could just give the unit "plague," but I want it to only affect undead.

I'm new at WML, so if replies could be dumbed-down, that'd be great. :wink:
I am your best nightmare...
Garen Voh
Posts: 69
Joined: July 29th, 2007, 2:19 am
Location: Wherever I Am
Contact:

Post by Garen Voh »

Oh, and I'm using v. 1.2.5
I am your best nightmare...
User avatar
Col Lightbeam
Posts: 46
Joined: November 18th, 2008, 1:01 am

Re: Weapon Special: Redemption

Post by Col Lightbeam »

I would also like something similar.

I am using version 1.6 something and would like my "naturalize" weapon special to work on everything, even undead.
It is supposed to turn anything it kills into a plant unit, even mechanical and undead. Is it even possible to make a plague-like weapon special that works on undead, and preferably also work even inside villages?
Mix Era Of Magic, Era of Myths, and Extended Era and you get all my favorite teams on one group! and ULTIMATE POWER!!!!!!!!!!!!

Also in the programming industry... later.
User avatar
StDrake
Posts: 996
Joined: July 21st, 2009, 6:50 am

Re: Weapon Special: Redemption

Post by StDrake »

uh it's hard for me to dumb down the reply enough, so do care to look into the wml reference page..
the thing starts pretty simple, you want whatever has the unit with this special to have an event triggering when a unit dies, filter by the victims race (should be undead) and by the attacking unit having the redemption special, and this should create an appropriate living unit on the tile where the undead stood
I have no idea how it would look in 1.2 i recommend changing to a newer version of wesnoth
should look something like

Code: Select all

[event]
name=die

[filter]
race=undead
[/filter]
[filter_second]
attack.special=redemption
[/filter_second]
[unit]
type=redempted_human
[/unit]
[/event]
of course it won't work if you just copy and paste the above, details need a ton of polishing and that's an occasion for you to learn and train your wml skills :)

the worst part might be finding out which attack was used to kill this victim
Like cats? I've made a whole faction of them to kick ass with!
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2178
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Re: Weapon Special: Redemption

Post by Ken_Oh »

It's not going to be as easy as just altering the Plague special, especially if you want to make it will work on villages.

My suggestion is to make an event-driven weapon special.

http://www.wesnoth.org/wiki/EventWML and here are some examples of event-driven abilities and weapon specials: http://www.wesnoth.org/wiki/WML_Abilities

First, when a unit gets killed (i.e. the die event) by a unit with Plague, you're going to want to store that unit. This is necessary if you want to keep that unit's name, sex, unit type, level, etc. since that isn't stored in the plagued unit's info AFAIK. You probably want to make an array of this since you could store more than one during a round.

Second, since there isn't any post-plague event (you could try attack end, but I doubt that will work), you're going to have to keep those stored units and then during the next side turn event put those units inside their respective plagued units (probably just using x,y to find the unit). Don't forget to clear those stored variables.

Make an event that triggers when the secondary unit is of the plagued type and is killed by the primary unit's weapon that has the Redemption ability. This is when you can changed the unit's type back to what it originally was (probably want to use [object] http://www.wesnoth.org/wiki/DirectActionsWML and [effect] http://www.wesnoth.org/wiki/EffectWML for this). After you have your new unit in place, fill in all of the variables of the old unit.

Sound complicated? It is. If you really try enough, people will be around to help. Maybe I can help more, but not today. Good luck.
User avatar
Col Lightbeam
Posts: 46
Joined: November 18th, 2008, 1:01 am

Re: Weapon Special: Redemption

Post by Col Lightbeam »

I notice that "charm type 2" is an attacker-only weapon special. I have been working on a similar idea, and so came up with the following (taking bits from GEB, thank you gambit, and wiki wesnoth):

I know that every line of the first half below works for 1.8 because that is what I am playing right now, except for up to four, which don't seem to work because I don't know the name of the variable of the second side:

Code: Select all

[event]
    name=attacker_hits
    first_time_only=no

    [filter_attack]
        special=convert01
    [/filter_attack]

    [filter_second]
        canrecruit=no
        [and]
            [not]
                [filter_wml]
                    [status]
                        not_living=yes
                    [/status]
                [/filter_wml]
            [/not]
        [/and]
	    [and]
		[not]
			race=devling
		[/not]
	    [/and]
	    [and]
		[not]
			race=vampire
		[/not]
	    [/and]
	    [and]
		[not]
			race=Infernai
		[/not]
	    [/and]
	    [and]
		[not]
			race=demon
		[/not]
	    [/and]
    [/filter_second]
[store_unit]
[filter]
x=$x2
y=$y2
[/filter]
kill=yes
mode=replace
variable=worker
[/store_unit]
[set_variable]
name=worker.side
value=$side_number
[/set_variable]
[unstore_unit]
variable=worker
[/unstore_unit]
[/event]

####above here all work####

[event]
    name=defender_hits
    first_time_only=no

    [filter_second_attack]
        special=convert01
    [/filter_second_attack]

    [filter]
        canrecruit=no
        [and]
            [not]
                [filter_wml]
                    [status]
                        not_living=yes
                    [/status]
                [/filter_wml]
            [/not]
        [/and]
	    [and]
		[not]
			race=devling
		[/not]
	    [/and]
	    [and]
		[not]
			race=vampire
		[/not]
	    [/and]
	    [and]
		[not]
			race=Infernai
		[/not]
	    [/and]
	    [and]
		[not]
			race=demon
		[/not]
	    [/and]
    [/filter]
[store_unit]
[filter]
x=$x1
y=$y1
[/filter]
kill=yes
mode=replace
variable=worker
[/store_unit]
[set_variable]
name=worker.side

###The below variable####

value=$second_side_number

###The above variable####

[/set_variable]
[unstore_unit]
variable=worker
[/unstore_unit]
[/event]
I know what everything else is here, but I don't know that one variable. I have checked the Wesnoth wiki and it doesn't seem to have an entry. Would $defender.side_number or $second.side_number work? If not, what would?
Mix Era Of Magic, Era of Myths, and Extended Era and you get all my favorite teams on one group! and ULTIMATE POWER!!!!!!!!!!!!

Also in the programming industry... later.
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Weapon Special: Redemption

Post by Dixie »

You DO know that this thread is about 4 years old, do you?

That being said, I think the variable you want is "unit.side". In a defender/attacker hits event, unit is the unit that hits, and second_unit is the unit that is hit. Also, units don't have a side_number key, but rather just "side". For these kind of information, you can always open a normal game of wesnoth (local multiplayer), allow debug mode and type inspect in the command bar. There, you can look at all the variables in the game and inspect each unit. This allows you to see what is contained in each unit's code exactly, and is pretty darn useful to know what you can access through wich variables exactly.
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Weapon Special: Redemption

Post by 8680 »

Dixie wrote:In a defender/attacker hits event, unit is the unit that hits, and second_unit is the unit that is hit.
No, unit is the attacker (as in the unit that initiated combat, not necessarily the one that's currently attacking) and second_unit is the defender.
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Weapon Special: Redemption

Post by Dixie »

Yeah, you're right, sorry, I didn't verify this before posting it. I really am rusty :/ Should be getting to it more seriously sometime soon.
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
User avatar
Col Lightbeam
Posts: 46
Joined: November 18th, 2008, 1:01 am

Re: Weapon Special: Redemption

Post by Col Lightbeam »

I know that "$" means the value of the variable immediately following it, like for instance $food meant the number that is equated to the variable "food". The problem is "$unit.side" didn't work for changing attacker side, when defender hit. I am right now seeing if

Code: Select all

[set_variable]
name=worker.side
value=$unit.side
[/set_variable]
was actually reached, though it should have. If it didn't, then what did it mean? If it meant the "defender" at that point, then why did the rest of the code encasing it didn't work? I know the first half (changing the side of the defending monster) of the code works.
Mix Era Of Magic, Era of Myths, and Extended Era and you get all my favorite teams on one group! and ULTIMATE POWER!!!!!!!!!!!!

Also in the programming industry... later.
User avatar
Dixie
Posts: 1757
Joined: February 10th, 2010, 1:06 am
Location: $x1,$y1

Re: Weapon Special: Redemption

Post by Dixie »

8680 wrote:
Dixie wrote:In a defender/attacker hits event, unit is the unit that hits, and second_unit is the unit that is hit.
No, unit is the attacker (as in the unit that initiated combat, not necessarily the one that's currently attacking) and second_unit is the defender.
I am sorry to have mislead you - the defender is actually stored in second_unit. The variable you need would be second_unit.side (with the dollars sign before it).

There are two things you can do to verify these sort of things by yourself. The first is calling the inspect window with [inspect][/inspect]. It allows you to see the state of the game midway through the execution of the code: all the units, all the stored variables, etc. The other is using the DEBUG_MSG macro: using one has the benefit of not only telling if the event/if/anything it was in has launched, but you can include variables to check in it. For example, in your code, you could have used this before and after the variable you doubted:
{DEBUG_MSG "unit.side= $unit.side second_unit.side= $second_unit.side worker.side= $worker.side"}

Two other things:
- Your code is unindented, it's a bit painful to read.
- I' not 100% certain, but fairly so, but this:

Code: Select all

      [not]
         race=devling
      [/not]
       [/and]
       [and]
      [not]
         race=vampire
      [/not]
       [/and]
       [and]
      [not]
         race=Infernai
      [/not]
       [/and]
       [and]
      [not]
         race=demon
      [/not]
Could probably have been simplified to this:

Code: Select all

[not]
    race=devling,vampire,infernai,demon
[/not]
Jazz is not dead, it just smells funny - Frank Zappa
Current projects: Internet meme Era, The Settlers of Wesnoth
Post Reply