Map Database  •  FAQ  •  RSS  •  Register  •  Login

Quick help:Hunger reseting script

<<

FatheriatorCZ

Serf

Posts: 8

Joined: 22 Apr 2016, 19:09

KaM Skill Level: Fair

Post 23 Apr 2016, 05:18

Quick help:Hunger reseting script

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

Esthlos

User avatar

Knight

Posts: 672

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 23 Apr 2016, 08:10

Re: Quick help:Hunger reseting script

If you only want to feed warriors, it shouldn't be necessary to make it time-based:

  Code:
procedure OnGroupHungry(aGroup: Integer);
begin
  Actions.GroupHungerSet(aGroup, States.UnitMaxHunger);
end;
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"
<<

FatheriatorCZ

Serf

Posts: 8

Joined: 22 Apr 2016, 19:09

KaM Skill Level: Fair

Post 23 Apr 2016, 16:45

Re: Quick help:Hunger reseting script

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

Black

User avatar

Warrior

Posts: 113

Joined: 20 May 2015, 20:14

Location: Italy

KaM Skill Level: Average

Post 23 Apr 2016, 18:00

Re: Quick help:Hunger reseting script

This should be fine :wink:
  Code:
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;
<<

Esthlos

User avatar

Knight

Posts: 672

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 23 Apr 2016, 20:34

Re: Quick help:Hunger reseting script

FatheriatorCZ wrote: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.

The code I posted will work for every player and feed the troops whenever they're hungry (which is a bit less often than once every 15 minutes). (H)

Black wrote:This should be fine :wink:

You could use States.LocationCount-1 instead of 11, and add a States.PlayerEnabled check to make sure the player ID is valid. :P
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"
<<

FatheriatorCZ

Serf

Posts: 8

Joined: 22 Apr 2016, 19:09

KaM Skill Level: Fair

Post 24 Apr 2016, 06:51

Re: Quick help:Hunger reseting script

Thank you for help i can not make esthlos code working but it is probably my fault.
Blackś code works just fine i have to put it trought some performance testing but it should be fine.
Thank you both for your time an effort.
<<

Black

User avatar

Warrior

Posts: 113

Joined: 20 May 2015, 20:14

Location: Italy

KaM Skill Level: Average

Post 24 Apr 2016, 11:03

Re: Quick help:Hunger reseting script

Esthlos wrote:You could use States.LocationCount-1 instead of 11, and add a States.PlayerEnabled check to make sure the player ID is valid. :P


Yes it will be better :)
<<

FatheriatorCZ

Serf

Posts: 8

Joined: 22 Apr 2016, 19:09

KaM Skill Level: Fair

Post 30 Apr 2016, 11:33

Re: Quick help:Hunger reseting script

Well thanks for your help and i am sorry for bothering you, but is there some kind of script which does sometching when you destroy said hose or group?
It would have to bee something where you just put coordinates, type and player not the ID that scripts from the tutorial require.
<<

Just_Harry

Militia

Posts: 46

Joined: 15 Feb 2018, 22:04

KaM Skill Level: Veteran

Post 17 Feb 2018, 11:24

Re: Quick help:Hunger reseting script

Hi there.
How would the code look like when only a specific player gets his hunger reset?
<<

grayter

Barbarian

Posts: 101

Joined: 18 Aug 2014, 12:06

Location: Poland

KaM Skill Level: Skilled

Post 17 Feb 2018, 12:04

Re: Quick help:Hunger reseting script

Just_Harry wrote:How would the code look like when only a specific player gets his hunger reset?


  Code:
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;
<<

Just_Harry

Militia

Posts: 46

Joined: 15 Feb 2018, 22:04

KaM Skill Level: Veteran

Post 09 Mar 2018, 16:30

Re: Quick help:Hunger reseting script

Hey thanks for the reply. Im completely noob.. xD what do i need to write if i want for example loc 3 being autofeed? or if more locations but not all get autofeed. Do I just simply need to replace "playerID" with 1 for loc1 etc?
<<

Black

User avatar

Warrior

Posts: 113

Joined: 20 May 2015, 20:14

Location: Italy

KaM Skill Level: Average

Post 10 Mar 2018, 18:02

Re: Quick help:Hunger reseting script

You should consider in script count start from 0; so if you want loc1 to be autofeeded you should write 0 in script, or simple modify the script like that.

  Code:
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;


Moreover to make this code work you should not modify nothing in the one here above, but call the procedure in another function. If you are not familiar with that just tell me ;)
<<

Just_Harry

Militia

Posts: 46

Joined: 15 Feb 2018, 22:04

KaM Skill Level: Veteran

Post 11 Mar 2018, 10:18

Re: Quick help:Hunger reseting script

How do i intergrate this script? I saved it as a .script dat in the missions folder..and it doesnt work somehow. Do they work for coop msiions? because i want to have all AI players not get hungry units but not the players.
<<

Black

User avatar

Warrior

Posts: 113

Joined: 20 May 2015, 20:14

Location: Italy

KaM Skill Level: Average

Post 11 Mar 2018, 15:13

Re: Quick help:Hunger reseting script

Because the code is not complete. Here it is a complete code that should work. You can simple copy and past in your script file and change in the Procedure OnTick; playerID with the player you want.
If you want more Ai player to be autofeeded simple add other AutoFeed(playerID) after the first one.

The script i make autofeed units every 30 minutes, which is enough cause soldier get hungry after 40 min iirc. You can change this value if you want ofc.

  Code:
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;   
<<

Just_Harry

Militia

Posts: 46

Joined: 15 Feb 2018, 22:04

KaM Skill Level: Veteran

Post 11 Mar 2018, 18:29

Re: Quick help:Hunger reseting script

Thank you very much now its works! Again sorry I am completely noob at scripting xD

Return to Dynamic Scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron