Map Database  •  FAQ  •  RSS  •  Login

Tutorial: Getting started with dynamic scripts

<<

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 Apr 2013, 11:23

Tutorial: Getting started with dynamic scripts

I made a quick tutorial to help people get started with dynamic mission scripts:
http://code.google.com/p/castlesand/wik ... icTutorial

If you have any questions or comments please write them here :)
Cheers,
Lewin.
<<

debtorr

Peasant

Posts: 3

Joined: 02 Jan 2014, 13:43

KaM Skill Level: Skilled

Post 19 Jan 2014, 23:02

Re: Tutorial: Getting started with dynamic scripts

Hi, do i need to use this Dynamic stripts, to make enemy attack at some time, or defend some locations ?
<<

pawel95

Castle Guard Swordsman

Posts: 1912

Joined: 03 Oct 2008, 22:00

KaM Skill Level: Skilled

Location: "Pawel95" on Youtube.com

Post 20 Jan 2014, 08:53

Re: Tutorial: Getting started with dynamic scripts

Hi, do i need to use this Dynamic stripts, to make enemy attack at some time, or defend some locations ?
No. This can be done also with thr "normal" sratic script. All you need for that is lewins missions editor and some knowledge about the commands. However with dynamic scripts, thats also possible.
<<

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 21 Jan 2014, 00:28

Re: Tutorial: Getting started with dynamic scripts

Hi, do i need to use this Dynamic stripts, to make enemy attack at some time, or defend some locations ?
No. This can be done also with thr "normal" sratic script. All you need for that is lewins missions editor and some knowledge about the commands. However with dynamic scripts, thats also possible.
There's no need to use my editor, it's quite hard to use compared to the build-in KaM Remake editor. The KaM Remake editor can edit AI attacks and defence positions as in r5503. It still needs a lot of improvement but the basics are working, and it's still better than my editor.

I would suggest opening up some of the campaign maps in the editor (press F11 then go to File -> Edit Mission and browse to the Campaigns folder). Go to the tab "Village planning" then the sub tab "AI attacks". Double click on the items in the list and check what values they used. You should be able to figure out how it works (basically the AI will attack when they have "Men" number of soldiers available, but only after the initial delay you set). Once means the attack will only occur once, repeat means it will happen whenever the AI has that many soldiers available.

I'm planning to make the AI attack editor more user friendly at some point.

Regarding defence, you should place defence positions where you want the AI to put its soldiers. Front line defence positions are not allowed to attack so they won't be counted.
<<

BLUE

Peasant

Posts: 3

Joined: 21 May 2015, 18:31

KaM Skill Level: Veteran

Post 25 Jun 2015, 08:56

Re: Tutorial: Getting started with dynamic scripts

I made a quick tutorial to help people get started with dynamic mission scripts:
http://code.google.com/p/castlesand/wik ... icTutorial

If you have any questions or comments please write them here :)
Cheers,
Lewin.
I click on the link you gave, but i can't find the tutorial on the page. I only find lot of different scripts, but i'm not able to use them.
Please help me.

BLUE
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 25 Jun 2015, 18:19

Re: Tutorial: Getting started with dynamic scripts

Correct link is now https://github.com/Kromster80/kam_remak ... icTutorial
Though the page suffers from lack of proper formatting. We dont have time to properly fix it, sorry.
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
<<

Maro

Peasant

Posts: 4

Joined: 11 Mar 2016, 12:34

KaM Skill Level: Fair

Post 11 Mar 2016, 17:38

Re: Tutorial: Getting started with dynamic scripts

I understand that this thread is extremely old but I've decided to try out this scripting thing.
I followed your tutorial but still don't get it at all.
for instance (and I litteraly copy pasted the code from the tutorial) in the second part of the tutorial it should give a message when a certain building is build, however I just got an error message "Script compile errors:
[Error] (9:49): Unknown identifier 'StatHouseTypeCount'"

after dabling around some more somehow that was no problem anymore but then it stated there there should be a period between "end" and ";" wich I added then the errors stopped but the script was not working (obviously)

also adding the same procedure twice within the script seems to give a problem?

after that I decided to do the most basic thing from the tutorial on a map I created I wanted a message to show but wanted it to pop up no matter wich position you choose. so I added the Actions.ShowMsg string 4 times but every time for another player wich resulted in getting the message once playing on position 1 but have it spawn consecutivly in a rapid phase for the other positions.

