Map Database  •  FAQ  •  RSS  •  Register  •  Login

Autofeed script for just recruits in towers




Posts: 101

Joined: 05 Aug 2013, 09:37

Location: at home

KaM Skill Level: Beginner

Post 10 Jun 2017, 21:27

Autofeed script for just recruits in towers

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?


User avatar


Posts: 622

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 11 Jun 2017, 06:44

Re: Autofeed script for just recruits in towers

You would get better results if you figured it out for yourself...

procedure OnTick;
  i, iPlayer: Integer;
  iUnits: array of Integer;
  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);

"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[i]) > 0) " checks that the unit "iUnits[i]" does have an home (Recruits could also have no home);
"(States.HouseType(States.UnitHome(iUnits[i])) = 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).
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"

Return to Dynamic Scripting

Who is online

Users browsing this forum: No registered users and 1 guest