Latest Posts

Topic: Copy Paste Script

Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2021-02-14, 20:13

This is the copy paste script i use to copy a map area x times to the right. It makes it much easier to create the same landmass and resources and for an arbitrary amount of players. Adjust the coordinates to your own case and give it some time for bigger maps. The editor might look frozen but it will work. Place in your main (widelands.exe) folder and open with a text editor.


Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2021-02-14, 20:17

Hm i could not attach the *.lua file, so you have to create it your own

players = 4

-- Make sure these coordinates and the loop below don't exceed your map dimensions!!
-- They should scan your first player area and stamp it down for the players to the right.
-- If you want to copy in a grid, first copy x times to the right, then attach the "+(a*32)" to the y in the same line.

for x = 0, 31 do
for y = 0, 95 do

copy=wl.Editor().map:get_field(x, y)

  for a = 1, players-1 do

  paste=wl.Editor().map:get_field(x+(a*32), y)

  paste.terr=(copy.terr)
  paste.terd=(copy.terd)
  paste.height=(copy.height)
  paste.resource=(copy.resource)
  paste.resource_amount=(copy.resource_amount)

  if paste.immovable ~= nil then
  paste.immovable:remove()
  end

  if copy.immovable ~= nil then
  wl.Editor().map:place_immovable(copy.immovable.descr.name, paste)
  end

  end

end
end

Edited: 2021-02-15, 18:11

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2550
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2021-02-15, 16:09

Edit: Attaching lua scripts do work, see attachment. Does your the file have the extension .lua?

Nice script face-smile.png

You might want to get the maps width and height automatically and make a check if this doesn't fit:

width = wl.Editor.().map.width
height = wl.Editor().map.height

if width < players*32 then

   --do stuff

end
Edited: 2021-02-15, 16:10

Attachment:
editor_copy_script_from_gilb.lua (795 bytes)

Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2021-02-15, 18:09

Yes, it's a .lua file. Error was something like "...looks like code, but we think it is text."

I thought about map.width and so on too, but guess i made a mistake implementing it, so i just stood with the numbers. If you want to copy in a grid you need 2 runs with different area too.


Top Quote
Alasia
Avatar
Joined: 2020-04-26, 05:07
Posts: 15
Ranking
Pry about Widelands
Location: Australia
Posted at: 2024-09-25, 08:41

Hi Glib (and Kaputtnik)

Thank you very much for sharing this example - it's been really helpful for me to look at and use and learn from. Reading through some of your other posts Glib, I see the learning curve you went through to get this script working, which makes me appreciate it even more.

I realise that this post is some years old now, but your script worked for me and so I wanted to say thank you for sharing.

Edit: I just now discovered an add-on which I shall play with, but my point stands - I learned from this and am still glad you shared it! :o)

Cheers, Alasia

Edited: 2024-09-25, 08:50

github: Alasiax

Top Quote