The parameters and types also seem to elude me, so what I would actually like to ask is if you can point me in a general direction on how to get started with the dynamic scripting?

Maro
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 11 Mar 2016, 19:06

Re: Tutorial: Getting started with dynamic scripts

Perhaps you should post your script code
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
<<

Maro

Peasant

Posts: 4

Joined: 11 Mar 2016, 12:34

KaM Skill Level: Fair

Post 11 Mar 2016, 19:27

Re: Tutorial: Getting started with dynamic scripts

Perhaps you should post your script code
for the one I've been going on for myself I figured it out just now (woohoo)
  Code:
procedure OnTick; var P : Integer; begin for P := 0 to 3 do if States.PlayerEnabled(P) then begin if States.GameTime = 10 then Actions.ShowMsg(P, 'message'); end; end;
the other code was exactly copy pasted from the tutorial
  Code:
procedure OnTick; begin if (States.GameTime mod 300 = 0) and ((States.StatHouseTypeCount(0, 13) > 0) or (States.StatHouseTypeCount(0, 27) > 0)) and not (States.StatHouseTypeCount(0, 14) > 0) then Actions.ShowMsg(0, 'You should built a stonemason'); end;
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 12 Mar 2016, 08:13

Re: Tutorial: Getting started with dynamic scripts

For the first code I would just reorganize it a bit. Seems it should work like so:
  Code:
procedure OnTick; var P: Integer; begin if States.GameTime = 10 then for P := 0 to 3 do if States.PlayerEnabled(P) then Actions.ShowMsg(P, 'message'); end;
For the second code - it looks good too:
  Code:
procedure OnTick; begin if (States.GameTime mod 300 = 0) and ((States.StatHouseTypeCount(0, 13) > 0) or (States.StatHouseTypeCount(0, 27) > 0)) and (States.StatHouseTypeCount(0, 14) <= 0) then Actions.ShowMsg(0, 'You should built a stonemason'); end;
In which version of KaM Remake are you trying these codes?
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
<<

Maro

Peasant

Posts: 4

Joined: 11 Mar 2016, 12:34

KaM Skill Level: Fair

Post 12 Mar 2016, 12:03

Re: Tutorial: Getting started with dynamic scripts

I'm using the lates version. I have also figured out what I did wrong with the tutorial code after scrolling trought the forum. so now it looks like this
  Code:
procedure OnTick; begin begin if States.GameTime = 10 then // 1 second Actions.ShowMsg(0, 'Hello World'); //0=payer 1 'hello world' = message end; begin if (States.GameTime mod 300 = 0) and ((States.StatHouseTypeCount(0, 13) > 0) or (States.StatHouseTypeCount(0, 27) > 0)) and not (States.StatHouseTypeCount(0, 14) > 0) then Actions.ShowMsg(0, 'You should built a stonemason'); end; end;
<<

thibmo

User avatar

Council Member

Posts: 124

Joined: 03 Aug 2015, 09:12

KaM Skill Level: Skilled

Website: https://kp-wiki.org/

Location: the Netherlands

Post 20 Mar 2016, 01:04

Re: Tutorial: Getting started with dynamic scripts

Looks OK, just a few things to note on the script
  • Try applying indentation (Mainly 2 or 4 spaces) throughout your script, it enhances readability for others.
  • Only use "Begin" and "end" where needed, it saves you time.
  • Procedures and functions can only be used once within a script unless "override" is used and the parameters/returns are different. (If this is even allowed by PascalScript)
Your code revised:
  Code:
procedure OnTick; begin if States.GameTime = 10 then // Roughly 1 second Actions.ShowMsg(0, 'Hello World'); // 0 = payer 1 message = 'hello world' if (States.GameTime mod 300 = 0) // Do this roughly every 30 seconds and ((States.StatHouseTypeCount(0, 13) > 0) or (States.StatHouseTypeCount(0, 27) > 0)) and (States.StatHouseTypeCount(0, 14) <= 0) then // <= stands for 'lower then or equal to', better then using 'not' Actions.ShowMsg(0, 'You should built a stonemason'); end;
~~ The magic wizard of PascalScriptus. ~~

KP-Wiki :
  • Information about Knights Province scripting ( unofficial )
  • Information about several hosting/server maintenance basics
  • Other random stuff

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: Google [Bot] and 0 guests