Page 1 of 1
					
				Quick help:Hunger reseting script
				PostPosted: 23 Apr 2016, 05:18
				by FatheriatorCZ
				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.
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 23 Apr 2016, 08:10
				by Esthlos
				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;
 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 23 Apr 2016, 16:45
				by FatheriatorCZ
				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.
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 23 Apr 2016, 18:00
				by Black
				This should be fine  
 
 
-   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;
 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 23 Apr 2016, 20:34
				by Esthlos
				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).  
 
 
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.  

 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 24 Apr 2016, 06:51
				by FatheriatorCZ
				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.
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 24 Apr 2016, 11:03
				by Black
				
You could use States.LocationCount-1 instead of 11, and add a States.PlayerEnabled check to make sure the player ID is valid.  

Yes it will be better  

 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 30 Apr 2016, 11:33
				by FatheriatorCZ
				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.
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 17 Feb 2018, 11:24
				by Just_Harry
				Hi there.
How would the code look like when only a specific player gets his hunger reset?
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 17 Feb 2018, 12:04
				by grayter
				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;
 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 09 Mar 2018, 16:30
				by Just_Harry
				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?
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 10 Mar 2018, 18:02
				by Black
				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 

 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 11 Mar 2018, 10:18
				by Just_Harry
				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.
			 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 11 Mar 2018, 15:13
				by Black
				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;    
 
			
					
				Re: Quick help:Hunger reseting script
				PostPosted: 11 Mar 2018, 18:29
				by Just_Harry
				Thank you very much now its works! Again sorry I am completely noob at scripting xD