Page 1 of 1

Tutorial: Getting started with dynamic scripts

PostPosted: 12 Apr 2013, 11:23
by Lewin
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.

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 19 Jan 2014, 23:02
by debtorr
Hi, do i need to use this Dynamic stripts, to make enemy attack at some time, or defend some locations ?

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 20 Jan 2014, 08:53
by pawel95
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.

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 21 Jan 2014, 00:28
by Lewin
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.

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 25 Jun 2015, 08:56
by BLUE
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

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 25 Jun 2015, 18:19
by Krom
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.

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 11 Mar 2016, 17:38
by Maro
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

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 11 Mar 2016, 19:06
by Krom
Perhaps you should post your script code

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 11 Mar 2016, 19:27
by Maro
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;

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 12 Mar 2016, 08:13
by Krom
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?

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 12 Mar 2016, 12:03
by Maro
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;

Re: Tutorial: Getting started with dynamic scripts

PostPosted: 20 Mar 2016, 01:04
by thibmo
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;