enclave's Lua thread

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

ok.. thanks for reply :)

I mean.. my nick is enclave, yours is gfgtdf
having scenario with my code (posted in previous message, and I need to keep this code for people to be able to make a team and still see where their starting position is.. so I use name for it) would rename my leader and your leader into Portugal and Spain..
so when I do "[store_side] variable=sideS..." and then use $sideS.name I will get Portugal and Spain.. the only place which would still have original names (enclave and gfgtdf) would be status table (Alt+s).. which shows names, team names, gold, gold income.. etc
And I have no idea how to get these names... (enclave and gfgtdf) because store_side doesn't capture them, it only returns leader names (Portugal and Spain).. but if the original names (enclave and gfgtdf) show in status, they must be still accessible somehow with lua?

I'm just trying to find way to rename leader names from Portugal and Spain back into enclave and gfgtdf when game started..
(it could be quicker to download New Settlers and run "NS South Europe" map with "use map settings" so you would understand exactly what I mean.. but I hope I was able to describe my problem better this time..? Thank you again in advance!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

wesnoth.wml_actions.message { message="player1name: " .. wesnoth.sides[1].name }
also returns Portugal unfortunately.. I need it to return enclave..

for team in helper.all_teams() do wesnoth.wml_actions.message { message="players names: " .. team.name } end
also says "Portugal", Spain.. etc.. need it to say enclave, gfgtdf.. etc..

wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.mp_settings.side_users }
gives nothing..
wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.mp_settings.side_users[1] }
gives error..

wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.era.leader[1]
gives error..

Code: Select all

		
local era = wesnoth.game_config.era
local count = 0
wesnoth.set_variable("era_name", era.name)
for multiplayer_side in helper.child_range(era, "multiplayer_side") do
    count = count + 1
    wesnoth.wml_actions.message { message="players names: " .. multiplayer_side.name }
	end
wesnoth.set_variable("num_factions", count)
doesnt give what I need.. plus it returns side names with picture.. something like "&units/humans/sergeant.png Humans"
doesnt give player names..

wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.era.multiplayer_sides.leader[1] }
wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.mp_settings.mp_era.leader[1]
error..
error..

At this point I give up for today..
Nobody really knows how to access status table Network players names (if you rename leader with canrecruit=yes into Dr Watson.. how to get enclave from it?)? :(
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

enclave wrote: wesnoth.wml_actions.message { message="players names: " .. wesnoth.game_config.mp_settings.side_users }
gives nothing..
Hmm this looks like the best approach to me. that fiels dis used to remember which side controls whcih side of the previosu scenario, so maybe it only works from the second scenario onwads?
enclave wrote: At this point I give up for today..
Nobody really knows how to access status table Network players names (if you rename leader with canrecruit=yes into Dr Watson.. how to get enclave from it?)? :(
Hmm the easiest way is most likeley to store the original name into a variable before renaming the side/unit.
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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

that's the problem... it is done before I can do anything... or I just don't know how..?

Code: Select all

[multiplayer]

id=NS_South_Europe
name="NS South Europe"
map_data="{~add-ons/New_Settlers/maps/NS_South_Europe.map}"
description="a cut of 18th Century Europe map for use with New Settlers Era Zombies Apocalypse"
experience_modifier=70%
turns=unlimited

{DEFAULT_SCHEDULE}
{DEFAULT_MUSIC_PLAYLIST}

#define NS_REG
gold=0
income=-2
fog=yes
shroud=no
village_gold=1
#enddef

[side]
side=1
team_name=Portugal
color=red
canrecruit=yes
controller=human
name=Portugal
{NS_REG}
[/side]
...
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

hmm maybe you shoudl just remove the name=Portugal from [side] and then rename the unit in a prestart event.
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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

thats another problem:)

i added it to [side] because I wanted players to know their starting positions.. (there was no other way I knew to add description..)
for example if host changes 4 sides into 1 team, it makes them all Portugal.. then the other players will not know where they start.. but having it in "name" shows them starting country.. so they can be in Portugal team, but still see they start in Italy..
but then their leaders become Italy etc also.. which is what I am trying to fix :D

My other map has names like "strong player", "weaker player", "middle ai"... so players can make AI into same team "zombies" and still see which ai is starting where... and may disable some if they like.. or put stronger players into harder starting positions.. etc..

So i thought maybe somebody knows lua way to access Status Table.. because there it shows all the network names as they are...
It's not toooo important for me, it just would be nice to fix it.. I just didn't expect this was such a rocket science as it turns to be :)
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

what you coudl try is the __cfg field of lua side objects.
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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

no idea how to do it, will try to search on it..
maybe you have tiny example?
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

untested code:

Code: Select all

for k,v in pairs(wesnoth.sides[1].__cfg) do
  if type(k) == "string" then  
    print(k .. "=" .. tostring(v))
  end
end
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.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Thank you very much gfgtdf for giving idea, I will try something with it. Will write the result. Thanks
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

haven't tried the __cfg thing yet.. because its obviously quite complicated.. so will require time and certain state of mood to dig into it..

but I just realized the #2 place where I see original names.. when people chat, all names shown are original.. not Leader unit names..
Maybe anyone knows way to access chat names in game? just realised.. (and since chat names are colored.. then they must have sides somewhere or color..)

Thank you!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Hi!
Anyone knows way to add hexes to map outside the map area? for example map is size 40x40, need to make it 41x41?
I know only 1 way to do it at the moment.. (may not even work) which is copy current map with [store_locations] then [replace_map] to something bigger from list of maps and then paste every hex back into place.. More peaceful solutions anyone?
Thank you!
GbDorn
Posts: 60
Joined: March 26th, 2014, 5:07 pm

Re: enclave's Lua thread

Post by GbDorn »

To get player's nick in MP, try this:

Code: Select all

wesnoth.sides[$side_you_want].__cfg.current_player
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

THANK YOU GbDorn!!!!!!!!!!! It works perfectly!!!! :) THANK YOU THANK YOU THANK YOU!!!!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

I have another lua question.. this one is easy.. if you know lua then you probably know the answer..

wesnoth.unit_defense(unit, terrain_code)

in this, what does "unit" mean? unit.type? unit.id? other? (if i transform wml variable into lua..)

Thank you!

PS. sorry I think I found the answer already...
its probably a different "unit"... one obtained by lua like this:

Code: Select all

   [lua]
      code=<<
         local x, y = wesnoth.current.event_context.x1, wesnoth.current.event_context.y1
         local u, t = wesnoth.get_units({ x = x, y = y })[1], wesnoth.get_terrain(x, y)
         wesnoth.set_variable("defense1", wesnoth.unit_defense(u, t))
         x, y = wesnoth.current.event_context.x2, wesnoth.current.event_context.y2
         u, t = wesnoth.get_units({ x = x, y = y })[1], wesnoth.get_terrain(x, y)
         wesnoth.set_variable("defense2", wesnoth.unit_defense(u, t))
...
if it doesn't work I may get back to this questions. Thanks for reading everyone...
Post Reply