Map Database  •  FAQ  •  RSS  •  Register  •  Login

Quick help:Hunger reseting script

Post a reply

Smilies
:arrow: (H) :'( :O :@ (!) :( :idea: :lol: :mad: :mrgreen: :| (?) :P :$ :rolleyes: (6) :D :) :o :? :wink:
View more smilies
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: Quick help:Hunger reseting script

Post by Just_Harry » 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

Post by Black » 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;   

Post by Just_Harry » 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.

Post by Black » 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 ;)

Post by Just_Harry » 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?

Post by grayter » 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;

Post by Just_Harry » 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?

Post by FatheriatorCZ » 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.

Post by Black » 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 :)

Post by FatheriatorCZ » 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.

Post by Esthlos » 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

Post by Black » 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;

Post by FatheriatorCZ » 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.

Post by Esthlos » 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;

Post by FatheriatorCZ » 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.

Top