Problem with laggy script
I hope you guys can help me with a script I'm writing. It is for a multiplayer map. In this map you can unlock technologies, that let your production buildings to be more efficent. So for example I have a technologie, which lets your woodcutters produce 2 Treetrunks instead of one, if they are build on dirt. The script is working fine, but is creating lag . I checked the log file and found a billion messages with : "22:04:01.107 2915,481s 1773ms Script Invalid parameter(s) passed to States.StatResourceProducedCount: 3, 0", "2:04:01.207 2915,581s 93ms Script Invalid parameter(s) passed to States.StatResourceProducedCount: 3, 0". I assume that this means the problem is in my code. But my scripting skills and understanding of it isn't good enough to understand why it is creating lag.
Here is the complete code I use to unlock the technologie (1), store the woodcutters on dirt (2) and adding extra Treetrunks to the building (3)
I'm thankful for any help.
(1)
- Code:
if ((States.UnitType(aUnit) = 14) and (States.HouseType(States.HouseAt(States.UnitPositionX(aUnit),(States.UnitPositionY(aUnit) -1))) = 18) and (bTimberSale = true) and (bPinePlantation = false)) then begin iOwner := States.UnitOwner(aUnit); Actions.UnitKill(aUnit, true); if bPinePlantation = true then Actions.ShowMsg(iOwner, 'Pine Plantation has already been researched'); if bPinePlantation = false then begin iaPinePlantation[iOwner] := iaPinePlantation[iOwner] +1 sTechText[iOwner] := ('[$'+ States.PlayerColorText(iOwner) + ']' + States.PlayerName(iOwner) + ' is researching: Pine Plantation '); sTechCount[iOwner] := inttostr(iaPinePlantation[iOwner]); sTechCountNeeded[iOwner] := (' /20'); Overlay; if iaPinePlantation[iOwner] = 20 then begin bPinePlantation := true iPinePlantationP := iOwner; iTree := States.StatResourceProducedCount(iPinePlantationP, 0); Actions.ShowMsgGoto(iPinePlantationP, 142, 2, 'Pine Plantation has been researched.'); sTechText[iOwner] := (''); sTechCount[iOwner] := (''); sTechCountNeeded[iOwner] := (''); Overlay; Actions.FogRevealCircle(iPinePlantationP, 138, 2, 2); Actions.FogRevealCircle(iPinePlantationP, 140, 2, 2); Actions.FogRevealCircle(iPinePlantationP, 142, 2, 2); Actions.FogRevealCircle(iPinePlantationP, 144, 2, 2); Actions.FogRevealCircle(iPinePlantationP, 146, 2, 2); iaHouses := States.PlayerGetAllHouses(iPinePlantationP); for iWhich := 0 to Length(iaHouses)-1 do begin iXW := States.HousePositionX(iaHouses[iWhich]); iYW := States.HousePositionY(iaHouses[iWhich]); if (States.HouseType(iaHouses[iWhich]) = 9) and (States.MapTileType(iXW, iYW) >=34) and (States.MapTileType(iXW, iYW) < 60) then begin iaTreesHouse[iTreesCounter] := iaHouses[iWhich]; iaTreesStored[iTreesCounter] := States.HouseResourceAmount(iaHouses[iWhich], 0); iTreesCounter := iTreesCounter +1 end; end; end; end; end;
- Code:
if ((States.HouseType(aHouse) = 9) and (States.HouseOwner(aHouse) = iPinePlantationP) and (bPinePlantation = true)) then begin iXB := States.HousePositionX(aHouse); iYB := States.HousePositionY(aHouse); if ((States.MapTileType(iXB, iYB) >=34) and (States.MapTileType(iXB, iYB) < 60)) then begin iaTreesHouse[iTreesCounter] := aHouse; iaTreesStored[iTreesCounter] := States.HouseResourceAmount(aHouse, 0); iTreesCounter := iTreesCounter +1 end; end;
- Code:
//Pine Plantations if ((States.StatResourceProducedCount(iPinePlantationP, 0) > iTree) and (bPinePlantation = true)) then begin iTree := iTree +1 for iWhich := 0 to iTreesCounter -1 do begin if ((States.HouseResourceAmount(iaTreesHouse[iWhich], 0) > iaTreesStored[iWhich]) and (States.HouseDestroyed(iaTreesHouse[iWhich]) = false)) then begin iTree := iTree +1 Actions.HouseAddWaresTo(iaTreesHouse[iWhich], 0, 1); iOverlayPinePlantation := iOverlayPinePlantation +1 end; iaTreesStored[iWhich] := States.HouseResourceAmount(iaTreesHouse[iWhich], 0); end; end;