Map Database  •  FAQ  •  RSS  •  Login

Autofeed script for just recruits in towers

<<

TheRagingBullet

Warrior

Posts: 115

Joined: 05 Aug 2013, 09:37

KaM Skill Level: Beginner

Location: at home

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?
<<

Esthlos

User avatar

Knight

Posts: 676

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...

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).
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 7 guests