Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

Vatrix

User avatar

Council Member

Posts: 410

Joined: 19 Apr 2013, 20:30

KaM Skill Level: Veteran

Location: Czech Republic

Post 29 Nov 2014, 14:54

Re: Dynamic Script Usage Questions

Thank you very much.
I fixed The Shattered Kingdom and The Peasants Rebellion here!
<<

The Dark Lord

User avatar

King Karolus Servant

Posts: 2154

Joined: 29 Aug 2007, 22:00

KaM Skill Level: Veteran

Location: In his dark thunderstormy castle

Post 25 Dec 2014, 20:38

Re: Dynamic Script Usage Questions

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

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 25 Dec 2014, 20:54

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

The Dark Lord

User avatar

King Karolus Servant

Posts: 2154

Joined: 29 Aug 2007, 22:00

KaM Skill Level: Veteran

Location: In his dark thunderstormy castle

Post 25 Dec 2014, 22:14

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;
:) <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"?
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 26 Dec 2014, 08:53

Re: Dynamic Script Usage Questions

Short variant:
  Code:
for i := 0 to 8 do if (i=1) or (i=2) or (i=5) or (i=6) then
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
<<

zaamoot

Militia

Posts: 41

Joined: 28 Mar 2013, 13:56

KaM Skill Level: Average

Post 31 Dec 2014, 14:27

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.
  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
Last edited by zaamoot on 31 Dec 2014, 14:35, edited 1 time in total.
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 31 Dec 2014, 14:29

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

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 16 Feb 2015, 20:37

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 used to spam this forum so much...
<<

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 16 Feb 2015, 22:01

Re: Dynamic Script Usage Questions

Is this possible?
Yes.
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"
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 16 Feb 2015, 22:54

Re: Dynamic Script Usage Questions

Thanks, perhaps I will make a map for it.
I used to spam this forum so much...
<<

kocsis1david

Crossbowman

Posts: 204

Joined: 12 Mar 2011, 23:00

KaM Skill Level: Skilled

Location: Hungary

Post 22 Feb 2015, 13:17

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

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 23 Feb 2015, 14:07

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.
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)
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"
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 23 Feb 2015, 14:33

Re: Dynamic Script Usage Questions

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

kocsis1david

Crossbowman

Posts: 204

Joined: 12 Mar 2011, 23:00

KaM Skill Level: Skilled

Location: Hungary

Post 24 Feb 2015, 07:19

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

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 24 Feb 2015, 10:24

Re: Dynamic Script Usage Questions

what bigger probolem? u cant "give house" ? why?

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 4 guests