Event that gives a unit for gold. Variables - Options wml
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.
Event that gives a unit for gold. Variables - Options wml
Ok, so maybe the title doesn't really explain perfectly, but I'd like an event where if your unit moves to a cave at 74,28, the unit sees a text like 'gold gold goooold' or something like that.
Then you can choose the give 1 gold, then 2 gold, then 3 gold etc. till 10. As long as you have the gold.
(So you'd have the options
"Throw a gold piece down there let's see what happens"
or
"Pahh. Who does this guy think he is? I need my own gold!")
In the Background I would like to calculate 1 gold = 10% chance that a unit joins you, 2 gold = 20%, 3 gold = 30% etc.
You can do this whenever your unit moves on the tile, until the unit joins you.
I hope that the event is clear.
I have so far avoided the options in dialogue and variables in wml, so I would greatly appreciate if someone explained it.
Second part, what would be a funny/interesting (maybe UMC) unit that could show up, thematically you are playing orcs and fighting other orcs, humans, elves and merfolk (in that szenario). mainly humans in the campaign.
Then you can choose the give 1 gold, then 2 gold, then 3 gold etc. till 10. As long as you have the gold.
(So you'd have the options
"Throw a gold piece down there let's see what happens"
or
"Pahh. Who does this guy think he is? I need my own gold!")
In the Background I would like to calculate 1 gold = 10% chance that a unit joins you, 2 gold = 20%, 3 gold = 30% etc.
You can do this whenever your unit moves on the tile, until the unit joins you.
I hope that the event is clear.
I have so far avoided the options in dialogue and variables in wml, so I would greatly appreciate if someone explained it.
Second part, what would be a funny/interesting (maybe UMC) unit that could show up, thematically you are playing orcs and fighting other orcs, humans, elves and merfolk (in that szenario). mainly humans in the campaign.
Re: Event that gives a unit for gold. Variables - Options wml
So you need to use [event] and [message].
Maintainer of Ageless Era. Ravana's Multiplayer Works
- Spannerbag
- Posts: 550
- Joined: December 18th, 2016, 6:14 pm
- Location: Yes
Re: Event that gives a unit for gold. Variables - Options wml
Hi,
this macro doesn't do what you want but might help a bit?
It's one of the core macros and it's in the
Cheers!
-- Spannerbag
this macro doesn't do what you want but might help a bit?
It's one of the core macros and it's in the
items.cfg
file.Code: Select all
#define ITM_WISHINGWELL X Y
# Places a wishing well that allows a player to drop in a coin to make a wish.
# There is no effect of the wish other than losing 1 gold.
[item]
x={X}
y={Y}
image=scenery/well.png
[/item]
[event]
name=moveto[url]
first_time_only=no
[filter]
x={X}
y={Y}
[/filter]
[message]
speaker=narrator
message= _ "You have come across a wishing well. What would you like to wish for?"
image=scenery/well.png
[option]
label= _ "A swift victory"
[command]
[gold]
amount=-1
side=1
[/gold]
[message]
speaker=unit
message= _ "With this golden coin, I wish that this battle end in a swift and safe victory."
[/message]
[/command]
[/option]
[option]
label= _ "Lots of gold"
[command]
[gold]
side=$side_number
amount=-1
[/gold]
[message]
speaker=unit
message= _ "I wish this single gold coin be returned ten-fold to me."
[/message]
[/command]
[/option]
[option]
label= _ "Peace throughout Wesnoth."
[command]
[gold]
side=$side_number
amount=-1
[/gold]
[message]
speaker=unit
message= _ "The only thing worth wishing for is peace throughout the land."
[/message]
[/command]
[/option]
[option]
label= _ "Don’t make a wish."
[/option]
[/message]
[/event]
#enddef[/url]
-- Spannerbag
Re: Event that gives a unit for gold. Variables - Options wml
thanks guys, I think I made it, in case anyone is interested here is my code:
Code: Select all
[event]
name=moveto
first_time_only=no
[filter]
side = 1
x=74
y=28
[/filter]
[fire_event]
name=goldder
[/fire_event]
[if]
[variable]
name=chancer
equals=0
[/variable]
[then]
[unit]
id=Volk
name= _ "Volk"
unrenamable=yes
type=White Mage
side=1
x,y=74,20
random_traits=no
[modifications]
{TRAIT_LOYAL}
[/modifications]
profile="portraits/volk.png"
[/unit]
[/then]
[/if]
[message]
speaker=Volk
message= _ "You gold, I fight!"
[/message]
[/event]
[event]
name = goldder
first_time_only=no
[store_gold]
side = 1
variable = current_gold
[/store_gold]
[if]
[variable]
name=dwarfIShere
equals=no
[/variable]
[then]
[message]
speaker=Tragtrad
message= _ "There is a sign here it just says... gold gold gooold"
[option]
[show_if]
[variable]
name=current_gold
greater_than_equal_to=$goldCounter
[/variable]
[/show_if]
label= _ "Throw "+ $goldCounter +" gold down there"
[command]
[gold]
amount=-$goldCounter
side=1
[/gold]
[set_variable]
name=chancer
value=$goldCounter
[/set_variable]
[fire_event]
name=getUnitRandom
[/fire_event]
[fire_event]
name=goldder
[/fire_event]
[/command]
[/option]
[option]
label= _ "My money is to rare."
[/option]
[/message]
[/then]
[/if]
[/event]
[event]
name=getUnitRandom
first_time_only=no
[message]
speaker = Tragtrad
message = "Nothing happened"
[/message]
[set_variable]
name=goldCounter
add=1
[/set_variable]
[lua]
code = <<
-- Get the value of the 'chancer' variable
local chance = wml.variables.chancer
print("Value of chance:", chance)
-- Roll a random number between 1 and 10
local dice_roll = math.random(1, 10)
print("Value of dice_roll:", dice_roll)
-- Check the 'chancer' value and set 'dwarfIShere' accordingly
if dice_roll <= chance then
wml.variables.dwarfIShere = true
wml.variables.chancer = 0
end
>>
[/lua]
[/event]
Last edited by Pentarctagon on November 24th, 2023, 6:49 pm, edited 1 time in total.
Reason: added [code]
Reason: added [code]
Re: Event that gives a unit for gold. Variables - Options wml
For reference you do not need Lua just for randomness.
Code: Select all
[set_variable]
name=random
rand=1..100
[/set_variable]
Maintainer of Ageless Era. Ravana's Multiplayer Works
Re: Event that gives a unit for gold. Variables - Options wml
Even worse: using math.rand will probably cause out of sync errors and corrupt replays, it's really better to use wesnoths Lua random function or just the Tag ravana mentioned.
Did you copy that part of the code from somewhere? Because their code might then be wrong too.
Did you copy that part of the code from somewhere? Because their code might then be wrong too.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: Event that gives a unit for gold. Variables - Options wml
ok I changed it, the code is now like that:
Also the code is from me. So no errors elsewhere
Code: Select all
#Süd-ost Zwerg Teil 1
[event]
name = dwarf_spawner
first_time_only=no
[store_gold]
side = 1
variable = current_gold
[/store_gold]
[if]
[variable]
name=doneD
equals=no
[/variable]
[then]
[message]
speaker=Tragtrad
message= _ "There is a sign here it just says... gold gold gooold"
[option]
[show_if]
[variable]
name=current_gold
greater_than_equal_to=$goldCounter
[/variable]
[/show_if]
label= _ "Throw "+ $goldCounter +" gold down there"
[command]
[gold]
amount=-$goldCounter
side=1
[/gold]
[set_variable]
name=random
rand=1..10
[/set_variable]
[if]
[variable]
name=random
less_than_equal_to=$goldCounter
[/variable]
[then]
[set_variable]
name=doneD
value=true
[/set_variable]
[unit]
id=Tester
name= _ "Brodoskie"
unrenamable=yes
type=Dwarvish Healer
side=1
x,y=73,28
random_traits=no
[modifications]
{TRAIT_LOYAL}
{TRAIT_RESILIENT}
[/modifications]
[/unit]
[message]
speaker=Tester
message= _ "You gold, I fight!"
[/message]
[/then]
[else]
[set_variable]
name=goldCounter
add=1
[/set_variable]
[fire_event]
name = dwarf_spawner
[/fire_event]
[/else]
[/if]
[/command]
[/option]
[option]
label= _ "My money is to rare."
[/option]
[/message]
[/then]
[/if]
[/event]
#süd ost Zwerg starter
[event]
name=moveto
first_time_only=no
[filter]
side = 1
x=74
y=28
[/filter]
[fire_event]
name = dwarf_spawner
[primary_unit]
id = unit
[/primary_unit]
[/fire_event]
[/event]