Difference between revisions of "LuaWML/Sides"
(→wesnoth.sides) |
(→wesnoth.sides: Commit a8f625f: Added faction and faction name to Lua Side proxy) |
||
Line 25: | Line 25: | ||
* '''hidden''': boolean (read/write) | * '''hidden''': boolean (read/write) | ||
* '''name''': string (read) | * '''name''': string (read) | ||
+ | * '''faction''': {{DevFeature1.13|5}} id of the selected faction, string (multiplayer-only, read) | ||
+ | * '''faction_name''': {{DevFeature1.13|5}} name of the selected faction, string(multiplayer-only, read) | ||
* '''color''': string (read/write) | * '''color''': string (read/write) | ||
* '''recruit''': table of strings (read/write) | * '''recruit''': table of strings (read/write) |
Revision as of 18:48, 6 August 2016
This page describes the LuaWML functions and helpers for handling sides and villages.
Contents
wesnoth.sides
This is not a function but a table indexed by side numbers. Its elements are proxy tables with these fields:
- side: the side number
- gold, village_gold, base_income: integers (read/write)
- total_income: integer (read only)
- objectives, user_team_name: translatable strings (read/write)
- objectives_changed: boolean (read/write)
- team_name: string (read/write)
- controller: string (read/write) :
- note: In networked multiplayer, the controller attribute is ambiguous (won't be the same on all clients). Be very careful or you'll have OOS errors.
- The controller attribute has 6 possible values: human, network, ai, network_ai, null, idle.
- A local human should always be "human", a local ai should always be "ai", a remote human should always be "network". and a remote ai should always be "network_ai". An empty side should be null on all clients.
- An idle side should appear similarly as a "human" side for all sides that don't own the idle side, i.e. as "network".
- These values may be checked using lua, or the :controller command in game.
- This value can only be set to 'human', 'ai' or 'null'.
- fog: boolean (read)
- shroud: boolean (read)
- hidden: boolean (read/write)
- name: string (read)
- faction: (Version 1.13.5 and later only) id of the selected faction, string (multiplayer-only, read)
- faction_name: (Version 1.13.5 and later only) name of the selected faction, string(multiplayer-only, read)
- color: string (read/write)
- recruit: table of strings (read/write)
- scroll_to_leader: boolean (read/write)
- village_support: string (read/write)
- flag: string (read)
- flag_icon: string (read)
- defeat_condition: string (read/write) See description at SideWML, ScenarioWML#Scenario_End_Conditions
- lost: bool (read/write) If lost=true this side will be removed from the persitent list at the end of the scenario. This key can also be used to stop the engine from removing a side by setting it to false. Writing this key only works in a victory/defeat event.
- persistent (Version 1.13.5 and later only): boolean (read/write)
- __cfg: WML table (dump)
The metatable of these proxy tables appears as "side".
local team = wesnoth.sides[1] team.gold = team.gold + 50 wesnoth.message(string.format("%d sides", #wesnoth.sides))
wesnoth.get_sides
- wesnoth.get_sides(filter)
Returns a table array containing proxy tables for these sides matching the passed StandardSideFilter. The output is the same format as the wesnoth.sides table, above.
--set gold to 0 for all sides with a leader local sides = wesnoth.get_sides({ {"has_unit", { canrecruit = true }} }) for i,v in ipairs(sides) do v.gold = 0 end
wesnoth.get_village_owner
- wesnoth.get_village_owner(x, y)
Returns the side that owns the village at the given location.
local owned_by_side_1 = wesnoth.get_village_owner(12, 15) == 1
wesnoth.set_village_owner
- wesnoth.set_village_owner(x, y, side, [fire_events])
Gives ownership of the village at the given location to the given side (or remove ownership if none). Ownership is also removed if nil or 0 is passed for the third parameter, but no capture events are fired in this case. An optional 4th parameter (boolean true|false, default: false) can be passed determining whether to fire any capture events.
wesnoth.set_village_owner(12, 15, 1)
wesnoth.is_enemy
- wesnoth.is_enemy(side1, side2)
Returns true if side A is enemy of side B, false otherwise.
local enemy_flag = wesnoth.is_enemy(1, 3)
wesnoth.match_side
- wesnoth.match_side(side, filter)
Matches a side against a given StandardSideFilter.
wesnoth.message(tostring(wesnoth.match_side(1, {{"has_unit", { type = "Troll" }}})))
wesnoth.get_starting_location
- wesnoth.get_starting_location(side)
Returns the starting location of the given side.
local loc = wesnoth.get_starting_location(1) wesnoth.message(string.format("side 1 starts at (%u, %u)", loc[1], loc[2]))
helper.all_teams
- helper.all_teams()
Returns an iterator over teams that can be used in a for-in loop.
for team in helper.all_teams() do team.gold = 200 end