BuildingMultiplayerExamples
From Wesnoth
Attention: This page has been marked for review for version 1.4. The information contained here appears to be outdated or obsolete.
If you can, please take the time to review and edit it to bring it up to date (if needed) for the lastest version of Wesnoth. For more information and discussion, check the appropriate thread in the fora.
Once this is done, remove this notice
Remarks on random may need revision.
Hopefully BuildingMultiplayer has shed some light on how a multiplayer scenario is structured. This is an example scenario to show you how to add units, labels, and objects to the map.
[multiplayer]
id=multiplayer_retlin
name= _ "Retlin's Awesome Map"
map_data="border_size=1
usage=map
Gs^Fp, Gs^Fp, Hh, Mm, Gs^Fp, Gg, Hh, Gg, Gg, Gg, Wwf
Gs^Fp, Gs^Fp, Hh, Mm, Gs^Fp, Gg, Hh, Gg, Gg, Gg, Wwf
Gg^Ve, Gg, Hh, Gg, Gg, Gg, Gg, Ch, Ch, Ch, Wwf
Gg, Gg, Mm, Gs^Fp, Gg, Re, Re, Ch, 1 Kh, Ch, Wwf
Gg, Gg, Gg, Re, Re, Gg, Hh, Gg, Ch, Wwf, Re
Gg, Re, Re, Gg, Gg, Gg, Gs^Fp, Wwf, Wwf, Ww, Ww
Re, Gg, Gg, Gg^Vh, Gg, Hh, Gg^Ve, Wwf, Ww, Gg, Gg
Re, Gs^Fp, Gg, Hh, Gs^Fp, Wwf, Gs^Fp, Wwf, Ww, Gg, Ss
Re, Gs^Fp, Hh, Wwf, Ww, Ww, Ww, Ww, Ww^Vm, Ww, Gg
Re, Mm, Mm, Ww, Ww, Gs, Ww, Ww, Wo, Ww, Gg
Re, Hh, Hh, Ww, Ww, Rr, Gs, Gs, Ww, Ww, Ww
Re, Gs^Fp, Gg, Gg, Wwf, Wwf, Gs^Fp, Rr, Gs, Rr, Wwf
Re, Wwf, Gg, Mm, Wwf, Ww, Wwf, Ww, Gs, Gs, Gs^Fp
Ww^Bw|, Wwf, Gs^Fp, Ss, Gg, Gg, Ww, Ww, Ww, Ww, Gs
Re, Re, Hh, Gs^Fp, Ss, Ss, Gg, Ww, Wo, Ww, Ww
Re, Gs^Fp, Mm, Ss, Ss, Ss, Gg, Gg, Ww^Vm, Wwf, Ww
Re, Re, Hh, Ss,Ss^Vhs, Ss, Ss, Gg, Ww, Wwf, Gs^Fp
Gg, Gg^Vh, Re, Re, Ss, Gg, Gg, Ww, Ww, Wwf, Gg^Ve
Gg, Gg, Gg, Mm, Re,Ww^Bw\, Ww, Wwf, Wwf, Gg, Mm
Gg, Hh, Gs^Fp, Hh, Gg, Ww, Re, Ch, Ch, Ch, Gs^Fp
Gs^Fp, Mm, Gs^Fp, Wwf, Wwf, Ww, Wwf, Ch, 2 Kh, Ch, Re
Ss, Gs^Fp, Wwf, Ww, Ww, Ww, Wwf, Gg, Ch, Gg, Gg
Ss, Gs^Fp, Wwf, Ww, Ww, Ww, Wwf, Gg, Ch, Gg, Gg"
description= _ "This will be my own super cool map with lots of extra units."
{DEFAULT_SCHEDULE}
[side]
side=1
canrecruit=yes
controller=human
team_name=north
[/side]
[side]
side=2
canrecruit=yes
controller=human
team_name=south
[/side]
# Comments are preceded with the # symbol
# Labels do not go inside [event] tags. Place them anywhere inside the [scenario] tags.
[label]
x,y=10,10
text="Joe's House"
[/label]
[event]
name=prestart
# Place a picture on the map - note that this only places the picture and does NOT do
# anything when the player steps on it. There is a moveto event below that grants the
# player the item
[item]
x,y=5,13
image=items/holy-water.png
[/item]
# This event does not need to be inside prestart. It is convenient to place item
# events next to items, though, especially when using macros.
[event]
name=moveto
[filter]
x,y=5,13
side=1
[/filter]
[object]
id=holy_water_item
duration=forever
image=items/holy-water.png
name= _ "A bottle of holy water"
description= _ "This makes your melee weapon holy!"
[filter]
x,y=5,13
[/filter]
[then]
[removeitem]
x,y=5,13
[/removeitem]
[/then]
[effect]
apply_to=attack
range=melee
set_type=holy
[/effect]
[/object]
[/event]
# The holy water, or any other item defined in items.cfg, could have been placed with
# the following command:
# {OBJ_POTION_HOLY 5 13 holy_water_item}
[/event]
[event]
name=turn 2
# This unit will have a random name with no random traits
[unit]
type=Spearman
generate_description=yes
side=1
x,y=11,10
[/unit]
# This unit will have the name "Slasher Joe" and be quick and intelligent
[unit]
type=Swordsman
description=Slasher Joe
side=1
x,y=10,10
{TRAIT_QUICK}
{TRAIT_INTELLIGENT}
[/unit]
# There is a key random_traits=yes that will generate random traits in a unit
[unit]
type=Pikeman
description=Spiky John
side=1
x,y=11,11
random_traits=yes
[/unit]
[message]
description=Slasher Joe
message= _ "Honey, I'm home! I brought a friend for dinner!"
[/message]
[/event]
[/multiplayer]
Random
It's possible to make random work in MP scenarios but there are a few caveats to keep in mind. The problem is that random is initialized once and needs to be kept in sync on all clients. That means that if random gets called more often on one client than on the others, they get out-of-sync. This happens in all select and ai turn events (so you cannot use random here). There are other situations not related to the type of event where code might not execute on all clients, an example of what this means follows. NOTE the new feature only works with the rand key and not with random
[event]
name = turn 3
[message]
side_for=2
message= _ "Play the casino!"
[option]
message="Yes, I'll bet 100 gold."
[command]
{RANDOM 0..200}
{MY_ADJUST_SIDE_GOLD_MACRO 2 $random}
[/command]
[/option]
[option]
message= _ "Not interested."
[/option]
[/message]
[/event]
Player 2 gets the chance to get his client's rand out of sync. Even if the message and options were displayed for all players, they could still make different choices (leading to {RANDOM} getting executed or not)! Moved out of the message, it would work:
[event]
name = turn 3
{RANDOM 0..200}
[message]
side_for=2
message= _ "Play the casino!"
[option]
message="Yes, I'll bet 100 gold."
[command]
{MY_ADJUST_SIDE_GOLD_MACRO 2 $random}
[/command]
[/option]
[option]
message= _ "Not interested."
[/option]
[/message]
[/event]
The {RANDOM} is now used by all players, but only used by player 2 if he makes the corresponding choice.
See Also
- Create
- BuildingMultiplayer
- ScenarioWML
- DirectActionsWML
- InterfaceActionsWML
- SingleUnitWML
- FilterWML
- EventWML
- EffectWML
