Page 1 of 1

Need a script for the map

PostPosted: 03 Oct 2014, 10:49
by Michalpl
So the script should do
show on script overlay amount of killed soldier for each player
show on script overlay time limit 4h that if runned out the winner will be the player with most kills

Re: Need a script for the map

PostPosted: 03 Oct 2014, 16:34
by Strangelove
I think you could adapt the script of "Coastal Encounter Scored" to your needs.

Re: Need a script for the map

PostPosted: 03 Oct 2014, 19:16
by Michalpl
Thanks but i could need more clear code than then one in coastal

Re: Need a script for the map

PostPosted: 04 Oct 2014, 09:32
by Esthlos
(4 hours is a lot... this script is set for 2 hours, you can edit this by changing aMaxTimeOut in OnMissionStart)
  Code:
var TheEndBye: Boolean; var aMaxTimeOut: Integer; var aCurrTimeOut: Integer; var aBest: array of Integer; var aPreviousS: Integer; var s: Integer; var m: Integer; var h: Integer; procedure OnMissionStart; begin TheEndBye := False; aMaxTimeOut := 72000 //Timer, in seconds times 10, at the moment it is 2 hours end; procedure OnTick; var i: Integer; var u: Integer; var t: Integer; var aCurrID: Integer; begin if TheEndBye = False then begin //Probably unneeded, but let's make sure that it will work. //Set overlay texts Actions.OverlayTextSet(-1, ''); for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); Actions.OverlayTextAppendFormatted(-1, '%s: '+IntToStr(t)+'|', [States.PlayerName(i)]); end; //Check time aCurrTimeOut := aMaxTimeOut-States.Gametime; if States.Gametime mod 10 = 0 then begin //No sense doing this more than once per second t := (aCurrTimeOut-(aCurrTimeOut mod 10))/10; s := t mod 60; //seconds m := ((t-s)/60) mod 60; //minutes h := (((t-s)/60)-m)/60; //hours end; Actions.OverlayTextAppend(-1, IntToStr(h)+':'+IntToStr(m)+':'+IntToStr(s)+'|'); //Winning conditions if aCurrTimeOut <= 0 then TheEndBye := True; //Time's out end; //Win commands if TheEndBye = True then begin //Check which is the highest score aPreviousS := 0; for i := 0 to States.LocationCount-1 do begin if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t >= aPreviousS then begin aPreviousS := t; aCurrID := i; end; end; end; //Chack which players reached the highest score aBest := [aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID]; //Static arrays never worked for me :( ; every value is defaulted to a player that we already know is going to be among the winners aCurrID := 0; for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t = aPreviousS then begin aBest[aCurrID] := i; aCurrID := aCurrID+1; end; end; Actions.PlayerWin(aBest, True); end; end;

Re: Need a script for the map

PostPosted: 04 Oct 2014, 11:21
by Michalpl
(4 hours is a lot... this script is set for 2 hours, you can edit this by changing aMaxTimeOut in OnMissionStart)
  Code:
var TheEndBye: Boolean; var aMaxTimeOut: Integer; var aCurrTimeOut: Integer; var aBest: array of Integer; var aPreviousS: Integer; var s: Integer; var m: Integer; var h: Integer; procedure OnMissionStart; begin TheEndBye := False; aMaxTimeOut := 72000 //Timer, in seconds times 10, at the moment it is 2 hours end; procedure OnTick; var i: Integer; var u: Integer; var t: Integer; var aCurrID: Integer; begin if TheEndBye = False then begin //Probably unneeded, but let's make sure that it will work. //Set overlay texts Actions.OverlayTextSet(-1, ''); for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); Actions.OverlayTextAppendFormatted(-1, '%s: '+IntToStr(t)+'|', [States.PlayerName(i)]); end; //Check time aCurrTimeOut := aMaxTimeOut-States.Gametime; if States.Gametime mod 10 = 0 then begin //No sense doing this more than once per second t := (aCurrTimeOut-(aCurrTimeOut mod 10))/10; s := t mod 60; //seconds m := ((t-s)/60) mod 60; //minutes h := (((t-s)/60)-m)/60; //hours end; Actions.OverlayTextAppend(-1, IntToStr(h)+':'+IntToStr(m)+':'+IntToStr(s)+'|'); //Winning conditions if aCurrTimeOut <= 0 then TheEndBye := True; //Time's out end; //Win commands if TheEndBye = True then begin //Check which is the highest score aPreviousS := 0; for i := 0 to States.LocationCount-1 do begin if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t >= aPreviousS then begin aPreviousS := t; aCurrID := i; end; end; end; //Chack which players reached the highest score aBest := [aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID, aCurrID]; //Static arrays never worked for me :( ; every value is defaulted to a player that we already know is going to be among the winners aCurrID := 0; for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t = aPreviousS then begin aBest[aCurrID] := i; aCurrID := aCurrID+1; end; end; Actions.PlayerWin(aBest, True); end; end;
Big thanks

Re: Need a script for the map

PostPosted: 04 Oct 2014, 12:09
by Esthlos
No problem.

Anyway, this one is better: :$ :wink: :P
  Code:
var TheEndBye: Boolean; var aMaxTimeOut: Integer; var aCurrTimeOut: Integer; var aBest: array of Integer; var aPreviousS: Integer; var s: Integer; var m: Integer; var h: Integer; procedure OnMissionStart; begin TheEndBye := False; aMaxTimeOut := 72000 //Timer, in seconds times 10, at the moment it is 2 hours end; procedure OnTick; var i: Integer; var u: Integer; var t: Integer; begin if TheEndBye = False then begin //Probably unneeded, but let's make sure that it will work. //Set overlay texts Actions.OverlayTextSet(-1, ''); for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); Actions.OverlayTextAppendFormatted(-1, '%s: '+IntToStr(t)+'|', [States.PlayerName(i)]); end; //Check time aCurrTimeOut := aMaxTimeOut-States.Gametime; if States.Gametime mod 10 = 0 then begin //No sense doing this more than once per second t := (aCurrTimeOut-(aCurrTimeOut mod 10))/10; s := t mod 60; //seconds m := ((t-s)/60) mod 60; //minutes h := (((t-s)/60)-m)/60; //hours end; Actions.OverlayTextAppend(-1, IntToStr(h)+':'+IntToStr(m)+':'+IntToStr(s)+'|'); //Winning conditions if aCurrTimeOut <= 0 then TheEndBye := True; //Time's out end; //Win commands if TheEndBye = True then begin //Check which is the highest score aPreviousS := 0; for i := 0 to States.LocationCount-1 do begin if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t >= aPreviousS then begin aPreviousS := t; end; end; end; //Check which players reached the highest score SetLength(aBest, 0) for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t = aPreviousS then begin SetLength(aBest, Length(aBest)+1) aBest[Length(aBest)-1] := i; end; end; Actions.PlayerWin(aBest, True); end; end;

Re: Need a script for the map

PostPosted: 04 Oct 2014, 12:57
by Michalpl
Can't get UnitAt to working i m doing something wrong?

begin
if States.UnitAt(124,145) < 14
then begin
Actions.MapTileSet(114,141,192,0);

Re: Need a script for the map

PostPosted: 04 Oct 2014, 13:18
by Esthlos
Can't get UnitAt to working i m doing something wrong?

begin
if States.UnitAt(124,145) < 14
then begin
Actions.MapTileSet(114,141,192,0);
States.UnitAt returns the UnitID, not the Unit Type :P

The UnitID is the "name" that the game gives to each unit... I guess you're trying to detect if the unit at 124,145 is a civilian, am I right?
Try this:
  Code:
begin if States.UnitType(States.UnitAt(124,145)) < 14 then begin Actions.MapTileSet(114,141,192,0);

Re: Need a script for the map

PostPosted: 04 Oct 2014, 13:28
by Michalpl
Still isn't working GroupAt

Let me describe what i want to achive:

I want to make if there is any type of unit on the specifed tile then do stuff

Re: Need a script for the map

PostPosted: 04 Oct 2014, 13:45
by Esthlos
Thank you for sending me the whole script. Let's see:

GroupAt returns a Group ID, not a Unit ID... it's the "name" of the troop, and since different unit types can be in the same troop, UnitType won't work with GroupAt.

Also, the game complains if UnitType is given an invalid UnitID... it will still work, just worse.

Lastly, you do not need to add a "begin": you only need it when opening a new "procedure", or when you want to have a series of commands "follow" the same line. :wink:

Oh, and the last "end" doesn't need a full stop... it should be "end;" even if it is the last one. :P

Try this:
  Code:
var TheEndBye: Boolean; var aMaxTimeOut: Integer; var aCurrTimeOut: Integer; var aBest: array of Integer; var aPreviousS: Integer; var s: Integer; var m: Integer; var h: Integer; procedure OnMissionStart; begin TheEndBye := False; aMaxTimeOut := 72000 //Timer, in seconds times 10, at the moment it is 2 hours end; procedure OnTick; var i: Integer; var u: Integer; var t: Integer; begin if TheEndBye = False then begin //Probably unneeded, but let's make sure that it will work. //Set overlay texts Actions.OverlayTextSet(-1, ''); for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); Actions.OverlayTextAppendFormatted(-1, '%s: '+IntToStr(t)+'|', [States.PlayerName(i)]); end; //Check time aCurrTimeOut := aMaxTimeOut-States.Gametime; if States.Gametime mod 10 = 0 then begin //No sense doing this more than once per second t := (aCurrTimeOut-(aCurrTimeOut mod 10))/10; s := t mod 60; //seconds m := ((t-s)/60) mod 60; //minutes h := (((t-s)/60)-m)/60; //hours end; Actions.OverlayTextAppend(-1, IntToStr(h)+':'+IntToStr(m)+':'+IntToStr(s)+'|'); //Winning conditions if aCurrTimeOut <= 0 then TheEndBye := True; //Time's out end; //Win commands if TheEndBye = True then begin //Check which is the highest score aPreviousS := 0; for i := 0 to States.LocationCount-1 do begin if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t >= aPreviousS then begin aPreviousS := t; end; end; end; //Check which players reached the highest score SetLength(aBest, 0) for i := 0 to States.LocationCount-1 do if States.PlayerEnabled(i) = True then begin t := 0; for u := 14 to 27 do t := t+States.StatUnitKilledCount(i, u); if t = aPreviousS then begin SetLength(aBest, Length(aBest)+1) aBest[Length(aBest)-1] := i; end; end; Actions.PlayerWin(aBest, True); end; if States.UnitAt(124,145) > -1 then begin //The game complains if asked the Unit Type of a non existing unit if States.UnitType(States.UnitAt(124,145)) > 14 then begin Actions.MapTileSet(114,141,192,0); Actions.MapTileSet(115,141,192,0); Actions.MapTileSet(116,141,192,0); Actions.MapTileSet(117,141,192,0); Actions.MapTileSet(118,141,192,0); Actions.MapTileSet(114,142,192,0); //2nd line Actions.MapTileSet(115,142,192,0); Actions.MapTileSet(116,142,192,0); Actions.MapTileSet(117,142,192,0); Actions.MapTileSet(118,142,192,0); end; end; end;

Re: Need a script for the map

PostPosted: 04 Oct 2014, 15:35
by Michalpl
Rage sorry.
this now works thanks