Page 24 of 26

Re: Dynamic Script Usage Questions

PostPosted: 29 Nov 2014, 14:54
by Vatrix
Thank you very much.

Re: Dynamic Script Usage Questions

PostPosted: 25 Dec 2014, 20:38
by The Dark Lord
After a long break I started working on TNL again. And of course I'm having scripting issues. :P
Look at this;
  Code:
if ((States.GroupDead(Sword1) = false) or (States.GroupDead(Sword2) = false) or (States.GroupDead(Sword3) = false) or (States.GroupDead(Crossbow1) = false) or (States.GroupDead(Crossbow2) = false) or (States.GroupDead(Crossbow3) = false)) and ((States.GameTime mod 100) = 0) and (BowAgression = true) then begin Actions.GroupOrderAttackUnit(Bow1, States.ClosestUnit(2, 4, 34, -1)); Actions.GroupOrderAttackUnit(Bow2, States.ClosestUnit(2, 4, 49, -1)); Actions.GroupOrderAttackUnit(Bow3, States.ClosestUnit(2, 8, 40, -1)); Actions.GroupOrderAttackUnit(Bow4, States.ClosestUnit(2, 8, 45, -1)); end; if (States.GroupDead(Sword1) = true) and (States.GroupDead(Sword2) = true) and (States.GroupDead(Sword3) = true) and (States.GroupDead(Crossbow1) = true) and (States.GroupDead(Crossbow2) = true) and (States.GroupDead(Crossbow3) = true) and ((States.GameTime mod 100) = 0) and (BowAgression = true) then begin BowAgression := false; end;
I know. It's terrible, but I don't really know how to make it shorter. Anyway, here is the problem: it lags. it lags horribly. And I don't know why, but I'm sure the lag is caused by the 'States.GameTIme mod 100' part (if I take it out, there is no lag, but then the bowmen behave like total imbeciles). The goal of the script is to have the bowmen actively take part in a battle until some particular groups are dead (while I'm writing this, I realize I could just use States.StatArmyCount instead of all those groups, I'll fix that). Now, at the start of the battle, everything runs perfectly smooth, even on x8 speed. But then something happens (no idea what it is though) and it starts to lag a lot, even on normal speed. I tried to somehow end this script with the boolean, but unfortunately that doesn't work. :P Again: when I remove the 'States.GameTime mode 100' bits, everything is perfectly fine for the whole game. Who can help me out?

Edit: the lag seems to occur around the time when those groups are dead. The weird thing is that it is not always exactly at that moment, but somewhere around it...

Re: Dynamic Script Usage Questions

PostPosted: 25 Dec 2014, 20:54
by Esthlos
Please try this:
  Code:
if BowAgression = true then begin if (States.GroupDead(Sword1) = true) and (States.GroupDead(Sword2) = true) and (States.GroupDead(Sword3) = true) and (States.GroupDead(Crossbow1) = true) and (States.GroupDead(Crossbow2) = true) and (States.GroupDead(Crossbow3) = true) then BowAgression := false; if BowAgression = true then begin if States.GroupIdle(Bow1) = true then Actions.GroupOrderAttackUnit(Bow1, States.ClosestUnit(2, 4, 34, -1)); if States.GroupIdle(Bow2) = true then Actions.GroupOrderAttackUnit(Bow2, States.ClosestUnit(2, 4, 49, -1)); if States.GroupIdle(Bow3) = true then Actions.GroupOrderAttackUnit(Bow3, States.ClosestUnit(2, 8, 40, -1)); if States.GroupIdle(Bow4) = true then Actions.GroupOrderAttackUnit(Bow4, States.ClosestUnit(2, 8, 45, -1)); end; end;

Re: Dynamic Script Usage Questions

PostPosted: 25 Dec 2014, 22:14
by The Dark Lord
Please try this:
  Code:
if BowAgression = true then begin if (States.GroupDead(Sword1) = true) and (States.GroupDead(Sword2) = true) and (States.GroupDead(Sword3) = true) and (States.GroupDead(Crossbow1) = true) and (States.GroupDead(Crossbow2) = true) and (States.GroupDead(Crossbow3) = true) then BowAgression := false; if BowAgression = true then begin if States.GroupIdle(Bow1) = true then Actions.GroupOrderAttackUnit(Bow1, States.ClosestUnit(2, 4, 34, -1)); if States.GroupIdle(Bow2) = true then Actions.GroupOrderAttackUnit(Bow2, States.ClosestUnit(2, 4, 49, -1)); if States.GroupIdle(Bow3) = true then Actions.GroupOrderAttackUnit(Bow3, States.ClosestUnit(2, 8, 40, -1)); if States.GroupIdle(Bow4) = true then Actions.GroupOrderAttackUnit(Bow4, States.ClosestUnit(2, 8, 45, -1)); end; end;
:) <3

Edit: I have a new question. Somewhere in my script I'm using this: "for i := 0 to 8 do". But I want to exclude some of the numbers in between. How should I write that? Or can I do something like "for i := 0, 1, 2, 3, 4, 7, 8 do"?

Re: Dynamic Script Usage Questions

PostPosted: 26 Dec 2014, 08:53
by Krom
Short variant:
  Code:
for i := 0 to 8 do if (i=1) or (i=2) or (i=5) or (i=6) then

Re: Dynamic Script Usage Questions

PostPosted: 31 Dec 2014, 14:27
by zaamoot
Hi All,

I have a question about the possilbity of disabling demolishment by the owner of a building when it is damaged.
A bit of context: the map.
In this map you get wares for demolishing buildings and I want to prevent that people demolish a building the last second, so the attacker wont get wares.

