Page 1 of 1

how to set human name and nation automatically

Posted: Wed Apr 18, 2018 1:53 am
by Dino the Dinosore
Now that I've figured out how to get my custom ruleset working, there's another thing I'd like. I always play with the same nation and leader name, and I'd like that to happen when I select my ruleset. My attempt in script.lua is -

Code: Select all

function set_human_name()
  human = find.player(0)
  human.name = "Dino"
  human.nation = find.nation_type("American")
  return true

signal.connect("map_generated", "set_human_name")
but it fails. I think it's because the event signal name "map_generated" is in the Server (ruleset) only scope and the Player name and nation variables are in the Game scope.
Anyone have an idea how to do this? or is it not possible?

Re: how to set human name and nation automatically

Posted: Thu Apr 19, 2018 8:12 am
by meynaf
Same problem for me.
I wanted to edit the ".serv" for my ruleset to emit commands that would choose the player and nation.
But i didn't find any server command able to do that : create just renames the first AI player, take says already taken, start has no parameter and does not allow choosing the nation, set allows choosing the nationset but not the nation itself, etc.

Re: how to set human name and nation automatically

Posted: Thu Apr 19, 2018 7:05 pm
by mir3x
U can only use function with edit.*** to change such things
http://freeciv.wikia.com/wiki/Lua_reference_manual <-(See those edit.functions)

There is no edit for this.
Its not working bc somethign like this wont work too:
human.gold = 99999999999
It doesnt go outside lua scope.
U would need to use edit.change_gold(human, 999999)

Closest thing I could do with that lua is just change name of next AI after human.

Code: Select all

function set_human_name()
signal.list()
    for player in players_iterate() do 
    if player.is_human then
      local extra_gold = math.floor(10 * player:gold())
      edit.create_player("Dino", player.Nation_type, nil)
    end
  end
end
signal.connect("map_generated", "set_human_name")
player.Nation_type is some monster structure - u can only copy it from another player. In theory that script should create extra player with the same nation as you named "Dino". In practise it changes next AI name to "Dino".

U need iterate via all players to find human - players_iterate() - bc u usually are not first, even if u were lucky to be first Im not sure if u woudl have index 0.

I've created simple script to double gold for each human:

Code: Select all

function richmode()
    for player in players_iterate() do
    if player.is_human then
      edit.change_gold(player, player:gold())
    end
  end
end
signal.connect("turn_started", "richmode")
I tried twith signal map_created and it didnt worked, maybe players have no gold then or even are not created yet ...

U can find some nice lua script in empires ruleset - google it.

Re: how to set human name and nation automatically

Posted: Sun May 27, 2018 1:42 am
by Dino the Dinosore
After digging some more I have to agree it is not currently possible to do this. Since I'm not the only one interested, I'll post a request on the Wishlist section.