Quick help:Hunger reseting script
can somebody please make me a script that would feed all units on the battlefield evry 15 minutes or so ?
I am total noob when it comes to dynamic scripting so something i could just copy and paste.
procedure AutoFeed;
var
I, K: Integer;
UnitsToFeed: array of Integer;
begin
for I := 0 to 11 do
begin
UnitsToFeed := States.PlayerGetAllUnits(I);
for K := 0 to Length(UnitsToFeed) - 1 do
begin
Actions.UnitHungerSet(UnitsToFeed[K],States.UnitMaxHunger);
end;
end;
end;
procedure OnTick;
begin
if States.GameTime mod 9000 = 0 then // autofeed every 15 minutes
AutoFeed;
end;
Because it is for multiplayer i would prefer something time based that would use the code only every 15 mins.
And would also work for all players.
This should be fine
You could use States.LocationCount-1 instead of 11, and add a States.PlayerEnabled check to make sure the player ID is valid.
How would the code look like when only a specific player gets his hunger reset?
procedure AutoFeed(playerId:integer);
var
K: Integer;
UnitsToFeed: array of Integer;
begin
UnitsToFeed := States.PlayerGetAllUnits(playerId);
for K := 0 to Length(UnitsToFeed) - 1 do
begin
Actions.UnitHungerSet(UnitsToFeed[K],States.UnitMaxHunger);
end;
end;
procedure OnTick;
begin
if States.GameTime mod 9000 = 0 then // autofeed every 15 minutes
AutoFeed(1);
end;
procedure AutoFeed(playerID:integer);
var
K: Integer;
UnitsToFeed: array of Integer;
begin
UnitsToFeed := States.PlayerGetAllUnits(playerID - 1);
for K := 0 to Length(UnitsToFeed) - 1 do
begin
Actions.UnitHungerSet(UnitsToFeed[K],States.UnitMaxHunger);
end;
end;
procedure OnTick;
begin
if States.GameTime mod (30*60*10) = 0 then // Autofeed every 30 minutes
begin
AutoFeed(playerID);
end;
end;
Users browsing this forum: Google [Bot] and 2 guests
Powered by phpBB® Forum Software © phpBB Group Designed by ST Software |