Page 1 of 1

Autofeed script for just recruits in towers

PostPosted: 10 Jun 2017, 21:27
by TheRagingBullet
I want a script to autofeed the recruits in towers, i have no idea how to do this.
i've checked other scripts for autofeeding but they all seem for every unit.
when i try to make one myself by using Actions.Unithungerset and using unitid 13(which should be the one for recruits), nothing happens.
any ideas on how to do this right?

Re: Autofeed script for just recruits in towers

PostPosted: 11 Jun 2017, 06:44
by Esthlos
You would get better results if you figured it out for yourself...

Anyway:
  Code:
procedure OnTick; var i, iPlayer: Integer; iUnits: array of Integer; begin iPlayer := States.GameTime mod States.LocationCount; if States.PlayerEnabled(iPlayer) then begin iUnits := States.PlayerGetAllUnits(iPlayer); for i := 0 to Length(iUnits)-1 do if (States.UnitHome(iUnits[i]) > 0) then if (States.HouseType(States.UnitHome(iUnits[i])) = 18) then Actions.UnitHungerSet(iUnits[i], States.UnitMaxHunger); end; end;
"iPlayer := States.GameTime mod States.LocationCount;" defines which player are we doing this for; using this formula allows us to spread the load over time, thus resulting in a slightly smoother script; if you wanted to you could also add a delay, since it's not necessary to feed units this often (OnTick = 10 times per second).

"States.PlayerEnabled(iPlayer)" checks that that player is actually being played.

"States.PlayerGetAllUnits(iPlayer)" finds and writes down the IDs of all the units owned by iPlayer (the names by which the program calls each unit);
"(States.UnitHome(iUnits) > 0) " checks that the unit "iUnits" does have an home (Recruits could also have no home);
"(States.HouseType(States.UnitHome(iUnits)) = 18) " checks that said home is a Tower (Recruits could also live in the Barracks);
And finally "Actions.UnitHungerSet" feeds the Recruit (no need to check that it actually is a Recruit, since only Recruits can live in the Tower).