Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 09 Jun 2013, 17:53

Re: Dynamic Script Usage

Whats wrong with my coding. i get an error with begin expected. but i don't know where. could someone help my?
  Code:
procedure OnMissionStart; begin //dorp zuidwest Actions.HouseWareBlock(States.HouseAt(44, 143), 1, true); Actions.HouseWareBlock(States.HouseAt(72, 139), 1, true); //dorp noordwest Actions.HouseWareBlock(States.HouseAt(44, 100), 1, true); Actions.HouseWareBlock(States.HouseAt(71, 96), 1, true); //dorp zuidoost Actions.HouseWareBlock(States.HouseAt(146, 131), 1, true); Actions.HouseWareBlock(States.HouseAt(172, 140), 1, true); //dorp noordoost Actions.HouseWareBlock(States.HouseAt(168, 82), 1, true); Actions.HouseWareBlock(States.HouseAt(187, 66), 1, true); //speler 1 Actions.FogCoverCircle (0, 97, 37, 30); Actions.FogCoverCircle (0, 124, 18, 30); Actions.FogCoverCircle (0, 44, 19, 40); //speler 2 Actions.FogCoverCircle (1, 44, 19, 40); Actions.FogCoverCircle (1, 117, 21, 30); Actions.FogCoverCircle (1, 90, 43, 30); end; produce OnTick; begin if States.GameTime = 1200 then begin //speler 1 Actions.ShowMsgGoto(0, 111, 147, '<$0>'); Actions.FogRevealCircle (0, 111, 147, 20); //speler 2 Actions.ShowMsgGoto(1, 111, 147, '<$0>'); Actions.FogRevealCircle (1, 111, 147, 20); Actions.GiveGroup (8, 21, 115, 147, 6, 12, 4); Actions.GiveGroup (8, 21, 115, 154, 6, 12, 4); end; end;
<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 09 Jun 2013, 17:58

Re: Dynamic Script Usage

Hi guys,

I am experiencing some troubles, which I cannot seem to solve. I am experimenting on a little script that makes all units die around a Vagabond that gets killed. To be precise, all units in a square within a range of 2 (so the total square is 5x5) have to die. Here is a piece of script that does this:
  Code:
Procedure OnUnitKilled(UnitID: integer; KillerID: integer); var ThisUnitType, VagabondX, VagabondY: integer; TileWalkerX, TileWalkerY: integer; UnitAtTile: integer; EmptyGroup, EmptyUnit: integer; begin ThisUnitType := States.UnitType(UnitID); if ThisUnitType = VAGABOND then begin VagabondX := States.UnitPositionX(UnitID); VagabondY := States.UnitPositionY(UnitID); for TileWalkerX := (VagabondX - VAGABOND_EXPLOSION_RANGE) to (VagabondX + VAGABOND_EXPLOSION_RANGE) do begin for TileWalkerY := (VagabondY - VAGABOND_EXPLOSION_RANGE) to (VagabondY + VAGABOND_EXPLOSION_RANGE) do begin if (TileWalkerX = VagabondX) and (TileWalkerY = VagabondY) then continue; // because vagabond already gets killed UnitAtTile := States.UnitAt(TileWalkerX, TileWalkerY); if UnitAtTile <> NOTHING then begin Actions.UnitKill(UnitAtTile,false); end; if UnitAtTile = NOTHING then begin EmptyGroup := Actions.GiveGroup(PLAYER_8, VAGABOND, TileWalkerX, TileWalkerY, States.KamRandomI(7),1,1); EmptyUnit := States.GroupMember(EmptyGroup, 0); Actions.UnitKill(EmptyUnit,false); end; end; end; end; end;
In this script, VAGABOND = 27, VAGABOND_EXPLOSION_RANGE = 2, NOTHING = -1. The problem is that this script sometimes causes a crash, especially when many enemy units start walking around the Vagabond. I think the problem has something to do with a tile having 'almost' a new unit (when the old unit is pushed away by the newly entering unit). I have illustrated this in two screenshots below with a circle. Can somebody tell me if this is just the result of an error in my mistake or a bug? (I've also just sent a bugreport to Lewin/Krom).

Note: I have also tried veryfing if the (x,y) of EmptyUnit are the same as the (x,y) of UnitAtTile and changing kill commands accordingly, but that does not seem to help either.
You do not have the required permissions to view the files attached to this post.
Last edited by Tef on 09 Jun 2013, 18:11, edited 1 time in total.
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 09 Jun 2013, 17:59

Re: Dynamic Script Usage

@Islar:

Your second procedure is declared wrong: "produce OnTick;".
It should be "PROCEDURE OnTick;"

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

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 09 Jun 2013, 18:32

Re: Dynamic Script Usage

how can i make a certain group attack a certain building.

i have this but i don't think it is good
  Code:
procedure OnTick; begin if States.GameTime = 2700 then begin Actions.GroupOrderAttackHouse (States.GroupAt (115, 147), true) (States.HouseAt (83, 137), true); end; end;
can someone help my?
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 09 Jun 2013, 18:36

Re: Dynamic Script Usage

Exploding vagabonds? That's the most creative use of dynamic scripts I've seen! :D :D :D
We have found the cause of the crash, it's not your fault, we'll let you know when it's fixed. If you're interested, the problem is that OnUnitKilled gets called by the attacking unit during the FightAction. But you kill the attacking unit within OnUnitKilled, so when it finishes it can't complete the FightAction because it was destroyed (and replaced with the DieAction since the unit is now dying).

Your attacking house order isn't working because of the unneeded "true)" bits of code floating in the middle. The correct code is:
Actions.GroupOrderAttackHouse(States.GroupAt(115, 147), States.HouseAt (83, 137));
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 10 Jun 2013, 04:35

Re: Dynamic Script Usage

We fixed the crash, I've PMed you an EXE so you can test your script. I'm really looking forward to seeing the final usage of this, it was very funny to test :P
Thanks for finding that bug.
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 10 Jun 2013, 13:01

Re: Dynamic Script Usage

wouldn't that be nice when someone destroyed your building (or unit) that something exploded or triggered and all the units died and the buildings destroyed or damaged in the AoE?
<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 10 Jun 2013, 13:18

Re: Dynamic Script Usage

@ Lewin: I don't have any message from you anywhere yet!

In the picture you can see some pretty awesome progress on the crazy vagabonds (H)
You do not have the required permissions to view the files attached to this post.
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 10 Jun 2013, 13:20

Re: Dynamic Script Usage

@ Lewin: I don't have any message from you anywhere yet!

In the picture you can see some pretty awesome progress on the crazy vagabonds (H)
i like it :D
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 10 Jun 2013, 13:45

Re: Dynamic Script Usage

@Tef: Sorry, I sent it to Islar by mistake. I've sent it to you now :)
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 10 Jun 2013, 16:28

Re: Dynamic Script Usage

Hi, i am busy to make a coop-mission with dynamic script, but i have some questions. :$

How can you make the AI build a house and road (and field/vinefield) after finishing a house?
How can you unblock a building when a player change alliance?
How can you make a certain AI group of soldiers move to a certain place if you don't know where they are at that moment and if it can, move multiple groups to different places at the same time (also if you don't know where they are)
EDIT: How can you make a AI to give a certain good from the storehouse to another player's or AI storehouse?

