Mod to Random Units
Moderator: Forum Moderators
Mod to Random Units
I'm using Random Units in the Ageless Era with the Random Campaign, lots of fun. But I wanted the Random Units to only be for the human side. In Radom_Units.lua at line 188 I added
So;
It works. If anyone knows a better way to do it?
Also, I'm not sure how the community feels about uploading mods to addons, which is why I simply posted the code here, in case anyone else wants to try it.
How would I go about make all the human side recruits start at lvl 1? I figure it's here;
Maybe I can simply return 1?
if wesnoth.sides[wesnoth.current.side].controller == "human" then
So;
onEvent(
'recruit',
function()
if wesnoth.sides[wesnoth.current.side].controller == "human" then
setRandomRecruit(wesnoth.sides[wesnoth.current.side], options) end end)
It works. If anyone knows a better way to do it?
Also, I'm not sure how the community feels about uploading mods to addons, which is why I simply posted the code here, in case anyone else wants to try it.
How would I go about make all the human side recruits start at lvl 1? I figure it's here;
local function levelWeight(level)
return 6 - level
end
Maybe I can simply return 1?
Re: Mod to Random Units
This add-on is under the GPL, so you have the right to upload a tweaked version of this code under a different name. I've already ported this to Wesnoth 1.15, so that's the only version I'm maintaining right now. I might be willing to add some options to avoid you having to port your fork when you upgrade Wesnoth. If you're familiar with git, you can clone it from https://github.com/luther9/Random_UnitsAlso, I'm not sure how the community feels about uploading mods to addons, which is why I simply posted the code here, in case anyone else wants to try it.
However, when I look up the
controller
attribute at https://wiki.wesnoth.org/LuaWML/Sides#wesnoth.sides, I see this: "note: In networked multiplayer, the controller attribute may not be the same on all clients. Be very careful or you'll have OOS errors." I don't know why the controller would be different for different clients, but apparently, it's unsafe to use that attribute in a mod that may be used in multiplayer.No, that function sets a probability weight that's used to make low level units more common than high level ones. Instead, look atHow would I go about make all the human side recruits start at lvl 1? I figure it's here;
W.randomUnits_loadUnitTypes
and try changing the if
statement to if not unitType.do_not_list and unitType.level == 1 then
(untested). Remember that some units are level 0. I assume you want to skip those. We could maybe add a checkbox option that restricts the unit selection to level 1.Re: Mod to Random Units
It is not explicitly unsafe, but controller has behaved differently in different wesnoth versions. You would need to test if it fits your use case with the version you develop for.
Reasoning for that note is that at some point it was decided to not publish if side is controlled by player, or player has set it to ai. And in such case it might be needed to load controller as that player in unsynced manner, and then sync it later.
Reasoning for that note is that at some point it was decided to not publish if side is controlled by player, or player has set it to ai. And in such case it might be needed to load controller as that player in unsynced manner, and then sync it later.
Re: Mod to Random Units
It works!
Now that I understand, I took a wild guess;
And this seemed to work well in playtesting. I seemed to have only gotten Loyalists and boats. Does it use units from faction addons, or only default?
I'm going to try
Now that I understand, I took a wild guess;
if not unitType.do_not_list and unitType.level == 1 and unitType.alignment == "lawful" then
And this seemed to work well in playtesting. I seemed to have only gotten Loyalists and boats. Does it use units from faction addons, or only default?
I'm going to try
unitType.level <= 1
and unitType.alignment ~= "chaotic"
next.Re: Mod to Random Units
So how would we test it to see if it works? bil is checking the controller at every recruit event, but it's conceivable that we might only check it at the prestart event. (I'm not sure it would make sense to change the recruit list every time a player enters or leaves the game.)Ravana wrote: ↑July 26th, 2021, 9:25 am It is not explicitly unsafe, but controller has behaved differently in different wesnoth versions. You would need to test if it fits your use case with the version you develop for.
Reasoning for that note is that at some point it was decided to not publish if side is controlled by player, or player has set it to ai. And in such case it might be needed to load controller as that player in unsynced manner, and then sync it later.
Re: Mod to Random Units
Prestart would be quite safe time, noone has had chance to droid their side yet.
In general I would test OOS kind of aspect by using wesnoth.message and being in game with 2 clients.
In general I would test OOS kind of aspect by using wesnoth.message and being in game with 2 clients.
Re: Mod to Random Units
I assume you're on Wesnoth 1.14, because Random Campaign isn't on the 1.15 server yet. That version only includes units from core and Era of Myths. The one for 1.15 only uses core, because EoM wasn't uploaded when I checked.
The units to be included must be hard-coded in _main.cfg, inside
[randomUnits_loadUnitTypes]
. This is mainly because different players in multiplayer will have different add-ons installed.Sounds interesting. Let me know what works best for you. This will help me decide what filtering options I might want to add.I'm going to tryunitType.level <= 1
andunitType.alignment ~= "chaotic"
next.
Re: Mod to Random Units
unitType.level <= 1
Didn't seem to do anything, all units were 1. unitType.alignment ~= "chaotic"
totally worked. I'm thinking anything that falls under unitType would work as a filter. Gender, Race, Usage, even Cost.My next change, I'm interested to see if I can get the recruit list to show 2 or 3 different choices. When the choice is made, then the next recruit will show 2 or 3 different options.