need help in small lua code for ageless WC2
Moderator: Forum Moderators
need help in small lua code for ageless WC2
Hi,
so I found this bit of code in Wesnoth1.14\data\add-ons\World_Conquest_II\lua\bonus
So i am not sure, but I think that this part is responsible for one of the 3 variants of map bonuses being chose, e.g. 1=training,2=artifact,3=hero
So what I am trying to do, is since Ageless has 100 factions or so, I want to single out from group of 'heroes' it chooses them.
So I created in \Wesnoth1.14\data\add-ons\World_Conquest_II\utils\era\campaign\heroes many groups besides default, and at the bottom you can see 'bonus_all' group, that is basically all the units in the game available, and also I created a group called 'dudes' - they are basically 9 other groups.
So how would I get the lua to select a random unit from that group/types called 'dudes' (I guess there are about 70 or 80 units in that group) instead of going through all the hero types available.
Thanks in advance
so I found this bit of code in Wesnoth1.14\data\add-ons\World_Conquest_II\lua\bonus
Code: Select all
elseif bonus_type == 3 then
bonus_subtype = bonus_subtype or bonus.get_random_hero()
bonus.found_hero(ec, bonus_subtype)
end
bonus.post_pickup(side_num, ec.x1, ec.y1)
assert(wc2_dropping.item_taken, "item still there")
end
function bonus.get_random_item()
return tonumber(wc2_utils.pick_random("wc2.random_items", wc2_artifacts.fresh_artifacts_list))
end
So what I am trying to do, is since Ageless has 100 factions or so, I want to single out from group of 'heroes' it chooses them.
So I created in \Wesnoth1.14\data\add-ons\World_Conquest_II\utils\era\campaign\heroes many groups besides default, and at the bottom you can see 'bonus_all' group, that is basically all the units in the game available, and also I created a group called 'dudes' - they are basically 9 other groups.
So how would I get the lua to select a random unit from that group/types called 'dudes' (I guess there are about 70 or 80 units in that group) instead of going through all the hero types available.
Thanks in advance
Re: need help in small lua code for ageless WC2
First I would look up the definition of bonus#get_random_hero function.
Re: need help in small lua code for ageless WC2
hmm could that be this?
Code: Select all
function wesnoth.wml_actions.wc2_random_hero(cfg)
local side_num = cfg.side or helper.wml_error("missing side= attribute in [wc2_initial_hero]")
local x = cfg.x or helper.wml_error("missing x= attribute in [wc2_initial_hero]")
local y = cfg.y or helper.wml_error("missing y= attribute in [wc2_initial_hero]")
local t = wc2_era.pick_deserter(side_num)
wc2_heroes.place(t, side_num, x, y)
end
Re: need help in small lua code for ageless WC2
I think what you need is in file "era.lua". There is a global function wc2_era#generate_bonus_heroes defined there, on which bonus#ger_random_hero relies on.
Code: Select all
function wc2_era.expand_hero_types(types_str)
local types = wc2_utils.split_to_array(types_str)
local types_new = {}
local types_res = {}
while #types > 0 do
for i,v in ipairs(types) do
if wesnoth.unit_types[v] then
table.insert(types_res, v)
else
local group = wc2_era.hero_types[v] or helper.wml_error("invalid group id '" .. v .. "'")
wc2_utils.split_to_array(group.types, types_new)
end
end
types = types_new
types_new = {}
end
remove_dublicates(types_res)
return types_res
end
Code: Select all
function wc2_era.generate_bonus_heroes()
return wc2_era.expand_hero_types("Bonus_All")
end
Re: need help in small lua code for ageless WC2
thanks man i will try it out now
Re: need help in small lua code for ageless WC2
Bladget it worked, thanks a bunch for giving your time to look into this! Peace out! =)