Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

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 16 Jan 2014, 08:08

Re: Dynamic Script Usage

hello,

i'm new to scripting and i have two question.
Is there a way to set this script(see below) repeats itself every 20sec??? or have i copy/paste the script(whitout the top line) and change the time?
also doesn't i get the items into my barracks.(not getting an error) am i doing something wrong or is it just an type-error??
You can make things repeat every X ticks using a little bit of mathematics ;) The operator "mod" (modulo) gives you the remainder of a division (6 mod 3 = 0, 7 mod 3 = 1, 8 mod 3 = 2, 9 mod 3 = 0, etc.). So States.GameTime mod 5 will give you these numbers on each subsequent tick: 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, etc. It repeats in a loop from 0 to 4 every 5 ticks.

So if you want something to repeat every 20 seconds do this:
if States.GameTime mod 200 = 0 then

That means it will be true on these ticks: 200, 400, 600, 800, 1000, etc. :)

With the barracks problem, check the latest log file for script errors (newest file in the Logs folder). You might have used an incorrect ware index or something.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 17 Jan 2014, 23:02

Re: Dynamic Script Usage

i have something ike this:
runs every 3 mins
  Code:
procedure RobHouse(aHouse: integer); var h, j: integer; begin if ( aHouse > 0 ) then begin Actions.ShowMsgGoto(States.HouseOwner(aHouse), States.HousePositionX(aHouse), States.HousePositionY(aHouse), '<$17>'); for j:= 0 to MAX_WARE_TYPE do begin Actions.HouseTakeWaresFrom(aHouse, j, 5); end; end; end;
its clear all houses resources , but it causing a lot of log error
  Code:
Mistake in script usage Actions.HouseTakeWaresFrom wrong ware type: 404765, 16, 5
, i know about them but im too lazy ;p to do a large script that return true ware types for every specific house. If i leave it like it is, will it be causing problems in multi?
<<

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 17 Jan 2014, 23:48

Re: Dynamic Script Usage

its clear all houses resources , but it causing a lot of log error
  Code:
Mistake in script usage Actions.HouseTakeWaresFrom wrong ware type: 404765, 16, 5
, i know about them but im too lazy ;p to do a large script that return true ware types for every specific house. If i leave it like it is, will it be causing problems in multi?
It will cause lag if it happens more than a few times in a second (logging errors takes a bit of time). You should be able to fix it like this:
  Code:
procedure RobHouse(aHouse: integer); var h, j: integer; begin if ( aHouse > 0 ) then begin Actions.ShowMsgGoto(States.HouseOwner(aHouse), States.HousePositionX(aHouse), States.HousePositionY(aHouse), '<$17>'); for j:= 0 to MAX_WARE_TYPE do if States.HouseResourceAmount(aHouse, j) > 0 then Actions.HouseTakeWaresFrom(aHouse, j, 5); end; end;
Wares that do not belong in the house will return 0 from HouseResourceAmount without logging an error.
<<

RandomLyrics

User avatar

Sword Fighter

Posts: 298

Joined: 21 Jul 2013, 02:15

KaM Skill Level: Fair

Post 18 Jan 2014, 03:45

Re: Dynamic Script Usage

thanks :)
<<

Vatrix

User avatar

Council Member

Posts: 410

Joined: 19 Apr 2013, 20:30

KaM Skill Level: Veteran

Location: Czech Republic

Post 11 Mar 2014, 19:47

Re: Dynamic Script Usage

