Carda's bunch of daily Lua questions

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
Carda
Posts: 11
Joined: December 21st, 2010, 2:20 pm

Carda's bunch of daily Lua questions

Post by Carda » December 23rd, 2010, 10:08 am

Hello there Wesnoth Community,

Downloaded the game last week and observed a lot of games. RPG maps are what makes this game very interesting to play for me and so found out about Bob's RPG addons what makes the game even cooler now.

Used to making scripts for Warcraft 3 in the long past and the scripting blood starts to boil again. My goal is to create a RPG multiplayer map like Labyrinth of Champions.

To test my map's progression I need to create an event that gives the player who enters a specific coordinate an # amount of xp.

[event]
name=moveto
[filter]
x="6"
y="74"
side=1,2,3,4,5
[/filter]
?????????????
[/event]

What command do I use to give the player who activated the script some xp?
Is there a clear guide on the internet where I can find the basic commands like this one?

Thank you all for your kind help,
Carda
Last edited by Carda on January 4th, 2011, 6:46 pm, edited 1 time in total.
10 FOR X = 0 TO 15
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10

User avatar
Sapient
Inactive Developer
Posts: 4449
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Script command to give XP to a unit?

Post by Sapient » December 23rd, 2010, 10:35 am

http://wiki.wesnoth.org/ReferenceWML

Read documentation for the following tags:

[store_unit]

[set_variable]

[unstore_unit]

Ask questions if you have any.

Yes, this can also be done with Lua, but I'm not the one to ask for that.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

Atz
Art Contributor
Posts: 313
Joined: August 21st, 2008, 2:22 am

Re: Script command to give XP to a unit?

Post by Atz » December 23rd, 2010, 11:54 am

If you just need to add XP for testing purposes (ie. it's not going to be in the finished version) you can also manually add experience and do various other things using debug mode. Start playing your scenario and type ":debug" to activate it. Then you can mouse over the unit you want and type ":unit experience=10" to set a unit's XP to 10, for instance. You can also make a unit level up with "unit advances=1". See http://wiki.wesnoth.org/CommandMode for more.

Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Script command to give XP to a unit?

Post by Ceres » December 23rd, 2010, 3:06 pm

An easier way to do this would be

Code: Select all

[modify_unit]
			[filter]
				id=$unit.id
			[/filter]
			experience=100
		[/modify_unit]
'unit' is a container stored automatically after each event, storing all values of the triggering unit. The macro didn't work for me, but this did.

User avatar
bumbadadabum
Developer
Posts: 1005
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands
Contact:

Re: Script command to give XP to a unit?

Post by bumbadadabum » December 23rd, 2010, 3:09 pm

Ceres wrote:An easier way to do this would be

Code: Select all

[modify_unit]
			[filter]
				id=$unit.id
			[/filter]
			experience=100
		[/modify_unit]
'unit' is a container stored automatically after each event, storing all values of the triggering unit. The macro didn't work for me, but this did.
This should work if you have 1.9.x. Else use:

Code: Select all

{MODIFY_UNIT x,y=$x1,$y1 experience 100}

User avatar
bigkahuna
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: Script command to give XP to a unit?

Post by bigkahuna » December 23rd, 2010, 6:44 pm

LightFighter wrote:This should work if you have 1.9.x. Else use:
Neither of those work. :eng:
That alters the modified unit to 100 xp, meaning no matter what the xp was before, it would have 100. This is how to add it.

Code: Select all

[store_unit]
    [filter]
        x,y=$x1,$y1
    [/filter]
    kill=no
    variable=unit_stored
[/store_unit]
{VARIABLE_OP unit_stored.experience add 100}
[unstore_unit]
    variable=unit_stored
[/unstore_unit]
Last edited by bigkahuna on December 23rd, 2010, 9:25 pm, edited 1 time in total.
Check out my campaign Sweet Revenge!
Join the new R2D forum!

Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Script command to give XP to a unit?

Post by Ceres » December 23rd, 2010, 6:58 pm

Corrected version of my code adding the experience instead of setting:

Code: Select all

		[modify_unit]
			[filter]
				id=$unit.id
			[/filter]
			experience="$($unit.experience+100)"
		[/modify_unit]

User avatar
Sapient
Inactive Developer
Posts: 4449
Joined: November 26th, 2005, 7:41 am
Contact:

Re: Script command to give XP to a unit?

Post by Sapient » December 23rd, 2010, 9:08 pm

Ceres wrote:Corrected version of my code adding the experience instead of setting:
Well done! You even remembered the quote marks.
This made my day to see a new WML wiz is joining the ranks. 8)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."

User avatar
bigkahuna
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: Script command to give XP to a unit?

Post by bigkahuna » December 23rd, 2010, 9:26 pm

