
Dynamic Script Usage Questions
Thank you very much.
I fixed The Shattered Kingdom and The Peasants Rebellion here!

King Karolus Servant
Posts: 2154
Joined: 29 Aug 2007, 22:00
KaM Skill Level: Veteran
Location: In his dark thunderstormy castle
Re: Dynamic Script Usage Questions
After a long break I started working on TNL again. And of course I'm having scripting issues. 
Look at this;
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.
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...

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;

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
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;
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"

King Karolus Servant
Posts: 2154
Joined: 29 Aug 2007, 22:00
KaM Skill Level: Veteran
Location: In his dark thunderstormy castle
Re: Dynamic Script Usage Questions
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;

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
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
Re: Dynamic Script Usage Questions
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.
Zaamoot
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.
Thanks in advance!
Zaamoot
Last edited by zaamoot on 31 Dec 2014, 14:35, edited 1 time in total.
Re: Dynamic Script Usage Questions
Behold the fastest reply ever (I was typing him a solution on TS in the time he was making the post
):
warning: completely no readability here as I am at work and need to go soon 

- 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;


Former Site Admin
Posts: 3814
Joined: 08 Jan 2009, 23:00
Location: California - Pacific Time (UTC -8/-7 Summer Time)
Re: Dynamic Script Usage Questions
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?
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?
I used to spam this forum so much...
Re: Dynamic Script Usage Questions
Is this possible?
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"

Former Site Admin
Posts: 3814
Joined: 08 Jan 2009, 23:00
Location: California - Pacific Time (UTC -8/-7 Summer Time)
Re: Dynamic Script Usage Questions
Thanks, perhaps I will make a map for it.
I used to spam this forum so much...
Re: Dynamic Script Usage Questions
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.
Here are two problems I need help solving:
- 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;
- 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
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.
(The object ID for "empty tile" should be 255)
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
Re: Dynamic Script Usage Questions
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.
But the other issue is a bigger problem, and it makes the whole idea not working.
Re: Dynamic Script Usage Questions
what bigger probolem? u cant "give house" ? why?
Who is online
Users browsing this forum: Google [Bot] and 4 guests