Could any of these be posible and can i use them if so?
That are my questions for now
Thanks in advance :D
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 10 Jun 2013, 21:03

Re: Dynamic Script Usage

How can you unblock a building when a player change alliance?
That's possible. You can have it from easy to difficult ;)

When you know the player ID at the start (like in singleplayer) then it's easy.
At the match beginning, you check States.PlayerAllianceCheck(yourID, otherID) and store it to a global variable.
Then during the match, you do a ' if States.PlayerAllianceCheck(yourID, otherID) <> StoredVariable then Actions.HouseAllow(yourID,houseID,true);

When you don't know the player ID (which is the case in multiplayer maps) then you have do a for-loop over all positions and store the results in an array.
Then during the match, you will do the same as above, but again in a for-loop over all locations and compare it to the stored array. The difficulty here lies in the fact, that you have to skip the self-reference-check where yourID = for-loop-variable, otherwise this will always be true and your house will be unlocked from the beginning.


But after all - since you can't change alliances during game but only with dynamic scripts, I'd do it in a much simpler way:
you write a function that does both - the alliance change and at the same time the house unblocking. No difficulty there.
<<

Tef

User avatar

Lance Carrier

Posts: 64

Joined: 15 Apr 2013, 15:12

KaM Skill Level: Skilled

Post 10 Jun 2013, 21:59

Re: Dynamic Script Usage

@ Islar. Are you aware of this page?

Bible for dynamic scripting --> https://code.google.com/p/castlesand/wi ... ptsDynamic <-- Bible for dynamic scripting
How can you make the AI build a house and road (and field/vinefield) after finishing a house?
The AI already automatically builds villages. You just have to make sure you have an AI village with sufficient starting resources and laborers. If you need the AI to make custom buildings, you could use PlanAddField, PlanAddRoad, PlanAddRoad, PlanAddHouse etc.
How can you make a certain AI group of soldiers move to a certain place if you don't know where they are at that moment and if it can, move multiple groups to different places at the same time (also if you don't know where they are)
If you create the AI groups through an AI script, you have defined the groups yourself so you should know their GroupID. For example, when you define the groups in your script, you could store the GroupID's into variables or an array. Later you can just call that ID and use GroupOrderWalk to make them go somewhere. If you do not create the AI groups yourself but you know where they wait at their defence positions, you can use GroupAt(known x, known y) to get their groupIDs. If you don't either, you need more creativity. You can get all groups from a certain player into an array through PlayerGetAllGroups(player). Next, you should use smart checks like UnitType(States.GroupMember(SomeGroup,0)) to gather information about the type of units, or GroupMemberCount(SomeGroup) to get the groupsize. That should enable you to create decision rules when to make a chosen group attack.
EDIT: How can you make a AI to give a certain good from the storehouse to another player's or AI storehouse?
Use HouseAddWaresTo(HouseID, ware, amount) to add goods to any (store)house, or GiveWares to the players first storehouse. I don't know how you can remove goods from a storehouse. To everybody: is this possible?

Use the link on top of this post. It's your/mine/anybody's Bible for dynamic scripting!
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 11 Jun 2013, 02:09

Re: Dynamic Script Usage

I don't know how you can remove goods from a storehouse. To everybody: is this possible?
Not yet. There are a lot of complications with that, for example you could take out all of the resources just before a serf arrives to take them, which would cause a crash. We'll hopefully implement it eventually, but not let you take out resources which have been "locked" by serfs on their way to deliver them.
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 11 Jun 2013, 13:22

Re: Dynamic Script Usage

My aim: infinite gold in all player's schools, without serfs and storehouse. My approach: OnUnitTrained, check who trained an unit, then States.PlayerGetAllHouses, for each house check if HouseType(HouseID)=school, then add 1 gold with HouseAddWaresTo. This will unnecessarily overcomplicate the script, and it's probably not the most efficient way. A more efficient - although not working out of the box on other maps, and that's why I don't like it - approach, would be to just note the coordinates of the schools, and if player makes an unit, add gold to each school. Can anyone think of a better way to make infinite gold without having to deal with serfs, food, inn etc.? (it's a fight map of sorts, and I need to have infinite flow of recruits coming)

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 2 guests