Sapient wrote:Well done! You even remembered the quote marks.
This made my day to see a new WML wiz is joining the ranks.
QFT :D
Check out my campaign Sweet Revenge!
Join the new R2D forum!

Carda
Posts: 11
Joined: December 21st, 2010, 2:20 pm

Re: Script command to give XP to a unit?

Post by Carda » January 3rd, 2011, 9:13 am

Thank you all for the detailed responses.

I tried reading the Lua manual about store_unit and such but if I don't have a working example before my nose that manual is still a bit too complicated for me. So I just started copying/paste a few examples you people gave here and I found a working example in bigkahuna's version. If works combined with a event like 'a unit moves to a specific coordinate' *big cheer*.

Going to study this further because I have a feeling I can use this script for changing the value of Max HP and more which is badly needed at the moment on my map.

Great job all ,
Carda
Statements usable with store_unit found in Wesnoth Manual and added later to the post
* advances_to
* alignment
* alpha
* attacks_left
* canrecruit
* cost
* experience
* facing
* flying
* gender
* goto_x
* goto_y
* hitpoints
* id
* language_name (same as the name key in the unit config)
* max_experience
* max_hitpoints
* max_moves
* moves
* overlays
* resting
* side
* type
* unit_description
* unrenamable
* upkeep
* x
* y
* zoc
* [movement_costs]
* [defense]
* [resistance]
* [variables]
* [status]
* [attack]
* [modifications_description]
* [modifications]
10 FOR X = 0 TO 15
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10

User avatar
Reepurr
Posts: 1088
Joined: August 29th, 2010, 5:38 pm

Re: Script command to give XP to a unit?

Post by Reepurr » January 3rd, 2011, 9:49 am

Carda wrote:Going to study this further because I have a feeling I can use this script for changing the value of Max HP and more which is badly needed at the moment on my map.
Probably.

Code: Select all

[store_unit]
    [filter]
        x,y=$x1,$y1
    [/filter]
    kill=no
    variable=unit_stored
[/store_unit]
{VARIABLE_OP unit_stored.max_hitpoints add 100} 
# Can also be max_moves if you want, etc. - though if you want to
# give a unit more attacks you'll probably have to do a silent [object]
[unstore_unit]
    variable=unit_stored
[/unstore_unit]
"What do you mean, "a dwarvish dragonguard with marksman is overpowered"?"

Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!

Carda
Posts: 11
Joined: December 21st, 2010, 2:20 pm

Re: Script command to give XP to a unit?

Post by Carda » January 3rd, 2011, 6:18 pm

Yeah it's starting to work out. Thanks. Already mastered how to give HP, add MAX HP, Restore HP to full and XP giving.

Next problem:

{VARIABLE_OP unit_stored.moves value unit_stored.max_moves}

Why doesn't this work? It sets the moves to 0 instead of his maximum moves (5).

And by the way... with VARIABLE_OP I use ADD for + , but what word replaces - ? And is = really replaced by the word value?

Thanks for making everything clear again,
Carda
10 FOR X = 0 TO 15
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10

Ceres
Forum Regular
Posts: 620
Joined: September 18th, 2010, 7:56 pm
Location: Germany

Re: Script command to give XP to a unit?

Post by Ceres » January 3rd, 2011, 6:22 pm

If you want to set something to the value of a variable, you have to use a $ sign.
[set_variable]
name=myvariable
value=$anothervariable
[/set_variable]
would work.
Carda wrote:{VARIABLE_OP unit_stored.moves value unit_stored.max_moves}
should be changed to {VARIABLE_OP unit_stored.moves value $unit_stored.max_moves}

And - is set with 'sub'. * is done with 'multiply' and / with 'divide'.

Carda
Posts: 11
Joined: December 21st, 2010, 2:20 pm

Re: Script command to give XP to a unit?

Post by Carda » January 3rd, 2011, 6:25 pm

*CHEERS* A quick reply again. Was breaking my brain why it didn't work. Going to study your post and the difference with the $

Also thanks for SUB. I tried 'subtract' but that didn't work either (heheh)

Going to fix the problem in my map at once and thanks,
Carda
10 FOR X = 0 TO 15
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10

User avatar
bigkahuna
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: Script command to give XP to a unit?

Post by bigkahuna » January 3rd, 2011, 11:45 pm

Carda wrote:{VARIABLE_OP unit_stored.moves value $unit_stored.max_moves}
Actually this would be much better (and simpler!):

Code: Select all

{VARIABLE unit_stored.moves $unit_stored.max_moves}
Which makes variable "$unit_stored.moves" equal to "$unit_stored.max_moves".
Check out my campaign Sweet Revenge!
Join the new R2D forum!

Post Reply