Problem with Dynamic Script in new RC3
PostPosted: 02 Oct 2014, 18:31
For testing purposes I copied my maps for my upcoming campaign in into the new RC3. The scripts that worked in RC2 do not work in RC3. I tried excluding certain parts of the script to troubleshoot, however, the error jumps from one part to the other. Also the error-massage does not give any hit, where the problem might be. It only states that there is a "mistake in script usage States.GroupMembers: 0, 0" (see attachment).
What the script does:
UnitsRandomHungerSet() finds all no-human-player units and gives them a individual Hunger-Level when executed. All Units that belong to the same group get the same Hunger level.
Pretty much the rest of the code checks if the AI builds a AxeFighter. If yes there is a change that it gets "replaced" (killed and "summoned") with a Barbarian by a certain chance. They become Barbarians when they are supposed to get linked to barbarians and will not be killed if they are supposed to link to a group of axefighters. If there are no other Units in that group, it gets rolled. The code is pretty messy and immature at the moment...
Sorry for the lack of comments in the code...
Maybe you guys got an idea? Did something fundamentally change from RC2 to RC3?
- Code:
//-- TBK08 --// var bGiveNext: array[1..10] of Boolean; var iX, iY, iGiveU, iGiveG: array[1..10] of Integer; var iD, iType, iOwner: array[1..10] of Byte; procedure UnitsRandomHungerSet(); var aUnits: array of Integer; var i, x, iHunger, iGroup: Integer; var iPlayerLoop: Byte; begin for iPlayerLoop := 1 to States.StatPlayerCount()-1 do begin aUnits := States.PlayerGetAllUnits(iPlayerLoop); for i := 0 to Length(aUnits)-1 do begin if States.UnitsGroup(aUnits[i]) = -1 then begin Actions.UnitHungerSet(aUnits[i], States.UnitMaxHunger/2 + States.KaMRandomI(States.UnitMaxHunger/2 +1)); end else iGroup := States.UnitsGroup(aUnits[i]); if States.GroupMember(iGroup, 0) = aUnits[i] then begin iHunger := States.UnitMaxHunger/2 + States.KaMRandomI(States.UnitMaxHunger/2 +1) for x := 0 to States.GroupMemberCount(iGroup)-1 do Actions.UnitHungerSet(States.GroupMember(iGroup, x), iHunger); end; end; end; end; procedure KilledUnitData(aUnitID, aGroupID: Integer; i: Byte); begin iX[i] := States.UnitPositionX(aUnitID); iY[i] := States.UnitPositionY(aUnitID); iD[i] := States.UnitDirection(aUnitID); iGiveU[i] := aUnitID; iGiveG[i] := aGroupID; iOwner[i] := States.UnitOwner(aUnitID); iType[i] := States.UnitType(aUnitID); Actions.UnitKill(aUnitID, true); end; procedure OnMissionStart(); begin UnitsRandomHungerSet(); //Block Ware to prevent AI Storehouse from getting too crowded //To be done end; procedure OnWarriorEquipped(aUnitID, aGroupID: Integer); var i, iOwnerLocal, iTypeLocal: Byte; var iFlagholder: Integer; begin iOwnerLocal := States.UnitOwner(aUnitID); //"Transform" Units of AI Players if (iOwnerLocal <> 0) then begin iTypeLocal := States.UnitType(aUnitID); if (States.GroupMemberCount(aGroupID) > 1) and (States.UnitType(aUnitID) = States.UnitType(States.GroupMember(aGroupID, 0))) then begin end; if (States.GroupMemberCount(aGroupID) > 1) and (States.UnitType(aUnitID) <> States.UnitType(States.GroupMember(aGroupID, 0))) then for i := 1 to 10 do begin if (iGiveU[i] = -1) then begin //Map specific if ((iOwnerLocal = 1) or (iOwnerLocal = 2)) and (iTypeLocal = 15) then KilledUnitData(aUnitID, aGroupID, i); //AxeFighter break; end; end; if (States.GroupMemberCount(aGroupID) = 1) then begin if States.KaMRandomI(2) = 0 then //% Chance begin for i := 1 to 10 do begin if (iGiveU[i] = -1) then begin if ((iOwnerLocal = 1) or (iOwnerLocal = 2)) and (iTypeLocal = 15) then KilledUnitData(aUnitID, aGroupID, i); break; end; end; end; end; end; end; procedure OnTick; var iGroup: Integer; var i: Byte; begin for i := 1 to 10 do begin //Give Unit to Player if (iGiveU[i] <> -1) and States.UnitDead(iGiveU[i]) then begin if bGiveNext[i] then begin bGiveNext[i] := false; iGiveU[i] := -1; //Replace Units (Map specific) if iType[i] = 15 then iGroup := Actions.GiveGroup(iOwner[i], 23, iX[i], iY[i], iD[i], 1, 1); //Axefighter -> Barbarian //Check if Unit belongs to a Group and Link it if not States.GroupDead(iGiveG[i]) then Actions.GroupOrderLink(iGroup, iGiveG[i]); end else bGiveNext[i] := true; end; end; end;
UnitsRandomHungerSet() finds all no-human-player units and gives them a individual Hunger-Level when executed. All Units that belong to the same group get the same Hunger level.
Pretty much the rest of the code checks if the AI builds a AxeFighter. If yes there is a change that it gets "replaced" (killed and "summoned") with a Barbarian by a certain chance. They become Barbarians when they are supposed to get linked to barbarians and will not be killed if they are supposed to link to a group of axefighters. If there are no other Units in that group, it gets rolled. The code is pretty messy and immature at the moment...
Sorry for the lack of comments in the code...

Maybe you guys got an idea? Did something fundamentally change from RC2 to RC3?