The sample code (just the show the idea) is shown below. If the damage of a building is above 0, it should be impossible to demolish that building by the owner.
  Code:
procedure OnHouseDamaged(HouseDamage: integer); begin if (HouseDamage < 0) then EXIT; if (states.HouseDamage > 0) then (Disable the ability to demolish building) end;
Thanks in advance!

Zaamoot

Re: Dynamic Script Usage Questions

PostPosted: 31 Dec 2014, 14:29
by sado1
Behold the fastest reply ever (I was typing him a solution on TS in the time he was making the post :P):
  Code:
onhousedamaged(blablabla) var HousesHealthArray: array of Integer; begin HousesHealthArray[HouseID] := tates.HouseDamage[HouseID] end; onhousedestroyed(djfkjsaskdbfdjsb) begin if HouseDestroyerID = -1 then // or maybe = house owner's ID? I am not sure how it works begin actions.givehouse(player,housetype,x,y); actions.houseadddamage(HouseID, (States.HouseTypeMaxHealth(States.Housetype(HouseID)) - HousesHealthArray[HouseID] ) ); end; end;
warning: completely no readability here as I am at work and need to go soon :P

Re: Dynamic Script Usage Questions

PostPosted: 16 Feb 2015, 20:37
by Ben
I am wondering if it is possible to have a script like this:

I want to have one coal placed in a coal-consuming building. However, I don't want it randomly placed in a building. I first want the script to check all coal buildings to see how much coal they have. First it will check the delivery of wares to make sure the coal won't push the limit allowed by the ware distribution (i.e., it won't put a 4th coal in a gold smithy of 3 is the current setting). Then, basically, it check to see which building needs it the most. For example, if there is a iron smithy with 4 coal and a weapon smithy with 2 coal, the weapon smithy will get the coal. HOWEVER, if there is an iron smithy with 3 coal (and the distribution for iron smithies is 5), and a gold smithy with 0 coal (and a distribution set to 1), the iron smithy will still get the coal since it needs 2 coal to meet its max but the gold smithy only needs one.
The coal will be taken from a coal mine. The script will check all coal mines and take the coal from a mine that is fullest.


Is this possible?

Re: Dynamic Script Usage Questions

PostPosted: 16 Feb 2015, 22:01
by Esthlos
Is this possible?
Yes.

Re: Dynamic Script Usage Questions

PostPosted: 16 Feb 2015, 22:54
by Ben
Thanks, perhaps I will make a map for it.

Re: Dynamic Script Usage Questions

PostPosted: 22 Feb 2015, 13:17
by kocsis1david
I tried to make small script. It would allow to build like in the editor: When a building plan is placed, the script removes the plan and places a built one instead.
  Code:
procedure OnHousePlanPlaced(aPlayerIndex, X, Y, aHouseType: Integer); begin Actions.PlanRemove(aPlayerIndex, X, Y); Actions.GiveHouse(aPlayerIndex, aHouseType, X, Y); end; procedure OnPlanRoadPlaced(aPlayerIndex, X, Y: Integer); begin Actions.PlanRemove(aPlayerIndex, X, Y); Actions.GiveRoad(aPlayerIndex, X, Y); Actions.FogRevealCircle(aPlayerIndex, X, Y, 7); end; procedure OnPlanFieldPlaced(aPlayerIndex, X, Y: Integer); begin Actions.PlanRemove(aPlayerIndex, X, Y); Actions.GiveField(aPlayerIndex, X, Y); Actions.FogRevealCircle(aPlayerIndex, X, Y, 7); end; procedure OnPlanWinefieldPlaced(aPlayerIndex, X, Y: Integer); begin Actions.PlanRemove(aPlayerIndex, X, Y); Actions.GiveWineField(aPlayerIndex, X, Y); Actions.FogRevealCircle(aPlayerIndex, X, Y, 7); end;
Here are two problems I need help solving:
  • You may want to cut a tree by placing a wine field and a road. But it's not working using the script. The road doesn't remove the wine field, the object of wine plant remains there and it also blocks building. This plant cannot be removed using MapTileObjectSet, and I can't find an action to remove the wine field.
  • Rarely happens that you cannot place a building, although it is allowed to place the building plan. There are no red X-es shown under the cursor, but GiveHouse method still fails. I guess it has something to do with elevation.

Re: Dynamic Script Usage Questions

PostPosted: 23 Feb 2015, 14:07
by Esthlos
You may want to cut a tree by placing a wine field and a road. But it's not working using the script. The road doesn't remove the wine field, the object of wine plant remains there and it also blocks building. This plant cannot be removed using MapTileObjectSet, and I can't find an action to remove the wine field.
As far as I know, you can't remove fields or winefields... but MapTileObjectSet will be able to remove trees.
(The object ID for "empty tile" should be 255)

Re: Dynamic Script Usage Questions

PostPosted: 23 Feb 2015, 14:33
by RandomLyrics
To remove vinefield or field:
  Code:
Actions.GiveRoad(0, 14, 10); Actions.MapTileObjectSet(14, 10, 255); Actions.RemoveRoad( 14, 10);
it leaves vine tile, u have to change it manually by SetTile to previous tile or just leave it ;P

Re: Dynamic Script Usage Questions

PostPosted: 24 Feb 2015, 07:19
by kocsis1david
Thanks, MapTileObjectSet works. I tried it earlier, but I called MapTileObjectSet first and GiveRoad next, and it didn't work that way.

But the other issue is a bigger problem, and it makes the whole idea not working.

Re: Dynamic Script Usage Questions

PostPosted: 24 Feb 2015, 10:24
by RandomLyrics
what bigger probolem? u cant "give house" ? why?