Resource icon

Extra Human-Player Units at Game Start 1.05

Sorry I didn't respond sooner, but THANK YOU! Works like a charm for Hotseat but there are two minor hiccups. I was playing with one other human.

1. Player 2 for some reason gets DOUBLE the units. I set it for players to get 5 extra scouts, builders, and settlers, but player 2 got 10 of each.
2. If you save and load on the very first turn (Player 1), then upon loading the game player 2 won't get any extra units at all.

Honestly not a huge deal but I Figured you'd want to hear about any bugs :). We just deleted the extra units for player 2.

Anyway thank you again gyogen. I really really appreciate you modding that in for me.
 
1. Player 2 for some reason gets DOUBLE the units. I set it for players to get 5 extra scouts, builders, and settlers, but player 2 got 10 of each.

Remove the line:
Events.LocalPlayerChanged.Add( OnPlayerTurnActivated );
at the bottom of the ScoutSpawn.lua and this will stop. I forgot to remove when I changed file.
 
Is there a limit on the number of different units to start the game with? I ask because I wanted to start with 2 settlers, 1 Builder, 1 scout, 1 Slinger and for those pesky barb horseman 2 Spearman for defence.
I am able to get it to work with the 4 units but as soon as I add the 5th unit it doesn't work. There are no errors or anything it just loads the default settler and warrior.
 
I just tried with six different units and it worked:
upload_2016-11-28_6-53-53.png

Might you have accidentally made a mistake in code? There where no errors in lua log?
 
Well, it appears I must have done something wrong then. I know my code knowledge is a bit old. I'll try again

Where is the Lua log? will that show what didn't load?
 
Thanks Gyogen2
I re-download and it's working now. It must have been a typo somewhere but I couldn't see where

This is a great mod to help against those early horseman barb rush's

Thanks
 
While I was trying this out I bumped the number of builders up to 12 and ran into a an unexpected problem. On one game start I couldn't end my turn because I didn't have anywhere for the builders to go so I was left with a couple still in a stack unable to move.

I've tried making a few changes to the script to spread the units out but I haven't had any luck yet. This is my first foray into modding and my first time using lua, so I'm not quite sure how to go about this. My initial experiment was as simple of an idea as I could come up with but it didn't work:
if numSettlers > 0 then
plotOffSet = 0;
for i = 1, numSettlers do
for direction = 1, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
adjacentPlot = Map.GetAdjacentPlot((lastPlot:GetX() ), lastPlot:GetY(), direction);
if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) and plotOffSet >= i then
break
end
plotOffSet = plotOffSet + 1;
end
pUnit2 = playerUnits:Create(iSettler, adjacentPlot:GetX(), adjacentPlot:GetY())
lastPlot = Map.GetPlot(pUnit:GetX(), pUnit:GetY());
end
end

It basically just caused it to stop working altogether and I'm pretty sure thats just because of my complete lack of of experience with lua. Any advice would be welcome!
 
... lastPlot should get plot of last unit spawned (so should be pUnit2:Get... not pUnit)...

Thanks for the response @gyogen2 !

The script just started to make a lot more sense to me now, I actually thought pUnit and pUnit2 were functions of some sort that I wasn't understanding, I think I get it now. I'll definitely play with this later when I get home.

Additional question if you don't mind, how does the direction parameter work in the GetAdjacentPlot function? Is it just a 1-6 value with 1 being toward the right and continuing around clockwise? If I have any success with the above perhaps I'll try finding a way to get units to spawn around the starting position rather than just to the right of it.
 
Yeah, I don't think I really need or want that many extra units, it would be a pretty overwhelming advantage, but I'm curious now to see if I can get it to work. It's been kind of fun so far:)

I've had limited success, my biggest obstacles are how long it takes to test each change (starting a new game) and trying to find debugging info. I read somewhere that errors show up in lua.log but it's inconvenient to sift through.

My thought at the moment is to place the units one plot from the initial settler in a circle, then 2 plots away from the settler, etc. I have also been toying with splitting the units to be added into builders/settlers and the rest of them, so each plot could have one builder or settler, and one military unit. If I manage to figure it out I'll be sure to share.
 
You could also rearrange the position of the create function like so:
Code:
repeat
    for direction = 0, DirectionTypes.NUM_DIRECTION_TYPES - 1, 1 do
            adjacentPlot = Map.GetAdjacentPlot(lastPlot:GetX(), lastPlot:GetY(), direction);
            if (adjacentPlot ~= nil) and not (adjacentPlot:IsWater() or adjacentPlot:IsImpassable()) then
                if numScouts > 0 then
                    pUnit = playerUnits:Create(iScout, adjacentPlot:GetX(), adjacentPlot:GetY());
                    numScouts = numScouts -1
                end
            end
    end
until numScouts = 0

Haven't tested, but should work.
 
Back
Top Bottom