Carda's bunch of daily Lua questions
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.
Carda's bunch of daily Lua questions
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
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
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10
Re: Script command to give XP to a unit?
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.
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."
Re: Script command to give XP to a unit?
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.
Re: Script command to give XP to a unit?
An easier way to do this would be
'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.
Code: Select all
[modify_unit]
[filter]
id=$unit.id
[/filter]
experience=100
[/modify_unit]
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Script command to give XP to a unit?
This should work if you have 1.9.x. Else use:Ceres wrote:An easier way to do this would be'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.Code: Select all
[modify_unit] [filter] id=$unit.id [/filter] experience=100 [/modify_unit]
Code: Select all
{MODIFY_UNIT x,y=$x1,$y1 experience 100}
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
Re: Script command to give XP to a unit?
Neither of those work.LightFighter wrote:This should work if you have 1.9.x. Else use:
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.
Re: Script command to give XP to a unit?
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]
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Script command to give XP to a unit?
Well done! You even remembered the quote marks.Ceres wrote:Corrected version of my code adding the experience instead of setting:
This made my day to see a new WML wiz is joining the ranks.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: Script command to give XP to a unit?
QFTSapient wrote:Well done! You even remembered the quote marks.
This made my day to see a new WML wiz is joining the ranks.
Re: Script command to give XP to a unit?
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
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
10 FOR X = 0 TO 15
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10
Re: Script command to give XP to a unit?
Probably.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.
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!
Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!
Re: Script command to give XP to a unit?
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
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
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10
Re: Script command to give XP to a unit?
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.
And - is set with 'sub'. * is done with 'multiply' and / with 'divide'.
[set_variable]
name=myvariable
value=$anothervariable
[/set_variable]
would work.
should be changed to {VARIABLE_OP unit_stored.moves value $unit_stored.max_moves}Carda wrote:{VARIABLE_OP unit_stored.moves value unit_stored.max_moves}
And - is set with 'sub'. * is done with 'multiply' and / with 'divide'.
Co-Creator of The Fellowship of the Clay (BfW 1.10) ~~ Maintainer of the German Code of Conduct
How to isolate problematic WML code ~~ WML error messages and their reasons
How to isolate problematic WML code ~~ WML error messages and their reasons
Re: Script command to give XP to a unit?
*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
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
20 POKE 53280,X ; PRINT " Hello World"
30 NEXT X
40 GOTO 10
Re: Script command to give XP to a unit?
Actually this would be much better (and simpler!):Carda wrote:{VARIABLE_OP unit_stored.moves value $unit_stored.max_moves}
Code: Select all
{VARIABLE unit_stored.moves $unit_stored.max_moves}