If time, can someone write here how to order Ai to build houses one by one. I mean on mission start I order Ai to build school, but how I can do he will then build inn then stonemason, etc. I want to make a map where Ai build his city with my instructions. I know it will be long and everytime the same, but I like it.
Thanks
Vatrix
(I'm so active this week :O )
I fixed The Shattered Kingdom and The Peasants Rebellion here!
<<

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 12 Mar 2014, 01:32

Re: Dynamic Script Usage

You can use the event OnHouseBuilt to detect when the school (or any other house) is finished, then put the code there to build the inn. If two houses of the same type will be built, you can use a global variable like FirstSchoolBuilt which you set to False in OnMissionStart and then True when the school is built, so you only order the inn for the first school that is build.
<<

Vatrix

User avatar

Council Member

Posts: 410

Joined: 19 Apr 2013, 20:30

KaM Skill Level: Veteran

Location: Czech Republic

Post 12 Mar 2014, 13:55

Re: Dynamic Script Usage

OK, I'll try to write what you said. :mrgreen:
I fixed The Shattered Kingdom and The Peasants Rebellion here!
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

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

Post 02 Apr 2014, 20:59

Re: Dynamic Script Usage

This code results in a game crash each time a tower (build ID: 17) is placed:
  Code:
var BuildLimit: array of Integer; var P: Integer; procedure OnHousePlanPlaced(Player, X, Y, HouseType: Integer); begin if HouseType = 17 then if BuildLimit[Player] >= 3 then begin Actions.PlanRemove(Player, X, Y); Actions.HouseAllow(Player, 17, False); end else begin BuildLimit[Player] := BuildLimit[Player] + 1; end; end;
Why? :'(
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 03 Apr 2014, 04:38

Re: Dynamic Script Usage

Did you allocated enough elements in BuildLimit variable with SetLength()? Otherwise you are trying to access 17th element of nothing = crash.
I would suggest you to make it a static array var BuildLimit: array [0..30] of Integer; (don't remember if PascalScript supports that, but try!)

Also note, that indentation helps only human eye to see blocks of conditions. In your code the logic that PC sees is different because else works for nearest if .. then branch:
  Code:
var BuildLimit: array of Integer; var P: Integer; procedure OnHousePlanPlaced(Player, X, Y, HouseType: Integer); begin if HouseType = 17 then if BuildLimit[Player] >= 3 then begin Actions.PlanRemove(Player, X, Y); Actions.HouseAllow(Player, 17, False); end else begin BuildLimit[Player] := BuildLimit[Player] + 1; end; end;
Did you mean that to be that way - controlling only house 17 count?
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
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

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

Post 03 Apr 2014, 05:34

Re: Dynamic Script Usage

Thanks, Krom :)

The else is used as intended. I only want house type 17 is count towards the limit. You might be able to figure out what I'm trying to do :P

As for your advice, I really don't understand what you mean. I'll have to wait till sado's online again so he can tutor me :)
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 03 Apr 2014, 08:58

Re: Dynamic Script Usage

Thanks, Krom :)

The else is used as intended. I only want house type 17 is count towards the limit. You might be able to figure out what I'm trying to do :P

As for your advice, I really don't understand what you mean. I'll have to wait till sado's online again so he can tutor me :)
If you only need to track Towers count then you can use a single variable for that - TowerCount and increment/check only it.
What I meant is that array of Integer has a length of 0 elements, so when you access element 17 it is out of range and that causes a crash. In order to access element 17 you need your array to have it, that can be done either by declaring array of known length [0..30] or setting array length in code with SetLength(array, elements_count).
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
<<

sado1

User avatar

Council Member

Posts: 1430

Joined: 21 May 2012, 19:13

KaM Skill Level: Skilled

Post 03 Apr 2014, 09:01

Re: Dynamic Script Usage

If you only need to track Towers count then you can use a single variable for that - TowerCount and increment/check only it.
Which means he needs 6 variables, one for each of 6 players. That's why he was supposed to use an array :P
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 03 Apr 2014, 09:37

Re: Dynamic Script Usage

If you only need to track Towers count then you can use a single variable for that - TowerCount and increment/check only it.
Which means he needs 6 variables, one for each of 6 players. That's why he was supposed to use an array :P
True, I forgot about players :D
In that case he needs array of 0..PlayerCount-1 length :)
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
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

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

Post 03 Apr 2014, 15:50

Re: Dynamic Script Usage

I'm not good with using arrays. Are you saying that I need to specify the range of which the array contains? Something like var PlayerAmount array of [0,1,2,3,4,5]; or something...not even close to that? XD
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 03 Apr 2014, 17:02

Re: Dynamic Script Usage

I'm not good with using arrays. Are you saying that I need to specify the range of which the array contains? Something like var PlayerAmount array of [0,1,2,3,4,5]; or something...not even close to that? XD
Kind of.
Array of known length are declared like so: var ArrayName: array [0..8] of Integer;
Where array is set to have elements from 0 to 8. So you can safely access ArrayName[0], ArrayName[1] .. ArrayName[8].
In your case, of course, you set your maps player count minus one instead of 8.
So that 1st player uses element 0, second player uses element 1, etc.
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

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 3 guests